Irrlicht with VSync on single-thread

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
keigen-shu
Posts: 8
Joined: Wed Dec 28, 2011 1:35 pm

Irrlicht with VSync on single-thread

Post by keigen-shu »

Hey guys. I have a question. I wrote my game to run in a single-thread, and when you turn on VSync, something in Irrlicht (I'm guessing endScene()) would stall the code to let the screen blank itself before letting the code continue. I want to know if there is a way to just render a scene without waiting for Vsync, and then Irrlicht will just display the last rendered frame when the screen is ready?

I'm doing this because my game that loads a lot of stuff on the background and calls a function to update some loading progress data that would be displayed on the screen. I was wondering if this is possible without delegating the job onto a seperate thread.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Irrlicht with VSync on single-thread

Post by hendu »

Yes, by taking control of the vsync yourself. Platform-dependant, in GL you would use one of the sync extensions to query when it's OK to draw, and then blit your quad.
keigen-shu
Posts: 8
Joined: Wed Dec 28, 2011 1:35 pm

Re: Irrlicht with VSync on single-thread

Post by keigen-shu »

Thanks for the info. Sorry for the really late reply though; I've been busy with the New Year.
Here's my workaround in case anyone was curious.

Code: Select all

/* simple loader callback to draw loading info */
 
IrrlichtDevice* _device;
IVideoDriver*   _driver;
unsigned int loadSize;      // amount of stuff to load
unsigned int loadProgress;  // amount of stuff loaded
unsigned int lastBlitTime;  // time of previous refresh
 
void load_callback (int loadIncrement)
{
    loadProgress += loadIncrement;
 
    /** Irrlicht pauses the code when blitting the screen when VSync is turned
      * on. This slows down the loading process. Thus, we will only update the  
      * loading screen every 16 milliseconds(62.5FPS) to bypass that pause.
      * 
      * The other workaround is to seperate the callback and draw process into
      * two seperate threads but you'll need another library to manage that.
      */
    if (_device->getTimer()->getRealTime() - lastBlitTime > 16) {
        lastBlitTime = _device->getTimer()->getRealTime();
        
        if (_device->run()) {
            _driver->beginScene(true, false);
            // draw loading info
            _driver->endScene();
        }
    } else { return; }
} 
Post Reply