Skip to content
This repository was archived by the owner on Dec 23, 2019. It is now read-only.

Using d vulkan with Derelict GLFW

Alex Parrill edited this page Mar 19, 2016 · 1 revision

At the time of this writing (2016/03/18), Vulkan support in GLFW is only in the git repository and hasn't been released, and the GLFW bindings for Derelict do not provide bindings for the GLFW Vulkan functions.

However, it is fairly easy to get around this by subclassing the Derelict loader, as so:

module glfwvulkan;

import derelict.glfw3;
import dvulkan;

extern(C) @nogc nothrow {
	enum GLFW_NO_API = 0;
	
	alias GLFWvkproc = void function();
	
	alias da_glfwVulkanSupported = int function();
	alias da_glfwGetRequiredInstanceExtensions = const(char*)* function(uint*);
	alias da_glfwGetPhysicalDevicePresentationSupport = int function(VkInstance, VkPhysicalDevice, uint);
	alias da_glfwGetInstanceProcAddress = GLFWvkproc function(VkInstance, const(char)*);
	alias da_glfwCreateWindowSurface = VkResult function(VkInstance, GLFWwindow*, const(VkAllocationCallbacks)*, VkSurfaceKHR*);
}

__gshared {
	da_glfwVulkanSupported glfwVulkanSupported;
	da_glfwGetRequiredInstanceExtensions glfwGetRequiredInstanceExtensions;
	da_glfwGetPhysicalDevicePresentationSupport glfwGetPhysicalDevicePresentationSupport;
	da_glfwGetInstanceProcAddress glfwGetInstanceProcAddress;
	da_glfwCreateWindowSurface glfwCreateWindowSurface;
}

final class GlfwVulkanLoader : DerelictGLFW3Loader {
	public this() {
		super();
	}
	
	protected override void loadSymbols() {
		super.loadSymbols();
		
		bindFunc(cast(void**)&glfwVulkanSupported,"glfwVulkanSupported");
		bindFunc(cast(void**)&glfwGetRequiredInstanceExtensions,"glfwGetRequiredInstanceExtensions");
		bindFunc(cast(void**)&glfwGetPhysicalDevicePresentationSupport,"glfwGetPhysicalDevicePresentationSupport");
		bindFunc(cast(void**)&glfwGetInstanceProcAddress,"glfwGetInstanceProcAddress");
		bindFunc(cast(void**)&glfwCreateWindowSurface,"glfwCreateWindowSurface");
	}
}

You can then load the instance creation functions with the following line:

DVulkanLoader.loadInstanceFunctions(cast(typeof(vkGetInstanceProcAddr)) glfwGetInstanceProcAddress(null, "vkGetInstanceProcAddr"));
Clone this wiki locally