Sampling OpenGL without texture binding

When fetching textures in GLSL, for example:

vec4 color = texture(mySampler, myCoords); 

If the textures are not tied to mySampler, the color always appears (0, 0, 0, 1).

Is this standard behavior? Or maybe undefined for some implementations? I could not find anything in the specifications.

+6
source share
2 answers

There really isnโ€™t such a thing as โ€œunboundโ€ โ€”you are just tied to the original texture object, which is known as texture 0. According to the OpenGL wiki ( http://www.opengl.org/wiki/OpenGL_Objects ),

 You are strongly encouraged to think of texture 0 as a non-existent texture. 

Ultimately, the value you are going to get in the shader depends on what happens in texture object 0 at that time. I can find nothing but one forum post that actually says it should be:

 The texture 0 represents an actual texture object, the default texture. All textures start out as 1x1 white textures. 

Of course, I would not trust that it is consistent in all drivers of GPUs, yours can be initialized to all zero or can be considered an incomplete texture, in which case the OpenGL specification (at least 2.0 and later)

 If a fragment shader uses a sampler whose associated texture object is not complete, the texture image unit will return (R, G, B, A) = (0, 0, 0, 1). 

... So really the wisest course of action seems to be "don't do this." Make sure you have a valid (non-zero identification) texture border if you intend to run the sampler.

+5
source

Nathan is right (but I'm too new / reputation too small to dodge).

I / of course / saw that on some OpenGL ES platforms, using an unrelated texture will display garbage on the screen (random contents of graphic memory). You cannot trust all driver providers to follow the specifications.

Never, ever, refer to unrelated OpenGL objects or state.

+2
source

All Articles