Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL shader cant bind attribute

i've got three glsl attributes in my vertex shader

attribute highp   vec4  Position;
attribute mediump vec4  UV;
attribute mediump vec3  Normal;

that im binding using

glBindAttribLocation(program, 0, "Position");
glBindAttribLocation(program, 1, "Normal");
glBindAttribLocation(program, 2, "UV");

However, i'm getting an error

Could not find vertex shader attribute 'Normal' to match BindAttributeLocation request.

Why can it find the Position and UV attributes but not the Normal attribute.

Any help would be highly appreciated as i'm pretty confused.

Cheers

Edit: I have the same issue on Android OpenGLES20. I'll add sample code : the rest of the class is the official GLSurfaceView tutorial

public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {

    String mVertexShader =  "uniform mat4 uMVPMatrix;\n " +
            "attribute vec4 aPosition;\n " +
            "attribute vec4 aNormal; \n " + //this is the line I added
            "attribute vec2 aTextureCoord;\n " +
            "varying vec2 vTextureCoord;\n " +
            "void main() {\n " +
            "gl_Position = uMVPMatrix * aPosition;\n" +
            "  vTextureCoord = aTextureCoord;\n" +
            "}\n";

    mProgram = createProgram(mVertexShader, mFragmentShader); // cf tutorial
    if (mProgram == 0) {
        return;
    }
    initShaderHandles(); //initializes the rest of the handles (cf tutorial)

     // my little additional code
    int maNormalHandle = GLES20.glGetAttribLocation(mProgram, "aNormal");
    Log.d("ATTRIB LOCATION Normal: ", maNormalHandle + "");
    checkGlError("glGetAttribLocation normal");
    if (maNormalHandle == -1) {
        throw new RuntimeException(
                "Could not get attrib location for normal");
    }
    // ...and we crash.

}
like image 842
user346443 Avatar asked Jul 12 '11 15:07

user346443


1 Answers

Are you using the normal in the shader or else it can be optimized out by the glsl-compiler. If it is something else please show us your shaders

like image 198
Rickard Avatar answered Jan 03 '23 19:01

Rickard