Code cleanup, use VK_USE_PLATFORM_ defines where available
This commit is contained in:
parent
18df00c7b4
commit
fd439a59e2
1 changed files with 35 additions and 78 deletions
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* A swap chain is a collection of framebuffers used for rendering and presentation to the windowing system
|
||||
*
|
||||
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
|
||||
* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de
|
||||
*
|
||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||
*/
|
||||
|
|
@ -12,16 +12,9 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#endif
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "VulkanTools.h"
|
||||
|
|
@ -80,102 +73,66 @@ public:
|
|||
uint32_t imageCount;
|
||||
std::vector<VkImage> images;
|
||||
std::vector<SwapChainBuffer> buffers;
|
||||
// Index of the deteced graphics and presenting device queue
|
||||
/** @brief Queue family index of the detected graphics and presenting device queue */
|
||||
uint32_t queueNodeIndex = UINT32_MAX;
|
||||
|
||||
// Creates an os specific surface
|
||||
/**
|
||||
* Create the surface object, an abstraction for the native platform window
|
||||
*
|
||||
* @pre Windows
|
||||
* @param platformHandle HINSTANCE of the window to create the surface for
|
||||
* @param platformWindow HWND of the window to create the surface for
|
||||
*
|
||||
* @pre Android
|
||||
* @param window A native platform window
|
||||
*
|
||||
* @pre Linux (XCB)
|
||||
* @param connection xcb connection to the X Server
|
||||
* @param window The xcb window to create the surface for
|
||||
* @note Targets other than XCB ar not yet supported
|
||||
*/
|
||||
void initSurface(
|
||||
#ifdef _WIN32
|
||||
void* platformHandle, void* platformWindow
|
||||
#else
|
||||
#ifdef __ANDROID__
|
||||
ANativeWindow* window
|
||||
#else
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
void* view
|
||||
#else
|
||||
#ifdef _DIRECT2DISPLAY
|
||||
uint32_t width, uint32_t height
|
||||
#else
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
wl_display *display, wl_surface *window
|
||||
#else
|
||||
xcb_connection_t* connection, xcb_window_t window
|
||||
/** @brief Creates the platform specific surface abstraction of the native platform window used for presentation */
|
||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||
void initSurface(void* platformHandle, void* platformWindow)
|
||||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
void initSurface(ANativeWindow* window)
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
void initSurface(wl_display *display, wl_surface *window)
|
||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||
void initSurface(xcb_connection_t* connection, xcb_window_t window)
|
||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
void initSurface(void* view)
|
||||
#elif defined(_DIRECT2DISPLAY)
|
||||
void initSurface(uint32_t width, uint32_t height)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
)
|
||||
{
|
||||
VkResult err = VK_SUCCESS;
|
||||
|
||||
// Create the os-specific surface
|
||||
#ifdef _WIN32
|
||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||
VkWin32SurfaceCreateInfoKHR surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||
surfaceCreateInfo.hinstance = (HINSTANCE)platformHandle;
|
||||
surfaceCreateInfo.hwnd = (HWND)platformWindow;
|
||||
err = vkCreateWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
|
||||
#else
|
||||
#ifdef __ANDROID__
|
||||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
|
||||
surfaceCreateInfo.window = window;
|
||||
err = vkCreateAndroidSurfaceKHR(instance, &surfaceCreateInfo, NULL, &surface);
|
||||
#else
|
||||
#ifdef VK_USE_PLATFORM_IOS_MVK
|
||||
VkIOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK;
|
||||
surfaceCreateInfo.pNext = NULL;
|
||||
surfaceCreateInfo.flags = 0;
|
||||
surfaceCreateInfo.pView = view;
|
||||
err = vkCreateIOSSurfaceMVK(instance, &surfaceCreateInfo, nullptr, &surface);
|
||||
#else
|
||||
#ifdef VK_USE_PLATFORM_MACOS_MVK
|
||||
VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
|
||||
surfaceCreateInfo.pNext = NULL;
|
||||
surfaceCreateInfo.flags = 0;
|
||||
surfaceCreateInfo.pView = view;
|
||||
err = vkCreateMacOSSurfaceMVK(instance, &surfaceCreateInfo, NULL, &surface);
|
||||
#else
|
||||
#if defined(_DIRECT2DISPLAY)
|
||||
#elif defined(VK_USE_PLATFORM_IOS_MVK)
|
||||
VkIOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK;
|
||||
surfaceCreateInfo.pNext = NULL;
|
||||
surfaceCreateInfo.flags = 0;
|
||||
surfaceCreateInfo.pView = view;
|
||||
err = vkCreateIOSSurfaceMVK(instance, &surfaceCreateInfo, nullptr, &surface);
|
||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||
VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
|
||||
surfaceCreateInfo.pNext = NULL;
|
||||
surfaceCreateInfo.flags = 0;
|
||||
surfaceCreateInfo.pView = view;
|
||||
err = vkCreateMacOSSurfaceMVK(instance, &surfaceCreateInfo, NULL, &surface);
|
||||
#elif defined(_DIRECT2DISPLAY)
|
||||
createDirect2DisplaySurface(width, height);
|
||||
#else
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
|
||||
surfaceCreateInfo.display = display;
|
||||
surfaceCreateInfo.surface = window;
|
||||
err = vkCreateWaylandSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
|
||||
#else
|
||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||
VkXcbSurfaceCreateInfoKHR surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
|
||||
surfaceCreateInfo.connection = connection;
|
||||
surfaceCreateInfo.window = window;
|
||||
err = vkCreateXcbSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (err != VK_SUCCESS) {
|
||||
|
|
@ -578,8 +535,8 @@ public:
|
|||
VkDisplayModePropertiesKHR* pModeProperties;
|
||||
bool foundMode = false;
|
||||
|
||||
for(uint32_t i = 0; i < displayPropertyCount;++i)
|
||||
{
|
||||
for(uint32_t i = 0; i < displayPropertyCount;++i)
|
||||
{
|
||||
display = pDisplayProperties[i].display;
|
||||
uint32_t modeCount;
|
||||
vkGetDisplayModePropertiesKHR(physicalDevice, display, &modeCount, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue