About textureSize

bool is_empty(sampler2D s)
	ivec2 size = textureSize(s, 0);
	return size.x == 1 && size.x == 1;

void main()
	vec2 uv = fragCoord;
	vec3 c1 = texture( iChannel0, uv ).xyz;
	vec3 c2 = is_empty(iChannel1) ? vec3(1.0) : texture(iChannel1, uv).xyz;
	fragColor = vec4( c1 * c2, 1.0 );

use glBindTexture(GL_TEXTURE_2D, texID), is texture color;
use glBindTexture(GL_TEXTURE_2D, 0), is white color.

If sampler2D is empty, what is the return value of the OpenGL standard?
On my computer, the return value is ivec2 (1).
Does the standard specify a specific value for this return value? ivec2(0), ivec2(-1) or ivec2(-1)?

There is no such thing as an “empty” sampler. Texture 0 is not “not a texture”; it’s a default texture. For each of the texture types, there is an effective default texture of size 1 and is of a floating-point format with a value of 1.0.

If you want to have a sampler be “empty”, you should explicitly create a uniform to tell when the sampler should not be used by the shader.

gl1.1,Texture 0 is white,in the shader, Texture 0 is black with alpha 0.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.