格式和内部格式之间的区别 [英] Difference between format and internalformat

查看:140
本文介绍了格式和内部格式之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实搜索并阅读了有关此内容,但听不懂.

I did search and read stuff about this but couldn't understand it.

纹理内部格式和调用之类的格式之间有什么区别

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

?

让我们假设data是一个32 x 32像素值的数组,其中红色,绿色,蓝色和alpha的每个像素有四个字节(无符号字符数据0-255).

Let's assume that data is an array of 32 x 32 pixel values where there are four bytes per each pixel (unsigned char data 0-255) for red, green, blue and alpha.

第一个GL_RGBA和第二个GL_RGBA有什么区别?为什么GL_RGBA_INTEGER在这种情况下无效?

What's the difference between the first GL_RGBA and the second one? Why is GL_RGBA_INTEGER invalid in this context?

推荐答案

format (第7个参数)与 type 参数一起描述了数据作为最后一个参数传递.因此, format / type 组合定义了您传入的 data 的内存布局.

The format (7th argument), together with the type argument, describes the data you pass in as the last argument. So the format/type combination defines the memory layout of the data you pass in.

internalFormat (第二个参数)定义OpenGL内部存储数据时应使用的格式.

internalFormat (2nd argument) defines the format that OpenGL should use to store the data internally.

通常,两者会非常相似.实际上,使两种格式直接兼容是有益的.否则,在加载数据时会发生转换,这会损害性能.完全OpenGL允许需要转换的组合,而OpenGL ES限制了受支持的组合,因此在大多数情况下不需要转换.

Often times, the two will be very similar. And in fact, it is beneficial to make the two formats directly compatible. Otherwise there will be a conversion while loading the data, which can hurt performance. Full OpenGL allows combinations that require conversions, while OpenGL ES limits the supported combinations so that conversions are not needed in most cases.

在这种情况下,GL_RGBA_INTEGER不合法的原因是存在关于在 format internalFormat 之间进行哪些转换的规则.在这种情况下, internalFormat GL_RGBA指定规范化格式,而 format GL_RGBA_INTEGER指定输入由应该用作整数的值组成.两者之间未定义任何转换.

The reason GL_RGBA_INTEGER is not legal in this case that there are rules about which conversions between format and internalFormat are supported. In this case, GL_RGBA for the internalFormat specifies a normalized format, while GL_RGBA_INTEGER for format specifies that the input consists of values that should be used as integers. There is no conversion defined between these two.

尽管仍然支持 internalFormat GL_RGBA以便向后兼容,但在现代OpenGL版本中, internalFormat 通常使用大小类型.例如,如果要将数据存储为每个组件RGBA图像8位,则 internalFormat 的值为GL_RGBA8.

While GL_RGBA for internalFormat is still supported for backwards compatibility, sized types are generally used for internalFormat in modern versions of OpenGL. For example, if you want to store the data as an 8-bit per component RGBA image, the value for internalFormat is GL_RGBA8.

坦率地说,我认为将会有更干净的方法来定义这些API.但这只是它的工作方式.它在某种程度上演变为保持向后兼容向OpenGL版本的向后兼容,在OpenGL版本中,功能受到更多限制.较新版本的OpenGL添加了glTexStorage*()入口点,这使其中的一些更好,因为它将内部数据分配和数据规范分开了.

Frankly, I think there would be cleaner ways of defining these APIs. But this is just the way it works. Partly it evolved this way to maintain backwards compatibility to OpenGL versions where features were much more limited. Newer versions of OpenGL add the glTexStorage*() entry points, which make some of this nicer because it separates the internal data allocation and the specification of the data.

这篇关于格式和内部格式之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆