所以我正在制作一个简单的3D立体(2视口)迷宫游戏,世界是10 x 10立方体宽。我在Android JAVA而不是NDK中运行它。在Nexus 5上,我得到大约55-58fps,然后下降到40左右。看到像Minecraft这样的东西必须有数千个立方体,我预计永久性的60fps。
我最多渲染80个立方体(+ 1个球体,2个广告牌)(10 x 10 - 实际路径),它们有纹理,我的片段着色器上有每像素点亮(这是一个恐怖游戏)
有什么建议吗?它可能是纹理吗?
private void drawScene(float[] VMatrix, float[] PMatrix) {
GLES20.glDisable(GLES20.GL_BLEND);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glEnable(GLES20.GL_CULL_FACE);
GLES20.glCullFace(GLES20.GL_BACK);
// Static map walls (repeated textures
leftWall.draw(VMatrix, PMatrix);
rightWall.draw(VMatrix, PMatrix);
backWall.draw(VMatrix, PMatrix);
frontWall.draw(VMatrix, PMatrix);
// Render Maze made out of Cubes (Maze is up to 10 x 10 cubes) textured
if (cubeList != null) {
for (Cube placeMarker : cubeList) {
if (placeMarker.loadedTexture == false) {
placeMarker.loadPlacemarkerTextures();
}
float cutOff = (Constants.SIZE_WORLD * Constants.SIZE_CUBE) / 2;
if (mCamera.mPosX + cutOff < placeMarker.position.x || mCamera.mPosZ - cutOff > placeMarker.position.z) {
placeMarker.draw(VMatrix, PMatrix);
} else {
placeMarker.draw(VMatrix, PMatrix);
}
}
}
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE);
// So you can see the text
GLES20.glDisable(GLES20.GL_CULL_FACE);
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
//GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
// Render GLTEXT
if (message.length() > 0)
{
drawTextInFront(VMatrix, PMatrix, 0.01f, message);
}
// Render monsters (BIllboards, only 2 in game)
for (GameTrigger trigger : triggers) {
//Matrix.multiplyMM(mMVPMatrix, 0, PMatrix, 0, VMatrix, 0);
if (trigger.triggered == true && trigger.sprite != null) {
trigger.sprite.rotation = new Vector3(0, -mCamera.mYaw, 0);
trigger.sprite.draw(VMatrix, PMatrix);
}
}
// render a Sphere as the game goal
sphere.draw(VMatrix, PMatrix);
}