Sign in to follow this  
Vortez

Texture memory alignment question

Recommended Posts

Vortez    2714

This is a follow-up of my previous thread.

 

Yesterday, i was trying my project on a resolution of 1366x768 and found the following bug. I didn't take long for me to realize what was wrong.

Im extracting the image from win32 DIBs bitmaps and they are padded to be aligned to 4 bytes, and 1366 is not aligned, so the extra 2 bytes was getting in the way.

So, i rewrote the algorithm to take padding into account and fixed the bug. However, im wondering if that was not a mistake.

 

If i continue on this path, and go for lower than 8 bpp, the algorithm is gonna get very messy. Ex 1366 / 8 = 170.75. That mean i would have to shift bits all around and such.

 

Then, it hit me, what if i leaved the padding as it is, and use

 

glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

 

instead of

 

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

 

would that solve the issue?

Edited by Vortez

Share this post


Link to post
Share on other sites
richardurich    1352

Yes. GL_UNPACK_ALIGNMENT from the spec: "Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries)." (http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)

Share this post


Link to post
Share on other sites

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