Hey,
We're generating scene objects in a background thread, from vertex and indice buffers we have generated.
We are also calling SceneInterface.ObjectManager.Submit / Remove in this background thread as the generated scene objects need to be refreshed with new data.
Sunburn is rendering on our main thread along with everything else.
Do we need to override the object manager with a threadsafe object manager, or is Sunburn already safe to use in this manner?
(We keep a single reference to the currently used scene object. After calling remove, we null the reference and replace it with a new sceneobject, we submit in the same frame)
Deja vu. I've asked something similar in the past:
http://www.synapsegaming.com/forums/p/2124/12142.aspx#12142
This time around, we have double buffers. I'm building a RenderableMesh, and adding it to the sunburn scene object instead of feeding the data straight to the sceneobjectconstructor. From there the scene object is added to a threadsafe dictionary, which is emptied into the objectmanager before the scene is updated, in the main thread.
So I guess a new question would be:
Should I add and remove renderable meshes from the scene object instead of building new scene objects?
Hi 2.0,
Deriving from the ObjectManager and overriding the methods with a "lock { base.method(...); }" will make access to the ObjectManager thread safe.
However after digging through the source code I've found a single access in RenderableMesh.Build() to a static member that breaks thread safety. The member is accessed both by RenderableMesh.Build() and the rendering code. If you pre-build temp meshes with all effects used in the level (on the main thread), this should assure no threading issues occur when multi-threading later.
Let me know if this helps!
Follow me on Twitter – development and personal tweetsAwesome XNA Videos – Lighting, Rendering, and game videos