Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

glTexImage2D null data pointer and memory initialization

Let’s assume that 2D texture is defined using glTexImage2D with the null data pointer. Does passing the null data pointer zeroes memory or I may get some garbage data when a fragment shader samples that texture ?

vec3 color = texture(texture0, texCoord).xyz;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The documentation clearly states:

data may be a null pointer. In this case, texture memory is allocated to accommodate a texture of width width and height height. … The image is undefined if the user tries to apply an uninitialized portion of the texture image to a primitive.

So yes — you will get garbage. Keep in mind that zeroes are also valid garbage, so don’t use that as a proof that it "works".

The easiest way to clear a texture to all-zeros is with glClearTexImage:

glClearTexImage(texture, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

For this function data == 0 actually means "all zeroes".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading