Jump to content
  • Advertisement
Jan Haas

Writing api agnostic rendering layer. How to design and where to start?

This topic is 389 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

Hello guys,

title says it, I want create an api agnostic rendering layer (like bgfx, but not trying to compete). 
My idea was to specify an interface IRenderLayer that defines the specific functions. Implementations will then override these functions and implement api specific behavior.
However I always read that virtual function calls should be avoided in hot code paths and I also understand why. 
But then again, how should I implement runtime api selection without using runtime polymorphism? 

Thanks ;)

Share this post


Link to post
Share on other sites
Advertisement

Thanks for the answer.
I want to implement the first option: API-Level abstraction and specify common interfaces for all APIs I want to target ;)
But how do you efficiently implement different backends? 

Share this post


Link to post
Share on other sites

Thanks so much guys, this really helps me :)

- Alright I will go with pure virutal interface. Decision made.
- Originally I wanted to, but having to write 800 loc just to draw a triangle was a turn off. So instead I will target AZDO opengl 4.5. Hope it's  somehow compatible with the other concepts.
- Command Buffers are essential with AZDO I think (because of Indirect draw calls)
- Well maybe I will target Vulkan if it's somehow the superset of the other APIs... 

Thanks again ;)

Share this post


Link to post
Share on other sites
1 minute ago, Jan Haas said:

- Originally I wanted to, but having to write 800 loc just to draw a triangle was a turn off. So instead I will target AZDO opengl 4.5. Hope it's  somehow compatible with the other concepts.

If you want this to work, I would start the implementation with two APIs. AZDO GL 4.5 and DX11 would be sufficient. Trust me, this will expose a lot of blindspots that you miss even if you're pretty familiar with multiple APIs. Been there, done that, have the wide-ranging commits to atone for my oversights.

Share this post


Link to post
Share on other sites

As well as picking between low-level (API wrapping) or high-level (scene type stuff -- models/materials/etc), you also have to choose whether you'll be making a state-machine API or a stateless API. GL/D3D/etc are all state-machines, so a simple wrapper will also be a state machine. Stateless rendering APIs are IMHO utterly superior though, so personally I'd recommend going down that path :D

3 hours ago, Jan Haas said:

But then again, how should I implement runtime api selection without using runtime polymorphism? 

The big alternative is to do compile-time API selection instead ;) 

Share this post


Link to post
Share on other sites
4 hours ago, Hodgman said:

The big alternative is to do compile-time API selection instead  

Can't on mobile, if you're looking for wide support. Is Metal available or run the GL ES pipeline? Is Vulkan available or run the GL ES pipeline?

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!