mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Fix] (Diligent/Texture): Fix the 'Overwriting reference' bug in TexImage2D.
This commit is contained in:
@@ -186,7 +186,6 @@ namespace MG_GL::GL {
|
|||||||
GLenum format, GLenum type, const void* data) {
|
GLenum format, GLenum type, const void* data) {
|
||||||
MG_Util::Debug::LogD("glTexImage2D, target: %d, level: %d, internalFormat: %d, width: %d, height: %d, format: %d, type: %d, data: %p",
|
MG_Util::Debug::LogD("glTexImage2D, target: %d, level: %d, internalFormat: %d, width: %d, height: %d, format: %d, type: %d, data: %p",
|
||||||
target, level, internalFormat, width, height, format, type, data);
|
target, level, internalFormat, width, height, format, type, data);
|
||||||
|
|
||||||
GLenum result = MG_State::UploadTexture2D(target, level, internalFormat, width, height,
|
GLenum result = MG_State::UploadTexture2D(target, level, internalFormat, width, height,
|
||||||
border, format, type, data);
|
border, format, type, data);
|
||||||
if (result != GL_NO_ERROR) {
|
if (result != GL_NO_ERROR) {
|
||||||
@@ -209,12 +208,12 @@ namespace MG_GL::GL {
|
|||||||
|
|
||||||
Diligent::ITexture* pTexture = nullptr;
|
Diligent::ITexture* pTexture = nullptr;
|
||||||
Diligent::ITextureView* pSRV = nullptr;
|
Diligent::ITextureView* pSRV = nullptr;
|
||||||
auto texIt = MG_Diligent::g_TextureMap.find(boundTextureID);
|
|
||||||
auto srvIt = MG_Diligent::g_TextureViewMap.find(boundTextureID);
|
|
||||||
|
|
||||||
|
auto texIt = MG_Diligent::g_TextureMap.find(boundTextureID);
|
||||||
if (texIt != MG_Diligent::g_TextureMap.end()) {
|
if (texIt != MG_Diligent::g_TextureMap.end()) {
|
||||||
pTexture = texIt->second;
|
pTexture = texIt->second;
|
||||||
}
|
}
|
||||||
|
auto srvIt = MG_Diligent::g_TextureViewMap.find(boundTextureID);
|
||||||
if (srvIt != MG_Diligent::g_TextureViewMap.end()) {
|
if (srvIt != MG_Diligent::g_TextureViewMap.end()) {
|
||||||
pSRV = srvIt->second;
|
pSRV = srvIt->second;
|
||||||
}
|
}
|
||||||
@@ -239,12 +238,17 @@ namespace MG_GL::GL {
|
|||||||
width, height, newFormat);
|
width, height, newFormat);
|
||||||
|
|
||||||
if (pSRV) {
|
if (pSRV) {
|
||||||
|
MG_Util::Debug::LogD("TexImage2D: Releasing existing SRV %p", (void*)pSRV);
|
||||||
pSRV->Release();
|
pSRV->Release();
|
||||||
MG_Diligent::g_TextureViewMap[boundTextureID] = nullptr;
|
MG_Diligent::g_TextureViewMap[boundTextureID] = nullptr;
|
||||||
|
pSRV = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTexture) {
|
if (pTexture) {
|
||||||
|
MG_Util::Debug::LogD("TexImage2D: Releasing existing texture %p", (void*)pTexture);
|
||||||
pTexture->Release();
|
pTexture->Release();
|
||||||
MG_Diligent::g_TextureMap[boundTextureID] = nullptr;
|
MG_Diligent::g_TextureMap[boundTextureID] = nullptr;
|
||||||
|
pTexture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
needCreateTexture = true;
|
needCreateTexture = true;
|
||||||
@@ -252,6 +256,9 @@ namespace MG_GL::GL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needCreateTexture) {
|
if (needCreateTexture) {
|
||||||
|
Diligent::ITexture* newTexture = nullptr;
|
||||||
|
Diligent::ITextureView* newSRV = nullptr;
|
||||||
|
|
||||||
Diligent::TextureDesc TexDesc;
|
Diligent::TextureDesc TexDesc;
|
||||||
TexDesc.Type = Diligent::RESOURCE_DIM_TEX_2D;
|
TexDesc.Type = Diligent::RESOURCE_DIM_TEX_2D;
|
||||||
TexDesc.Width = width;
|
TexDesc.Width = width;
|
||||||
@@ -265,22 +272,29 @@ namespace MG_GL::GL {
|
|||||||
|
|
||||||
MG_Util::Debug::LogD("TexImage2D: Creating new Diligent texture with Width: %d, Height: %d, Format: %d",
|
MG_Util::Debug::LogD("TexImage2D: Creating new Diligent texture with Width: %d, Height: %d, Format: %d",
|
||||||
width, height, newFormat);
|
width, height, newFormat);
|
||||||
MG_Diligent::g_pDevice->CreateTexture(TexDesc, nullptr, &pTexture);
|
|
||||||
|
|
||||||
MG_Diligent::g_TextureMap[boundTextureID] = pTexture;
|
MG_Diligent::g_pDevice->CreateTexture(TexDesc, nullptr, &newTexture);
|
||||||
|
|
||||||
|
if (newTexture) {
|
||||||
MG_Util::Debug::LogD("TexImage2D: Created new Diligent texture %p for GL name %u.",
|
MG_Util::Debug::LogD("TexImage2D: Created new Diligent texture %p for GL name %u.",
|
||||||
(void*)pTexture, boundTextureID);
|
(void*)newTexture, boundTextureID);
|
||||||
|
|
||||||
if (pTexture) {
|
|
||||||
Diligent::TextureViewDesc SRVDesc;
|
Diligent::TextureViewDesc SRVDesc;
|
||||||
SRVDesc.ViewType = Diligent::TEXTURE_VIEW_SHADER_RESOURCE;
|
SRVDesc.ViewType = Diligent::TEXTURE_VIEW_SHADER_RESOURCE;
|
||||||
SRVDesc.TextureDim = Diligent::RESOURCE_DIM_TEX_2D;
|
SRVDesc.TextureDim = Diligent::RESOURCE_DIM_TEX_2D;
|
||||||
SRVDesc.MostDetailedMip = 0;
|
SRVDesc.MostDetailedMip = 0;
|
||||||
SRVDesc.NumMipLevels = TexDesc.MipLevels;
|
SRVDesc.NumMipLevels = TexDesc.MipLevels;
|
||||||
|
|
||||||
pTexture->CreateView(SRVDesc, &pSRV);
|
newTexture->CreateView(SRVDesc, &newSRV);
|
||||||
MG_Diligent::g_TextureViewMap[boundTextureID] = pSRV;
|
MG_Util::Debug::LogD("TexImage2D: Created new SRV %p for texture.", (void*)newSRV);
|
||||||
MG_Util::Debug::LogD("TexImage2D: Created new SRV %p for texture.", (void*)pSRV);
|
|
||||||
|
MG_Diligent::g_TextureMap[boundTextureID] = newTexture;
|
||||||
|
MG_Diligent::g_TextureViewMap[boundTextureID] = newSRV;
|
||||||
|
|
||||||
|
pTexture = newTexture;
|
||||||
|
pSRV = newSRV;
|
||||||
|
} else {
|
||||||
|
MG_Util::Debug::LogE("TexImage2D: Failed to create new texture!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,6 +325,7 @@ namespace MG_GL::GL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TexParameterf(GLenum target, GLenum pname, GLfloat param) {
|
void TexParameterf(GLenum target, GLenum pname, GLfloat param) {
|
||||||
MG_Util::Debug::LogD("glTexParameterf, target: %d, pname: %d, param: %f", target, pname, param);
|
MG_Util::Debug::LogD("glTexParameterf, target: %d, pname: %d, param: %f", target, pname, param);
|
||||||
GLenum result = MG_State::SetTexturePropertyFloat(target, pname, param);
|
GLenum result = MG_State::SetTexturePropertyFloat(target, pname, param);
|
||||||
@@ -414,7 +429,6 @@ namespace MG_GL::GL {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 更新纹理子区域
|
|
||||||
Diligent::TextureSubResData SubResData;
|
Diligent::TextureSubResData SubResData;
|
||||||
SubResData.pData = pixels;
|
SubResData.pData = pixels;
|
||||||
SubResData.Stride = width * GetBytesPerPixel(format, type);
|
SubResData.Stride = width * GetBytesPerPixel(format, type);
|
||||||
|
|||||||
Reference in New Issue
Block a user