From 852b843b4ab98b80a820266793e8519463b881e7 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sat, 7 Jun 2025 20:49:48 +0800 Subject: [PATCH] [Fix] (Diligent/Texture): Add BIND_RENDER(/DEPTH)_TARGET for texture. --- .../Implementations/GL/Texture/GL_Texture.cpp | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp b/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp index 8a1b4106..503b4ddc 100644 --- a/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp +++ b/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp @@ -264,8 +264,29 @@ namespace MG_GL::GL { TexDesc.Width = width; TexDesc.Height = height; TexDesc.Format = newFormat; - TexDesc.BindFlags = Diligent::BIND_SHADER_RESOURCE; + bool isDepthStencil = false; + switch (internalFormat) { + case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT24: + case GL_DEPTH_COMPONENT32: + case GL_DEPTH_COMPONENT32F: + case GL_DEPTH_STENCIL: + case GL_DEPTH24_STENCIL8: + case GL_DEPTH32F_STENCIL8: + isDepthStencil = true; + break; + default: + isDepthStencil = false; + } + + if (isDepthStencil) { + TexDesc.BindFlags = Diligent::BIND_SHADER_RESOURCE | Diligent::BIND_DEPTH_STENCIL; + } else { + TexDesc.BindFlags = Diligent::BIND_SHADER_RESOURCE | Diligent::BIND_RENDER_TARGET; + } + if (level > 0) { TexDesc.MipLevels = level + 1; }