OpenGL纹理上传:UNSIGNED_BYTE与UNSIGNED_INT_8_8_8_8 [英] OpenGL texture upload: UNSIGNED_BYTE vs UNSIGNED_INT_8_8_8_8

查看:241
本文介绍了OpenGL纹理上传:UNSIGNED_BYTE与UNSIGNED_INT_8_8_8_8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在呼叫glTexSubImage2D.如果我的像素格式为GL_RGBA,那么像素类型GL_UNSIGNED_BYTEGL_UNSIGNED_INT_8_8_8_8是否完全等效?

I'm calling glTexSubImage2D. If my pixel format is GL_RGBA, then are the pixel types GL_UNSIGNED_BYTE and GL_UNSIGNED_INT_8_8_8_8 fully equivalent?

还有,这两对是等价的吗?

Also, are these two pairs equivalent?

  • Format = GL_RGBA, Type = GL_UNSIGNED_INT_8_8_8_8
  • Format = GL_BGRA, Type = GL_UNSIGNED_INT_8_8_8_8_REV
  • Format = GL_RGBA, Type = GL_UNSIGNED_INT_8_8_8_8
  • Format = GL_BGRA, Type = GL_UNSIGNED_INT_8_8_8_8_REV

我已经尝试阅读OpenGL规范和GL_EXT_packed_pixels规范,但是说实话,我无法理解它们的头或尾.

I've tried reading the OpenGL spec and the GL_EXT_packed_pixels spec, but honestly I can't make head or tail of them.

推荐答案

答案为否"和否".您必须考虑计算机中的字节顺序.如果您具有GL_RGBAGL_UNSIGNED_INT_8_8_8_8,则表示像素以32位整数存储,并且颜色以RGBA的逻辑顺序以这样的整数存储,例如红色在高位字节中,而alpha在低位字节中.但是,如果机器是低位字节序的(与Intel CPU一样),则内存中的实际顺序为ABGR.而GL_RGBAGL_UNSIGNED_BYTE则会以RGBA顺序存储字节,而不管计算机是低端字节序还是大端字节序.

The answers are No and No. You have to think about the byte order in your computer. If you have GL_RGBA and GL_UNSIGNED_INT_8_8_8_8, that means that pixels are stored in 32-bit integers, and the colors are in the logical order RGBA in such an integer, e.g. the red is in the high-order byte and the alpha is in the low-order byte. But if the machine is little-endian (as with Intel CPUs), it follows that the actual order in memory is ABGR. Whereas, GL_RGBA with GL_UNSIGNED_BYTE will store the bytes in RGBA order regardless whether the computer is little-endian or big-endian.

GL_BGRAGL_UNSIGNED_INT_8_8_8_8_REV会将颜色按ARGB逻辑顺序存储在整数中,但是随后在小端机器上,您将BGRA顺序存储在内存中.

GL_BGRA with GL_UNSIGNED_INT_8_8_8_8_REV would store colors in an integer in the logical order ARGB, but then on a little-endian machine, you get BGRA order in memory.

这篇关于OpenGL纹理上传:UNSIGNED_BYTE与UNSIGNED_INT_8_8_8_8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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