我的片段着色器有问题。我想获取纹理的大小(从图像加载)。
我知道可以使用textureSize(sampler)获取包含纹理大小的ivec2。但是我不知道为什么这不起作用(它不能编译):
#version 120
uniform sampler2D tex;
float textureSize;
float texelSize;
void main()
{
textureSize = textureSize(tex).x;//first line
//textureSize = 512.0;//if i set the above line as comment and use this one the shader compiles.
texelSize = 1.0 / textureSize;
vec4 color = texture2D(tex,gl_TexCoord[0].st);
gl_FragColor = color * gl_Color;
}
Run Code Online (Sandbox Code Playgroud)