*ALIGNMENT parameter of function glPixelStore()

Started by
3 comments, last by Brother Bob 16 years, 10 months ago
Hello all!I read chapter 8 of redbook,and I don't understand what does the *alignment parameter of function glPixelStore().Can someone help me?And if it's possible can you give me some examples of what does this parameter,because I think I will understand in this mode.
Advertisement
GL_UNPACK_ALIGNMENT is used when you upload some texture or bitmap to GL
It effect glTexImage2D and glDrawPixels and other functions.
GL_PACK_ALIGNMENT is for download : glReadPixels, glGetTexImage

It's for improving performance. For example, if you will be using 24 bit texture, in some cases the width is not a multiple of 4.
Example :
width = 3 pixels

3 bytes is not a multiple of 4, so it must be padded by 1 byte.
As you might know, computers prefer 4 bytes, 8, 16 and so on.

But to keep is simple, just use 32 bit textures and leave GL_UNPACK_ALIGNMENT and GL_PACK_ALIGNMENT at their default values : 4

Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
"3 bytes is not a multiple of 4, so it must be padded by 1 byte."
In this case alignment must be set to 1?If so,you said:
"But to keep is simple, just use 32 bit textures and leave GL_UNPACK_ALIGNMENT and GL_PACK_ALIGNMENT at their default values : 4"
32 bits=4 bytes(multiple of 4) => it must not be padded by any value(because it's a multiple of 4).So,why the default value is 4?
PS:I didn't find a quote button,and sorry for bad english.
That's correct. You either set alignement = 1 or you pad it yourself.
In some cases, it's already padded. BMP files contain this kind of padding.

I don't know why the default value is 4. It's is rather arbitrary very much like what is the default state of GL_TEXTURE_2D? Enable or not?
How about depth testing? How about stencil testing?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by V-man
I don't know why the default value is 4. It's is rather arbitrary very much like what is the default state of GL_TEXTURE_2D? Enable or not?
How about depth testing? How about stencil testing?

As some platform flat out refuses data access on unaligned memory, I assume the default alignment is becuase some platforms simply cannot trivially copy lines which does not begin on an unaligned address. Setting a non-default alignment may cause some OpenGL implementation to use special code (inefficient regarding memory accesses) for unaligned access.

Personally, I don't see any of the default states as arbitrary choises. All but one state (dithering) are disabled by default. And otherwise, the common rule being that default states repreresents a no-op (GL_ONE and GL_ZERO blend function for example), or the intuitive state (GL_LESS for depth testing; draw only the object closest).

This topic is closed to new replies.

Advertisement