When sampling a texture in GLSL like this:
vec4 color = texture(mySampler, myCoords);
If there is no texture bound to mySampler, color seems to be always (0, 0, 0, 1).
Is this the standard behavior? Or may it be undefined on some implementations? I couldn't find anything in the specs.
A Sampler Object is an OpenGL Object that stores the sampling parameters for a Texture access inside of a shader.
GL_RGBA. Red, green, blue, and alpha values (RGBA)
in display() function : GLuint texture; texture = LoadTexture("bubble. png"); glBindTexture(GL_TEXTURE_2D, texture);
A texture is an OpenGL Object that contains one or more images that all have the same image format. A texture can be used in two ways: it can be the source of a texture access from a Shader, or it can be used as a render target.
There's really no such thing as being "unbound" -- you're simply bound to the initial 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're going to get in the shader depends on what happens to be in Texture Object 0 at the time. I can't really find anything except one forum post that actually says what this should be:
The texture 0 represents an actual texture object, the default texture.
All textures start out as 1x1 white textures.
I certainly wouldn't trust that to be consistent across all GPU drivers, yours might have it initialized to all zero, or it might be considered an incomplete texture, in which case the OpenGL spec (2.0 and later at least) says:
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 that." Make sure you have a valid (non-zero id) texture bound if you're going to run a sampler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With