top of page

RenderAPI abstraction

  • Writer: Pablo Narvaja
    Pablo Narvaja
  • Oct 10, 2019
  • 1 min read

Updated: Oct 11, 2019

After having the mesh, texture and shader classes I realize that they were all opengl code which would be awful later on as I will add support for DirectX3D, so I decided to start abstracting the render API.

This is a very complicated thing to do as you dont wanna be too low level that make the code too verbose nor high level that there is no much reusable code.

The choice I made is working very well so far and that is to abstract:

  • Vertex and index buffers

  • Texture2D / inherit from virtual class Texture

  • Cubemaps / inherit from virtual class Texture

  • Meshes

  • Shaders

A singleton static class called "VideoDriver" that handle context initialization, set window as current context, and buffer swap. A class called "Renderer" that handle 3D rendering, sorting meshes by shaders (so we have minimal shader binding/unbinding) and sort alpha materials from far to near the camera for propper rendering, also give access to and keep track of (to minimize state changes):

  • clear render buffers

  • set clear color

  • enable cullfaces, blending and depth testing

  • viewport dimensions.

Some notes:

The skybox gets rendered after all opaque objects and before alpha objects. This process doesn't touch any render api code.

The alpha sorting is kinda rubbish since it doesn't have into account the direction the camera is facing.

The last class bothers me a bit since I believe that the enumerated features should be in "VideoDriver" as static members instead. I am still considering this change.


That's all for this post, folks. Bye!

Comments


  • facebook
  • linkedin
  • youtube
  • generic-social-link
  • Grey LinkedIn Icon
  • Facebook
  • YouTube

2019 Pablo Narvaja. Llamathrust GameEngine

bottom of page