0

Hi Android Developers,

What is the best way to interrupt a current rendering phase of GLSurfaceView and start a new one when mode is equal to "Render_when_dirty"? I artificially stop rendering in "onDraw" method by checking a flag and returning from actual rendering method which is called in "onDraw" method; then, in main thread's context i call "requestRender()" to refresh the scene. However, due to a reason that i am not aware of, some of the intermediary old frames are displayed for a very very short period of time(on the other hand, they endure for so long period of time that users can realize the transition); before actual scene is rendered by opengl es 2.x engine. It doesn't affect anything at all; but troublesome to be fixed. What do you suggest?

P.S. Throwing InterruptedException within onDraw method is useless due to the destruction of actual rendering thread of GLSurfaveView.

Kind Regards.

iliTheFallen
  • 466
  • 7
  • 16
  • Bailing out of `onDraw` isn't recommended. It would be best to `requestRender` when you have something new to draw, and then commit to actually drawing what you have in `onDraw`. – fadden Apr 18 '13 at 00:16

1 Answers1

0

When you say some of the old frames are drawn - do you mean part of the frame that is drawn is old or multiple calls of onDraw() still lead to some of the old information being shown on the display.

There are a few things I can see happening here. If you have a onDraw() like this:

  onDrawFrame(){
  ... stuff ...
  if (stateVariableSet)
     return;
  ... stuff ...

my understanding is that when the function is done being run, that the back/front buffer get swapped and drawn. One thing that could be happening here is that you see a few calls of onDrawFrame() being rendered while you try to update the state/State variable.

On the other hand, if you have something like this:

   onDrawFrame(){
   ... stuff..
   semaphore.acquire(); // lock the thread waiting for the state to update
   ... stuff ...

then the things that have been drawn before the lock will be stale (for that frame only though - at least that's what I'd anticipate).

Also are you running on a multi-core system?

paulczak
  • 96
  • 6