我已經有一個程序繪製了90個2D形狀,帶有紋理,用戶可以通過觸摸屏幕進行拾取和拖動。有很明顯的不連貫性,DDMS告訴我,佔用CPU時間最多(〜85%)的一種方法是draw()方法。由於實際上只有一個形狀正在移動,而其他89個形狀不移動,使用FrameBuffer對象將89個形狀渲染爲紋理並在填充整個屏幕的形狀上繪製該紋理可能會更快/更快?如果沒有,有沒有其他可能的加速方法?OpenGL ES2:使用FrameBuffer對象更快地渲染多個形狀
private void draw() {
// Pass in the position information
mCubePositions.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, mCubePositions);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the color information
mCubeColors.position(0);
GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false, 0, mCubeColors);
GLES20.glEnableVertexAttribArray(mColorHandle);
// Pass in the texture coordinate information
mCubeTextureCoordinates.position(0);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false, 0, mCubeTextureCoordinates);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
// This multiplies the view matrix by the model matrix, and stores the
// result in the MVP matrix
// (which currently contains model * view).
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
// This multiplies the modelview matrix by the projection matrix, and
// stores the result in the MVP matrix
// (which now contains model * view * projection).
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
}
在此先感謝。
我在S5570上運行。大多數立方體非常小,改變尺寸對幀率沒有明顯影響。立方體的數量,大小和紋理根據其他立方體的位置而變化很大,每次用戶完成拖動形狀時都會發生變化。重新調整一個ArrayList並將其轉換爲一個數組並且每次都是低效率的多維數據集?我怎樣才能讓一個繪畫調用從一個數組渲染單獨的形狀? –
感謝您的詳細回覆。但有一個問題:這種方法是否允許不。立方體的繪製和沒有。的紋理支持在飛行中增加或減少? –
是的,儘管我建議您決定最大數量的多維數據集,並預先分配這個最大數據結構,以避免動態分配。在上面的例子中,例如,我已經允許最多16個紋理。 –