Files
XCEngine/docs/api/resources/texture-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

3.6 KiB
Raw Blame History

TextureLoader

命名空间: XCEngine::Resources

类型: class

描述: 纹理资源加载器,负责从文件加载纹理资源。

继承自: IResourceLoader

概述

TextureLoader 是 XCEngine 中的纹理资源加载器实现类,继承自 IResourceLoader。它支持从多种图像格式加载纹理数据,包括 PNG、JPG、TGA、BMP、GIF、HDR 和 DDS。

头文件

#include <XCEngine/Resources/TextureLoader.h>

支持的格式

扩展名 描述
png PNG 图像
jpg / jpeg JPEG 图像
tga TGA 图像
bmp BMP 图像
gif GIF 图像
hdr HDR 图像
dds DDS 压缩纹理

公共方法

方法 描述
TextureLoader 构造函数
~TextureLoader 析构函数
GetResourceType 返回 ResourceType::Texture
GetSupportedExtensions 获取支持的扩展名列表
CanLoad 检查是否支持加载指定路径的纹理
Load 加载纹理资源
GetDefaultSettings 获取默认导入设置

GetResourceType

ResourceType GetResourceType() const override

返回资源的类型标识。

返回值: ResourceType::Texture


GetSupportedExtensions

Containers::Array<Containers::String> GetSupportedExtensions() const override

返回所有支持的纹理文件扩展名列表。

返回值: 包含所有支持扩展名的字符串数组。

支持的扩展名: png, jpg, jpeg, tga, bmp, gif, hdr, dds


CanLoad

bool CanLoad(const Containers::String& path) const override

检查指定的文件路径是否可以被此加载器处理。

参数:

  • path: 文件路径

返回值: 如果文件扩展名受支持返回 true,否则返回 false


Load

LoadResult Load(const Containers::String& path, const ImportSettings* settings = nullptr) override

从指定路径加载纹理资源。

参数:

  • path: 纹理文件路径
  • settings: 导入设置(可选,当前未使用)

返回值: 加载成功返回包含 Texture 指针的 LoadResult;失败返回包含错误信息的 LoadResult

实现说明: 当前实现仅读取文件数据和创建基础 Texture 对象,不解析实际的图像格式数据。


GetDefaultSettings

ImportSettings* GetDefaultSettings() const override

获取默认的纹理导入设置。

返回值: nullptr(当前无默认设置)

使用示例

#include <XCEngine/Resources/TextureLoader.h>
#include <XCEngine/Resources/ResourceManager.h>

using namespace XCEngine::Resources;

// 通过 ResourceManager 加载纹理
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("textures/player.png");

// 检查加载器是否支持特定格式
TextureLoader loader;
if (loader.CanLoad("assets/image.dds")) {
    // 可以加载 DDS 格式
}

相关文档

实现说明

注意: Load() 方法当前为示例实现,不解析 PNG/JPG 等格式的实际图像像素数据,仅创建空 Texture 对象并设置基础资源参数name、path、guid、memorySize。实际图像数据解析需要在后续版本中实现。