Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualHodgman

Posted 16 May 2013 - 09:48 PM

IMO the portable graphics layer should be:
• Not just a thin wrapper of the underlying API; some abstraction should be done.
• At the very least, the "state machine" behavior of the underlying API must be abstracted away (so that higher level rendering code does not have to worry about 'which states were previously set').
• The majority of API differences should be hidden, and helpers provided for any that do leak (thing like D3D9's idiotic pixel coords, or GL's idiotic NDC are hard to fully hide).
• Keeping the above in mind, it should be as low level as possible so that new rendering code can easily be written across platforms using these abstractions.
• Pet peeve: please don't use abstract base classes (virtual) to separate the interface and implementation(s) of your API. It's unnecessary, it's a huge cause of poor cache behavior and it's a violation of OO design to boot.

I've worked as a graphics-programmer on a game team and on an engine team, so I've been a user of these abstractions and an implementer of them.
When working on the game side, our abstract render layer was hiding about 5 different graphics APIs underneath. I had a lot of unique effects that I had to make for the game, which required low-level graphics programming -- I would much rather do this work once on an abstract API as described above rather than doing it 5 times!

In my API, I expose textures, vertex buffers, index buffers, constant buffers, input layouts (buffer->shader binding), render states and a high-level shader object (vertex/pixel/etc all set in one go) because then you can write nearly any graphical effect on top of this API, instead of repeating work.
As long as you abstract away the state machine and submission of commands, it's fairly easy to hide most underlying API differences.

It kinda depends on who the target users of your abstract API are. If you don't want/need the users to be able to implement new lighting pipelines, shadowing techniques or special effects, then you can make your API very high level without any worries. You then implement this high level API once for each 'back-end' API, with a large amount of very different code. A graphics programmer maintains the back-end.
If however, you're making an engine that should be able to be used by graphics programmer to implement new features, then your API needs to be a bit lower level, as described above. You have graphics-programmers maintaining the fairly thin/simple back-ends (not any real graphical techniques here, just mapping one abstraction to another) and you also have graphics-programmers implementing graphical techniques on top of your API.

I actually recommend a 3-tier system, where I've described the lowest tier above (the abstraction of D3D/GL/etc into a single stateless API), then there's a middle tier that implements lighting/shadows/effects/etc on top of this API and exposes high level objects like lights and models, which are used by the top tier to build a game without specialist graphics knowledge.

#2Hodgman

Posted 16 May 2013 - 09:37 PM

IMO the portable graphics layer should be:
• Not just a thin wrapper of the underlying API; some abstraction should be done.
• At the very least, the "state machine" behavior of the underlying API must be abstracted away (so that higher level rendering code does not have to worry about 'which states were previously set').
• The majority of API differences should be hidden, and helpers provided for any that do leak (thing like D3D9's idiotic pixel coords, or GL's idiotic NDC are hard to fully hide).
• Keeping the above in mind, it should be as low level as possible so that new rendering code can easily be written across platforms using these abstractions.
• Pet peeve: please don't use abstract base classes (virtual) to separate the interface and implementation(s) of your API. It's unnecessary, it's a huge cause of poor cache behavior and it's a violation of OO design to boot.

I've worked as a graphics-programmer on a game team and on an engine team, so I've been a user of these abstractions and an implementer of them.
When working on the game side, our abstract render layer was hiding about 5 different graphics APIs underneath. I had a lot of unique effects that I had to make for the game, which required low-level graphics programming -- I would much rather do this work once on an abstract API as described above rather than doing it 5 times!

In my API, I expose textures, vertex buffers, index buffers, constant buffers, input layouts (buffer->shader binding), render states and a high-level shader object (vertex/pixel/etc all set in one go) because then you can write nearly any graphical effect on top of this API, instead of repeating work.
As long as you abstract away the state machine and submission of commands, it's fairly easy to hide most underlying API differences.

#1Hodgman

Posted 16 May 2013 - 08:49 PM

IMO the portable graphics layer should be:
• Not just a thin wrapper of the underlying API; some abstraction should be done.
• At the very least, the "state machine" behavior of the underlying API must be abstracted away (so that higher level rendering code does not have to worry about 'which states were previously set').
• The majority of API differences should be hidden, and helpers provided for any that do leak (thing like D3D9's idiotic pixel coords, or GL's idiotic NDC are hard to fully hide).
• Keeping the above in mind, it should be as low level as possible so that new rendering code can easily be written across platforms using these abstractions.
• Pet peeve: please don't use abstract base classes (virtual) to separate the interface and implementation(s) of your API. It's unnecessary, it's a huge cause of poor cache behavior and it's a violation of OO design to boot.

I've worked as a graphics-programmer on a game team and on an engine team, so I've been a user of these abstractions and an implementer of them.
When working on the game side, our abstract render layer was hiding about 5 different graphics APIs underneath. I had a lot of unique effects that I had to make for the game, which required low-level graphics programming -- I would much rather do this work once on an abstract API as described above rather than doing it 5 times!

PARTNERS