开发者

Opengl ES - Is there a way to speed up my rendering?

I have a textured square. I draw it with this method:

    public void draw(GL10 gl) {

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_F开发者_Python百科LOAT, 0, vertexBuffer);

        if (mShouldLoadTexture) {
            loadGLTexture(gl);
            mShouldLoadTexture = false;
        }
        if (mTextureId != -1 && mTextureBuffer != null) {
            gl.glEnable(GL10.GL_TEXTURE_2D);
            gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

            gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureId);
        }
            gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, 4);

        if (mTextureId != -1 && mTextureBuffer != null) {
            gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        }

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}




    public void onDrawFrame(GL10 gl) {

        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
...


for (int i=0; i<50; i++) {
...loadidentity
...translatef
...rotatef

...alphaenabled

square1.draw(gl);

...alphadisabled
}

...etc

i have only 10+10 textured (and animated, blended) square, on a HTC Legend i get 48 FPS, Galaxy S get 60 FPS.

when i put 10+10+40 textured (and animated, blended) square, on a HTC Legend i get 14-20 FPS, Galaxy S get again 60 FPS.

Is there a way to speed up my application (and FPS)? Or am i doing something wrong?


The very basic way to optimize is to minimize state changes, in this case switching textures is expensive, so sort your draw calls so they minimize the number of texture switches (Bind texture A, draw all squares using that texture, then switch to texture B, draw all squares using that texture, etc).

The same applies to blending.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜