在Ogre 1.7中,对多线程的支持有三个选择:
要在Ogre 1.7中使用多线程:
- 在OgreBuildSettings.h改写2行
- OGRE_THREAD_SUPPORT 2 // 通过ResourceBackgroundQueue实现。
- OGRE_THREAD_PROVIDER 3 // TBB library provides threading functionality
我采用C++的并行编程模板库Threading Building Blocks。采用CMake构造的需要把TBB的文件拷贝到Ogre的Dependence的相关目录下。
Ogre 1.7 的 Threading changes
- WorkQueue added to accept generalised work items to be executed in background worker threads
- WorkQueue starts the number of workers based on hardware, or can be told to start a different number
- Main Ogre WorkQueue is in Root::getWorkQueue. You can also subclass WorkQueue and provide your own if you want
- ResourceBackgroundQueue now uses WorkQueue instead of using its own queue and can have multiple tasks running at once
- New focus on data-driven, task-based parallel execution with separation of GPU and CPU activities
- Boost, POCO and Thread Building Blocks supported as threading back-ends (Boost preferred)
- All Ogre thread support will use WorkQueue in future
备注:1.7添加了一个Character Sample,其中SinbadCharacterController有参考价值。
采用OGRE_THREAD_SUPPORT = 1并不被推荐,而应该使用OGRE_THREAD_SUPPORT = 2。sinbad在Using the new threading scheme说明了原因。更具体的讨论在high performance thread support - request for comments。当前,有Proposal: OGRE_THREAD_SUPPORT == 3,但是没有整合到Ogre 1.7中。
关于多线程参考:多线程的渲染与物理模拟(pdf)和Threading the OGRE3DRender System(pdf)