Files
XCEngine/docs/api/rhi/opengl/opengl-sampler.md

103 lines
2.2 KiB
Markdown
Raw Normal View History

# OpenGLSampler
OpenGL 采样器实现。
## 头文件
```cpp
#include <XCEngine/RHI/OpenGL/OpenGLSampler.h>
```
## 继承关系
```
RHISampler (interface)
└── OpenGLSampler (implementation)
```
## 枚举
### SamplerWrapMode
| 值 | OpenGL 常量 |
|----|-------------|
| `Repeat` | `GL_REPEAT` |
| `MirroredRepeat` | `GL_MIRRORED_REPEAT` |
| `ClampToEdge` | `GL_CLAMP_TO_EDGE` |
| `ClampToBorder` | `GL_CLAMP_TO_BORDER` |
### SamplerFilter
| 值 | OpenGL 常量 |
|----|-------------|
| `Nearest` | `GL_NEAREST` |
| `Linear` | `GL_LINEAR` |
| `NearestMipmapNearest` | `GL_NEAREST_MIPMAP_NEAREST` |
| `LinearMipmapNearest` | `GL_LINEAR_MIPMAP_NEAREST` |
| `NearestMipmapLinear` | `GL_NEAREST_MIPMAP_LINEAR` |
| `LinearMipmapLinear` | `GL_LINEAR_MIPMAP_LINEAR` |
### SamplerCompareMode
| 值 | OpenGL 常量 |
|----|-------------|
| `None` | `GL_NONE` |
| `CompareToRef` | `GL_COMPARE_REF_TO_TEXTURE` |
## OpenGLSamplerDesc
```cpp
struct OpenGLSamplerDesc {
SamplerFilter minFilter = SamplerFilter::LinearMipmapLinear;
SamplerFilter magFilter = SamplerFilter::Linear;
SamplerWrapMode wrapS = SamplerWrapMode::Repeat;
SamplerWrapMode wrapT = SamplerWrapMode::Repeat;
SamplerWrapMode wrapR = SamplerWrapMode::Repeat;
SamplerCompareMode compareMode = SamplerCompareMode::None;
int compareFunc = 0;
float maxAnisotropy = 1.0f;
float minLod = -1000.0f;
float maxLod = 1000.0f;
};
```
## 公共成员函数
#### `OpenGLSampler()`
#### `~OpenGLSampler() override`
#### `bool Initialize(const OpenGLSamplerDesc& desc)`
#### `void Shutdown() override`
#### `void Bind(unsigned int unit) override`
#### `void Unbind(unsigned int unit) override`
#### `unsigned int GetID() const`
#### `void* GetNativeHandle() override`
## 内部成员
| 成员 | 类型 | 描述 |
|------|------|------|
| `m_sampler` | `unsigned int` | GL sampler ID |
| `m_desc` | `OpenGLSamplerDesc` | 采样器描述 |
## 使用示例
```cpp
OpenGLSampler sampler;
OpenGLSamplerDesc desc;
desc.minFilter = SamplerFilter::LinearMipmapLinear;
desc.magFilter = SamplerFilter::Linear;
desc.wrapS = desc.wrapT = SamplerWrapMode::Repeat;
desc.maxAnisotropy = 16.0f;
sampler.Initialize(desc);
sampler.Bind(0);
glBindTextureUnit(0, texture.GetID());
```