Question

In OpenGL Renderer onDrawFrame is called several time, until the page is completely rendered. I cannot find an event that my page is completeley rendered in order to take a snapshot of the OpenGL page and animate it.

I have the solution to take snapshot on at the animation trigger (specific button), but this will imply a specific delay, until Bitmap is created, such as i would like to keep in memory a mutable copy of every page.

Do you know other way to animate GLSurfaceView with rendered content?

Snippet for triggering snapshot.

 glSurfaceView.queueEvent(new Runnable() {

                @Override
                public void run() {
                    glSurfaceView.getRenderer().takeGlSnapshot();
                }
            });

EGLContext for passing the GL11 object.

    public void takeGlSnapshot() {
         EGL10 egl = (EGL10) EGLContext.getEGL();
         GL11 gl = (GL11) egl.eglGetCurrentContext().getGL();
         takeSnapshot(gl);

}

onDrawFrame(Gl10 gl) {
 //is last call for this page event ???????????? 
Was it helpful?

Solution

No such event exists, as I will explain below.

OpenGL is designed as a client/server architecture, with the two running asynchronously. In a modern implementation, you can generally think of the client as the API front-end that you use to issue commands and the server as the GPU/driver back-end. API calls will do a little bit of work to validate input parameters etc, but save for a few exceptions (like glReadPixels (...)) they buffer up a command for the server to execute at a later point. You never truly know when your commands are finished, unless you explicitly call glFinish (...).

Calling glFinish (...) at the end of each frame is an awful idea, as it will create a CPU/GPU synchronization point and undo the benefits of having the CPU and GPU run asynchronously. But, if you just want to take a screenshot of the current frame every once in a while, then glFinish (...) could be an acceptable practice.

Another thing to consider, if you are using double-buffered rendering is that you may be able to access the last fully rendered frame by reading the front-buffer. This is implementation specific behavior however, as some systems are designed to discard the contents of the front-buffer after the buffer swap operation, others make reading its contents an undefined operation. In any case, if you do attempt this solution, be aware that the image returned will have a 1 frame latency (however, the process of reading it will not require you to finish your current frame), which may be unacceptable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top