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 " +
"v开发者_开发百科arying 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.
}
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
Are you sure you are passing the correct index to the shader? You could try getting the index by calling
glGetAttribLocation(program,"Normal");
精彩评论