Wednesday, July 31, 2013

[android-developers] Re: GLSurfaceView lag/delay on Galaxy S3.

Is your render-mode continuously or when-dirty? 
If it is when-dirty, be sure to call surfaceView.requestRender() in your onTouchEvent implementation.

On Tuesday, July 30, 2013 7:14:22 AM UTC-4, Edvinas Kilbauskas wrote:

The best solution to your problem is probably to "bite the bullet" and rewrite your code to use shaders in OpenGL ES 2.0. All major phones and quite a few minor ones support it now.

It may be your only solution, if the Galaxy S3 has to move too many more bits than the P350 did, or has a slower OpenGL client-server path. Or if Motorola took too many shortcuts in maintaining OpenGL ES 1.0 backwards compatibility.

Finally, from this snippet, we cannot tell if you are handling your buffers correctly. For example is 'buffer' a directly allocated ByteBuffer?


This is full code, I optimized it even more, but only making 4 OpenGL calls every frame.


public class MainActivity extends Activity implements Renderer, OnTouchListener {
    private GLSurfaceView surfaceView;
    private FloatBuffer vertices;
    private float x;
    private float y;
    private int SCREEN_WIDTH = 1280;
    private int SCREEN_HEIGHT = 720;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        surfaceView = new GLSurfaceView(this);
        surfaceView.setOnTouchListener(this);
        surfaceView.setEGLConfigChooser(8,8,8,8,8,8);
        surfaceView.setRenderer(this);

        vertices = ByteBuffer.allocateDirect(12 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();

        vertices.put(new float[]{
                -1,-1,
                 1,-1,
                -1, 1,
                -1, 1,
                 1, 1,
                 1,-1
        });
        vertices.flip();

        setContentView(surfaceView);
    }

    public boolean onTouch(View view, MotionEvent motionEvent){
        x = motionEvent.getRawX();
        y = motionEvent.getRawY();

        return true;
    }

    public void onDrawFrame(GL10 gl){
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        float frustumWidth = SCREEN_WIDTH/100.0f;
        float frustumHeight = SCREEN_HEIGHT/100.0f;

        gl.glLoadIdentity();
        gl.glTranslatef((x/SCREEN_WIDTH)*frustumWidth,(y/SCREEN_HEIGHT)*frustumHeight,0);
        gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 6);

    }

    public void onSurfaceChanged(GL10 gl, int width, int height){
        gl.glViewport(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();

        gl.glOrthof(0,SCREEN_WIDTH/100.0f,SCREEN_HEIGHT/100.0f,0,-1,1);

        gl.glMatrixMode(GL10.GL_MODELVIEW);

        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertices);
    }

    public void onSurfaceCreated(GL10 gl, EGLConfig config){

    }

}

You can't make it any simpler than that, and there is still delay.

Well, I guess I will have to move on to OpenGL ES 2.0, I was actually planning on rewriting that framework in ES 2.0 entirely, but only after I finish this game first. So I guess I have to stop working on my game, and start rewriting my framework now... I HOPE this will do the trick. If not, then i'm screwed, big time.
 

--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate