我的顶点着色器中有三个glsl属性
attribute highp vec4 Position;
attribute mediump vec4 UV;
attribute mediump vec3 Normal;
使用
进行即时绑定glBindAttribLocation(program, 0, "Position");
glBindAttribLocation(program, 1, "Normal");
glBindAttribLocation(program, 2, "UV");
但是,我收到了错误
无法找到顶点着色器属性“Normal”以匹配BindAttributeLocation请求。
为什么它可以找到Position和UV属性,但不能找到Normal属性。
任何帮助都会受到高度赞赏,因为我很困惑。
干杯
编辑: 我在Android OpenGLES20上遇到了同样的问题。 我将添加示例代码:该类的其余部分是官方的GLSurfaceView教程
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.
}
答案 0 :(得分:15)
您是在着色器中使用法线还是可以通过glsl-compiler进行优化。如果是其他内容请向我们展示您的着色器
答案 1 :(得分:0)
您确定要将正确的索引传递给着色器吗? 您可以尝试通过调用
来获取索引glGetAttribLocation(program,"Normal");