Texture memory alignment question

Started by
2 comments, last by Vortez 10 years, 3 months ago

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?

Advertisement

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)

Ok thx, ill try it out.

And ill make sure to rate you up later when i have more points to spend :) .

That seem to do the trick!

This topic is closed to new replies.

Advertisement