View Full Version : sampling from a non-existing texture

10-03-2013, 09:46 AM

I have a shader in which i use the texture() function to lookup from a non-existing sampler. I expected that I should get errors from complingmy shader. But it compiles clean.

static const char render_fs[] =
"#version 430 core\n"
"layout (location = 0) out vec4 color;\n"
"uniform sampler2D output_image;\n"
"void main(void)\n"
" color = texture(output_image1, vec2(gl_FragCoord.xy) / vec2(textureSize(output_image, 0)));\n"
" if(color.r < 0.0) {color=vec4(1.0,0.0,0.0,1.0);} else{color=vec4(0.0,1.0,0.0,0.0);}\n"

Note: I am sampling from output_image1 instead of output_image.output_image1 is an intentional typo.

Also, if it compiles and links cleanly, I would have expected it to go to the else part of the test color.r < 0.0 , since color would be undefined. (Really, I should be getting an error since how on earth can you be trying to access .r from an undefined color. Or am i returning some default value if the texture being sampled is undefined/errornous??)

It appears that I get a white color render instead of erroring out or a green screen ( color assigned from the else part).

10-04-2013, 02:22 AM
On Radeon 7870 with Catalyst 13.4

ERROR: 0:9: error(#143) Undeclared identifier: output_image1
ERROR: 0:9: error(#202) No matching overloaded function found: texture
WARNING: 0:9: warning(#402) Implicit truncation of vector from size: 1 to size: 4
ERROR: error(#273) 2 compilation errors. No code generate