[Fix] (MG_Impl/Tetxture): properly fix CopyTexImage2D's frontend state

This commit is contained in:
2026-01-05 12:52:47 +08:00
parent b3fe9c1544
commit 08a9c9bb61
2 changed files with 12 additions and 12 deletions
@@ -826,18 +826,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
});
// Protector will automatically revert to previous fbo states
}
// TODO: potential desync between MG_State and backend
auto activeUnit = MG_State::pGLContext->GetTextureUnitObject(MG_State::pGLContext->GetActiveTextureUnit());
TextureTarget textureTarget = MG_Util::ConvertGLEnumToTextureTarget(target);
auto& bindingSlot = activeUnit.GetBindingSlot(textureTarget);
auto textureObject = bindingSlot.GetBoundObject();
textureObject->SetInternalFormat(mglInternalFormat);
MOBILEGL_ASSERT(nullptr != dynamic_cast<MG_State::GLState::TextureObjectMipmap*>(textureObject.get()),
"Texture object here should always be an object with mipmap");
auto textureMipmapObject = static_cast<MG_State::GLState::TextureObjectMipmap*>(textureObject.get());
textureMipmapObject->AllocateStorage(TextureUploadTarget::Texture2D, level, {{width, height, 1}, 0});
}
void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width,
@@ -16,6 +16,7 @@
#include "ProxyTexture.h"
#include "MG_State/GLState/TextureState/TextureObjectBuffer.h"
#include "MG_Util/Converters/GLToStr/GLEnumConverter.h"
#include "MG_Util/Texture/TextureFormatProcessor.h"
#include <MG_State/GLState/Core.h>
#include <MG_Util/Metrics/TextureMetrics.h>
@@ -1210,6 +1211,16 @@ namespace MobileGL {
// TODO: implement
}
void CopyTexImage2D_State(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width,
GLsizei height, GLint border) {
GLenum outInternalFormat, format, type;
MG_Util::TextureFormatProcessor::NormalizePixelFormat(internalformat, &outInternalFormat, &format, &type);
const auto pixelUnpackBufferObject =
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).GetBoundObject();
TexImage2D_State(target, level, outInternalFormat, width, height, border, format, type, nullptr);
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).Bind(pixelUnpackBufferObject);
}
void CopyTexImage2D_Backend(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width,
GLsizei height, GLint border) {
#if MOBILEGL_BACKEND == MOBILEGL_BACKEND_TYPE_DIRECT_GLES
@@ -1434,6 +1445,7 @@ namespace MobileGL {
void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width,
GLsizei height, GLint border) {
CopyTexImage2D_State(target, level, internalformat, x, y, width, height, border);
CopyTexImage2D_Backend(target, level, internalformat, x, y, width, height, border);
}