Files
XCEngine/docs/api/rhi/opengl/opengl-depth-stencil-view.md

106 lines
2.3 KiB
Markdown

# OpenGLDepthStencilView
OpenGL 深度模板视图实现。
## 头文件
```cpp
#include <XCEngine/RHI/OpenGL/OpenGLDepthStencilView.h>
```
## 枚举
### DepthStencilFormat
| 值 | OpenGL 内部格式 |
|----|----------------|
| `D16_UNORM` | `GL_DEPTH_COMPONENT16` |
| `D24_UNORM_S8_UINT` | `GL_DEPTH24_STENCIL8` |
| `D32_FLOAT` | `GL_DEPTH_COMPONENT32F` |
| `D32_FLOAT_S8X24_UINT` | `GL_DEPTH32F_STENCIL8` |
### DepthStencilType
| 值 | 描述 |
|----|------|
| `Texture2D` | 2D 纹理 |
| `Texture2DArray` | 2D 纹理数组 |
| `TextureCube` | 立方体贴图 |
## OpenGLDepthStencilViewDesc
```cpp
struct OpenGLDepthStencilViewDesc {
DepthStencilType type = DepthStencilType::Texture2D;
int mipLevel = 0;
int baseArraySlice = 0;
int arraySize = 1;
int layer = 0;
};
```
## 公共成员函数
#### `OpenGLDepthStencilView()`
#### `~OpenGLDepthStencilView()`
#### `bool Initialize(unsigned int texture, const OpenGLDepthStencilViewDesc& 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()`
#### `void ClearDepth(float depth)`
#### `void ClearStencil(uint8_t stencil)`
#### `void ClearDepthStencil(float depth, uint8_t stencil)`
#### `unsigned int GetFramebuffer() const`
#### `unsigned int GetTexture() const`
#### `int GetMipLevel() const`
#### `int GetWidth() const`
#### `int GetHeight() const`
#### `static void BindFramebuffer(unsigned int framebuffer)`
#### `static void UnbindFramebuffer()`
## 内部成员
| 成员 | 类型 | 描述 |
|------|------|------|
| `m_texture` | `unsigned int` | GL texture ID |
| `m_framebuffer` | `unsigned int` | GL framebuffer ID |
| `m_mipLevel` | `int` | Mip 级别 |
| `m_width/height` | `int` | 尺寸 |
| `m_type` | `DepthStencilType` | 类型 |
| `m_format` | `DepthStencilFormat` | 格式 |
## 使用示例
```cpp
OpenGLDepthStencilView dsv;
dsv.Initialize(depthTexture.GetID());
dsv.Bind();
dsv.ClearDepthStencil(1.0f, 0);
dsv.Unbind();
// Combined with RTV
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthTex, 0);
```