As I know, OpenGL has highly supported NPOT textures since 3.0. Now I' m facing an bizarre phenomenon that NPOT texture cannot be allocated with precise corresponding data.
Words are plain. My testing code is as below.

As code shown above, I need to allocate an NPOT cubic texture of 2^N +1. But program will exit error on glTexImage3D(). The error, I think, is caused by "the size of data less than the texture needed". Because if I allocate data larger enough, the program will pass.
Could anybody please explain this thing for me? I think it is a hardware-related question. Anyway, how could I use NPOT texture and allocate data like this? Even though when the size of data is larger enough the program passes, I am really not sure about how data exactly corresponds to the texture location then.
PS. My graphic card is quadro fx 4800, which supports OpenGL 3.3.

To fix it you could either:
a) set your data to 516x513x513 (513*1 byte/pixel rounded up to next multiple of 4) + only fill the first 513 bytes.
b) call glPixelStorei(GL_PACK_ALIGNMENT, 1), but it could have performance consequences.

To fix it you could either:
a) set your data to 516x513x513 (513*1 byte/pixel rounded up to next multiple of 4) + only fill the first 513 bytes.
b) call glPixelStorei(GL_PACK_ALIGNMENT, 1), but it could have performance consequences.

Thanks a lot! I didn' t know this well before.
About performance consequences, will it avoid the influence if I use PBO to upload texture data, compared to directly uploading data?