Tubulii
11-09-2012 10:27:20
I want to show you, how to enable thread support for (M)Ogre.
There are three avaiable options: None, background resource loading and full thread support.
I will focus on option number two: background resource loading.
The "thread provider" will be Poco (alternatives are Boost and TPM). I chooose Poco just because Boost caused some trouble with Mogre, nothing more.
But first some remarks:
There are three avaiable options: None, background resource loading and full thread support.
I will focus on option number two: background resource loading.
The "thread provider" will be Poco (alternatives are Boost and TPM). I chooose Poco just because Boost caused some trouble with Mogre, nothing more.
But first some remarks:
- This is an advanced tutorial, not a really step-by-step bullet proof tutorial[/*]
- Although I managed to compile (M)Ogre with Poco successfuly and also set up an test project, this guide is some how "theoretical". The first reason is: Ogre is not desinged to be thread safe, because thread safe does not means "faster" but "more difficult to maintain" (and there is an additional overhead). Thread safety is accomplished by using mutexes. But mutexes are tricky...[/*]
- Ogre 1.7.* (and higher) have a "bug", the second reason why this guide is "theoretical". There is a race condition and possible dead lock caused by the mutexes in both the resource manager and D3D. As a result, as soon as you start your project, ogre freezes because it locked itself (and not only the background thread): both main thread and background thread are wainting for each other[/*][/list:u]
Let's start:
- Download poco from here, extract it somewhere (e.g. C:\) and compile it.[/*]
- We have to compile both mogre and ogre. For that we will use MogreBuilder. Compile it, too, and make sure that you can compile mogre without any modifications[/*]
- Start mogre builder and wait until it compiled the dependencies. Kill it now (completely).[/*]
- Open cmake-gui and navigate to the ogre source (e.g. C:\...\Main\OgreSrc\ogre\). The build directory will be "C:\...\Main\OgreSrc\build\" (you may need to create the directory).[/*]
- Press "configure" and fill in the fields for "Poco": POCO_INCLUDE_DIR = [The include dir of poco, e.g. "C:/poco-1.4.4/Foundation/include"] and POCO_LIBRARY_DBG = [the PocoFoundationd.lib, e.g. "C:/poco-1.4.4/lib/PocoFoundationd.lib"][/*]
- Press "Generate" (if there are any erros, try to solve them )[/*]
Now download the attached "attributes.xml"Copy patch and apply itand replace it with the original in "C:\...\Codegen\AutoWrap\". This modified file includes some fixes which include the class "ResourceBackgroundQueue" into the auto wrapper process and "restores" the workqueue id.[/*]
[/list:u]
diff -r c2be4e87dc8b Codegen/AutoWrap/Attributes.xml
--- a/Codegen/AutoWrap/Attributes.xml Wed Apr 18 02:28:03 2012 +0200
+++ b/Codegen/AutoWrap/Attributes.xml Tue Sep 11 11:09:44 2012 +0200
@@ -215,7 +215,7 @@
<class name="ControllerFunctionRealPtr" Ignore=""/>
<class name="ManualResourceLoader" WrapType="Interface"/>
<class name="MaterialSerializer" WrapType="PlainWrapper"/>
- <class name="ResourceBackgroundQueue" Ignore=""/>
+ <!-- <class name="ResourceBackgroundQueue" Ignore=""/> -->
<!-- to avoid name clash with System.Exception -->
<class name="Exception" WrapType="PlainWrapper" ReadOnly="" Rename="OgreException">
@@ -302,7 +302,15 @@
<class name="Listener" WrapType="NativeDirector"/>
</class>
<class name="ResourceBackgroundQueue">
- <class name="Listener" WrapType="Interface"/>
+ <_CustomIncDeclaration>
+ public: typedef unsigned long BackgroundProcessTicket&
+ </_CustomIncDeclaration>
+ <class name="Listener" WrapType="Interface">
+ </class>
+ <function name="canHandleRequest" Ignore=""/>
+ <function name="handleRequest" Ignore=""/>
+ <function name="canHandleResponse" Ignore=""/>
+ <function name="handleResponse" Ignore=""/>
</class>
<class name="SceneManager">
<class name="SkyBoxGenParameters" WrapType="ReadOnlyStruct"/>
@@ -898,8 +906,8 @@
<_CustomIncPreDeclaration>
public: typedef Ogre::WorkQueue::RequestID RequestID;
</_CustomIncPreDeclaration>
- <typedef name="RequestID" Ignore="" />
- <function name="addRequest" Ignore="" />
+ <typedef name="RequestID" ReplaceBy="unsigned long" />
+ <!-- <function name="addRequest" Ignore="" /> -->
<class name="Request" WrapType="PlainWrapper">
<function name="Request" Ignore="" />
</class>
Sorry, the board attachment quota has been reached.
Could the admin please fix this?
- Open "C:\...\Main\OgreSrc\ogre\OgreMain\include\OgreConfig.h" and change
#define OGRE_THREAD_SUPPORT 0
to#define OGRE_THREAD_SUPPORT 1
and#define OGRE_THREAD_PROVIDER 0
to#define OGRE_THREAD_PROVIDER 2
Save the file.[/*]
- Fire up MogreBuilder again and let it finish (if the AutoWrapper step is skipped, do it manually by starting "C:\...\Codegen\AutoWrap\bin\Debug\AutoWrap.exe" and pressing "Produce".[/*][/list:u]
And that's it (do not forget to copy "PocoFoundationd.dll" into your app directory). Ogre now supports background resource loading (which is not working properly ).
Edit: Renamed topic to match content. This is not a question but a guide.
- Open "C:\...\Main\OgreSrc\ogre\OgreMain\include\OgreConfig.h" and change
- Download poco from here, extract it somewhere (e.g. C:\) and compile it.[/*]