82 lines
1.8 KiB
Markdown
82 lines
1.8 KiB
Markdown
# OpenGLDevice::CreateTexture
|
||
|
||
```cpp
|
||
RHITexture* CreateTexture(const TextureDesc& desc) override
|
||
```
|
||
|
||
创建 OpenGL 纹理对象。
|
||
|
||
## 详细描述
|
||
|
||
根据 `TextureDesc` 创建一个 OpenGL 纹理对象。纹理类型映射:
|
||
|
||
| TextureDesc.textureType | OpenGLTextureType |
|
||
|------------------------|-------------------|
|
||
| 0 | Texture1D |
|
||
| 1 (默认) | Texture2D |
|
||
| 2 | Texture3D |
|
||
| 3 | TextureCube |
|
||
|
||
### 纹理格式
|
||
|
||
当前实现固定使用 `RGBA8` (RGBA, 8 bits per channel) 格式。
|
||
|
||
### 纹理参数
|
||
|
||
| 参数 | 值 |
|
||
|------|-----|
|
||
| 格式 | RGBA8 |
|
||
| Mipmap | 根据 `desc.mipLevels` |
|
||
| 类型 | GL_UNSIGNED_BYTE |
|
||
|
||
## 参数
|
||
|
||
- `desc` - 纹理描述符
|
||
|
||
### TextureDesc 字段
|
||
|
||
| 字段 | 描述 |
|
||
|------|------|
|
||
| `textureType` | 纹理类型 (0=1D, 1=2D, 2=3D, 3=Cube) |
|
||
| `width` | 纹理宽度 |
|
||
| `height` | 纹理高度 |
|
||
| `depth` | 纹理深度(用于 3D 纹理) |
|
||
| `mipLevels` | Mipmap 级别数量 |
|
||
|
||
## 返回值
|
||
|
||
`RHITexture*` - 创建的纹理指针
|
||
|
||
## 注意事项
|
||
|
||
- 当前实现创建的纹理初始数据为 `nullptr`(空纹理)
|
||
- 返回的纹理对象归调用者所有,需自行管理生命周期
|
||
- 1D 纹理使用 `height=1`,3D 纹理使用 `depth` 参数
|
||
|
||
## 示例
|
||
|
||
```cpp
|
||
// 创建 2D 纹理
|
||
TextureDesc tex2dDesc;
|
||
tex2dDesc.textureType = 1; // Texture2D
|
||
tex2dDesc.width = 1024;
|
||
tex2dDesc.height = 1024;
|
||
tex2dDesc.mipLevels = 1;
|
||
|
||
RHITexture* tex2d = device.CreateTexture(tex2dDesc);
|
||
|
||
// 创建立方体纹理
|
||
TextureDesc texCubeDesc;
|
||
texCubeDesc.textureType = 3; // TextureCube
|
||
texCubeDesc.width = 512;
|
||
texCubeDesc.height = 512;
|
||
texCubeDesc.mipLevels = 1;
|
||
|
||
RHITexture* texCube = device.CreateTexture(texCubeDesc);
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [OpenGLDevice](device.md) - 类总览
|
||
- [OpenGLTexture](../opengl-texture.md) - OpenGL 纹理实现
|