NPOT texture allocating problem

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.


	glGenTextures(1, &texVoxels);
	glBindTexture(GL_TEXTURE_3D, texVoxels);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

	int width = 513;
	int height = 513;
	int depth = 513;
	unsigned char *data = new unsigned char[width*height*depth];
	memset(data, 0, sizeof(unsigned char)*width*height*depth);

	glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE8, width, height,depth, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);

	delete []data;
	data = NULL;

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.

Best regards.

Pixel rows must be aligned on a 4-byte boundary if you are using OpenGL’s initial value for GL_PACK_ALIGNMENT. See http://www.opengl.org/sdk/docs/man/xhtml/glPixelStore.xml

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.

[QUOTE=Dan Bartlett;1243429]Pixel rows must be aligned on a 4-byte boundary if you are using OpenGL’s initial value for GL_PACK_ALIGNMENT. See http://www.opengl.org/sdk/docs/man/xhtml/glPixelStore.xml

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.[/QUOTE]

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?