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
" );
}
break;
case KeyRelease:
{
fprintf( stderr, "KeyRelease event
" );
}
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
" );
}
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