diff --git a/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp b/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp index 65300db7..a9b5c842 100644 --- a/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp +++ b/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp @@ -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(textureObject.get()), - "Texture object here should always be an object with mipmap"); - auto textureMipmapObject = static_cast(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, diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 6f4ff773..3a663bf0 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -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 #include @@ -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); }