View Full Version : Multi-thread application about OpenGL
06-04-2005, 10:30 AM
I want to use OpenGL in a multi-thread Application. It should be worked under Linux/Windows or Mac OS.
I need one thread to load the resource(eg.model , terrain data , textures) and one thread do the major works (eg. logics , AI , and rendering.)
Someone can tell what should I do or what issues should pay more attention ?
very thanks .
06-05-2005, 03:15 PM
By all means load your model and texture data in a worker thread, but just make sure you leave the job of creating the opengl-specific resource to the render thread.
Don't get carried away (like a lot of people who've asked the question before you) by the idea that your worker thread can upload the data to opengl by sharing the context between threads via mutexes or whatever - it's a bad idea, because firstly the graphics card is a serial device and therefore cannot process upload and render commands in parallel, therefore what's the point? And secondly it will make your code very messy and not robust or portable.
The render thread should just do a quick check before using a mesh or texture that it's created the resource, if not it should create it. If you want to eliminate the render lag you'd get if the render thread created resources only when the object comes into view, then implement a "create resource" queue (and likewise a "destroy resource" queue) which the render thread processes before it begins a frame render, then your render lag would be reduced to the number of objects loaded during the last frame.
Keep it simple is my advice.
06-05-2005, 04:09 PM
I would add that if this is a game level, some engines will pre-cache the entire game-level's assets up front, when the level is loaded, possibly eliminating the need for an extra thread of this kind altogether. Obviously, the feasability of this is going to depend on level size and complexity, among other things; but I believe this is the approach taken by many popular engines, including Unreal and Quake.
You might adopt a similar strategy: lazy load lightweight, temporary objects as the need arises, but go ahead and load up the vast majority of the static world--the world the engine knows about at load time--from the get-go. If the aim is to remove the pauses caused by resource binding, then this should help quite a bit.
Needless to say, these approaches are not mutually exclusive.
06-05-2005, 05:17 PM
I just want to make a little 3D engine for VR . but the VR scene maybe very large (eg 1000 x 1000 km or a very big city). so it's impossible to precache all data in memory.
You can use pthread for the threading library, it's free and ported from Linux to Windows. Major functionalities are implemented on both OSes.
Also, read the available docs on the net (about XFree, glx, pthreads and gl behaviors under threading).
Hope that helps.
06-06-2005, 12:46 PM
Originally posted by stanlylee:
I just want to make a little 3D engine for VR . but the VR scene maybe very large (eg 1000 x 1000 km or a very big city). so it's impossible to precache all data in memory.Why not use a scene graph? OpenSceneGraph supports database paging in a background thread, and can cope with models right up to whole earth in size. It also multi-theaded multi-pipe support where you have multiple graphics cards such as a Prism/Onyx.
OpenThreads supplies the threading support in a cross platform way.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.