Search code examples
openglopengl-esglslshaderglsles

'texture' : no matching overloaded function found even though it *should* comply with documentation


I am trying to convert an OpenGL glsl shader into a OpenGL ES one but it doesn't seem to work that well. The shader works flawlessly in normal OpenGL but it completely breaks in OpenGL ES. Here is the normal OpenGL glsl code:

#version 330
uniform sampler2D texture0;
float amnt = 8.0;
vec2 uv = gl_FragCoord.xy / vec2(1270,720).xy;
void main() {
   float thing = -1.0; 
   if (uv.y <= 0.5) {
      thing = 1.0;
   }
   uv.y += distance(uv.x, 0.5) * (distance(uv.x, 0.5) * 0.25 ) * distance(uv.y, 0.5) * thing * amnt;

   
   
   gl_FragColor = texture(texture0, vec2(uv.x, uv.y));
}

The OpenGL ES glsl code:

precision highp float;
uniform sampler2D texture0;
void main() {

    const float amnt = 8.0; 
    const vec2 resol = vec2(1270,720); 
    vec2 uv = gl_FragCoord.xy / resol.xy;
    float thing = -1.0; 
    if (uv.y <= 0.5) {
      thing = 1.0;
    }
   uv.y += distance(uv.x, 0.5) * (distance(uv.x, 0.5) * 0.25 ) * distance(uv.y, 0.5) * thing * amnt;

   
   
   gl_FragColor = texture(texture0, vec2(uv.x, uv.y));
}

With this code I get the following errors:

SHADER_INFO_LOG:
ERROR: 0:18: 'texture' : no matching overloaded function found
ERROR: 0:18: '=' : dimension mismatch
ERROR: 0:18: 'assign' : cannot convert from 'const mediump float' to 'FragColor mediump 4-component vector of float'

Both of these shaders are fragment shaders.


Solution

  • texture() was added in #version 300 es

    #version 100 es (the default if no #version is specified) is limited to texture2D()/texture2DProj()/texture2DLod()/texture2DProjLod()/textureCube()/textureCubeLod().

    See section 8.7 "Texture Lookup Functions" (page 71-72) in the OpenGL ES Shading Language 1.00 Specification.