Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: NPOT texture allocating problem

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    11

    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.
    Code :
    	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.

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    433
    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/x...PixelStore.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.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    11
    Quote Originally Posted by Dan Bartlett View Post
    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/x...PixelStore.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.
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •