Files
XCEngine/docs/api/resources/shaderloader/methods/load.md

46 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.
# ShaderLoader::Load
## 方法签名
```cpp
LoadResult Load(const Containers::String& path, const ImportSettings* settings = nullptr) override;
```
## 详细描述
加载指定路径的着色器资源文件。加载流程如下:
1. 读取文件数据到内存
2. 根据扩展名识别着色器语言HLSL 或 GLSL
3. 检测着色器类型Vertex/Fragment/Geometry/Compute
4. 创建 `Shader` 对象并设置属性
如果加载失败,返回的 `LoadResult` 将包含错误信息。
## 参数
- `path` - 着色器文件的路径
- `settings` - 可选的导入设置指针(当前实现中未使用)
## 返回值
`LoadResult` - 加载结果,成功时包含 `Shader` 指针,失败时包含错误信息
## 示例
```cpp
#include "Resources/ShaderLoader.h"
using namespace XCEngine::Resources;
ShaderLoader loader;
LoadResult result = loader.Load("shaders/forward.vert");
if (result.IsSuccess()) {
Shader* shader = static_cast<Shader*>(result.GetResource());
// 使用着色器...
} else {
// 处理错误
const String& error = result.GetErrorMessage();
}
```