[Fix] (MG_Backend/DirectGLES): fix bad texture binding in CopyTexImage2D

This commit is contained in:
2026-01-08 14:07:51 +08:00
parent d7139894da
commit 39182f3a5e
2 changed files with 49 additions and 1 deletions
+46 -1
View File
@@ -784,6 +784,46 @@ namespace MobileGL::MG_Backend::DirectGLES {
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
});
{
#ifdef TRACY_ENABLE
ZoneScopedNC("BindCurrentTexturesAtTarget", TRACY_ZONECOLOR_BACKEND);
#endif
auto unit = MG_State::pGLContext->GetActiveTextureUnit();
auto& textureUnit = MG_State::pGLContext->GetTextureUnitObject(unit);
MG_External::GLES::glActiveTexture(GL_TEXTURE0 + unit);
auto textureTarget = MG_Util::ConvertGLEnumToTextureTarget(target);
if (textureTarget == TextureTarget::Texture1D ||
textureTarget == TextureTarget::TextureRectangle ||
textureTarget == TextureTarget::Texture2DMultisampleArray ||
textureTarget == TextureTarget::Texture1DArray ||
textureTarget == TextureTarget::Texture2DMultisample ||
textureTarget == TextureTarget::Texture2DArray) {
MOBILEGL_ASSERT(false, " Texture target %s is not supported, skipping.",
MG_Util::ConvertTextureTargetToString(textureTarget).c_str());
return;
}
const auto& bindingSlot = textureUnit.GetBindingSlot(textureTarget);
{
const auto &textureObject = bindingSlot.GetBoundObject();
if (!textureObject) {
MGLOG_W("%s: Texture target %s does not have texture bound.", __func__,
MG_Util::ConvertTextureTargetToString(textureTarget).c_str());
}
const auto &backendTextureIt = TextureImpl::g_backendTextureObjects.find(
textureObject);
if (backendTextureIt == TextureImpl::g_backendTextureObjects.end()) {
MGLOG_W("%s: No backend texture object found for frontend texture object %d.", __func__,
textureObject->GetExternalIndex());
return;
}
backendTextureIt->second->Bind(target);
}
}
// GLint realInternalFormat;
// MG_External::GLES::glGetTexLevelParameteriv(target, level, GL_TEXTURE_INTERNAL_FORMAT, &realInternalFormat);
// errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
@@ -794,7 +834,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
GLenum format = GL_DEPTH_COMPONENT;
GLenum type = GL_UNSIGNED_INT;
TextureImpl::GenerateTextureFormatInfo(mglInternalFormat, &internalformat, &type, &format);
TextureImpl::GenerateTextureFormatInfo(mglInternalFormat, &internalformat, &format, &type);
MOBILEGL_ASSERT(format != GL_NONE && type != GL_NONE, "%s: cannot GenerateTextureFormatInfo(%s): out internalformat=%s, format=%s, type=%s",
MG_Util::ConvertTextureInternalFormatToString(mglInternalFormat).c_str(),
MG_Util::ConvertGLEnumToString(internalformat).c_str(),
MG_Util::ConvertGLEnumToString(format).c_str(),
MG_Util::ConvertGLEnumToString(type).c_str());
TexturePixelDataType texturePixelDataType = MG_Util::ConvertGLEnumToTexturePixelDataType(type);
bool isDepthFormat =
@@ -679,6 +679,9 @@ namespace MobileGL {
const SizeT internalBpp = MG_Util::GetInternalBytesPerPixel(textureInternalFormat, texturePixelDataType);
const SizeT internalBytes = width * height * internalBpp;
MGLOG_D("%s: texture object had internal format %s, new format %s", __func__,
MG_Util::ConvertTextureInternalFormatToString(textureObject->GetFormat()).c_str(),
MG_Util::ConvertTextureInternalFormatToString(textureInternalFormat).c_str());
textureObject->SetInternalFormat(textureInternalFormat);
// if isProxy, no more pixel transfer needed below