Files
XCEngine/docs/api/rhi/opengl/device/create-texture.md
ssdfasd b414bc5326 refactor(docs): Fix broken links across multiple modules
Fixed broken references:
- texture-import-settings: Fix 16 files referencing wrong overview filename
- math/rectint: Fix 9 method links (rectint-* → get*, contains, intersects)
- rhi/opengl/device: Fix 8 cross-references (opengl-* → */**)
- resources/mesh: Fix meshsection and vertexattribute links
- rhi/d3d12/sampler: Fix RHISampler reference path
- math/vector3: Fix projectonplane → project-on-plane
- rhi/opengl/command-list: Remove broken ClearFlag enum ref
- rhi/opengl/device: Create 2 new method docs (MakeContextCurrent, GetNativeContext)
- rhi/device: Fix device-info types reference

All 0 broken references remaining.
2026-03-26 02:41:00 +08:00

1.8 KiB
Raw Blame History

OpenGLDevice::CreateTexture

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=13D 纹理使用 depth 参数

示例

// 创建 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);

相关文档