Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
Yes! Just like you can use OpenGL in multi-threaded applications. But, you have to know what you are doing. VL was designed to make it possible to be used in multi-threaded applications, but not to make multi-threaded applications development dumb-proof! So you will have to follow certain guide lines and use a few precautions common to all multi-threaded applications.
Also VL does not provide an OS-independent threading library, just a few abstract classes, such as vl::IMutex and vl::ScopedMutex, required to interoperate with your favourite threading api.
VL does not provide any out of the box multi-threading tricks or optimizations as those are out of the scope and purpose of VL. VL is a generic framework to be used to create your own rendering pipeline. Therefore making your rendering pipeline multi-threaded is up to you because it's heavily dependent on the architecture that you choose.
It is important also not to confuse multi-threaded application with multi-threaded rendering. Keep in mind that, unless your rendering is CPU bound, i.e. your GPU is starving, performing multiple renderings at the same time, is probably going to impact negatively the efficiency of the GPU! Always try to optimize to the limit your single-thread rendering pipeline and work on your application's specific CPU bottlenecks before considering issuing OpenGL commands from multiple threads.
We have to distinguish between thread-safety
and reentrancy
. See http://doc.qt.nokia.com/latest/threads-reentrancy.html for a nice introduction to the concept. Strictly speaking, VL is not thread-safe. That actually would be very bad performance-wise. As you probably expect, you can't call the same method of the same objects with the same parameters from two different threads and expect VL to produce predictable results unless you provide some kind of synchronization! However VL is designed to be reentrant (see below for the details) which in this case is the important bit of information in order to develop performant multi-threaded applications.
In a nutshell you can safely use VL in multi-threaded applications by following the four following rules: