Files
XCEngine/docs/api/resources/shader-loader/index.md
ssdfasd 6af872e9eb docs: fix Resources module API docs naming conventions and broken links
- Rename constructor/destructor files to follow template spec:
  - ctor.md → constructor.md, dtor.md → destructor.md (audioclip)
  - texture_constructor.md → constructor.md, texture_destructor.md → destructor.md (texture)
  - material-loader-constructor.md → constructor.md, material-loader-destructor.md → destructor.md

- Create missing constructor/destructor docs:
  - audio-loader: constructor.md, destructor.md
  - texture-loader: constructor.md, destructor.md

- Fix broken links to ResourceManager:
  - shader-loader/index.md
  - material-loader/index.md

- Remove duplicate folders (keep hyphenated versions):
  - Delete shaderloader/ (keep shader-loader/)
  - Delete resourcepackage/ (keep resource-package/)
  - Merge textureimportsettings/ into texture-import-settings/

- Rename audio-loader method files:
  - canload.md → can-load.md
  - getdefaultsettings.md → get-default-settings.md
  - getsupportedextensions.md → get-supported-extensions.md

- Update overview pages with proper method links and constructor/destructor entries
2026-03-22 14:42:27 +08:00

60 lines
2.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.
# ShaderLoader
## 命名空间
`XCEngine::Resources`
## 类型
类 (Class)
## 描述
着色器资源加载器,负责从磁盘加载 `.vert``.frag``.geom``.comp``.glsl``.hlsl``.shader` 格式的着色器资源文件。
## 概述
`ShaderLoader` 继承自 `IResourceLoader`,实现了着色器资源的加载功能。它支持多种图形 API 的着色器格式,包括 GLSLOpenGL/Vulkan和 HLSLDirectX。加载过程中会根据文件扩展名自动检测着色器类型和语言创建 `Shader` 对象并设置相应的元数据。当前实现专注于文件读取和基础资源创建,着色器编译和实际绑定由渲染层完成。
## 公共方法
| 方法 | 签名 | 描述 |
|------|------|------|
| [ShaderLoader](methods/constructor.md) | `ShaderLoader()` | 默认构造函数 |
| [~ShaderLoader](methods/destructor.md) | `virtual ~ShaderLoader()` | 析构函数 |
| [GetResourceType](methods/get-resource-type.md) | `ResourceType GetResourceType() const` | 返回资源类型为 Shader |
| [GetSupportedExtensions](methods/get-supported-extensions.md) | `Array<String> GetSupportedExtensions() const` | 返回支持的扩展名列表 |
| [CanLoad](methods/can-load.md) | `bool CanLoad(const String& path) const` | 检查给定路径是否可被加载 |
| [Load](methods/load.md) | `LoadResult Load(const String& path, const ImportSettings* settings = nullptr)` | 加载指定路径的着色器资源 |
| [GetDefaultSettings](methods/get-default-settings.md) | `ImportSettings* GetDefaultSettings() const` | 返回默认导入设置 |
## 使用示例
```cpp
#include "Resources/ShaderLoader.h"
#include "Resources/ResourceManager.h"
using namespace XCEngine::Resources;
// 通过 ResourceManager 加载着色器
auto shaderHandle = ResourceManager::Get().Load<Shader>("assets/shaders/pbr.vert");
if (shaderHandle.IsValid()) {
Shader* shader = shaderHandle.Get();
// 使用着色器...
}
// 直接使用 ShaderLoader
ShaderLoader loader;
LoadResult result = loader.Load("assets/shaders/pbr.frag");
if (result.IsSuccess()) {
Shader* shader = static_cast<Shader*>(result.GetResource());
// 使用着色器...
}
```
## 相关文档
- [Shader](../shader/shader.md)
- [IResourceLoader](../iloader/iloader.md)
- [ResourceManager](../resourcemanager/resourcemanager.md)