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

44 lines
1.1 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.
# RHIPipelineState::GetNativeHandle
```cpp
virtual void* GetNativeHandle() = 0;
```
获取底层图形 API 的原生句柄。此方法返回的句柄类型取决于具体实现:
- **D3D12**: `ID3D12PipelineState*`
- **OpenGL**: `GLuint`(管线对象 ID
- **Vulkan**: `VkPipeline`
- **Metal**: `id<MTLRenderPipelineState>`
**参数:**
**返回:** `void*` - 指向底层图形 API 管线状态对象的指针
**线程安全:**
**复杂度:** O(1)
**示例:**
```cpp
#include "XCEngine/RHI/RHIPipelineState.h"
#include "XCEngine/RHI/RHIEnums.h"
void InspectNativeHandle(RHIPipelineState* pipeline) {
void* handle = pipeline->GetNativeHandle();
PipelineType type = pipeline->GetType();
if (type == PipelineType::Graphics && handle) {
// D3D12: ID3D12PipelineState* d3d12Pipeline = static_cast<ID3D12PipelineState*>(handle);
// OpenGL: GLuint glPipeline = static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle));
}
}
```
## 相关文档
- [RHIPipelineState](pipeline-state.md) - 返回类总览
- [RHIPipelineState::GetType](get-type.md) - 获取管线类型