PDA

View Full Version : Acheiving the Tightest, fastest rendering loop



CelticDaddio
01-16-2007, 02:36 PM
I am writing a simulation which must run at very high frame rates, ~1000 FPS. The rendered scene will be fed to a separate system for processing rather than display for human viewing. I do not have user input events, i.e. no mouse events, window resizing, keystrokes etc. All input to the simluation is via network packets. I am developing on and for Fedora Core 6.

My question is this: How do I achieve the smallest, tightest, fastest render loop possible?
The goal is to just render, render, render... with an occasional check of a buffer for incoming network packets.

The GLX examples I have seen have the render loop wrapped by an event loop. For example;

// Enter the render loop and don't forget to dispatch X events as
// they occur.
//

while(1)
{
do
{
XNextEvent( g_pDisplay, &event );

switch( event.type )
{
case ButtonPress:
{
if( event.xbutton.button == 1 ) {

g_nLastMousePositX = event.xmotion.x;
g_nLastMousePositY = event.xmotion.y;
g_bMousing = true;
}
}
break;

case ButtonRelease:
{
if( event.xbutton.button == 1 )
g_bMousing = false;
}
break;

case KeyPress:
{
fprintf( stderr, "KeyPress event\n" );
}
break;

case KeyRelease:
{
fprintf( stderr, "KeyRelease event\n" );
}
break;

case MotionNotify:
{
if( g_bMousing ) {

g_fSpinX -= (event.xmotion.x - g_nLastMousePositX);
g_fSpinY -= (event.xmotion.y - g_nLastMousePositY);

g_nLastMousePositX = event.xmotion.x;
g_nLastMousePositY = event.xmotion.y;
}
}
break;

case Expose:
{
fprintf( stderr, "Expose event\n" );
}
break;

case ConfigureNotify:
{
glViewport( 0, 0, event.xconfigure.width, event.xconfigure.height );
}
}
}
while( XPending(g_pDisplay) ); // Loop to compress events

Render();
}
}


Can I simple dispense with the outer even loop? Should I consider something other than GLX, if so, what, if any, are the other options? Should my render loop be in a separate thread? Any examples out there to look at?

Thanks,
CD

glBug
01-16-2007, 05:31 PM
I m not sure if I understood your question right, but the event handling has nothing to do with render loop, your example snippet could be simplified to:


while (1) {
handle_events();
render();
}and
you are saying that you are not interested in mouse and keyboard events, only to handle some
networking, so i guess you want something like:


while (1) {
handle_net();
render();
}

Zengar
01-17-2007, 01:37 AM
You can always make two threads, one - with higher priority - for rendering and another one - with low priority - for event checking. Or if this is not an option, just check for events once in 50 frames or such. But if you want to get high framerates there is one very good advice: get a decent videocard :-)

CelticDaddio
01-17-2007, 07:05 AM
Thanks for the info... We are using a NVIDIA Quadro FX 4500, which should be pretty good. :)

CB


Originally posted by Zengar:
You can always make two threads, one - with higher priority - for rendering and another one - with low priority - for event checking. Or if this is not an option, just check for events once in 50 frames or such. But if you want to get high framerates there is one very good advice: get a decent videocard :-)