繁体   English   中英

Android上使用OpenGL的低FPS

[英]Low FPS with OpenGL on Android

我联系是因为,我尝试在Android中使用openGL,以便制作2D游戏:)

这是我的工作方式:

我有一堂课GlRender

public class GlRenderer implements Renderer

在此类中,我在onDrawFrame上执行GameRender()GameDisplay()

gameDisplay()我有:

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
            // Reset the Modelview Matrix
            gl.glMatrixMode(GL10.GL_PROJECTION);    //Select The Modelview Matrix
            gl.glLoadIdentity();                    //Reset The Modelview Matrix


            // Point to our buffers
            gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

            // Set the face rotation
            gl.glFrontFace(GL10.GL_CW);

            for(Sprites...)
            {
                sprite.draw(gl, att.getX(), att.getY());
            }
            //Disable the client state before leaving
            gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
            gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

在精灵的绘制方法中,我有:

    _vertices[0] = x;
    _vertices[1] = y;

    _vertices[3] = x;
    _vertices[4] = y + height;

    _vertices[6] = x + width;
    _vertices[7] = y;   

    _vertices[9] = x + width;
    _vertices[10] = y + height; 


    if(vertexBuffer != null)
    {
        vertexBuffer.clear();
    }
    // fill the vertexBuffer with the vertices
    vertexBuffer.put(_vertices);
    // set the cursor position to the beginning of the buffer
    vertexBuffer.position(0);


    // bind the previously generated texture
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

    // Point to our vertex buffer
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer.mByteBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer.mByteBuffer);

    // Draw the vertices as triangle strip
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, _vertices.length / 3);

我的问题是我的帧速率很低,即使以30 FPS的速度我有时也会丢失只有1个Sprite的某些帧(但对于50 Sprite来说还是一样)

难道我做错了什么? 如何改善FPS?

通常,您不应为绘制的每个精灵更改顶点缓冲区。 除非您要创建粒子系统,否则“一般”的意思是“从不”。 即使那样,您仍将使用适当的流技术,而不是一次写入四元组。

对于每个子画面,您都有一个预制的四边形。 要渲染它,可以使用shader uniform s将精灵从中性位置转换为想要在屏幕上看到的实际位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM