tôi đã có ba GLSL thuộc tính trong vertex tôiOpenGL shader không thể ràng buộc thuộc tính
attribute highp vec4 Position;
attribute mediump vec4 UV;
attribute mediump vec3 Normal;
mà im ràng buộc sử dụng
glBindAttribLocation(program, 0, "Position");
glBindAttribLocation(program, 1, "Normal");
glBindAttribLocation(program, 2, "UV");
Tuy nhiên, tôi nhận được một lỗi
Không thể tìm thấy thuộc tính shader vertex 'Normal' để khớp với yêu cầu BindAttributeLocation.
Tại sao nó có thể tìm thấy thuộc tính Vị trí và UV nhưng không tìm thấy thuộc tính Thông thường.
Mọi trợ giúp sẽ được đánh giá cao vì tôi khá bối rối.
Cheers
Edit: Tôi có cùng một vấn đề trên Android OpenGLES20. Tôi sẽ thêm mẫu mã: phần còn lại của lớp là GLSurfaceView hướng dẫn chính thức
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.
}
Tôi nên thêm rằng tôi đã thử trình đổ bóng để đảm bảo các sửa đổi hoạt động chính xác, nhưng vẫn không thể liên kết thuộc tính thông thường – user346443
Bạn nhận được lỗi này từ đâu? – kvark
Tôi nên chỉ ra rằng tôi có cùng một vấn đề chính xác "đôi khi" trên Android OpenGLES20. Đi theo hướng dẫn, thêm "bình thường", "aNormal", "norm", "any" vào mã trình tạo mẫu, cố gắng liên kết nó ngay sau đó và nó bị treo. –