Sign in to follow this  

*ALIGNMENT parameter of function glPixelStore()

This topic is 3842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
"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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

This topic is 3842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this