Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

fire_and_life

Getting the polys all in one place.

This topic is 5729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In coding my latest engine endeavor I was experimenting with new (to me) ways of getting all of the triangles (vertices) in one place to push through to the renderer. I''m keeping the engine API independent so this wont be using any helper API functions. Everything is kept to it''s own class ( render, scene, objects, characters, etc.) I was thinking of using linked lists as the transport mechanism for all the objects. Perhaps having them BE ths links in the chain. Does anyone have any experience in doing this? Or perhaps this is just a foolhardy idea? I''m just trying to dynamically make the objects draw themselves without the need to say Object[1]->DrawObject(), Object[2]->DrawObject(), etc. Any ideas? Doug P.S. This may be the wrong forum. If so just let me know. The door to paradise can only be opened with the key. The key can only be found through peace. To obtain peace one must learn to cry.

Share this post


Link to post
Share on other sites
Advertisement
Make a struct that holds geometry for the renderer to use. Keep a vector of pointers to that struct in the renderer. Push all geometry you want to draw onto the vector, and then loop through every frame.
basic code:

  
struct model;
model *m = LoadModelFile();


//somewhere in your renderer class/struct/whatever it's organized with

...
std::vector< model* > geometry; //#include <vector>
...



//make sure the renderer knows to draw this model. Making an API function so you don't need to know the name of the renderer is a good idea

Renderer->geometry.push_back(m);


//loop through and draw

for(i=0; i < geometry.size(); ++i)
{
geometry[ i ]->DrawObject();
}

Just a basic way to keep track of things.
EDIT: Arg, since when has code tags started screwing up source code?

------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It's all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."

[edited by - LockePick on February 7, 2003 1:36:18 PM]

[edited by - LockePick on February 7, 2003 1:36:47 PM]

[edited by - LockePick on February 7, 2003 1:38:09 PM]

Share this post


Link to post
Share on other sites
Ah...

Didn't think of it that way. I will definitely be giving that a whirl. Anyone else have any suggestions? I want to stress test each of the ways and see what works the best. I'm going for speed over reliability right now so if anyone has any crazy ideas let me know. I get to sit and experiment all day while I'm at my job.

[edited by - fire_and_life on February 7, 2003 2:17:39 PM]

Share this post


Link to post
Share on other sites
i use a scenemanager that contains an array, the higher level manager adds, removes and resorts my polys. the render simply iterates thru the array. im currently experimenting with a "buffer" idea, where i populate an array and "present" it to the renderer. meanwhile, my code is organizing and populating the next frame in a different array. once the new array is populated i "flip" the chain, etc...

Dreddnafious Maelstrom

"If I have seen further, it was by standing on the shoulders of Giants"

Sir Isaac Newton

Share this post


Link to post
Share on other sites
The way i have it implemented is to have a base class Renderable from which anything 3D to be drawn derives from. This class implements the methods that the renderer will use such as getTexture(), getVertexBuffer(), getIndexBuffer(), getRenderMode(), getIndexBufferSize() these are all non-virtual btw cause the derived class doesn''t need to overload them.

The derived class is then responsible for filling these structs through a series of functions such as addVertex(Vertex &), addIndex(int), setTexture(Texture &), setRenderMode(RenderMode )

The advantage of this is that it is easy to add new components to the engine and it will automatically know how to render them. This also enables me to easily sort the objects by texture since there is a common interface to query the texture/lightmap values.

Share this post


Link to post
Share on other sites
I was going to use an array but for some reason as I was working through my last iteration of this thing pointing to it seemed to cause problems. I got a bunch of crazy exception errors that after three days almost caused my laptop to go flying. Does anyone know if using linked lists like:


class Object{

Object* pNext;
Object* pPrev;

//all of the objects properties;
...
//Object Functions
DrawMyself()
UpdateMyself()
etc...
AddMyselfToChain()
DeleteMyselfFromChain()
}

Object::DrawMyself(){
GetPolys;
SendPolysToBuffer;
}
class SceneManager{
private:
//Scene Stuff
// Scene gets level, map, whatever info from file loader calls
// object to load itself

//not inline just trying to save space
LoadObjects(){ for(i; i Object->LoadMyself();}
DrawObjects(){ for(i; i Object->DrawMyself();}

}
main{

//Initialization Stuff

GameLoop(){
switch(GameState)
case: game_starting
{
Object* pHead;
Object* pTail;

Object* GameObject;

GameObject = new Object;
//InitSceneManager()
//InitOtherStuff()
}
case: game_running
{
//GameUpdate()

SceneManager()->DrawObjects;
}

...will work;

I tried to get the gist of what I was attempting but trying to cull(?) the excess code out was a little rough.
Thanks
Doug

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!