#pragma once #include #include #include #include #include namespace extra2d { /** * @brief 纹理类 * * 基于 RHI 的纹理包装类,管理纹理资源的创建和加载 * 支持从文件或内存加载 */ class Texture : public RefCounted { public: /** * @brief 默认构造函数 */ Texture(); /** * @brief 析构函数 */ ~Texture() override; /** * @brief 从文件加载纹理 * @param path 文件路径 * @return 加载是否成功 */ bool loadFromFile(const std::string& path); /** * @brief 从内存加载纹理 * @param data 像素数据 * @param width 宽度 * @param height 高度 * @param format 像素格式 * @return 加载是否成功 */ bool loadFromMemory(const uint8_t* data, int width, int height, TextureFormat format); /** * @brief 创建空纹理 * @param width 宽度 * @param height 高度 * @param format 像素格式 * @return 创建是否成功 */ bool create(int width, int height, TextureFormat format); /** * @brief 获取纹理宽度 * @return 宽度 */ int getWidth() const { return width_; } /** * @brief 获取纹理高度 * @return 高度 */ int getHeight() const { return height_; } /** * @brief 获取纹理格式 * @return 像素格式 */ TextureFormat getFormat() const { return format_; } /** * @brief 获取 RHI 纹理句柄 * @return RHI 纹理句柄 */ TextureHandle getHandle() const { return handle_; } /** * @brief 检查是否已加载 * @return 是否已加载 */ bool isLoaded() const { return handle_.isValid(); } private: /** * @brief 获取每个像素的字节数 * @param format 纹理格式 * @return 字节数 */ static uint32_t getBytesPerPixel(TextureFormat format); TextureHandle handle_; // RHI 纹理句柄 int width_ = 0; // 纹理宽度 int height_ = 0; // 纹理高度 TextureFormat format_ = TextureFormat::RGBA8; // 像素格式 }; } // namespace extra2d