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

Complete API independancy

Started by _goat Jan 2, 2004 at 6:55 AM 13 replies 1k views
Original Post
_goat
_goat
Okay. I''m writing your barebones graphics engine. I''m just setting up how everything will interface with everything else. I want it to be completely API independant. Now, I need to work with vertices, etc. So how do I make my engine API independant? I mean, I created a vertex struct... with all the overloaded operators and such... but, I''m completely lost when it comes to this sort of thing. Can anyone help?
_goat
_goat
Thanks, I''ll have a look at that. Also, I forgot to mention that I am also striving for OS independance. Heh. Fun fun fun.
bishop_pass
bishop_pass
Since it''s API dependent, I would imagine your engine has no API that one needs to fiddle with and learn, correct?
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in
joelmartinez
joelmartinez
quote:
Original post by Anonymous Poster
but that''s not a big problem, if your engine is api independent, it''s also os independent

Not nescessarily true ... they could abstract the hell out of their graphics api but still use win32 stuff.

that being said, if it''s api independent, the OP will *probably* be, by default, doing os independant things


Joel Martinez
http://www.codecube.net/
Joel Martinez
http://codecube.net
[twitter]joelmartinez[/twitter]
Qatal
Qatal
...is a nice dream. I like it.

A ''pure'' API-independent engine will, yes, have a lot of limitations because you can''t take advantage of all the "tricky good things" that you can do if you were exploiting, say, Direct3D.

However, the way to do things in my opinion is to abstract the concepts you make the app developer handle to a high level (Models, [Logical] Shaders, etc) and then write highly tuned renderers that implement things using all the tricks in the book...

Maybe im just rambling... I found it hell to write a D3D and OpenGL renderer at the same time though...
die or be died...i think
Wandering Relic
Wandering Relic
Hi _goat. Your safest bet would be to follow in the footsteps of the vertex stream model for the programmable vertex pipeline in DirectX 9. This allows you do a number of things such as decouple vertex shaders from vertex buffers, and interpolate between multiple morph targets for individual vertex components (perhaps using vertex tweening) without duplicating the components that aren''t animated.

What you essentially do is set up a vertex declaration array which defines the order, type, and stream for each vertex component, and from this you can create an IDirect3DVertexDeclaration9 object which describes the entire vertex format. And then you declare your custom vertex structures/classes to match the vertex declaration.

You could probably stream line setting up vertex declarations by wrapping the process up up in a class which can automatically infer offset positions for components and what not.

Anyway, good luck!
_goat
_goat
Yeah, Qatal, I have sort of done what you suggested.

I wrote "attributes". Such as ALinkList (the A for attribute )
(Damn post doesn't allow me to use triangle brackets. Does anyone know how to turn HTML codes off for your post?)

template class listtype class ALinkList
{
ALinkList * ALinkList_pNext;
ALinkList * ALinkList_pPrev;
char * ALinkList_ID;
// static functions are here to manipulate, search, etc the list
};

Then all you have to do is if, say, you're writing a TerrainMesh:

class CTerrainMesh : public ALinkList CTerrainMesh
{
int Terrain;
};

And you've just set up your linked list.

int main()
{
CTerrainMesh * t = ALinkList CTerrainMesh ::SearchForID("chicken");
}

And that's how I plan to make it independant... I think. I'm pretty sure it's going to work, I just need to work with vertices and stuff, and I need to convert them into D3DXVECTOR3 and OGL's version as well. I'll probably need to do it with other stuff (actually, WILL need to), like colour, etc. So a general idea about how to abstract or something would be appreciated. I mean, a reference to a tutorial or something would be even better. :D

Cheers


[edited by - _goat on January 2, 2004 8:18:07 PM]
neurokaotix
neurokaotix
quote:
Original post by Anonymous Poster
quote:
Original post by neurokaotix
Why not? If you''re going to write an engine, write an engine. Otherwise, write a game.

Go hard or go home



Well, it''s your life. Waste it as you see fit



I don''t consider learning how to write an engine with abstracted rendering APIs a waste of time.

MindEngine Development
http://medev.sourceforge.net
coelurus
coelurus
Let _goat decide whether to have API-independence or not

First of all, you need to determine what you want to be possible with the engine and what you won''t need. Second, you have to decide how things should flow from total API independence down into total API independence.
I use "shaders" in libs that take care of all low-level rendering. Before that, everything is totally free from any bonds, the dependent shaders take care of all the grunt work. It is however possible to extend the dependence into details and to actually "exploit" tricks in OpenGL and D3D for complex rendering setups, if you''re clever. I''m experimenting with one idea for extendable communication atm...
treething
treething
I agree with CodeDemon, you should set up a vertex declaration system. See the Ogre engine for one way to do this.

Having a bunch of hard-coded vertex types is fine as a convenience, but the low-level renderer should only deal with abstract vertex types.

Topic Locked

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

Sign in to reply to this topic.