Enhance OpenGL RTV and DSV with comprehensive framebuffer support
OpenGLRenderTargetView: - Add RenderTargetType enum for different texture types - Add RenderTargetViewDesc struct with mip level, array slice, layer info - Add Initialize() with desc parameter for 2D/2DArray/3D/Cube - Add InitializeCubemap() for cubemap faces - Add Bind(count) overload for multiple framebuffers - Add Clear() methods for color and depth-stencil - Add static BindFramebuffer/UnbindFramebuffer methods OpenGLDepthStencilView: - Add DepthStencilType enum for different texture types - Add DepthStencilViewDesc struct with mip level, array slice, layer info - Add Initialize() with desc parameter for 2D/2DArray/Cube - Add InitializeCubemap() for cubemap faces - Add ClearDepth, ClearStencil, ClearDepthStencil methods - Add static BindFramebuffer/UnbindFramebuffer methods
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
@@ -12,23 +13,54 @@ enum class DepthStencilFormat {
|
||||
D32_FLOAT_S8X24_UINT
|
||||
};
|
||||
|
||||
enum class DepthStencilType {
|
||||
Texture2D,
|
||||
Texture2DArray,
|
||||
TextureCube
|
||||
};
|
||||
|
||||
struct DepthStencilViewDesc {
|
||||
DepthStencilType type = DepthStencilType::Texture2D;
|
||||
int mipLevel = 0;
|
||||
int baseArraySlice = 0;
|
||||
int arraySize = 1;
|
||||
int layer = 0;
|
||||
};
|
||||
|
||||
class OpenGLDepthStencilView {
|
||||
public:
|
||||
OpenGLDepthStencilView();
|
||||
~OpenGLDepthStencilView();
|
||||
|
||||
bool Initialize(unsigned int texture, const DepthStencilViewDesc& desc);
|
||||
bool Initialize(unsigned int texture, int mipLevel = 0);
|
||||
bool InitializeCubemap(unsigned int cubemap, int face, int mipLevel = 0);
|
||||
void Shutdown();
|
||||
|
||||
void Bind();
|
||||
void Unbind();
|
||||
|
||||
unsigned int GetID() const { return m_texture; }
|
||||
void ClearDepth(float depth);
|
||||
void ClearStencil(uint8_t stencil);
|
||||
void ClearDepthStencil(float depth, uint8_t stencil);
|
||||
|
||||
unsigned int GetFramebuffer() const { return m_framebuffer; }
|
||||
unsigned int GetTexture() const { return m_texture; }
|
||||
int GetMipLevel() const { return m_mipLevel; }
|
||||
int GetWidth() const { return m_width; }
|
||||
int GetHeight() const { return m_height; }
|
||||
|
||||
static void BindFramebuffer(unsigned int framebuffer);
|
||||
static void UnbindFramebuffer();
|
||||
|
||||
private:
|
||||
unsigned int m_texture;
|
||||
unsigned int m_framebuffer;
|
||||
int m_mipLevel;
|
||||
int m_width;
|
||||
int m_height;
|
||||
DepthStencilType m_type;
|
||||
DepthStencilFormat m_format;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -1,27 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
enum class RenderTargetType {
|
||||
Texture2D,
|
||||
Texture2DArray,
|
||||
Texture3D,
|
||||
TextureCube,
|
||||
TextureCubeArray
|
||||
};
|
||||
|
||||
struct RenderTargetViewDesc {
|
||||
RenderTargetType type = RenderTargetType::Texture2D;
|
||||
int mipLevel = 0;
|
||||
int baseArraySlice = 0;
|
||||
int arraySize = 1;
|
||||
int layer = 0;
|
||||
uint32_t format = 0;
|
||||
};
|
||||
|
||||
class OpenGLRenderTargetView {
|
||||
public:
|
||||
OpenGLRenderTargetView();
|
||||
~OpenGLRenderTargetView();
|
||||
|
||||
bool Initialize(unsigned int texture, const RenderTargetViewDesc& desc);
|
||||
bool Initialize(unsigned int texture, int mipLevel = 0);
|
||||
bool InitializeCubemap(unsigned int cubemap, int face, int mipLevel = 0);
|
||||
void Shutdown();
|
||||
|
||||
void Bind(unsigned int slot);
|
||||
void Bind(unsigned int slot = 0);
|
||||
void Bind(unsigned int count, const unsigned int* framebuffers, const int* drawBuffers);
|
||||
void Unbind();
|
||||
|
||||
unsigned int GetID() const { return m_texture; }
|
||||
void Clear(float r, float g, float b, float a);
|
||||
void Clear(float r, float g, float b, float a, float depth, uint8_t stencil);
|
||||
|
||||
unsigned int GetFramebuffer() const { return m_framebuffer; }
|
||||
unsigned int GetTexture() const { return m_texture; }
|
||||
int GetMipLevel() const { return m_mipLevel; }
|
||||
int GetWidth() const { return m_width; }
|
||||
int GetHeight() const { return m_height; }
|
||||
|
||||
static void BindFramebuffer(unsigned int framebuffer);
|
||||
static void UnbindFramebuffer();
|
||||
|
||||
private:
|
||||
unsigned int m_texture;
|
||||
unsigned int m_framebuffer;
|
||||
int m_mipLevel;
|
||||
int m_width;
|
||||
int m_height;
|
||||
RenderTargetType m_type;
|
||||
std::vector<unsigned int> m_framebuffers;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
Reference in New Issue
Block a user