我有一个与 [x, y, z, textureX, textureY,.....] 交错的 VBO,所有这些都可以正常工作和显示。我试图弄清楚在初始化时可以做什么并忘记了。
这是我目前正在尝试初始化的内容。
已编辑:修复了我的缓冲区的解除绑定并移动了一些代码。
mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "vPosition");
mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, glBufferObjects.get(0));
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, interleavedBuffer.capacity() * BYTES_PER_FLOAT, interleavedBuffer, GLES20.GL_STATIC_DRAW);
//////////These are superfluous but I'd like to do them once since they never change/////
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false,
INTERLEAVED_VERTEX_TEXTURE_STRIDE, 3 * BYTES_PER_FLOAT);
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
INTERLEAVED_VERTEX_TEXTURE_STRIDE, 0);
////////////////////////////////////////////////////
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix");
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, glBufferObjects.get(1));
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER,
drawListBuffer.capacity() * BYTES_PER_SHORT,
drawListBuffer,
GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
这是有效的。我弄乱了一堆,但我不知道每个并条机需要什么,因为它需要或者我做错了。任何帮助,将不胜感激。
public void draw(float[] mvpMatrix) {
GLES20.glUseProgram(mProgramHandle);
GLES20.glUniform1i(mTextureUniformHandle, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, glBufferObjects.get(0));
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, glBufferObjects.get(1));
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false,
INTERLEAVED_VERTEX_TEXTURE_STRIDE, 3 * BYTES_PER_FLOAT);
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
INTERLEAVED_VERTEX_TEXTURE_STRIDE, 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
}
编辑:更新 - 如果我删除
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false,
INTERLEAVED_VERTEX_TEXTURE_STRIDE, 3 * BYTES_PER_FLOAT);
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
INTERLEAVED_VERTEX_TEXTURE_STRIDE, 0);
从我的 draw() 它抛出一个 gl_draw_error_checks:418: GL_INVALID_OPERATION