GL_RGB or GL_BGR in TEXTURE_2D_ARRAY?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

GL_RGB or GL_BGR in TEXTURE_2D_ARRAY?

PJDM
I'm using

gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, GL3.GL_RGB, 64, 64, 5, 0, GL3.GL_RGB, GL3.GL_UNSIGNED_BYTE, null);
for(int i=0; i<5; i++)
{
  data = ...
  gl.glTexSubImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, 64, 64, 1, GL3.GL_BGR, GL3.GL_UNSIGNED_BYTE, data.getBuffer());
}

to load 5 64x64 png images into a 2D texture array. Note that glTexImage3D uses GL_RGB, but glTexSubImage3D uses GL_GBR. If I use GL_RGB in both calls, the images when displayed have their reds and blues swapped. I would expect that the format value in each call should be the same, but the code above works as-is.

What's going on here? What don't I understand?

(jogl-2.0-b23-20110303-windows-amd64 on Windows 7)

Thanks.

PJDM
Reply | Threaded
Open this post in threaded view
|

Re: GL_RGB or GL_BGR in TEXTURE_2D_ARRAY?

Worker
Oh man

make a simple

gl.glTexImage2D( GL2.GL_TEXTURE_2D, 0, textures[0].getPixelOrCompressionsFormat(), textures[0].getWidth(), textures[0].getHeight(), 0, textures[0].getPixelOrCompressionsFormat(), GL2.GL_UNSIGNED_BYTE, datas);

and it works .
Reply | Threaded
Open this post in threaded view
|

Re: GL_RGB or GL_BGR in TEXTURE_2D_ARRAY?

PJDM
There is no .getPixelOrCompressionsFormat() method, but changing the code to the following works, and is obviously more flexible.

        gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, data.getInternalFormat(), 64, 64, 5, 0, data.getPixelFormat(), GL3.GL_UNSIGNED_BYTE, null);
...
            gl.glTexSubImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, 64, 64, 1, data.getPixelFormat(), GL3.GL_UNSIGNED_BYTE, data.getBuffer());

Yes, hard-coding widths and heights is also bad. :-)

Thanks.

PJDM
Reply | Threaded
Open this post in threaded view
|

Re: GL_RGB or GL_BGR in TEXTURE_2D_ARRAY?

Worker
Ah sorry

textures[0].getPixelOrCompressionsFormat() means GL_RGB/GL_RGBA and so, or e.g. when you work with compressed dds-textures the dds-compression-format.