Sign in to follow this  
dave

Engine Concepts

Recommended Posts

dave    2187
Hi all, It's been a while since i posted anything so i thought i'd make it a good'un. I have been working on a rendering engine which to begin with is just going to render quads. The details of the quads are stored in a script file and that is parsed. I have a Primitive Manager which through a polymorphic collection stores a collection of primitives. Quad derives from Primitive and so will other primitives when i get it working as is. So far it is a bit more flexible than just rendering quads as you can see. Now my rendering is done like so. I have a renderer that simply recieves calls and gets passed a vertexbuffer, indexbuffer, appearance details and renders what it is told to. I have a dx_scene class and this retrieves a pointer to the collection of primitives in the Primitive Manager. The scene class firstly sorts all the primtives by material. Then it fills a batch vector with information about how to render batches of vertices, batched by material. Then these batches are rendered using separate DIP calls. Now i have a few things, concepts, that im not entirely sure about, so here goes: 1) I wrote a simple class called maptable. This is a std::map holding vectors of pointers to primitives, by material name. The definition looks like this: std::map< std::string, vector< primitive* >* >; When the primitives are sorted they are organised in this map table. If a primitive is being added that has a different material to any others in the table then a new 'row' is added and a new vector for the primitives is allocated, simple. I am sure that this is not how it is done in commercial engines, but at the same i can't think of a better way of sorting the scene. I can't think of the second one this second, but i will post it when i remember... So can u critique my engine concepts and throw any useful advice my way? Thanks, ace

Share this post


Link to post
Share on other sites
supagu    148
why do you want to handle each individual primitive?
usually you export your mesh from your 3d application already batched.

this is what i do: my meshes have arrays of indices, positions, normals etc.. then i have a material table which says that the polys from index 0 to say 100 use material 1, while index 100 to 250 for example use material 2.

Then when i go to add these to be rendered i sort these by material by using a linked list.

I then iterate through this information and render everything. I lot simpler than handling each primitive.

Maybe you have over engineered the problem ;)

Share this post


Link to post
Share on other sites
dave    2187
Well maybe you're right, maybe i have over engineered. But do commerical engines never deal with individual quads. I mean i will handle meshes as meshes, no individual quads. What about flat walls in games?, are they not just quads?

ace

Share this post


Link to post
Share on other sites
supagu    148
generally most things in commercial games are meshes, except for particle systems, and decals etc. In these cases you dont deal with primitives really, its more a thing of keeping enough information around to generate this primitive data and adding it strait in to dynamic rendering buffers.

Share this post


Link to post
Share on other sites
_the_phantom_    11250
They are probably infact groups of triangles, either a strip or list depending on the engine.

Take a look at the doom3 md5mesh format (its text so pretty easy to read), it has a mesh section is is basically a list of vertices with postional and other infomation. Then, further down it has a triangle list section which gives you the indices for each triangle of the model.

To render, load the mesh data into a buffer, load the index data into an indice buffer, and just draw it, you never have to worry about the individual triangles, infact doing so would be horribly slow as you'd have to iterate over each triangle.

What you'll want todo is have mesh objects which all have the same material properites, that way you swap to a material and draw all the triangles with that material in one blast.

Now, the mesh might only be 4 vertices in rare cases (a low tessalated mirror for example) but in the majority of case its going to be a lot lot more.. now, imagine having to deal with each primative which makes it up one at a time while iterating over a vector... (take for example the doom3 fatty model, it defines 1273 triangles in its list, thats a lot of iteration...)

edit:
you appear to have got caught in the classic OOP problem of 'shape, circle, square' inheritance... an example which has alot to answer for imo [wink].

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this