From 5142f3c72ba39a74ac3c98932a4ffa63c1ec2816 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 8 May 2025 20:53:42 +0800 Subject: [PATCH] [Fix] (TextureState, GL_Drawing): mark dirty textures to skip uploading unmodified ones --- MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp | 3 +++ MG/MG_GL/State/Texture/TextureState.cpp | 5 +++-- MG/MG_GL/State/Texture/TextureState.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp index b465ca50..484a0498 100644 --- a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp +++ b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp @@ -416,6 +416,9 @@ namespace MG_GL::GL { } for (auto& [level, mip] : texObj.params.mipmapData) { + if (!mip.dirty) + continue; + mip.dirty = false; const void* data = !mip.pixelData.empty() ? mip.pixelData.data() : nullptr; switch (target) { case GL_TEXTURE_2D: { diff --git a/MG/MG_GL/State/Texture/TextureState.cpp b/MG/MG_GL/State/Texture/TextureState.cpp index ba7fe964..78f552f3 100644 --- a/MG/MG_GL/State/Texture/TextureState.cpp +++ b/MG/MG_GL/State/Texture/TextureState.cpp @@ -258,7 +258,7 @@ GLenum TextureState::Upload2D(GLenum target, GLint level, GLint internalFormat, if (isProxyTexture) { MG_Util::Debug::LogD("MG_State: Texture: Upload2D proxy texture detected"); TextureObject& proxyTex = proxyTextures_[target]; - TextureParams::MipmapLevel mip{}; + auto& mip = proxyTex.params.mipmapData[level]; mip.width = width; mip.height = height; mip.internalFormat = internalFormat; @@ -266,7 +266,6 @@ GLenum TextureState::Upload2D(GLenum target, GLint level, GLint internalFormat, mip.type = type; proxyTex.generated = true; proxyTex.target = target; - proxyTex.params.mipmapData[level] = mip; return GL_NO_ERROR; } @@ -280,6 +279,7 @@ GLenum TextureState::Upload2D(GLenum target, GLint level, GLint internalFormat, mip.internalFormat = internalFormat; mip.format = format; mip.type = type; + mip.dirty = true; if (data == nullptr) { mip.hasData = false; @@ -491,6 +491,7 @@ GLenum TextureState::UpdateRegion2D(GLenum target, GLint level, GLint xoffset, // } mip.hasData = true; + mip.dirty = true; MG_Util::Debug::LogD("MG_State: Texture: UpdateRegion2D succeeded"); return GL_NO_ERROR; } diff --git a/MG/MG_GL/State/Texture/TextureState.h b/MG/MG_GL/State/Texture/TextureState.h index 63cff3ef..ea0de3af 100644 --- a/MG/MG_GL/State/Texture/TextureState.h +++ b/MG/MG_GL/State/Texture/TextureState.h @@ -31,6 +31,7 @@ struct TextureParams { GLenum type = GL_UNSIGNED_BYTE; std::vector pixelData; bool hasData = false; + bool dirty = false; // TODO: encapsulate this with an public API to RHI }; unordered_map mipmapData; };