Sign in to follow this  
Subotron

Drawing the whole scene using one drawing function

Recommended Posts

Subotron    182
What I have is a complete list of all the objects I want to draw in my scene. What I need is a clever way to draw all those objects with one drawing function. Note however, that some objects might require multitexturing, with a certain number of textures, which can vary. Also, some objects might require certain shaders. Use of lighting, etc, there's a lot of possible variation. The advantage is that all the geometry of an object is stored in an array of vertices, and the vertices are a predefined class (which can hold vertex coordinates, but also texture coordinates, and what not). I expect this has been attempted before, so I was wondering if this is (to some degree) possible, and what would be a good way to do it. Thanks a lot for the help :)

Share this post


Link to post
Share on other sites
ScottC    100
Give each object a pointer to their model, and each model a render function. SceneGraph[i].GetModel()->Render(SceneGraph[i].GetFrame(), SceneGraph[i].GetKeyframe());

You could also go ahead and give each object its own render function, since some objects may not need frames or keyframes. In said render function, you can do your multitexturing, apply shaders, etc. I myself have each object with its own render function along with models have render functions.

Share this post


Link to post
Share on other sites
Subotron    182
Thanks, this way is kind off what I have been thinking to do, but I was wondering if it was somehow possible not to have to write a drawing function for each type of object. But well, I guess that even if it is possible, the overhead/redudancy would be too much.

Share this post


Link to post
Share on other sites
Ranger_One    300
So, If I read your first post right, you want to create a single function to take all the world objects and render them to view using GL? If so, that is both quite possible and easily handled.

Without getting language specific, all you'd have to do is define all the possible states of the object (shaders, lighting, etc) and then setup the modes for each and then pass through the vertex data to GL. Now, you may want to look at intelligent grouping if you have any transparency and/or depth testing.

I'm also a bit confused about 'clever'. What would a clever solution here entail?

Share this post


Link to post
Share on other sites
Subotron    182
well Ranger_One, although that would be possible, I'd have to do a lot of checks for every rendered object. Also, without any ordering and knowledge of what was drawn before, I'd have to set everything up for every object (color, right texture(s), enable/disable multitexturing, blending, shaders). I think this would all cost way too much speed, so I'd need an efficient way (which was what I meant by 'clever') to render objects, to make sure the amount of OpenGL functions to call (like glEnable/glDisables, glColor, etc) would be minimized, since this sure takes a lot of frametime away.

In other words, ideally I would use one function to draw everything, but if it will cost me too much performance, I think having a base object with a virtual draw function (and making derived classes for all specific objects) would be a better way to go. That way it would still be pretty simple to draw the scene, but I'd have some more flexibility.

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