Skip to main content
GameDev.net gamedev.net
🔒 Locked

Support for multiple rendering systems

Started by Klarre Jan 10, 2007 at 3:30 PM 1 replies 950+ views
Original Post
Klarre
Klarre
Hi! I have been writing on a 3d rendering engine for a couple of months now. I have written it so it is easy to port to other systems by splitting the engine code from the platform dependent parts, like window and input, by putting all this kind of stuff in its own dynamic library. Though my idea of the engine was to make it as portable as possible, the engine is working close with the OpenGL API. The thing now is that I want it to run on an XBOX, so I have to do add Direct3D support also. My skills and knowledge about this API is equal to zero, so I will spend some time learning it. But before start adding this support to my engine I will check with you guys, who have written engines with support for multiple rendering systems, first. How should I do this? My idea is to write some kind of render system interface which each system (OpenGL, D3D) will implement. It will have functions like pushModelviewMatrix, enableDepthTest and stuff like that. What I want to know is if this is the right approach. Are the two APIs so totally different from each other so this approach won't work? Any ideas are welcome about how to prepare a 3D engine for multiple rendering systems! Thanks for your thoughts! /Klarre
http://www.klarre.se
smitty1276
smitty1276
An interface is definately what you will need to use, but your suggested functions (pushModelViewMatrix, etc) may be a bit too lowlevel and particularly flavored by OpenGL.

You may want to look at the Ogre API docs to see how they did it. You just have to implement the interface in whichever API you want to support.
gharen
gharen
Yes, going the Ogre3D route of creating some sort of RenderSystem interface and doing different implementations is the way to go. Load the implementation you want at runtime, and voila!

This can be a hassle and a half, but I think it's worth it. My engine has OpenGL, Managed Direct3D9, and Xna implementations. You could look at my source here: https://sourceforge.net/projects/facilis-engine , but it's in c# and early in development. I suggest you look at Ogre3D: it's documentation is excellent, it's mature, and it's written in c++ (which is what I'm assuming you're using). Ogre3D has been a great inspiration to me.

Here's a few of the problems you'll have to tackle, that I can think of off the top of my head:

- The different handedness of OpenGL and Direct3D9 matrices.
- The fact that OpenGL combines the view and world matrices into a single modelview matrix. Direct3D9 keeps them seperate. Personally, I prefer the direct3d method.
- OpenGL and Direct3D have very different projection matrices. The view and world matrices are the same though (except for the handedness).
- Different shader languages. Yes, there's cg, but it's not quite a portable as people think it is: a cg shader that's written for directx won't necessarily work in opengl, and vice versa.
- Different ways of declaring vertex data. The main one being that in Direct3D you can define provide multiple sets of vertex positions for use in say, a shader that does vertex interpolation. In opengl you can only provide one set of positions and must hijack one of the texture coordinates for the other.
- You'll have to drop support for rendering quads, as direct3d can't do this.

Once you've handled those problems, the rest is surprisingly easy. Everything else works pretty much the same between the two apis.

You'll have to try to get away from opengl, making your api too much like one of the implementations will make other implementations harder to do. But it's inevitable that it will be similar to one. I'll openly admit that my API is much closer to directx, largely because I find opengl's api clumsy (no flames please, just my personal opinion. To each their own).

edit- there's no reason you couldn't implement an opengl-style push/pop matrix system in direct3D. It even provides matrix stacks you could use to do this.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.