Multithread Ogre Support

baishan

04-09-2009 13:52:05

I have been using the paged geometry add-on with success. However, I have been trying to run the add-on with ogre compiled with OGRE_THREAD_SUPPORT defined(1 and 2).
The first issue I had was with this line
if (!root->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_VERTEX_PROGRAM)) and any other line that runs the hasCapability function. This probably a bug in Ogre and I just commented it out and got the system to run.
I am still having crashes at this line in BatchedGeometry::SubBatch::SubBatch
vertexData = meshType->vertexData->clone(false);

I am manually creating building meshes in a separate background thread and then attempt to add them as batched geometry in the main render thread. I check to see if the meshes have been loaded before attempting to add them and also register the render thread and the other thread with the render system(although I dont see why I should need to ). This is the section of code where I add my geometry.

for(int x = 0; x < buildings.size(); ++x)
{
if(!buildings[x].buildingExteriorMesh->isLoaded())
{
while(!buildings[x].buildingExteriorMesh->isPrepared())
{
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
printf("creating entity: %s\n",buildings[x].entityName.c_str());
buildings[x].entity = BuildingGenerator::sceneManager->createEntity(buildings[x].entityName,buildings[x].buildingExteriorMesh->getName());
Ogre::MaterialPtr wallMat = Ogre::MaterialManager::getSingleton().getByName(buildings[x].wallTexture);
while(!wallMat->isLoaded())
{
wallMat->load();
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
buildings[x].entity->getSubEntity(0)->setMaterialName(buildings[x].wallTexture);
}

this->addEntity(buildings[x].entity,Ogre::Vector3(buildings[x].offset_x,0,buildings[x].offset_z),Ogre::Quaternion::IDENTITY,Ogre::Vector3::UNIT_SCALE);
//this->renderWindowEntities(&(buildings[x]),buildings[x].offset_x,buildings[x].offset_z);
}


If I set the page to load with EntityPage it will load all the buildings but they look kind of weird(as if the index buffers are wrong).
Again if I run the code with ogre compiled without thread support everything works fine except it will occasionally crash because the meshes are being created in a background thread and ogre is not thread safe.
If anyone has any ideas on how to fix this or has tried to run the paged geometry with a multi-threaded ogre please let me know. I'm not sure if this is something I can fix without changing the paged geometry code?