【问题标题】:What does immutable texture mean?不可变纹理是什么意思?
【发布时间】:2013-07-24 22:58:26
【问题描述】:

ARB_texture_storage 被引入 OpenGL 4.2 核心。

你能解释一下纹理对象的不变性是什么意思吗?

为什么它比以前的纹理使用更好,这个功能有什么缺点?

我知道我可以阅读此扩展程序的规范(我做过 :)),但我希望看到一些示例或其他解释。

【问题讨论】:

  • "这个特性有什么缺点?" 事实上它不在 OpenGL 1.1 中。
  • 它基本上修复了 OpenGL 中的设计缺陷。除了极少数真正有趣的功能外,大多数现代 OpenGL 都是关于 API 更改而不是提供新功能。事实是,现在我们对 GPU 功能有了一个准确的想法(新东西还有空间,嗯 XD),我们需要更好、更一致的 API 来为用户提供功能。

标签: opengl textures opengl-4


【解决方案1】:

只需阅读扩展本身的介绍:

The texture image specification commands in OpenGL allow each level
to be separately specified with different sizes, formats, types and
so on, and only imposes consistency checks at draw time. This adds
overhead for implementations.

This extension provides a mechanism for specifying the entire
structure of a texture in a single call, allowing certain
consistency checks and memory allocations to be done up front. Once
specified, the format and dimensions of the image array become
immutable, to simplify completeness checks in the implementation.

When using this extension, it is no longer possible to supply texture
data using TexImage*. Instead, data can be uploaded using TexSubImage*,
or produced by other means (such as render-to-texture, mipmap generation,
or rendering to a sibling EGLImage).

This extension has complicated interactions with other extensions.
The goal of most of these interactions is to ensure that a texture
is always mipmap complete (and cube complete for cubemap textures).

明显的优势是该实现可以在运行时移除完整性/一致性检查,并且您的代码更加健壮,因为您不会意外创建错误的纹理。


详细说明:这里的“不可变”意味着纹理存储(纹理的三个组成部分之一:存储、采样、参数)被分配一次并且它是已经完成。请注意,存储并不意味着存储内容——它们可以随时更改;它指的是为这些内容(如 malloc)获取资源的逻辑过程。

使用非不可变纹理,您可以通过glTexImage<N>D 调用随时更改存储。以这种方式射击自己的脚有很多方法:

  • 您可以创建 mipmap-incomplete 纹理(可能是纹理最常见的新手错误,因为纹理默认有 1000 个 mipmap 级别,而人们只上传一张图像)
  • 您可以在不同的 mipmap 级别创建具有不同格式的纹理(非法)
  • 您可以创建立方体贴图不完整的立方体贴图(非法)
  • 您可以在不同的面上创建具有不同格式的立方体贴图(非法)

由于您可以在任何时间调用glTexImage<N>D,因此实现必须始终在绘制时间检查您的纹理是否合法。不可变存储总是以正确的格式一次性分配所有内容(所有 mipmap 级别、所有立方体贴图面等),从而为您做正确的事情。因此,您不能再(轻易地)搞砸纹理,并且实现可以删除一些检查,从而加快速度。每个人都很高兴:)

【讨论】:

  • 感谢您的回答。我看到总的来说,这个扩展降低了复杂性并且应该提高速度。当您从磁盘加载一个简单的纹理时,您应该使用 TexStorage2D 预先完成所有工作。
  • @fen “当你从磁盘加载一个简单的纹理时” - 不,应该是“当你有任何纹理时”。
猜你喜欢
  • 2010-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多