7
\$\begingroup\$

I'm building an engine, which has Vulkan for its primary rendering engine. But to have at least some backwards compatibility with devices that don't get drivers for (Mainly mobile) it I want to implement an OpenGL fallback. Now, how do I check what API's are available in the current system?

I want to check if Vulkan support exists, if not then if GL support exists and if not that then crash.

\$\endgroup\$
3
  • \$\begingroup\$ Try posting this on computergraphics.stackexchange.com You're probably more likely to get an answer there. \$\endgroup\$
    – Almo
    Commented Jun 17, 2016 at 17:40
  • \$\begingroup\$ You need some kind of library to open a window for you application and accept an input from it. Exact way of checking API support depends on what library you choose. \$\endgroup\$ Commented Jun 17, 2016 at 17:41
  • 2
    \$\begingroup\$ Also, why even use Vulkan? There are not too many devices with Vulkan support, and you're getting yourself lots of problems just to get extra tiny bits of performance. Do you really need this performance? Isn't simple OpenGL enough? \$\endgroup\$ Commented Jun 17, 2016 at 17:43

1 Answer 1

6
\$\begingroup\$

Your first check is likely to be a LoadLibrary call (or equivalent for your platform) for the Vulkan DLL:

HMODULE vulkanDll = LoadLibrary("vulkan-1.dll");

Then you'll want to acquire the pointer to vkCreateInstance.

PFN_vkCreateInstance vkCreateInstance;
// ...
vkCreateInstance = GetProcAddress(vulkanDll, "vkCreateInstance");

Then you'll want to fill out the appropriate parameters and call vkCreateInstance. This can be involved, you'll want to read the documentation. vkCreateInstance will return a result code which may indicate that it has failed to load. If it fails or if any of the prior steps fail (with an error that is not "you called the function wrong" or similar), Vulkan's not available, fall back to OpenGL.

The above is a fairly low-level, library (but not OS) agnostic approach; if you're using additional frameworks they may abstract away some of this work for you. For example, GLFW apparently provides a function you can use to tell if Vulkan is available.


For OpenGL, pretty much everything already has the DLL or equivalent available, but you can apply the same LoadLibrary et cetera steps if you want. Initializing OpenGL is a more platform-specific task, which seems out of scope for this question, but it can fail: if it fails, OpenGL is for some reason not available.

Chances are it will succeed, though, but you may have fallen back to a version of OpenGL you did not want or that is too primitive for your game. You can call glGetString with GL_VERSION to determine the actual version of OpenGL you were able to load. Other values, such as GL_VENDOR or GL_RENDERER, may tell you information about the driver you are interested in. Based on that you can determine if your overall OpenGL load was "successful" per your own metrics and handle that accordingly (crashing, in your case).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .