Fix OpenGL render target binding composition
This commit is contained in:
@@ -10,6 +10,53 @@
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
namespace {
|
||||
|
||||
GLenum ResolveFramebufferTextureTarget(OpenGLTextureType textureType, const ResourceViewDesc& desc) {
|
||||
switch (textureType) {
|
||||
case OpenGLTextureType::Texture1D:
|
||||
return GL_TEXTURE_1D;
|
||||
case OpenGLTextureType::Texture2D:
|
||||
return GL_TEXTURE_2D;
|
||||
case OpenGLTextureType::TextureCube: {
|
||||
const uint32_t face = desc.firstArraySlice < 6 ? desc.firstArraySlice : 0;
|
||||
return GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
|
||||
}
|
||||
case OpenGLTextureType::Texture2DArray:
|
||||
case OpenGLTextureType::Texture3D:
|
||||
case OpenGLTextureType::TextureCubeArray:
|
||||
return 0;
|
||||
default:
|
||||
return GL_TEXTURE_2D;
|
||||
}
|
||||
}
|
||||
|
||||
int ResolveFramebufferAttachmentLayer(OpenGLTextureType textureType, const ResourceViewDesc& desc) {
|
||||
switch (textureType) {
|
||||
case OpenGLTextureType::Texture2DArray:
|
||||
case OpenGLTextureType::Texture3D:
|
||||
case OpenGLTextureType::TextureCubeArray:
|
||||
return static_cast<int>(desc.firstArraySlice);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Format ResolveViewFormat(OpenGLTexture* texture, const ResourceViewDesc& desc) {
|
||||
if (desc.format != 0) {
|
||||
return static_cast<Format>(desc.format);
|
||||
}
|
||||
return texture ? texture->GetFormat() : Format::Unknown;
|
||||
}
|
||||
|
||||
FramebufferAttachmentType ResolveDepthAttachmentType(Format format) {
|
||||
return format == Format::D24_UNorm_S8_UInt
|
||||
? FramebufferAttachmentType::DepthStencil
|
||||
: FramebufferAttachmentType::Depth;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
OpenGLResourceView::OpenGLResourceView()
|
||||
: m_viewType(ResourceViewType::RenderTarget)
|
||||
, m_format(Format::Unknown)
|
||||
@@ -47,6 +94,7 @@ void OpenGLResourceView::Shutdown() {
|
||||
m_framebuffer = nullptr;
|
||||
m_textureUnitAllocator = nullptr;
|
||||
m_uniformBufferManager = nullptr;
|
||||
m_framebufferAttachment = {};
|
||||
m_framebufferID = 0;
|
||||
m_texture = nullptr;
|
||||
m_buffer = nullptr;
|
||||
@@ -101,11 +149,17 @@ bool OpenGLResourceView::InitializeAsRenderTarget(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::RenderTarget;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_format = ResolveViewFormat(texture, desc);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_framebuffer = framebuffer;
|
||||
m_framebufferID = framebuffer->GetFramebuffer();
|
||||
m_framebufferAttachment.texture = texture->GetID();
|
||||
m_framebufferAttachment.target = ResolveFramebufferTextureTarget(texture->GetOpenGLType(), desc);
|
||||
m_framebufferAttachment.mipLevel = static_cast<int>(desc.mipLevel);
|
||||
m_framebufferAttachment.layer = ResolveFramebufferAttachmentLayer(texture->GetOpenGLType(), desc);
|
||||
m_framebufferAttachment.type = FramebufferAttachmentType::Color;
|
||||
m_framebufferAttachment.format = static_cast<uint32_t>(m_format);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -118,11 +172,17 @@ bool OpenGLResourceView::InitializeAsDepthStencil(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::DepthStencil;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_format = ResolveViewFormat(texture, desc);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_framebuffer = framebuffer;
|
||||
m_framebufferID = framebuffer->GetFramebuffer();
|
||||
m_framebufferAttachment.texture = texture->GetID();
|
||||
m_framebufferAttachment.target = ResolveFramebufferTextureTarget(texture->GetOpenGLType(), desc);
|
||||
m_framebufferAttachment.mipLevel = static_cast<int>(desc.mipLevel);
|
||||
m_framebufferAttachment.layer = ResolveFramebufferAttachmentLayer(texture->GetOpenGLType(), desc);
|
||||
m_framebufferAttachment.type = ResolveDepthAttachmentType(m_format);
|
||||
m_framebufferAttachment.format = static_cast<uint32_t>(m_format);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -135,7 +195,7 @@ bool OpenGLResourceView::InitializeAsShaderResource(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::ShaderResource;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_format = ResolveViewFormat(texture, desc);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_textureUnit = -1;
|
||||
@@ -157,7 +217,7 @@ bool OpenGLResourceView::InitializeAsUnorderedAccess(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::UnorderedAccess;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_format = ResolveViewFormat(texture, desc);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_textureUnit = unit;
|
||||
|
||||
Reference in New Issue
Block a user