Seperation of Render and SceneSystem.

Started by
9 comments, last by Krypt0n 11 years, 9 months ago
Hi,
im try to write my own render engine as a hobby so its nothing fancy. Im trying to seperate scence graphics and graphics objects from the Rendering part of engine.

Lets say i have a object that contains the Geometry, lets call the one DX11Geometry. It contains stuff like DX11buffers and other DX11 related stuff. This object does only exist in the rendersystem..

in the SceneManagment i have a scenobject that repesent the actuall object in the ending, it contain the stuff like translation, rotation..


Here's my question, how do I best link the SceneObject to the DX11Geometry object. Remeber i do want the RenderSystem completet independent of the ScenceObject, so SceneObject dont know what a DX11Geometryobject is..

I was think that SceneObjectcould have some kind uID that points to a DX11Gemotry object in the RenderSystem..
like RenderSystem->RenderGeometry(int uid). Im not sure how efficent this methody is, when because i would need some kind of array in the RendetrSystem to store all the DX11Gemotry object..

any thoughts on this are more then welcome.. im quite new to this kind of graphics programing.
Advertisement
In my engine I do this:

class Scene
Object[] objects
class Object
vec3 pos
Quaterion rot
Model *model
virtual void draw()
class Renderer
vec3 cameraPos
Scene *scene //draws scene at cameraPos
virtual void draw()

class Model
vec3 verts,norms,etc
virtual void process()
void load(string path)
do stuff
process()


I then make custom implementations of Model and Renderer for each API (and even rendering technique, deferred vs forward, etc). You can have a load that's API independant and then subclass Model to make a DX11Model that would store any necessary info and override process() to handle uploading the data to the GPU, and have different subclasses of Renderer that override draw() to handle the different APIs, etc

Here's my question, how do I best link the SceneObject to the DX11Geometry object. Remeber i do want the RenderSystem completet independent of the ScenceObject, so SceneObject dont know what a DX11Geometryobject is..


Create a data bridge type that links a SceneObject to a DX11GeometryObject, SceneObject doesnt know about DX11GeoObject and vice-versa. std::pair<SceneObject*,DX11GeometryObject*> fits well for that. Then you have a process that goes through the pairs and copies the appropriate data across from SceneObject (transforms etc) into your DX11 constant buffers. The object is a two way association, but a 1 way data pipeline.
Hi, thx a lot for two excellent answers. Think i will actually look in to both solutions two my problem. Have to say that i totally forgot about the std::pair.
I like this forum already people that actually know there stuff! wink.png

[quote name='korvax' timestamp='1340221764' post='4951096']
Here's my question, how do I best link the SceneObject to the DX11Geometry object. Remeber i do want the RenderSystem completet independent of the ScenceObject, so SceneObject dont know what a DX11Geometryobject is..


Create a data bridge type that links a SceneObject to a DX11GeometryObject, SceneObject doesnt know about DX11GeoObject and vice-versa. std::pair<SceneObject*,DX11GeometryObject*> fits well for that. Then you have a process that goes through the pairs and copies the appropriate data across from SceneObject (transforms etc) into your DX11 constant buffers. The object is a two way association, but a 1 way data pipeline.
[/quote]

Is this a better way of doing it than using a int ID thats mapping them, and then storing DX11GeometryObject in a array structure, or is it faster to use pair and then map it with objects?

I then make custom implementations of Model and Renderer for each API (and even rendering technique, deferred vs forward, etc). You can have a load that's API independant and then subclass Model to make a DX11Model that would store any necessary info and override process() to handle uploading the data to the GPU, and have different subclasses of Renderer that override draw() to handle the different APIs, etc

In this case do you end up doing a a lot of static_cast in each frame in the RenderSystem between the Model and the DX11Model? If so isn't it rather costly to cast ever model each fram?
I use something similar to what I've read in a presentation from the halo guys.
my logic side requests an ID from the renderer when it creates an object, based on strings to a mesh+material.
this ID is 32bit, lower 16bit represent an index into an array of object references in the renderer, and upper 16bit represent a counter that identifies the object in the array slot.

int createObject(std::string Mesh,std::string Material)
{
int ID=find(Mesh,Material);
if(ID>=0)
return ID;
int ID=FindEmptySlot();
QueueObjectForStreaming(ID,Mesh,Material);
ID|=(m_CounterArray[ID]+1)<<16;
return ID;
}

every time I create an object I try to find a free slot in the array of obiect, increase that counter and return (Counter<<16)|ObjectIndex;
if the array is full, I obviously overwrite some old object. when the logic side want to render, it just passes the ID + world matrix and the renderer indexes into the object array, if the upper 16bit match with the counter, the object is rendered, if not, it's obviously not the right one.
if the counter is < of the ID, then it means the streaming system is trying to load it in a queue, then I drop to some default object (box in my case), if the counter is higher, the object needs to be recreated. there are various ways the handle it, e.g. your "draw" call to the renderer could return that this object is invalid.

the nice part is that the rendering and logic are really completely separated (ok, not fully true, my collision checks try to access the mesh to share data), you can have a lot of references to the same object, it's transparently streamed in and also it can be removed (if not replaced), if memory is getting critical.

I use something similar to what I've read in a presentation from the halo guys.
my logic side requests an ID from the renderer when it creates an object, based on strings to a mesh+material.
this ID is 32bit, lower 16bit represent an index into an array of object references in the renderer, and upper 16bit represent a counter that identifies the object in the array slot.

int createObject(std::string Mesh,std::string Material)
{
int ID=find(Mesh,Material);
if(ID>=0)
return ID;
int ID=FindEmptySlot();
QueueObjectForStreaming(ID,Mesh,Material);
ID|=(m_CounterArray[ID]+1)<<16;
return ID;
}

every time I create an object I try to find a free slot in the array of obiect, increase that counter and return (Counter<<16)|ObjectIndex;
if the array is full, I obviously overwrite some old object. when the logic side want to render, it just passes the ID + world matrix and the renderer indexes into the object array, if the upper 16bit match with the counter, the object is rendered, if not, it's obviously not the right one.
if the counter is < of the ID, then it means the streaming system is trying to load it in a queue, then I drop to some default object (box in my case), if the counter is higher, the object needs to be recreated. there are various ways the handle it, e.g. your "draw" call to the renderer could return that this object is invalid.

the nice part is that the rendering and logic are really completely separated (ok, not fully true, my collision checks try to access the mesh to share data), you can have a lot of references to the same object, it's transparently streamed in and also it can be removed (if not replaced), if memory is getting critical.


That looks like a good solution but I have some questions...

How is the logic side able generate the ID? Since it is separated from the renderer it has no way of knowing where the object is stored right? the createObject() function is part of the renderer?, if so the scene system shouldn't be able to call it.
at some place you need to have an interface where you pass data. so yes, "CreateObject" is a renderer interface that the logic side uses. but it's not a connection, it's still separate. if you e.g. want to run on a server without a GPU, you just don't run the renderer thread (or update, if single threaded), the logic still can get some handles and pass them for rendering, they would have no meaning, they also have no meaning of the engine, it's just a handle that could potentially represent something. if you want, you can create a compile time flag (aka #define) that does not create any rendering code at all and "CreateObject" always just immediately returns 0;

(my system is actually a bit more complicated and it's not the renderer that is handling that part, but the resource system that is shared between game logic, scene'graph', renderer, streaming, physics etc.).

I use something similar to what I've read in a presentation from the halo guys.


Do you remeber where you found that articlepls?

thx for you help thought.

This topic is closed to new replies.

Advertisement