我在我的opengl 2.0遊戲中有性能問題。在我改變遊戲之前,幀率是好的。它有64種形狀(磚塊)的某種爆發遊戲。我現在想要的是,當球擊中磚塊時,它不會立即移除 - 它會改變狀態,包括改變紋理或更正確 - 地圖集的uv座標。我有一個textureatlas,我所做的只是爲循環中的每個紋理調用GLES20.bindBuffer(),而不是調用循環外部。此前我有同樣的UV-座標爲各種形狀,但現在我把它取決於磚狀態改變,這就是爲什麼我需要使用綁定環路OpenGL ES 2.0:性能下降使用bindbuffer頻繁
private void drawShape() {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboDataListLevelSprites.get(iName).getBuff_id_vertices());
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, 0);
//used this snipped before when using the same image (uv-coords) for all bricks
/*GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboDataListLevelSprites.get(iName).getBuff_id_uvs());
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, 2, GLES20.GL_FLOAT, false, 0, 0);
*/
for (Iterator<BrickProperties> it = arrayListBricks.iterator(); it.hasNext();) {
BrickProperties bp = it.next();
//now bindbuffer inside loop just too switch uv-coords of the atlas when its time to use another image
int buffIndexVal = bp.get_status_diff();
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, BrickProperties.get_buff_id_uvs()[buffIndexVal]);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, 2, GLES20.GL_FLOAT, false, 0, 0);
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, bp.getTranslateData()[0], bp.getTranslateData()[1], bp.getTranslateData()[2]);
if (bp.get_status() == 0) {
it.remove();
}
render();
}
}
private void render() {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
}
我明白其中的道理,以業績下滑裏面所有的bindbuffer調用GPU,但我怎麼可能解決這個問題?
謝謝 - 我會仔細研究一下。我想我找到了問題 – java