Hi,
I wrote code for grabbing some screenshots using a PBO. it works well - but only with certain window sizes. 800x600 works fine. With 961x713, the PBO contains only black pixels. 1268 x 942 works fine again.
What is going on here? Are there any size restrictions I am unaware of? Already tried 962x714, it gives me a black shot too, so the restriction doesnt seem to be even-sizes-only.
Just a quick clarification…From what I understood, you need to call glPixelStore once, before you start playing arround with your TexImage calls or PBO calls. You do NOT need to call it everytime you bind a texture or a buffer, right?
So, I’m guessing if this only affects one particular area of your code…it’s probably best to have something like:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
/*
lots of code here that does PBO operations and
glBindTexture, glTexSubImage2D, etc.
*/
// set it back to it’s default value so you don’t mess other things up.
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
Am I right in assuming this? (or do I need to call it more often?).
Yes, you are right.
According to the specs, the GL_UNPACK_ALIGNMENT flag is initialized to 4.
But as said before, you might want to change the GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_ROWS, GL_UNPACK_SKIP_PIXELS values to only download/upload a subrectangle of a given texture/image.
Therefore, i would advise you to call:
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); // Save state
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Maybe some other glPixelStorei calls
and
glPopClientAttrib(); // Back to the previous state
Rather than
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
and
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
sure thing…pushing and popping is much better…
But still, do I need to call all the glPixelStore stuff ONCE, or do I need to call them everytime I bind a texture/buffer?