We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Odd hanging when drawing image in OpenGL
Page Index Toggle Pages: 1
Odd hanging when drawing image in OpenGL (Read 760 times)
Odd hanging when drawing image in OpenGL
Feb 5th, 2010, 11:11am
 
Hi. After scratching my head for a few days, I thought it would be time to scratch elsewhere.

An OpenGL sketch I am working on is giving me a little trouble. Basically, I am drawing text to offscreen 2D buffers, and then moving, rotating and rendering the buffers to screen, which gives something like this:
http://bruno.wyldind.com/cityspeak/imgs/screenshot-05.png

People send SMS, which slowly appear in the bottom-left of the screen, and then move following the different lines to disappear in the back.

My problem is with the rendering of the bottom-left message. Using the code below, the offscreen buffer of the bottom-right text is updated and the text filled in a little more every frame. When the filling is completed, the buffer is 'cached' (not modified anymore), and then it starts moving to the right.

The issue is that, if the buffer of the text is slightly larger than normal (e.g. 2 or more lines of text, as in the image above), the code below takes a constant 20-40ms to execute, EXCEPT for one odd frame that will suddently take 120-220ms, then it goes back to normal, and then the execution time is trivial once the text is cached.

This causes a tiny, but noticeable hang, in the animation.

Code:

if (!cached) {
 gBuffer.beginDraw();
 gBuffer.pushMatrix();
 gBuffer.translate(-theString.bounds.x+getWidthPadding(), -theString.bounds.y+getHeightPadding());  
 drawMotes(gBuffer); //update and draw motes  
 gBuffer.popMatrix();
 gBuffer.endDraw();
}

//copy the buffer to the main graphics
g.pushMatrix();
g.translate(theString.bounds.x-getWidthPadding(),
     theString.bounds.y-getHeightPadding(), theString.position.z);  
g.image(gBuffer, 0, 0);
g.popMatrix();

//at some point below this 'cached' is set to true
//...


This is also true when using P3D.

Any idea what might cost 100-200ms to execute, for only one frame, in the Processing code?

EDIT:
If it helps, I have hint(DISABLE_DEPTH_TEST); set.
Re: Odd hanging when drawing image in OpenGL
Reply #1 - Feb 6th, 2010, 10:52am
 
My guess would be that it could be a garbage collection issue. I know processing has moved into using java's more incremental garbage collector, but I've still noticed hitches like you described.

As much as possible, I try to make sure big allocations are done in setup and the objects persist through the lifetime of the sketch. That way the gc will never run on those large objects.

Otherwise, you might check if your off screen buffer has crossed a 2^n size with those additional lines of text. My understanding is that normally graphics cards allocate texture sizes where their dimensions are powers of two, and they scale up from whatever you ask -- it could be that processing's renderer's reflect this, and it has to create a buffer four times the size than normal just because of an extra 100 pixels or so.

Lastly, you could try increasing the memory size for your sketch, which might keep the gc from needing to run.

If it's not any of that, I'd probably need to take a look at all the code in your sketch to get a better idea.

Hope that helps a bit,

Jack

Re: Odd hanging when drawing image in OpenGL
Reply #2 - Feb 9th, 2010, 9:28am
 
Thanks for the reply, it gave me enough to think about to figure where the problem is.

You got it right, the problem is with the garbage collector. Because I have dynamic textures rendered on quads in OpenGL, if the texture are fairly large, the memory use shoots up drastically and it requires the gc to clean up more often, which makes the sketch hangs just enough to be glitchy.

I'm gonna try to hack something together to improve texture management.
Page Index Toggle Pages: 1