Initialize Vulkan
Initializing Vulkan is different than initializing other graphics APIs such as OpenGL, but FPL helps you in the first steps.
The very first thing you need is a Vulkan Instance (VkInstance).
Secondly you require a Vulkan Surface (VkSurfaceKHR) to present the graphical result to the screen.
FPL can create the Instance and the Surface for you.
The surface creation is mandatory, but an exiting instance can optionally be passed to the fplSettings structure if needed.
Create a Vulkan Instance and a Surface
First you have to create a fplSettings structure and initialize it with default settings using fplSetDefaultSettings().
Second you set the fplVideoSettings::backend to fplVideoBackendType_Vulkan .
We can reference the fplVulkanSettings type stored in fplGraphicsApiSettings::vulkan for convenience usage later.
fpl_common_api void fplSetDefaultSettings(fplSettings *settings)
Resets the given settings container to default values for window, video, audio, etc.
@ fplVideoBackendType_Vulkan
Vulkan.
fplVulkanSettings vulkan
Vulkan settings.
A structure containing settings, such as window, video, etc.
fplVideoSettings video
Video settings.
A structure that contains video settings such as backend, v-sync, API-settings, etc.
fplVideoBackendType backend
video backend type
fplGraphicsApiSettings graphics
Graphics API settings.
A structure that contains Vulkan video settings.
Fill in the application, engine and api versions
vulkanSettings->
appName =
"The name of your application";
vulkanSettings->
engineName =
"The name of your engine";
#define fplStructInit
Initializes a struct by the given type.
A structure that contains version informations.
fplVersionInfo engineVersion
The engine version (Only required if fplVulkanSettings::instanceHandle is fpl_null)
fplVersionInfo apiVersion
The preferred Vulkan api version (Only required if fplVulkanSettings::instanceHandle is fpl_null)
const char * appName
The application name (Only required if fplVulkanSettings::instanceHandle is fpl_null)
fplVersionInfo appVersion
The application version (Only required if fplVulkanSettings::instanceHandle is fpl_null)
const char * engineName
The engine name (Only required if fplVulkanSettings::instanceHandle is fpl_null)
Choose a Vulkan validation mode
static void VulkanValidationLayerCallback(void *userData, const char *message, const VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, const VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *debugUtilsMessengerCallbackData) {
}
vulkanSettings->
userData = (
void *)YourUserData;
fpl_common_api void fplConsoleFormatOut(const char *format,...)
Writes the given formatted text to the standard output console buffer.
@ fplVulkanValidationLayerMode_Disabled
Do not use the validation.
fplVulkanValidationLayerMode validationLayerMode
The fplVulkanValidationLayerMode.
void * userData
User data passed to any callbacks.
fplVulkanValidationLayerCallback * validationLayerCallback
The validation layer callback fplVulkanValidationLayerCallback.
Continue with Vulkan Usage
Create a Vulkan Surface from an existing Instance
If you already have a Vulkan Instance (VkInstance), you can simply pass that to the fplVulkanSettings::instanceHandle field and initialize FPL with fplPlatformInit():
VkInstance yourVulkanInstance;
vulkanSettings->instance = yourVulkanInstance;
}
@ fplInitFlags_Video
Use a video backbuffer (This flag ensures that fplInitFlags_Window is included always)
Continue with Vulkan Usage
Vulkan Usage
After you have created a Vulkan Instance and a Surface, you can query it by calling fplGetVideoSurface() directly after fplPlatformInit():
VkInstance instanceHandle = (VkInstance)surface->
vulkan.instanceHandle;
VkSurfaceKHR surfaceHandle = (VkSurfaceKHR)surface->vulkan.surfaceKHR;
}
#define fplAssert(exp)
Breaks with an runtime assertion, when the specified expression evaluates to false.
@ fplInitFlags_All
All init flags.
fpl_common_api const fplVideoSurface * fplGetVideoSurface()
Gets the current fplVideoSurface that stores all handles used for the active video backend.
Stores the surface properties for the active video backend.
fplVideoSurfaceVulkan vulkan
The Vulkan surface properties.
After that, the typical Vulkan process continues:
See the FPL_Vulkan demo for more details or learn more about Vulkan: Vulkan-Tutorials
Memory Allocator
If you have an existing memory allocator for Vulkan, you can pass that to FPL before calling fplPlatformInit():
VkAllocationCallbacks *yourMemoryAllocator;
vulkanSettings->
allocator = (
void *)yourMemoryAllocator;
const void * allocator
The vulkan allocator (VkAllocationCallbacks)