# RHITexture **命名空间**: `XCEngine::RHI` **类型**: `class` (abstract) **描述**: GPU 纹理资源抽象接口,用于管理 1D、2D、3D 纹理和立方体贴图等 GPU 资源。 ## 概述 `RHITexture` 封装了 GPU 纹理的创建、状态管理和属性访问。纹理是 GPU 渲染中最常用的资源类型之一。 ## 公共方法 ### 生命周期 | 方法 | 描述 | |------|------| | `virtual void Shutdown()` | 释放纹理资源 | ### 属性访问 | 方法 | 描述 | |------|------| | `virtual uint32_t GetWidth() const` | 获取纹理宽度(像素) | | `virtual uint32_t GetHeight() const` | 获取纹理高度(像素) | | `virtual uint32_t GetDepth() const` | 获取纹理深度(3D 纹理) | | `virtual uint32_t GetMipLevels() const` | 获取 Mipmap 级别数 | | `virtual Format GetFormat() const` | 获取纹理格式 | | `virtual TextureType GetTextureType() const` | 获取纹理类型 | ### 状态管理 | 方法 | 描述 | |------|------| | `virtual ResourceStates GetState() const` | 获取当前资源状态 | | `virtual void SetState(ResourceStates state)` | 设置资源状态 | ### 其他 | 方法 | 描述 | |------|------| | `virtual void* GetNativeHandle()` | 获取原生 API 句柄 | | `virtual const std::string& GetName() const` | 获取纹理名称 | | `virtual void SetName(const std::string& name)` | 设置纹理名称(用于调试) | ## 纹理类型 (TextureType) | 枚举值 | 描述 | |--------|------| | `TextureType::Texture1D` | 1D 纹理 | | `TextureType::Texture2D` | 2D 纹理 | | `TextureType::Texture2DArray` | 2D 纹理数组 | | `TextureType::Texture3D` | 3D 纹理(体积纹理) | | `TextureType::TextureCube` | 立方体贴图 | | `TextureType::TextureCubeArray` | 立方体贴图数组 | ## 纹理格式 (Format) | 格式 | 描述 | |------|------| | `Format::Unknown` | 未知格式 | | `Format::R8_UNorm` | 单通道 8 位归一化 | | `Format::R8G8_UNorm` | 双通道 8 位归一化 | | `Format::R8G8B8A8_UNorm` | 四通道 8 位归一化 | | `Format::R16G16B16A16_Float` | 四通道 16 位浮点 | | `Format::R32G32B32A32_Float` | 四通道 32 位浮点 | | `Format::D32_Float` | 32 位深度 | | `Format::D24_UNorm_S8_UInt` | 24 位深度 + 8 位模板 | | `Format::BC1_UNorm` | 压缩格式 (DXT1) | | `Format::BC7_UNorm` | 压缩格式 | ## 使用示例 ```cpp // 创建 2D 纹理 TextureDesc desc; desc.width = 1024; desc.height = 1024; desc.depth = 1; desc.mipLevels = 1; desc.arraySize = 1; desc.format = (uint32_t)Format::R8G8B8A8_UNorm; desc.textureType = (uint32_t)TextureType::Texture2D; desc.sampleCount = 1; desc.sampleQuality = 0; desc.flags = 0; RHITexture* texture = device->CreateTexture(desc); // 设置资源状态 texture->SetState(ResourceStates::PixelShaderResource); // 使用完毕后关闭 texture->Shutdown(); ``` ## 相关文档 - [RHIDevice](./rhi-device.md) - 创建设备 - [RHIBuffer](./rhi-buffer.md) - 缓冲区资源 - [RHISampler](./rhi-sampler.md) - 纹理采样器