不可变纹理是什么意思?

时间:2013-07-25 07:17:59

标签: opengl textures opengl-4

ARB_texture_storage被引入OpenGL 4.2核心。

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

为什么从以前的纹理使用情况来看更好,这个功能的缺点是什么?

我知道我可以阅读这个扩展的规范(我做了:)),但我想看一些例子或其他解释。

1 个答案:

答案 0 :(得分:15)

请阅读扩展程序本身的介绍:

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级别,所有立方体图面等),不可变存储始终为您做正确的事情。因此,您不能再轻松搞砸一个纹理,并且实现可以删除一些检查,从而加快速度。每个人都很高兴:)