lundi 9 octobre 2017

Handing of C code in C++ (Vulkan)

I am trying to write a rendering engine in C++ based on Vulkan. Vulkan is written in C, as a result it has some interesting conventions.

A recurring pattern I see in tutorials/code snippets from Vulkan apps is that most code is in 1 very big class. (right now my vulkan class is already about 2000 lines too). But to make a proper rendering engine, I will need to compartmentalize my code till some degree.

One of the aforementioned interesting bits is that it has something called a Logical Device, which is an abstract reference to the graphics card.

It is used everywhere, to create and allocate things in the following way:

  1. Create structs with creation info
  2. Create variable that the code will output into
  3. Call the actual vkCreateSomething or vkAllocateSomething function, pass in the logical device, the creation info and the reference to the variable to output to and check if it was a success.

on its own there is nothing wrong with this style I'd say. It's just that it's not really handy at all in OOP because it relies on the logical device being available everywhere.

How would I deal with this problem? Service locators and singletons are considered to be horrible solutions by many (which I can understand), so that seems like something I'd rather avoid.

Are there design patterns that deal with this?

Aucun commentaire:

Enregistrer un commentaire