Files
XCEngine/docs/api/rhi/sampler/bind.md
2026-03-20 02:35:45 +08:00

56 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# RHISampler::Bind
```cpp
virtual void Bind(unsigned int unit) = 0;
```
将采样器绑定到指定的纹理单元。该方法将采样器状态设置到渲染管线的对应纹理采样槽位,使其后续的纹理采样操作可以使用此采样器。
**参数:**
| 参数 | 类型 | 描述 |
|------|------|------|
| `unit` | `unsigned int` | 纹理单元索引,指定绑定到哪个纹理采样槽位(通常 0-15 |
**返回:**
**线程安全:**
**复杂度:** O(1)
**示例:**
```cpp
#include "XCEngine/RHI/RHISampler.h"
class MySampler : public XCEngine::RHI::RHISampler {
public:
void Shutdown() override { }
void Bind(unsigned int unit) override {
m_boundUnit = unit;
}
void Unbind(unsigned int unit) override {
if (m_boundUnit == unit) {
m_boundUnit = -1;
}
}
void* GetNativeHandle() override { return nullptr; }
unsigned int GetID() override { return 0; }
private:
int m_boundUnit = -1;
};
void Example() {
MySampler sampler;
sampler.Bind(0);
sampler.Bind(1);
sampler.Bind(2);
}
```
## 相关文档
- [RHISampler 总览](sampler.md) - 返回类总览
- [RHISampler::Unbind](unbind.md) - 解绑采样器