RHI: 增强RHIResourceView抽象接口,添加GetViewType/GetDimension/GetFormat虚函数
- 在RHIResourceView基类添加3个纯虚函数:GetViewType()、GetDimension()、GetFormat() - D3D12ResourceView和OpenGLResourceView子类实现这些虚函数 - 在各InitializeAs*方法中正确存储format和dimension信息 - 消除调用者必须向下转型才能获取视图类型的需求
This commit is contained in:
@@ -12,6 +12,8 @@ namespace RHI {
|
||||
|
||||
OpenGLResourceView::OpenGLResourceView()
|
||||
: m_viewType(ResourceViewType::RenderTarget)
|
||||
, m_format(Format::Unknown)
|
||||
, m_dimension(ResourceViewDimension::Unknown)
|
||||
, m_framebufferID(0)
|
||||
, m_textureUnit(-1)
|
||||
, m_bindingPoint(-1)
|
||||
@@ -81,12 +83,13 @@ bool OpenGLResourceView::InitializeAsRenderTarget(
|
||||
OpenGLTexture* texture,
|
||||
const ResourceViewDesc& desc,
|
||||
OpenGLFramebuffer* framebuffer) {
|
||||
(void)desc;
|
||||
if (!texture || !framebuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::RenderTarget;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_framebuffer = framebuffer;
|
||||
m_framebufferID = framebuffer->GetFramebuffer();
|
||||
@@ -97,12 +100,13 @@ bool OpenGLResourceView::InitializeAsDepthStencil(
|
||||
OpenGLTexture* texture,
|
||||
const ResourceViewDesc& desc,
|
||||
OpenGLFramebuffer* framebuffer) {
|
||||
(void)desc;
|
||||
if (!texture || !framebuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::DepthStencil;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_framebuffer = framebuffer;
|
||||
m_framebufferID = framebuffer->GetFramebuffer();
|
||||
@@ -123,6 +127,8 @@ bool OpenGLResourceView::InitializeAsShaderResource(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::ShaderResource;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_textureUnit = unit;
|
||||
m_textureUnitAllocator = allocator;
|
||||
@@ -144,6 +150,8 @@ bool OpenGLResourceView::InitializeAsUnorderedAccess(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::UnorderedAccess;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_textureUnit = unit;
|
||||
m_textureUnitAllocator = allocator;
|
||||
@@ -169,6 +177,8 @@ bool OpenGLResourceView::InitializeAsConstantBuffer(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::ConstantBuffer;
|
||||
m_format = Format::Unknown;
|
||||
m_dimension = ResourceViewDimension::Buffer;
|
||||
m_buffer = buffer;
|
||||
m_bindingPoint = bindingPoint;
|
||||
m_uniformBufferManager = manager;
|
||||
|
||||
Reference in New Issue
Block a user