Adapting TinyWindow to Vulkan

With the release of Vulkan, I have been looking and looking for useful tutorials on the subject. I am not going to go into the specifics of the API, why it’s amazing and has incredible potential. Instead in this post I will tell you how I followed a strong tutorial on the subject, and adapted TinyWindow to support Vulkan as well as the challenges I faced.

The first hurdle I had working with Vulkan was finding a decent tutorial. Sure there are plenty that showed me how to create an instance of Vulkan and get retrieve the necessary metadata and there are of course pre-built open source frameworks such as
this one written by Sascha Willems but I wanted a step by step guide and luckily I found just that on a thread in the Vulkan subreddit forum. The tutorial itself can be found here.

One of the first hurdles I had found was that to create a drawing  “surface” on Windows I need to give the API platform dependant information from TinyWindow. This caused a small design problem as I had designed TinyWindow to keep information that is platform dependant private and so to work around that I added a few functions to TinyWindow that would allow me to only GET the necessary information for Vulkan.

The next and also the largest issue that TinyWindow had with Vulkan is that OpenGL and Vulkan rendering instances cannot share the same window. I discovered this when after following the first part of the tutorial to the letter, my version kept inexplicably crashing when I tried to create a Vulkan rendering context. After some time and frustration I noticed that in the tutorial when creating the window, the tutorial does not initially create a rendering instance, instead the instance is created at a later point in the code. To fix this issue I simply commented out an internal function call within TinyWindow that would ordinarily create a OpenGL rendering context which would then conflict with Vulkan causing my program to crash.

Once that was fixed and I completed the tutorial I went back and made some minor (and temporary) fixes to TinyWindow that would Allow TinyWindow to support Vulkan without needing the code to edited. To allow TinyWindow to switch between Vulkan and OpenGL I implemented a simple hack that involves anyone using TinyWindow to first define the C style macro “TW_USE_VULKAN” before the TinyWindow header into their code. If the Macro has been defined, TinyWindow will simply not create a OpenGL instance in that window which prevents any conflicts with Vulkan.

In the future I want to implement a more elegant system that will allow for the simultaneous creation of different types of rendering contexts whether they be OpenGL, Vulkan or even possibly DirectX. To implement this I am considering developing a class enumeration based system wherein a TinyWindow window would contain a constant member enum that states what type of rendering context the window will be using.

There are of course issues with this as DirectX is only (natively) supported on Windows as well as a myriad of other issues including functions that are made for swapping drawbuffer functions and also playing with multiple contexts with functions such as (wgl/glx)MakeCurrent being different depending on rendering context as well as platform.

Hopefully with some skill and a lot of patience I may actually be able to develop a truly unique window API.

Leave a comment