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

47 lines
1.3 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::GetNativeHandle
```cpp
virtual void* GetNativeHandle() = 0;
```
获取底层图形 API 的原生句柄。该方法返回采样器在对应图形 API 中的原生对象指针或句柄,可用于调试或高级图形 API 互操作。
**参数:**
**返回:** 指向原生图形 API 采样器对象的 void 指针具体类型取决于底层实现D3D11: `ID3D11SamplerState*`D3D12: `D3D12_GPU_VIRTUAL_ADDRESS``ID3D12Resource*`Vulkan: `VkSampler`
**线程安全:**
**复杂度:** O(1)
**示例:**
```cpp
#include "XCEngine/RHI/RHISampler.h"
class MySampler : public XCEngine::RHI::RHISampler {
public:
void Shutdown() override { }
void Bind(unsigned int unit) override { }
void Unbind(unsigned int unit) override { }
void* GetNativeHandle() override { return reinterpret_cast<void*>(m_nativeHandle); }
unsigned int GetID() override { return 0; }
private:
uint64_t m_nativeHandle = 0x12345678;
};
void Example() {
MySampler sampler;
void* handle = sampler.GetNativeHandle();
if (handle != nullptr) {
// 使用原生句柄进行调试或高级操作
}
}
```
## 相关文档
- [RHISampler 总览](sampler.md) - 返回类总览
- [RHISampler::GetID](get-id.md) - 获取采样器 ID