简体   繁体   中英

OpenGL ES vertex shader won't compile with a function

When I try to compile the simplified vertex shader below on Galaxy S (PowerVR SGX540, Android), it does not compile and no error is given. Just "Compile failed." is in the log.

#ifdef GL_ES
   precision mediump float;
   precision lowp int;
#endif

uniform mat4 u_m;   //model 
uniform mat4 u_mvp; //model view projection
uniform vec3 u_lightPos[1];

uniform int u_lightCount;

attribute vec3 a_position;

varying vec3 v_lightDir[1];

void pointLight(int i, vec3 vertPos){
    v_lightDir[i] = u_lightPos[i] - vertPos;
}

void main( void )
{   
    vec3 vertPos = (u_m * vec4(a_position, 1.0)).xyz;

    if(u_lightCount > 0){
        pointLight(0, vertPos);
    }

    gl_Position = u_mvp * vec4(a_position, 1.0);
}

However, when I move the function block into the main function, it compiles just fine:

#ifdef GL_ES
   precision mediump float;
   precision lowp int;
#endif

uniform mat4 u_m;   //model 
uniform mat4 u_mvp; //model view projection
uniform vec3 u_lightPos[1];

uniform int u_lightCount;

attribute vec3 a_position;

varying vec3 v_lightDir[1];

void main( void )
{   
    vec3 vertPos = (u_m * vec4(a_position, 1.0)).xyz;

    if(u_lightCount > 0){
        v_lightDir[0] = u_lightPos[0] - vertPos;
    }

    gl_Position = u_mvp * vec4(a_position, 1.0);
}

On desktop, both compiles. I can't figure out, why it behaves that way. Could anyone explain it or is it a bug inside the system?

看来您的OpenGL ES实现不支持按变量( v_lightDir[i] = ... )进行数组索引

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM