[SDL] (openGL repaint) thread problem

David Olofson david.olofson at reologica.se
Fri Aug 10 11:18:01 PDT 2001


On Friday 10 August 2001 19:35, Ryan C. Gordon wrote:
> > What to do? Well, you could use some kind of wrapper API for the
> > rendering functions, designed with asynchronous execution in mind.
> > Then implement that wrapper API on top of some thread safe queue
> > mechanism (one lock-free FIFO per client thread, perhaps), so that
> > the API calls enqueue "commands" instead of calling the "real" API.
> > Finally, implement a "server" that takes commands from the queue
> > (possibly with some priority system, and perhaps even
> > splitting/interleaving of large operations) and performs them using
> > the underlying "real" API.
>
> ...or don't use OpenGL in immediate mode. To a degree, you're
> describing what happens under the hood between your first OpenGL call
> and glFlush().

Not really, unless I'm missing something... The very point of my proposed 
solution is to be able to interleave the actual rendering operations with 
whatever timing granularity you may need.

For example, I've developed a method of doing buffered, flicker and 
tearing free animation on targets without hardware pageflipping. The 
"trick" is based on two fundamental principles:

	1) Refresh only part of the screen at a time, to reduce
	   the timing accuracy requirements for the raster sync.
	   This could be seen as a "pageflipping emulator".

	2) Provide as much buffering as possible (keeping the
	   latency at an acceptable level) between the rendering
	   engine and the "pageflipping emulator".

That is, the "pageflipping emulator" has to blit from off-screen buffers 
generated by the actual actual rendering code. The refreshing has to be 
done either by polling a timer inside every rendering API call - or by a 
higher priority thread. In the latter case, you can't use a rendering API 
that isn't thread safe, so you have to resort to something like the queue 
hack described above.

Both methods would require an API wrapper and some timer thread or 
polling stuff for the "flipping". The only difference is whether the 
latter is done in another thread in the other end of a FIFO, or directly 
inside every rendering API call. (Note that the latter relies on the 
application using those calls rather frequently, without stalling. If it 
doesn't, the "pageflipping emulator" won't work!)


//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`--------------------------------------> david at linuxdj.com -'




More information about the SDL mailing list