OpenGL Shader Link Attribute

I have three glsl attributes in my vertex shader

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

what im binding using

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

However, I get an error

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

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

Any help would be greatly appreciated as I am rather confused.

Greetings

Edit: I have the same problem on Android OpenGLES20. I'll add an example 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. } 
+6
source share
2 answers

Do you use regular mode in the shader, otherwise it can be optimized by the glsl compiler. If this is something else, please show us your shaders.

+15
source

Are you sure you are passing the correct pointer to the shader? You can try to get the index by calling

 glGetAttribLocation(program,"Normal"); 
0
source

Source: https://habr.com/ru/post/892589/


All Articles