2016-02-16 15:07:25 +01:00
/*
* Vulkan Example base class
*
2019-06-10 08:46:11 +02:00
* Copyright ( C ) by Sascha Willems - www . saschawillems . de
2016-02-16 15:07:25 +01:00
*
* This code is licensed under the MIT license ( MIT ) ( http : //opensource.org/licenses/MIT)
*/
# pragma once
# ifdef _WIN32
# pragma comment(linker, " / subsystem:windows")
# include <windows.h>
# include <fcntl.h>
# include <io.h>
2018-04-23 21:28:35 +03:00
# include <ShellScalingAPI.h>
2017-08-13 10:24:25 +02:00
# elif defined(VK_USE_PLATFORM_ANDROID_KHR)
2016-03-20 14:55:46 +01:00
# include <android/native_activity.h>
2016-03-20 15:45:40 +01:00
# include <android/asset_manager.h>
# include <android_native_app_glue.h>
2017-03-06 21:54:06 +01:00
# include <sys/system_properties.h>
2017-03-25 12:09:45 +01:00
# include "VulkanAndroid.h"
2017-02-02 08:54:56 +00:00
# elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
# include <wayland-client.h>
2019-01-16 01:16:58 -07:00
# include "xdg-shell-client-protocol.h"
2017-05-26 11:37:47 +05:30
# elif defined(_DIRECT2DISPLAY)
//
2017-08-13 10:24:25 +02:00
# elif defined(VK_USE_PLATFORM_XCB_KHR)
2016-02-16 15:07:25 +01:00
# include <xcb/xcb.h>
# endif
2020-08-09 13:16:35 +02:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <assert.h>
# include <vector>
# include <array>
# include <numeric>
# include <ctime>
2016-02-16 15:07:25 +01:00
# include <iostream>
# include <chrono>
2020-08-09 13:16:35 +02:00
# include <random>
# include <algorithm>
2017-01-27 19:02:55 +01:00
# include <sys/stat.h>
2016-02-16 15:07:25 +01:00
# define GLM_FORCE_RADIANS
2016-03-08 21:52:40 +01:00
# define GLM_FORCE_DEPTH_ZERO_TO_ONE
2017-02-09 21:51:10 +01:00
# define GLM_ENABLE_EXPERIMENTAL
2016-02-16 15:07:25 +01:00
# include <glm/glm.hpp>
2020-08-09 13:16:35 +02:00
# include <glm/gtc/matrix_transform.hpp>
# include <glm/gtc/matrix_inverse.hpp>
# include <glm/gtc/type_ptr.hpp>
2016-02-16 15:07:25 +01:00
# include <string>
2017-07-29 19:31:00 +02:00
# include <numeric>
2020-04-19 10:11:50 +02:00
# include <array>
2016-02-16 15:07:25 +01:00
# include "vulkan/vulkan.h"
2016-08-03 21:44:04 +02:00
# include "keycodes.hpp"
2017-02-12 13:10:05 +01:00
# include "VulkanTools.h"
2017-02-12 11:33:04 +01:00
# include "VulkanDebug.h"
2017-10-29 11:41:43 +01:00
# include "VulkanUIOverlay.h"
2020-08-08 18:48:00 +02:00
# include "VulkanSwapChain.h"
2020-08-08 22:18:35 +02:00
# include "VulkanBuffer.h"
2020-08-08 22:36:01 +02:00
# include "VulkanDevice.h"
2020-08-08 22:54:34 +02:00
# include "VulkanTexture.h"
2016-02-16 15:07:25 +01:00
2017-01-06 22:48:37 +01:00
# include "VulkanInitializers.hpp"
2016-06-11 15:54:16 +02:00
# include "camera.hpp"
2017-08-26 14:05:48 +02:00
# include "benchmark.hpp"
2016-02-16 15:07:25 +01:00
class VulkanExampleBase
{
2020-02-07 18:28:20 +01:00
private :
2016-03-13 16:51:00 +01:00
std : : string getWindowTitle ( ) ;
2016-07-31 12:41:50 +02:00
bool viewUpdated = false ;
2016-04-10 11:12:04 +02:00
uint32_t destWidth ;
uint32_t destHeight ;
2016-10-16 17:39:30 +02:00
bool resizing = false ;
2016-04-10 11:12:04 +02:00
void windowResize ( ) ;
2017-11-02 13:40:27 +01:00
void handleMouseMove ( int32_t x , int32_t y ) ;
2020-04-19 10:05:47 +02:00
void nextFrame ( ) ;
void updateOverlay ( ) ;
void createPipelineCache ( ) ;
void createCommandPool ( ) ;
void createSynchronizationPrimitives ( ) ;
void initSwapchain ( ) ;
void setupSwapChain ( ) ;
2020-04-20 20:29:15 +02:00
void createCommandBuffers ( ) ;
void destroyCommandBuffers ( ) ;
2020-05-29 16:36:27 +01:00
std : : string shaderDir = " glsl " ;
2016-02-16 15:07:25 +01:00
protected :
2020-05-29 16:36:27 +01:00
// Returns the path to the root of the glsl or hlsl shader directory.
std : : string getShadersPath ( ) const ;
2016-03-13 16:51:00 +01:00
// Frame counter to display fps
uint32_t frameCounter = 0 ;
2016-05-14 21:19:52 +02:00
uint32_t lastFPS = 0 ;
2019-02-23 20:38:09 +00:00
std : : chrono : : time_point < std : : chrono : : high_resolution_clock > lastTimestamp ;
2016-02-16 15:07:25 +01:00
// Vulkan instance, stores all per-application states
VkInstance instance ;
2020-08-29 11:32:48 +02:00
std : : vector < std : : string > supportedInstanceExtensions ;
2020-08-08 13:25:58 +02:00
// Physical device (GPU) that Vulkan will use
2016-02-16 15:07:25 +01:00
VkPhysicalDevice physicalDevice ;
2016-03-13 16:51:00 +01:00
// Stores physical device properties (for e.g. checking device limits)
VkPhysicalDeviceProperties deviceProperties ;
2016-12-14 21:38:45 +01:00
// Stores the features available on the selected physical device (for e.g. checking if a feature is available)
2016-04-24 10:28:27 +02:00
VkPhysicalDeviceFeatures deviceFeatures ;
2016-02-16 15:07:25 +01:00
// Stores all available memory (type) properties for the physical device
VkPhysicalDeviceMemoryProperties deviceMemoryProperties ;
2019-06-10 08:46:11 +02:00
/** @brief Set of physical device features to be enabled for this example (must be set in the derived constructor) */
2016-12-14 21:38:45 +01:00
VkPhysicalDeviceFeatures enabledFeatures { } ;
2017-02-09 19:22:48 +01:00
/** @brief Set of device extensions to be enabled for this example (must be set in the derived constructor) */
2018-03-03 11:49:46 +01:00
std : : vector < const char * > enabledDeviceExtensions ;
std : : vector < const char * > enabledInstanceExtensions ;
2019-06-10 08:46:11 +02:00
/** @brief Optional pNext structure for passing extension structures to device creation */
void * deviceCreatepNextChain = nullptr ;
2016-07-16 17:36:35 +02:00
/** @brief Logical device, application's view of the physical device (GPU) */
2016-02-16 15:07:25 +01:00
VkDevice device ;
// Handle to the device graphics queue that command buffers are submitted to
VkQueue queue ;
2017-01-25 18:54:09 +01:00
// Depth buffer format (selected during Vulkan initialization)
2016-02-16 15:07:25 +01:00
VkFormat depthFormat ;
// Command buffer pool
VkCommandPool cmdPool ;
2016-08-11 19:29:40 +02:00
/** @brief Pipeline stages used to wait at for graphics queue submissions */
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ;
2016-03-06 19:22:41 +01:00
// Contains command buffers and semaphores to be presented to the queue
VkSubmitInfo submitInfo ;
2016-02-16 15:07:25 +01:00
// Command buffers used for rendering
std : : vector < VkCommandBuffer > drawCmdBuffers ;
// Global render pass for frame buffer writes
VkRenderPass renderPass ;
// List of available frame buffers (same as number of swap chain images)
std : : vector < VkFramebuffer > frameBuffers ;
// Active frame buffer index
uint32_t currentBuffer = 0 ;
// Descriptor set pool
2016-04-02 12:47:08 +02:00
VkDescriptorPool descriptorPool = VK_NULL_HANDLE ;
2016-02-16 15:07:25 +01:00
// List of shader modules created (stored for cleanup)
std : : vector < VkShaderModule > shaderModules ;
// Pipeline cache object
VkPipelineCache pipelineCache ;
// Wraps the swap chain to present images (framebuffers) to the windowing system
VulkanSwapChain swapChain ;
2016-03-06 19:22:41 +01:00
// Synchronization semaphores
struct {
// Swap chain image presentation
VkSemaphore presentComplete ;
// Command buffer submission and execution
VkSemaphore renderComplete ;
} semaphores ;
2018-06-03 09:38:14 +02:00
std : : vector < VkFence > waitFences ;
2020-05-29 16:36:27 +01:00
public :
2016-02-16 15:07:25 +01:00
bool prepared = false ;
2020-08-16 10:22:45 +02:00
bool resized = false ;
2016-02-16 15:07:25 +01:00
uint32_t width = 1280 ;
uint32_t height = 720 ;
2018-08-31 21:15:43 +02:00
vks : : UIOverlay UIOverlay ;
2017-03-30 19:27:57 +02:00
/** @brief Last frame time measured using a high performance timer (if available) */
float frameTimer = 1.0f ;
2017-03-31 09:52:26 +02:00
2018-01-15 20:40:17 +01:00
vks : : Benchmark benchmark ;
2017-03-31 09:52:26 +02:00
/** @brief Encapsulated physical and logical vulkan device */
vks : : VulkanDevice * vulkanDevice ;
2017-03-30 19:27:57 +02:00
2017-01-22 13:38:57 +01:00
/** @brief Example settings that can be changed e.g. by command line arguments */
struct Settings {
/** @brief Activates validation layers (and message output) when set to true */
bool validation = false ;
/** @brief Set to true if fullscreen mode has been requested via command line */
bool fullscreen = false ;
/** @brief Set to true if v-sync will be forced for the swapchain */
bool vsync = false ;
2017-10-29 11:41:43 +01:00
/** @brief Enable UI overlay */
bool overlay = false ;
2017-01-22 13:38:57 +01:00
} settings ;
2016-02-16 15:07:25 +01:00
VkClearColorValue defaultClearColor = { { 0.025f , 0.025f , 0.025f , 1.0f } } ;
2016-11-10 22:56:15 +01:00
static std : : vector < const char * > args ;
2016-11-10 22:29:55 +01:00
2016-02-16 15:07:25 +01:00
// Defines a frame rate independent timer value clamped from -1.0...1.0
// For use in animations, rotations, etc.
float timer = 0.0f ;
// Multiplier for speeding up (or slowing down) the global timer
float timerSpeed = 0.25f ;
bool paused = false ;
2016-06-11 15:54:16 +02:00
Camera camera ;
2016-02-16 15:07:25 +01:00
glm : : vec2 mousePos ;
std : : string title = " Vulkan Example " ;
std : : string name = " vulkanExample " ;
2018-06-01 18:42:18 +02:00
uint32_t apiVersion = VK_API_VERSION_1_0 ;
2016-02-16 15:07:25 +01:00
2020-02-07 18:28:20 +01:00
struct {
2016-02-16 15:07:25 +01:00
VkImage image ;
VkDeviceMemory mem ;
VkImageView view ;
} depthStencil ;
2017-10-05 21:22:10 +02:00
struct {
2016-06-20 22:08:50 +02:00
glm : : vec2 axisLeft = glm : : vec2 ( 0.0f ) ;
glm : : vec2 axisRight = glm : : vec2 ( 0.0f ) ;
2016-03-20 21:46:49 +01:00
} gamePadState ;
2016-05-15 11:13:14 +02:00
2017-10-05 21:22:10 +02:00
struct {
bool left = false ;
bool right = false ;
bool middle = false ;
} mouseButtons ;
2020-05-29 16:36:27 +01:00
// OS specific
2016-05-15 11:13:14 +02:00
# if defined(_WIN32)
HWND window ;
HINSTANCE windowInstance ;
2017-08-13 10:24:25 +02:00
# elif defined(VK_USE_PLATFORM_ANDROID_KHR)
2016-05-15 11:13:14 +02:00
// true if application has focused, false if moved to background
bool focused = false ;
2017-03-06 21:16:51 +01:00
struct TouchPos {
int32_t x ;
int32_t y ;
} touchPos ;
2017-03-06 22:11:19 +01:00
bool touchDown = false ;
double touchTimer = 0.0 ;
2017-03-25 11:15:30 +01:00
int64_t lastTapTime = 0 ;
2017-04-14 12:00:05 -04:00
# elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
2017-07-29 19:31:00 +02:00
void * view ;
2017-02-02 08:54:56 +00:00
# elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
wl_display * display = nullptr ;
wl_registry * registry = nullptr ;
wl_compositor * compositor = nullptr ;
2019-01-16 01:16:58 -07:00
struct xdg_wm_base * shell = nullptr ;
2017-02-02 08:54:56 +00:00
wl_seat * seat = nullptr ;
wl_pointer * pointer = nullptr ;
wl_keyboard * keyboard = nullptr ;
wl_surface * surface = nullptr ;
2019-01-16 01:16:58 -07:00
struct xdg_surface * xdg_surface ;
struct xdg_toplevel * xdg_toplevel ;
2017-02-02 08:54:56 +00:00
bool quit = false ;
2019-01-16 01:16:58 -07:00
bool configured = false ;
2017-10-05 21:22:10 +02:00
2017-05-26 11:37:47 +05:30
# elif defined(_DIRECT2DISPLAY)
bool quit = false ;
2017-08-13 10:24:25 +02:00
# elif defined(VK_USE_PLATFORM_XCB_KHR)
2016-07-18 20:43:41 +02:00
bool quit = false ;
2016-02-16 15:07:25 +01:00
xcb_connection_t * connection ;
xcb_screen_t * screen ;
xcb_window_t window ;
xcb_intern_atom_reply_t * atom_wm_delete_window ;
2016-03-20 14:55:46 +01:00
# endif
2016-02-16 15:07:25 +01:00
2019-04-22 18:29:24 +02:00
VulkanExampleBase ( bool enableValidation = false ) ;
2017-04-22 20:30:06 +02:00
virtual ~ VulkanExampleBase ( ) ;
2020-04-19 10:05:47 +02:00
/** @brief Setup the vulkan instance, enable required extensions and connect to the physical device (GPU) */
2018-05-01 11:23:36 +02:00
bool initVulkan ( ) ;
2016-02-16 15:07:25 +01:00
2016-03-20 14:55:46 +01:00
# if defined(_WIN32)
2016-02-16 15:07:25 +01:00
void setupConsole ( std : : string title ) ;
2018-04-23 21:28:35 +03:00
void setupDPIAwareness ( ) ;
2016-02-16 15:07:25 +01:00
HWND setupWindow ( HINSTANCE hinstance , WNDPROC wndproc ) ;
void handleMessages ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam ) ;
2017-08-13 10:24:25 +02:00
# elif defined(VK_USE_PLATFORM_ANDROID_KHR)
2016-03-20 21:46:49 +01:00
static int32_t handleAppInput ( struct android_app * app , AInputEvent * event ) ;
2016-03-20 17:35:54 +01:00
static void handleAppCommand ( android_app * app , int32_t cmd ) ;
2017-04-14 12:00:05 -04:00
# elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
2017-07-29 19:31:00 +02:00
void * setupWindow ( void * view ) ;
2017-02-02 08:54:56 +00:00
# elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
2019-01-16 01:16:58 -07:00
struct xdg_surface * setupWindow ( ) ;
2017-02-02 08:54:56 +00:00
void initWaylandConnection ( ) ;
2019-01-16 01:16:58 -07:00
void setSize ( int width , int height ) ;
2017-02-02 08:54:56 +00:00
static void registryGlobalCb ( void * data , struct wl_registry * registry ,
uint32_t name , const char * interface , uint32_t version ) ;
void registryGlobal ( struct wl_registry * registry , uint32_t name ,
const char * interface , uint32_t version ) ;
static void registryGlobalRemoveCb ( void * data , struct wl_registry * registry ,
uint32_t name ) ;
static void seatCapabilitiesCb ( void * data , wl_seat * seat , uint32_t caps ) ;
void seatCapabilities ( wl_seat * seat , uint32_t caps ) ;
static void pointerEnterCb ( void * data , struct wl_pointer * pointer ,
uint32_t serial , struct wl_surface * surface , wl_fixed_t sx ,
wl_fixed_t sy ) ;
static void pointerLeaveCb ( void * data , struct wl_pointer * pointer ,
uint32_t serial , struct wl_surface * surface ) ;
static void pointerMotionCb ( void * data , struct wl_pointer * pointer ,
uint32_t time , wl_fixed_t sx , wl_fixed_t sy ) ;
void pointerMotion ( struct wl_pointer * pointer ,
uint32_t time , wl_fixed_t sx , wl_fixed_t sy ) ;
static void pointerButtonCb ( void * data , struct wl_pointer * wl_pointer ,
uint32_t serial , uint32_t time , uint32_t button , uint32_t state ) ;
void pointerButton ( struct wl_pointer * wl_pointer ,
uint32_t serial , uint32_t time , uint32_t button , uint32_t state ) ;
static void pointerAxisCb ( void * data , struct wl_pointer * wl_pointer ,
uint32_t time , uint32_t axis , wl_fixed_t value ) ;
void pointerAxis ( struct wl_pointer * wl_pointer ,
uint32_t time , uint32_t axis , wl_fixed_t value ) ;
static void keyboardKeymapCb ( void * data , struct wl_keyboard * keyboard ,
uint32_t format , int fd , uint32_t size ) ;
static void keyboardEnterCb ( void * data , struct wl_keyboard * keyboard ,
uint32_t serial , struct wl_surface * surface , struct wl_array * keys ) ;
static void keyboardLeaveCb ( void * data , struct wl_keyboard * keyboard ,
uint32_t serial , struct wl_surface * surface ) ;
static void keyboardKeyCb ( void * data , struct wl_keyboard * keyboard ,
uint32_t serial , uint32_t time , uint32_t key , uint32_t state ) ;
void keyboardKey ( struct wl_keyboard * keyboard ,
uint32_t serial , uint32_t time , uint32_t key , uint32_t state ) ;
static void keyboardModifiersCb ( void * data , struct wl_keyboard * keyboard ,
uint32_t serial , uint32_t mods_depressed , uint32_t mods_latched ,
uint32_t mods_locked , uint32_t group ) ;
2017-05-26 11:37:47 +05:30
# elif defined(_DIRECT2DISPLAY)
//
2017-08-13 10:24:25 +02:00
# elif defined(VK_USE_PLATFORM_XCB_KHR)
2016-02-16 15:07:25 +01:00
xcb_window_t setupWindow ( ) ;
void initxcbConnection ( ) ;
void handleEvent ( const xcb_generic_event_t * event ) ;
# endif
2020-04-19 10:05:47 +02:00
/** @brief (Virtual) Creates the application wide Vulkan instance */
2016-12-13 19:59:15 +01:00
virtual VkResult createInstance ( bool enableValidation ) ;
2020-04-19 10:05:47 +02:00
/** @brief (Pure virtual) Render function to be implemented by the sample application */
2016-02-16 15:07:25 +01:00
virtual void render ( ) = 0 ;
2020-04-19 10:05:47 +02:00
/** @brief (Virtual) Called when the camera view has changed */
2016-02-16 15:07:25 +01:00
virtual void viewChanged ( ) ;
2017-04-22 16:02:39 +02:00
/** @brief (Virtual) Called after a key was pressed, can be used to do custom key handling */
virtual void keyPressed ( uint32_t ) ;
2020-04-19 10:05:47 +02:00
/** @brief (Virtual) Called after the mouse cursor moved and before internal events (like camera rotation) is handled */
2017-10-05 21:22:10 +02:00
virtual void mouseMoved ( double x , double y , bool & handled ) ;
2020-04-19 10:05:47 +02:00
/** @brief (Virtual) Called when the window has been resized, can be used by the sample application to recreate resources */
2016-04-10 11:12:04 +02:00
virtual void windowResized ( ) ;
2020-08-08 13:25:58 +02:00
/** @brief (Virtual) Called when resources have been recreated that require a rebuild of the command buffers (e.g. frame buffer), to be implemented by the sample application */
2016-04-10 11:12:04 +02:00
virtual void buildCommandBuffers ( ) ;
2020-04-19 10:05:47 +02:00
/** @brief (Virtual) Setup default depth and stencil views */
2016-06-03 13:15:55 +02:00
virtual void setupDepthStencil ( ) ;
2020-04-19 10:05:47 +02:00
/** @brief (Virtual) Setup default framebuffers for all requested swapchain images */
2016-03-28 21:43:31 +02:00
virtual void setupFrameBuffer ( ) ;
2020-04-19 10:05:47 +02:00
/** @brief (Virtual) Setup a default renderpass */
2016-03-28 21:43:31 +02:00
virtual void setupRenderPass ( ) ;
2017-04-22 16:02:39 +02:00
/** @brief (Virtual) Called after the physical device features have been read, can be used to set features to enable on the device */
2017-03-08 21:29:38 +01:00
virtual void getEnabledFeatures ( ) ;
2020-04-19 10:05:47 +02:00
/** @brief Prepares all Vulkan resources and functions required to run the sample */
2016-03-20 17:35:54 +01:00
virtual void prepare ( ) ;
2016-02-16 15:07:25 +01:00
2020-04-19 10:05:47 +02:00
/** @brief Loads a SPIR-V shader file for the given shader stage */
2016-03-21 20:10:09 +01:00
VkPipelineShaderStageCreateInfo loadShader ( std : : string fileName , VkShaderStageFlagBits stage ) ;
2020-05-29 16:36:27 +01:00
2020-04-19 10:05:47 +02:00
/** @brief Entry point for the main render loop */
2016-02-16 15:07:25 +01:00
void renderLoop ( ) ;
2020-04-19 10:05:47 +02:00
/** @brief Adds the drawing commands for the ImGui overlay to the given command buffer */
2018-08-29 20:49:13 +02:00
void drawUI ( const VkCommandBuffer commandBuffer ) ;
2016-05-18 19:33:15 +02:00
2020-08-08 13:25:58 +02:00
/** Prepare the next frame for workload submission by acquiring the next swap chain image */
2016-05-15 20:11:28 +02:00
void prepareFrame ( ) ;
2020-04-19 10:05:47 +02:00
/** @brief Presents the current image to the swap chain */
2016-05-15 20:11:28 +02:00
void submitFrame ( ) ;
2020-04-19 10:05:47 +02:00
/** @brief (Virtual) Default image acquire + submission and command buffer submission function */
virtual void renderFrame ( ) ;
2016-05-15 20:11:28 +02:00
2017-10-29 11:41:43 +01:00
/** @brief (Virtual) Called when the UI overlay is updating, can be used to add custom elements to the overlay */
2017-10-30 12:36:44 +01:00
virtual void OnUpdateUIOverlay ( vks : : UIOverlay * overlay ) ;
2016-02-16 15:07:25 +01:00
} ;
2016-06-25 23:01:09 +02:00
// OS specific macros for the example main entry points
# if defined(_WIN32)
// Windows entry point
2016-06-27 22:28:21 +02:00
# define VULKAN_EXAMPLE_MAIN() \
2016-06-26 00:04:13 +02:00
VulkanExample * vulkanExample ; \
LRESULT CALLBACK WndProc ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam ) \
{ \
if ( vulkanExample ! = NULL ) \
{ \
vulkanExample - > handleMessages ( hWnd , uMsg , wParam , lParam ) ; \
} \
return ( DefWindowProc ( hWnd , uMsg , wParam , lParam ) ) ; \
} \
2017-04-22 16:54:25 +02:00
int APIENTRY WinMain ( HINSTANCE hInstance , HINSTANCE , LPSTR , int ) \
2016-06-25 23:01:09 +02:00
{ \
2017-04-22 16:54:25 +02:00
for ( int32_t i = 0 ; i < __argc ; i + + ) { VulkanExample : : args . push_back ( __argv [ i ] ) ; } ; \
2016-06-26 00:04:13 +02:00
vulkanExample = new VulkanExample ( ) ; \
2016-12-13 19:59:15 +01:00
vulkanExample - > initVulkan ( ) ; \
2016-06-26 00:04:13 +02:00
vulkanExample - > setupWindow ( hInstance , WndProc ) ; \
vulkanExample - > prepare ( ) ; \
vulkanExample - > renderLoop ( ) ; \
delete ( vulkanExample ) ; \
2016-06-25 23:01:09 +02:00
return 0 ; \
2020-05-29 16:36:27 +01:00
}
2017-08-13 10:24:25 +02:00
# elif defined(VK_USE_PLATFORM_ANDROID_KHR)
2016-06-25 23:01:09 +02:00
// Android entry point
2016-06-27 22:28:21 +02:00
# define VULKAN_EXAMPLE_MAIN() \
2016-06-26 00:04:13 +02:00
VulkanExample * vulkanExample ; \
2016-06-25 23:01:09 +02:00
void android_main ( android_app * state ) \
{ \
2016-06-26 00:04:13 +02:00
vulkanExample = new VulkanExample ( ) ; \
2016-06-25 23:01:09 +02:00
state - > userData = vulkanExample ; \
state - > onAppCmd = VulkanExample : : handleAppCommand ; \
state - > onInputEvent = VulkanExample : : handleAppInput ; \
2017-01-18 19:21:40 +01:00
androidApp = state ; \
2017-03-25 11:15:30 +01:00
vks : : android : : getDeviceConfig ( ) ; \
2016-06-26 00:04:13 +02:00
vulkanExample - > renderLoop ( ) ; \
delete ( vulkanExample ) ; \
2016-06-25 23:01:09 +02:00
}
2016-11-04 13:32:58 -07:00
# elif defined(_DIRECT2DISPLAY)
// Linux entry point with direct to display wsi
# define VULKAN_EXAMPLE_MAIN() \
VulkanExample * vulkanExample ; \
static void handleEvent ( ) \
{ \
} \
int main ( const int argc , const char * argv [ ] ) \
{ \
2017-01-23 13:54:23 +01:00
for ( size_t i = 0 ; i < argc ; i + + ) { VulkanExample : : args . push_back ( argv [ i ] ) ; } ; \
2016-11-10 22:56:15 +01:00
vulkanExample = new VulkanExample ( ) ; \
2016-12-13 19:59:15 +01:00
vulkanExample - > initVulkan ( ) ; \
2016-11-04 13:32:58 -07:00
vulkanExample - > prepare ( ) ; \
vulkanExample - > renderLoop ( ) ; \
delete ( vulkanExample ) ; \
return 0 ; \
}
2017-02-02 08:54:56 +00:00
# elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
# define VULKAN_EXAMPLE_MAIN() \
VulkanExample * vulkanExample ; \
int main ( const int argc , const char * argv [ ] ) \
{ \
for ( size_t i = 0 ; i < argc ; i + + ) { VulkanExample : : args . push_back ( argv [ i ] ) ; } ; \
vulkanExample = new VulkanExample ( ) ; \
vulkanExample - > initVulkan ( ) ; \
vulkanExample - > setupWindow ( ) ; \
vulkanExample - > prepare ( ) ; \
vulkanExample - > renderLoop ( ) ; \
delete ( vulkanExample ) ; \
return 0 ; \
}
2017-08-13 10:24:25 +02:00
# elif defined(VK_USE_PLATFORM_XCB_KHR)
2016-06-27 22:28:21 +02:00
# define VULKAN_EXAMPLE_MAIN() \
2016-06-26 00:04:13 +02:00
VulkanExample * vulkanExample ; \
static void handleEvent ( const xcb_generic_event_t * event ) \
{ \
if ( vulkanExample ! = NULL ) \
{ \
vulkanExample - > handleEvent ( event ) ; \
} \
2016-07-04 19:12:30 +02:00
} \
2016-06-25 23:01:09 +02:00
int main ( const int argc , const char * argv [ ] ) \
{ \
2016-11-10 22:29:55 +01:00
for ( size_t i = 0 ; i < argc ; i + + ) { VulkanExample : : args . push_back ( argv [ i ] ) ; } ; \
2016-06-26 00:04:13 +02:00
vulkanExample = new VulkanExample ( ) ; \
2016-12-13 19:59:15 +01:00
vulkanExample - > initVulkan ( ) ; \
2016-06-26 00:04:13 +02:00
vulkanExample - > setupWindow ( ) ; \
vulkanExample - > prepare ( ) ; \
vulkanExample - > renderLoop ( ) ; \
delete ( vulkanExample ) ; \
2016-06-25 23:01:09 +02:00
return 0 ; \
}
2017-04-14 12:00:05 -04:00
# elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
# define VULKAN_EXAMPLE_MAIN()
2017-02-02 08:54:56 +00:00
# endif