Ogre1.7的多线程分析

http://blog.csdn.net/butwang/article/details/6219424

 

在OgreConfig.h文件中有关于Ogre使用多线程的配置
1. 多线程支持的级别


/** Support for multithreading, there are 3 options
OGRE_THREAD_SUPPORT = 0
    No support for threading.       
OGRE_THREAD_SUPPORT = 1
    Thread support for background loading, by both loading and constructing resources
    in a background thread. Resource management and SharedPtr handling becomes
    thread-safe, and resources may be completely loaded in the background.
    The places where threading is available are clearly
    marked, you should assume state is NOT thread safe unless otherwise
    stated in relation to this flag.
OGRE_THREAD_SUPPORT = 2
    Thread support for background resource preparation. This means that resource
    data can streamed into memory in the background, but the final resource
    construction (including RenderSystem dependencies) is still done in the primary
    thread. Has a lower synchronisation primitive overhead than full threading
    while still allowing the major blocking aspects of resource management (I/O)
    to be done in the background.
*/
#ifndef OGRE_THREAD_SUPPORT
#define OGRE_THREAD_SUPPORT 0
#endif
#if OGRE_THREAD_SUPPORT!= 0 && OGRE_THREAD_SUPPORT!= 1 && OGRE_THREAD_SUPPORT!= 2
#define OGRE_THREAD_SUPPORT 0
#endif


2.支持多线程库的thread lib来源


/** Provider for threading functionality, there are 4 options.
OGRE_THREAD_PROVIDER = 0
    No support for threading.
OGRE_THREAD_PROVIDER = 1
    Boost libraries provide threading functionality.
OGRE_THREAD_PROVIDER = 2
    Poco libraries provide threading functionality.
OGRE_THREAD_PROVIDER = 3
    TBB library provides threading functionality.
*/
#ifndefOGRE_THREAD_PROVIDER
#define OGRE_THREAD_PROVIDER 0
#endif


2.1 一个是boost提供的线程库


2.2 一个是Poco libraries
POCO C++ Libraries 提供一套 C++ 的类库用以开发基于网络的可移植的应用程序,功能涉及线程、线程同步、文件系统访问、流操作、共享库和类加载、套接字以及网络协议包括:HTTP、FTP、SMTP 等;其本身还包含一个 HTTP 服务器,提供 XML 的解析和 SQL 数据库的访问接口。
http://www.google.com.hk/search?hl=zh-CN&source=hp&biw=1241&bih=575&q=Poco+libraries&aq=f&aqi=&aql=&oq=


2.3 TBB library
http://threadingbuildingblocks.org/
Intel® Threading Building Blocks (Intel TBB) offers a rich and complete approach to expressing parallelism in a C++ program. It is a library that helps you take advantage of multi-core processor performance without having to be a threading expert. Intel TBB is not just a threads-replacement library. It represents a higher-level, task-based parallelism that abstracts platform details and threading mechanisms for scalability and performance.


3.Ogre多线程的初始化
在OgreMain中搜索OGRE_THREAD_SUPPORT得出以下文件清单
[转]Ogre1.7的多线程分析_第1张图片

3.1分析OgreRoot.cpp中有关OGRE_THREAD_SUPPORT的代码:

 

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。sinbadUsing 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)

2010/07/07刷新:关于WorkQueue可以参考OGRE多线程的使

 

PS. 在用CMake编译Ogre时,通过以下两个选项配置Ogre对多线程的支持:

OgreConfigThread

你可能感兴趣的:(多线程)