- 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
2.3 KiB
2.3 KiB
ShaderLoader
命名空间
XCEngine::Resources
类型
类 (Class)
描述
着色器资源加载器,负责从磁盘加载 .vert、.frag、.geom、.comp、.glsl、.hlsl 和 .shader 格式的着色器资源文件。
概述
ShaderLoader 继承自 IResourceLoader,实现了着色器资源的加载功能。它支持多种图形 API 的着色器格式,包括 GLSL(OpenGL/Vulkan)和 HLSL(DirectX)。加载过程中会根据文件扩展名自动检测着色器类型和语言,创建 Shader 对象并设置相应的元数据。当前实现专注于文件读取和基础资源创建,着色器编译和实际绑定由渲染层完成。
公共方法
| 方法 | 签名 | 描述 |
|---|---|---|
| ShaderLoader | ShaderLoader() |
默认构造函数 |
| ~ShaderLoader | virtual ~ShaderLoader() |
析构函数 |
| GetResourceType | ResourceType GetResourceType() const |
返回资源类型为 Shader |
| GetSupportedExtensions | Array<String> GetSupportedExtensions() const |
返回支持的扩展名列表 |
| CanLoad | bool CanLoad(const String& path) const |
检查给定路径是否可被加载 |
| Load | LoadResult Load(const String& path, const ImportSettings* settings = nullptr) |
加载指定路径的着色器资源 |
| GetDefaultSettings | ImportSettings* GetDefaultSettings() const |
返回默认导入设置 |
使用示例
#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());
// 使用着色器...
}