Original Post
ive implemented my 3d engine in a somewhat MVC fashion to make it easier to thread... basicly ive got a "scene/model" subsystem and a "renderer/view" subsystem... the "scene" loads all meshes, textures and materials and then sends the one that should be rendered to the "renderer" in the form of a "displaylist".. this basicly means that the renderer has to see if there are "hardware" instances of all these objects and if not create them and then render... my problem is how i map these "hardware" instances to the ones in the "scene" subsystem... this is how i ma doing it now... very ugly its not actual code just demostrating the problem... scene::Mesh renderer is sent a list of "Geometry" objects that consist of a Mesh, Material and Transform... it then checks if all these objects has a hardware instance, if not creates it and then renders them.. using void* pointers like this and then doing unsafe static_casts like this is just horrible... im unsure how to solve this? i could assign every object a unique id... and then put them in a splaytree or something... but im unsure about how good that is performance wise... and how would i create the unique ids? i give all the objects string names when they are created but comparing strings isnt all that fast... EDIT: another problem i have is that since i have already created the hardware instance of the "scene" object... the "scene object" is actually no longer needed and is just wasting memory... and for example just emptying the "VertexData" and "IndexData" of the mesh object would make the object lie since it then no longer is a mesh but just a holder of a hardware instance
namespace scene
{
class Mesh
{
const VertexData& VertexData();
const IndexData& IndexData();
void* HardwareInstance();
void HardwareInstance(void* instance);
}
}
namespace renderer
{
/*........*/
void Render()
{
DisplayList dpList;
if(!scene->DisplayList(dpList))
return;
BOOST_FOREACH(GeometryPtr& geo, dpList.Geometries())
{
if(geo->Mesh()->HardwareInstance() == NULL)
// create and set hardware instance
if(geo->Texture()->HardwareInstance() == NULL)
// create and set hardware instance
}
// DO RENDERING
boost::polymorphic_downcast<d3d10:Mesh*>(geo->Mesh()->HardwareInstance())->Render();
}
/*........*/
}