Archived

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

bkt

Platform-independant Render Help

Recommended Posts

So I've been working for a few months (on and off, more off) on my game engine. I have the core done (based it upon Richard Fine's tutorial in the articles) and I finished writing my simple "drivers" for opengl and direct3d9 initalizing. I've hit bit of a snag. I'm going to focus primarily on direct3d9 right now, but I still want to be able to include opengl support sometime down the road (when opengl2.0 becomes mainstream). I just need to figure out how I'm going to work out rendering everything over both platforms without it touching my core DLL. Right now my CoreEngine.dll uses the iVideoDevice interface and grabs either OGL or DX9 driver and loads it up. I was thinking of using a iRender interface, and then having seperate render classes for different things (rendering planes, projectiles, etc). But at this point, I'm lost. Looking at a DX9 tutorial it starts getting into using DX9 interfaces that I know that opengl doesn't have. Basically, I'm wondering what I should do :]! Here's some of my code for my iRender intterface, cRenderPlane class. I was going to throw all of the iRender objects into a linked list and then pass the linked list into the correct driver (basically calling each classes Render() method from inside the driver dll) but I have a real feeling that it won't work, mind you, I haven't tested it yet. It's just one of those feelings that you know will go wrong! So how would I go about making a platform-independant model for rendering the objects in the game, and then throwing them into the corresponding graphics driver and then having that render properly? Code snippets: iRender.cpp (CoreEngine.dll)
void iRender::Release(void) {
	for(std::list<iRender *>::iterator it=renderList.begin();it!=renderList.end();) {
		iRender *r=(*it);
		it++;

		r->Shutdown( );
		renderList.remove(r);
		delete r;
		r=0;
	}
	renderList.clear();
}
cRenderPlane.cpp (CoreEngine.dll)
void cRenderPlane::Render(void) {
}

void cRenderPlane::RenderUpdate(void) {
}

void cRenderPlane::Shutdown(void) {
}
I guess "Render" in each iRender object wouldn't do anything, it would really just setup for the render process that cDirect3D9->RenderScene does. Any suggestions are welcome, thanks. -John "bkt" Bellone Flipside Software FlipEngine! [edited by - bkt on May 18, 2004 6:45:30 AM]

Share this post


Link to post
Share on other sites
Seems like your idea would work ok... a little hard to tell from only seeing the Release() function of your renderer though
The only critical thing about making it work on different renderers is that you keep anything renderer specific out of the definition of the objects that you want to render. ie. for a color dont have
GLfloat diffuseColor[4];
or
D3DCOLOR diffuseColor; (or whatever...)
but leave it at the most basic representation, ie. probably float[4] in this case. Then you will be passing a simple lump of data to the renderer and it can do as it pleases with it. I have also found it useful to have in each object a pointer which the renderer can use to allocate things that the core doesnt care about, but which do need to be kept around for rendering (textures, etc). The rendering module can access the reference pointer to get this data each time. The header file for each object needs to be accessible by both modules, but try to keep it so that the renderer does not ''call'' anything, but merely work with data.
Your linked list suggestion is ok but if you want to optimize by rendering objects in a certain order (which will likely be different for different renderers) the renderer should be in charge of this. Rather than assembling a list in the core module which the renderer will need to re-order, why not just pass each object one by one... I am at a similar stage to you at the moment, and I am thinking to have something like this:

clear shader tree
game module determines visible objects
for each object {
game module passes render module the object
renderer passes it down shader-tree to get optimal ordering
}
renderer renders objects by traversing shader-tree

not implemented yet so take this with a grain of salt mmmkay?

Share this post


Link to post
Share on other sites
Hmm, so pass all the objects into the renderer and have it choose which to do? I was considering just rendering in the order that I put them in specifically. I didn't know that there was a better order for either of the operating systems.

Here is my current render code for both drivers:

cDirect3D9.cpp

int cDirect3D9::RenderFrame(void) {
Flip( );
return 1;
}


cOpenGL3D.cpp

int cOpenGL3D::RenderFrame(void) {
Flip( );
return 1;
}


I was able to draw a simple 3D grid in opengl while I was just testing some of the drawing features. But when I got to DX9, I realized that I would need some type of iterface for all of the functions if I want to perform them outside of the renderer in order to keep everything platform independant.



[edited by - bkt on May 18, 2004 11:33:18 AM]

Share this post


Link to post
Share on other sites
I''m really stuck on this, if anyone can offer any input that''d be great! Thanks everyone.

Share this post


Link to post
Share on other sites