mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 22:28:32 +09:00
[Misc] (MG_Backend/DirectGLES): Separate BackendTextureObject::SyncToBackend
This commit is contained in:
@@ -192,7 +192,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
} else {
|
||||
backendTextureObject = backendTextureIt->second;
|
||||
}
|
||||
backendTextureObject->SyncToBackend(textureObject);
|
||||
backendTextureObject->SyncTextureParamsToBackend(textureObject);
|
||||
backendTextureObject->SyncBuiltinSamplerToBackend(textureObject);
|
||||
backendTextureObject->SyncMipmapsToBackend(textureObject);
|
||||
return backendTextureObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -319,17 +319,24 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return m_backendTextureId;
|
||||
}
|
||||
|
||||
void BackendTextureObject::SyncToBackend(SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject) {
|
||||
#ifdef TRACY_ENABLE
|
||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||
#endif
|
||||
DebugImpl::ErrorLopper errorLopper;
|
||||
void BackendTextureObject::SyncMipmapsToBackend(
|
||||
SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject) {
|
||||
if (!stateTextureObject) {
|
||||
MGLOG_E("State texture object is null, cannot sync to backend.");
|
||||
return;
|
||||
}
|
||||
|
||||
MGLOG_D("Syncing texture with backend ID %u to backend for state ID %u", m_backendTextureId,
|
||||
if (!stateTextureObject->CheckDirtyBit(MG_State::GLState::TextureDirtyBit::StorageDirtyBit)) {
|
||||
MGLOG_D("Texture parameters changed but storage is not dirty, skipping mipmap sync for texture ID: %u",
|
||||
m_backendTextureId);
|
||||
return;
|
||||
}
|
||||
#ifdef TRACY_ENABLE
|
||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||
#endif
|
||||
DebugImpl::ErrorLopper errorLopper;
|
||||
|
||||
MGLOG_D("Syncing texture mipmaps with backend ID %u to backend for state ID %u", m_backendTextureId,
|
||||
stateTextureObject->GetExternalIndex());
|
||||
|
||||
GLenum target = MG_Util::ConvertTextureTargetToGLEnum(stateTextureObject->GetTarget());
|
||||
@@ -354,11 +361,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return;
|
||||
}
|
||||
|
||||
// BackendTextureBindingProtector backendTextureBindingProtector(target);
|
||||
Bind(target);
|
||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||
});
|
||||
|
||||
const auto baseSize = stateTextureObject->GetBaseSize();
|
||||
StateTextureBasicInfo currentTextureInfo = {stateTextureObject->GetFormat(),
|
||||
static_cast<SizeT>(baseSize.x()),
|
||||
@@ -366,8 +370,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
static_cast<SizeT>(baseSize.z()),
|
||||
0,
|
||||
0};
|
||||
|
||||
if (stateTextureObject->CheckDirtyBit(MG_State::GLState::TextureDirtyBit::StorageDirtyBit)) {
|
||||
switch (stateTextureObject->GetStorageType()) {
|
||||
case TextureStorageType::Mipmap: {
|
||||
auto* textureMipmapObject =
|
||||
@@ -382,8 +384,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
MG_Util::ConvertTextureInternalFormatToString(textureMipmapObject->GetFormat()).c_str());
|
||||
|
||||
if (needsRegeneration) {
|
||||
MGLOG_D(
|
||||
"Texture state changed significantly or not initialized, regenerating texture with ID: %u",
|
||||
MGLOG_D("Texture state changed significantly or not initialized, regenerating texture with ID: %u",
|
||||
m_backendTextureId);
|
||||
|
||||
// Regenerate all mipmap levels
|
||||
@@ -403,9 +404,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
: nullptr;
|
||||
MGLOG_D("%s: target: %s: syncing mip %d: %dx%dx%d, byteSize = %d, pData = %p, "
|
||||
"levelDirty = %s",
|
||||
__func__, MG_Util::ConvertTextureUploadTargetToString(uploadTarget).c_str(),
|
||||
level, levelTexelSize.x(), levelTexelSize.y(), levelTexelSize.z(),
|
||||
levelByteSize, pData, levelDirty ? "true" : "false");
|
||||
__func__, MG_Util::ConvertTextureUploadTargetToString(uploadTarget).c_str(), level,
|
||||
levelTexelSize.x(), levelTexelSize.y(), levelTexelSize.z(), levelByteSize, pData,
|
||||
levelDirty ? "true" : "false");
|
||||
|
||||
errorLopper.Clear();
|
||||
MG_External::GLES::glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
@@ -416,15 +417,14 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
case TextureTarget::TextureCubeMap: {
|
||||
MG_External::GLES::glTexImage2D(
|
||||
glUploadTarget, static_cast<GLint>(level), glInternalFormat,
|
||||
static_cast<GLsizei>(levelTexelSize.x()),
|
||||
static_cast<GLsizei>(levelTexelSize.y()), 0, glFormat, glType, pData);
|
||||
static_cast<GLsizei>(levelTexelSize.x()), static_cast<GLsizei>(levelTexelSize.y()),
|
||||
0, glFormat, glType, pData);
|
||||
break;
|
||||
}
|
||||
case TextureTarget::Texture3D: {
|
||||
MG_External::GLES::glTexImage3D(
|
||||
glUploadTarget, static_cast<GLint>(level), glInternalFormat,
|
||||
static_cast<GLsizei>(levelTexelSize.x()),
|
||||
static_cast<GLsizei>(levelTexelSize.y()),
|
||||
static_cast<GLsizei>(levelTexelSize.x()), static_cast<GLsizei>(levelTexelSize.y()),
|
||||
static_cast<GLsizei>(levelTexelSize.z()), 0, glFormat, glType, pData);
|
||||
break;
|
||||
}
|
||||
@@ -435,8 +435,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__, glUploadTarget,
|
||||
glInternalFormat, glFormat, glType, pData](GLenum err) {
|
||||
MGLOG_D(
|
||||
"%s(%s:%d) ES error: %s. glTexImage*: target=%s, internalformat=%s, format=%s, "
|
||||
MGLOG_D("%s(%s:%d) ES error: %s. glTexImage*: target=%s, internalformat=%s, format=%s, "
|
||||
"type=%s, pixels=%p",
|
||||
func, file, line, MG_Util::ConvertGLEnumToString(err).c_str(),
|
||||
MG_Util::ConvertGLEnumToString(glUploadTarget).c_str(),
|
||||
@@ -444,8 +443,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
MG_Util::ConvertGLEnumToString(glFormat).c_str(),
|
||||
MG_Util::ConvertGLEnumToString(glType).c_str(), pData);
|
||||
});
|
||||
MGLOG_D("Regenerated mipmap level %d for texture with ID: %u", level,
|
||||
m_backendTextureId);
|
||||
MGLOG_D("Regenerated mipmap level %d for texture with ID: %u", level, m_backendTextureId);
|
||||
textureMipmapObject->MarkStorageDirty(uploadTarget, level, false);
|
||||
}
|
||||
}
|
||||
@@ -485,10 +483,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
MG_Util::ConvertGLEnumToString(err).c_str());
|
||||
});
|
||||
auto texelSize = textureMipmapObject->GetMipmapTexelSize(uploadTarget, level);
|
||||
MG_External::GLES::glTexSubImage2D(
|
||||
glUploadTarget, static_cast<GLint>(level), 0, 0,
|
||||
static_cast<GLsizei>(texelSize.x()), static_cast<GLsizei>(texelSize.y()), glFormat,
|
||||
glType, textureMipmapObject->MapMipmapData(uploadTarget, level));
|
||||
MG_External::GLES::glTexSubImage2D(glUploadTarget, static_cast<GLint>(level), 0, 0,
|
||||
static_cast<GLsizei>(texelSize.x()),
|
||||
static_cast<GLsizei>(texelSize.y()), glFormat, glType,
|
||||
textureMipmapObject->MapMipmapData(uploadTarget, level));
|
||||
textureMipmapObject->MarkStorageDirty(uploadTarget, level, false);
|
||||
}
|
||||
}
|
||||
@@ -526,8 +524,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
auto backendId = backendBufferObject->GetBackendBufferId();
|
||||
|
||||
GLenum glInternalFormat, glType, glFormat;
|
||||
TextureImpl::GenerateTextureFormatInfo(textureBufferObject->GetFormat(), &glInternalFormat,
|
||||
&glFormat, &glType);
|
||||
TextureImpl::GenerateTextureFormatInfo(textureBufferObject->GetFormat(), &glInternalFormat, &glFormat,
|
||||
&glType);
|
||||
|
||||
MG_External::GLES::glTexBuffer(GL_TEXTURE_BUFFER, glInternalFormat, backendId);
|
||||
|
||||
@@ -537,9 +535,44 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
default:
|
||||
THROW_UNIMPL_EXCEPTION;
|
||||
}
|
||||
|
||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||
});
|
||||
|
||||
m_prevTextureInfo = currentTextureInfo;
|
||||
}
|
||||
|
||||
{ // Update built-in sampler parameters
|
||||
void BackendTextureObject::SyncBuiltinSamplerToBackend(
|
||||
SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject) {
|
||||
#ifdef TRACY_ENABLE
|
||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||
#endif
|
||||
DebugImpl::ErrorLopper errorLopper;
|
||||
if (!stateTextureObject) {
|
||||
MGLOG_E("State texture object is null, cannot sync to backend.");
|
||||
return;
|
||||
}
|
||||
|
||||
MGLOG_D("Syncing texture built-in sampler with backend ID %u to backend for state ID %u",
|
||||
m_backendTextureId, stateTextureObject->GetExternalIndex());
|
||||
|
||||
GLenum target = MG_Util::ConvertTextureTargetToGLEnum(stateTextureObject->GetTarget());
|
||||
auto targetInternal = stateTextureObject->GetTarget();
|
||||
MGLOG_D(" Texture target for syncing is %s",
|
||||
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
||||
if (!IsSupportedTextureTarget(targetInternal)) {
|
||||
MGLOG_E(" Texture target %s is not supported, skipping.",
|
||||
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
Bind(target);
|
||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||
});
|
||||
|
||||
// Update built-in sampler parameters
|
||||
MGLOG_D("Updating sampler parameters for texture with ID: %u", m_backendTextureId);
|
||||
const auto& samplerParams = stateTextureObject->GetSamplerObject()->GetAllSamplerParameters();
|
||||
|
||||
@@ -592,22 +625,49 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#undef SYNC_TEX_SAMPLER_PARAM_IF_CHANGED
|
||||
}
|
||||
|
||||
{ // Update texture parameters
|
||||
void BackendTextureObject::SyncTextureParamsToBackend(
|
||||
SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject) {
|
||||
#ifdef TRACY_ENABLE
|
||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||
#endif
|
||||
DebugImpl::ErrorLopper errorLopper;
|
||||
if (!stateTextureObject) {
|
||||
MGLOG_E("State texture object is null, cannot sync to backend.");
|
||||
return;
|
||||
}
|
||||
|
||||
MGLOG_D("Syncing texture params with backend ID %u to backend for state ID %u", m_backendTextureId,
|
||||
stateTextureObject->GetExternalIndex());
|
||||
|
||||
GLenum target = MG_Util::ConvertTextureTargetToGLEnum(stateTextureObject->GetTarget());
|
||||
auto targetInternal = stateTextureObject->GetTarget();
|
||||
MGLOG_D(" Texture target for syncing is %s",
|
||||
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
||||
if (!IsSupportedTextureTarget(targetInternal)) {
|
||||
MGLOG_E(" Texture target %s is not supported, skipping.",
|
||||
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
Bind(target);
|
||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||
});
|
||||
|
||||
// Update texture parameters
|
||||
MGLOG_D("Updating texture parameters for texture with ID: %u", m_backendTextureId);
|
||||
|
||||
const auto& levelRange = stateTextureObject->GetLevelRange();
|
||||
|
||||
if (m_cacheLodRange.x() != levelRange.x()) {
|
||||
MG_External::GLES::glTexParameteri(target, GL_TEXTURE_BASE_LEVEL,
|
||||
static_cast<GLint>(levelRange.x()));
|
||||
MG_External::GLES::glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, static_cast<GLint>(levelRange.x()));
|
||||
m_cacheLodRange.x() = levelRange.x();
|
||||
}
|
||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||
MGLOG_D("%s(%s:%d) ES error %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||
});
|
||||
if (m_cacheLodRange.y() != levelRange.y()) {
|
||||
MG_External::GLES::glTexParameteri(target, GL_TEXTURE_MAX_LEVEL,
|
||||
static_cast<GLint>(levelRange.y()));
|
||||
MG_External::GLES::glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(levelRange.y()));
|
||||
m_cacheLodRange.y() = levelRange.y();
|
||||
}
|
||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||
@@ -644,13 +704,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
}
|
||||
|
||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||
});
|
||||
|
||||
m_prevTextureInfo = currentTextureInfo;
|
||||
}
|
||||
|
||||
UnorderedMap<SharedPtr<MG_State::GLState::ITextureObject>, SharedPtr<BackendTextureObject>>
|
||||
g_backendTextureObjects;
|
||||
} // namespace TextureImpl
|
||||
|
||||
@@ -86,7 +86,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
class BackendTextureObject {
|
||||
public:
|
||||
BackendTextureObject();
|
||||
void SyncToBackend(SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
void SyncMipmapsToBackend(SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
void SyncBuiltinSamplerToBackend(SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
void SyncTextureParamsToBackend(SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
void Bind(GLenum target);
|
||||
Uint GetBackendTextureId();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user