mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Fix] (Diligent/Texture): Fix glTexSubImage2D crashing.
This commit is contained in:
@@ -440,16 +440,36 @@ namespace MG_GL::GL {
|
||||
GLuint boundTextureID = unitState->GetBoundTexture(target);
|
||||
|
||||
if (boundTextureID == 0) {
|
||||
MG_Util::Debug::LogD("TexSubImage2D: No texture bound. Skipping update.");
|
||||
MG_Util::Debug::LogD("TexSubImage2D: No texture bound to active unit. Skipping update.");
|
||||
return;
|
||||
}
|
||||
|
||||
Diligent::ITexture* pTexture = MG_Diligent::g_TextureMap[boundTextureID];
|
||||
Diligent::ITexture* pTexture = nullptr;
|
||||
auto texIt = MG_Diligent::g_TextureMap.find(boundTextureID);
|
||||
if (texIt != MG_Diligent::g_TextureMap.end()) {
|
||||
pTexture = texIt->second;
|
||||
}
|
||||
|
||||
if (!pTexture) {
|
||||
MG_Util::Debug::LogW("TexSubImage2D: Diligent texture not found for GL name %u", boundTextureID);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& texDesc = pTexture->GetDesc();
|
||||
if (!(texDesc.BindFlags & Diligent::BIND_SHADER_RESOURCE)) {
|
||||
MG_Util::Debug::LogE("TexSubImage2D: Texture %u does not have BIND_SHADER_RESOURCE flag", boundTextureID);
|
||||
return;
|
||||
}
|
||||
|
||||
Diligent::TextureDesc desc = pTexture->GetDesc();
|
||||
if (xoffset < 0 || yoffset < 0 ||
|
||||
(xoffset + width) > desc.Width ||
|
||||
(yoffset + height) > desc.Height) {
|
||||
MG_Util::Debug::LogE("TexSubImage2D: Update region out of bounds: [%d, %d, %d, %d] vs texture size [%u, %u]",
|
||||
xoffset, yoffset, width, height, desc.Width, desc.Height);
|
||||
return;
|
||||
}
|
||||
|
||||
Diligent::TextureSubResData SubResData;
|
||||
SubResData.pData = pixels;
|
||||
SubResData.Stride = width * GetBytesPerPixel(format, type);
|
||||
@@ -459,10 +479,17 @@ namespace MG_GL::GL {
|
||||
UpdateBox.MaxX = xoffset + width;
|
||||
UpdateBox.MinY = yoffset;
|
||||
UpdateBox.MaxY = yoffset + height;
|
||||
UpdateBox.MinZ = 0;
|
||||
UpdateBox.MaxZ = 1;
|
||||
|
||||
MG_Util::Debug::LogD("TexSubImage2D: Updating region [%d,%d]-[%d,%d] at level %d",
|
||||
xoffset, yoffset, xoffset+width, yoffset+height, level);
|
||||
|
||||
if (MG_Diligent::IsInRenderPass) {
|
||||
MG_Diligent::g_pContext->EndRenderPass();
|
||||
MG_Diligent::IsInRenderPass = false;
|
||||
}
|
||||
|
||||
MG_Diligent::g_pContext->UpdateTexture(
|
||||
pTexture,
|
||||
level,
|
||||
@@ -472,8 +499,11 @@ namespace MG_GL::GL {
|
||||
Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
|
||||
Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION
|
||||
);
|
||||
|
||||
MG_Util::Debug::LogD("TexSubImage2D: Update completed successfully");
|
||||
}
|
||||
|
||||
|
||||
void GetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint* params) {
|
||||
MG_Util::Debug::LogD("glGetTexLevelParameteriv, target: %d, level: %d, pname: %d, params: %p",
|
||||
target, level, pname, params);
|
||||
|
||||
Reference in New Issue
Block a user