Files
XCEngine/docs/api/XCEngine/RHI/OpenGL/OpenGLTextureUnitAllocator/BindTexture.md

994 B
Raw Blame History

OpenGLTextureUnitAllocator::BindTexture

void BindTexture(int32_t unit, OpenGLTexture* texture);

作用

把纹理绑定到指定 texture unit并更新分配器缓存。

参数说明

  • unit: 目标纹理单元。
  • texture: 需要绑定的纹理对象;可为空。

当前实现行为

  • 非法 unit 直接返回。
  • 调用 glActiveTexture(GL_TEXTURE0 + unit)
  • 如果 texture 非空:
    • 使用 texture->GetOpenGLType() 作为绑定目标
    • 使用 texture->GetID() 作为纹理 id
  • 如果 texture == nullptr:
    • 执行 glBindTexture(GL_TEXTURE_2D, 0)
  • 最后把 m_boundTextures[unit] 缓存为该纹理指针。

重要限制

  • 该函数会修改当前 active texture unit但不会恢复之前的活动单元。
  • 空纹理解绑路径固定写死为 GL_TEXTURE_2D,并不区分先前绑定的是 3D、cubemap 或 array 纹理。

相关文档