Opengl 不变的纹理意味着什么?

Opengl 不变的纹理意味着什么?,opengl,textures,opengl-4,Opengl,Textures,Opengl 4,被引入OpenGL 4.2内核 你能解释一下纹理对象的不变性意味着什么吗 为什么它比以前使用的纹理更好?此功能的缺点是什么 我知道我可以阅读这个扩展的规范(我读过:),但我想看一些示例或其他解释。只要阅读扩展本身的介绍: The texture image specification commands in OpenGL allow each level to be separately specified with different sizes, formats, types and so

被引入OpenGL 4.2内核

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

为什么它比以前使用的纹理更好?此功能的缺点是什么


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

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

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)获取资源的逻辑过程

对于非不变纹理,您可以通过
glTexImageD
调用随时更改存储。有很多方法可以用这种方式射中自己的脚:

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

由于允许您随时调用
glTexImageD
,因此实现必须在绘制时始终检查您的纹理是否合法。不可变存储总是以正确的格式一次分配所有内容(所有mipmap级别、所有cubemap面等),为您做正确的事情。因此,您不能再(轻松地)破坏纹理了,而实现可以删除一些检查,从而加快速度。每个人都很高兴:)

“这个功能的缺点是什么?”事实上它不在OpenGL 1.1中。它的可能复制基本上修复了OpenGL中的设计缺陷。除了极少数真正有趣的功能外,现代OpenGL的大部分功能都是关于API的更改,而不是提供新的功能。事实上,现在我们已经对GPU功能有了一个精确的概念(仍然有空间容纳新的东西eh XD),我们需要更好、更一致的API来为用户提供能力。感谢aswer。我看到,一般来说,这种扩展降低了复杂性,应该可以提高速度。当从磁盘加载简单纹理时,应使用TexStorage2D提前完成所有工作。@fen“当从磁盘加载简单纹理时”-否,应为“当您有任何纹理时”。