Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - glTexImage2D with NULL pointer to texture memory: (3 Items)
   
glTexImage2D with NULL pointer to texture memory  
Just question, not a bug report, as usual :)

This is quote from OpenGL 1.5 spec:
"In OpenGL version 1.1 or greater, pixels may be a null pointer. In this case texture memory is allocated to accommodate
 a texture of width width and height height.  You can then download subtextures to initialize this texture memory. The 
image is undefined if the user tries to apply an uninitialized	portion of the texture image to a primitive."

I can't find this notice in OpenGL ES 1.0 and 1.1 specs.

I tried to do this in QNX, Looks like glTexImage2D checks for NULL pointer as pixel data and doesn't set an error. But 
later when I upload subimage using glTexSubImage2D it also doesn't set an error, but texture contains of trash pixels in
 which I can't recognize even a part of my texture.

Construction looks like:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_w, texture_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data->pixels);

Is this behavior is supported under QNX's implementation of OpenGL ES 1.0 ?

The reason to use this construction is constantly modified texture, which is need to be re-uploaded each time after 
modification. But I do not want to pass any texture an initialization time, just allocate it for future usage.
Re: glTexImage2D with NULL pointer to texture memory  
What you are trying to do, i.e. call glTexImage2D with no data to allocate memory for a texture, and then use 
glTexSubImage2D to upload data should be supported in OpenGL ES 1.0.

You can write a test app that does:
...
glBindTexImage2D(GL_TEXTURE_2D, tex1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_w, texture_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data->pixels);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glEnable(GL_TEXTURE_2D);
glDrawArrays(...);

and compare with:
...
glBindTexImage2D(GL_TEXTURE_2D, tex1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_w, texture_h, 0, GL_RGBA, GL_UNSIGNED_BUTE, NULL)
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture_w, texture_h, GL_RGBA, GL_UNSIGNED_BYTE, data->pixels);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glEnable(GL_TEXTURE_2D);
glDrawArrays(...);

Both should give the same results.

Note that the texture data may not be updated immediately after the call to glTexImage2D or glTexSubImage2D returns. A 
copy of the texture data may be held in system memory until the texture is actually needed.
Re: glTexImage2D with NULL pointer to texture memory  
> Note that the texture data may not be updated immediately after the call to 
> glTexImage2D or glTexSubImage2D returns. A copy of the texture data may be 
> held in system memory until the texture is actually needed.

Ok, thank you.