mirror of
https://github.com/opus-tango/IntroductionToVulkan.git
synced 2026-03-20 12:05:20 +00:00
Changed line endings from Windows (\r\n) to Linux (\n) style.
This commit is contained in:
@@ -1,185 +1,185 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Exported functions //
|
// Exported functions //
|
||||||
// //
|
// //
|
||||||
// These functions are always exposed by vulkan libraries. //
|
// These functions are always exposed by vulkan libraries. //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
|
|
||||||
#if !defined(VK_EXPORTED_FUNCTION)
|
#if !defined(VK_EXPORTED_FUNCTION)
|
||||||
#define VK_EXPORTED_FUNCTION( fun )
|
#define VK_EXPORTED_FUNCTION( fun )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VK_EXPORTED_FUNCTION( vkGetInstanceProcAddr )
|
VK_EXPORTED_FUNCTION( vkGetInstanceProcAddr )
|
||||||
|
|
||||||
#undef VK_EXPORTED_FUNCTION
|
#undef VK_EXPORTED_FUNCTION
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Global level functions //
|
// Global level functions //
|
||||||
// //
|
// //
|
||||||
// They allow checking what instance extensions are available //
|
// They allow checking what instance extensions are available //
|
||||||
// and allow creation of a Vulkan Instance. //
|
// and allow creation of a Vulkan Instance. //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
|
|
||||||
#if !defined(VK_GLOBAL_LEVEL_FUNCTION)
|
#if !defined(VK_GLOBAL_LEVEL_FUNCTION)
|
||||||
#define VK_GLOBAL_LEVEL_FUNCTION( fun )
|
#define VK_GLOBAL_LEVEL_FUNCTION( fun )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Tutorial 01
|
// Tutorial 01
|
||||||
VK_GLOBAL_LEVEL_FUNCTION( vkCreateInstance )
|
VK_GLOBAL_LEVEL_FUNCTION( vkCreateInstance )
|
||||||
|
|
||||||
// Tutorial 02
|
// Tutorial 02
|
||||||
VK_GLOBAL_LEVEL_FUNCTION( vkEnumerateInstanceExtensionProperties )
|
VK_GLOBAL_LEVEL_FUNCTION( vkEnumerateInstanceExtensionProperties )
|
||||||
|
|
||||||
#undef VK_GLOBAL_LEVEL_FUNCTION
|
#undef VK_GLOBAL_LEVEL_FUNCTION
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Instance level functions //
|
// Instance level functions //
|
||||||
// //
|
// //
|
||||||
// These functions allow for device queries and creation. //
|
// These functions allow for device queries and creation. //
|
||||||
// They help choose which device is well suited for our needs. //
|
// They help choose which device is well suited for our needs. //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
|
|
||||||
#if !defined(VK_INSTANCE_LEVEL_FUNCTION)
|
#if !defined(VK_INSTANCE_LEVEL_FUNCTION)
|
||||||
#define VK_INSTANCE_LEVEL_FUNCTION( fun )
|
#define VK_INSTANCE_LEVEL_FUNCTION( fun )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Tutorial 01
|
// Tutorial 01
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkEnumeratePhysicalDevices )
|
VK_INSTANCE_LEVEL_FUNCTION( vkEnumeratePhysicalDevices )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceProperties )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceProperties )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceFeatures )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceFeatures )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceQueueFamilyProperties )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceQueueFamilyProperties )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkCreateDevice )
|
VK_INSTANCE_LEVEL_FUNCTION( vkCreateDevice )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetDeviceProcAddr )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetDeviceProcAddr )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkDestroyInstance )
|
VK_INSTANCE_LEVEL_FUNCTION( vkDestroyInstance )
|
||||||
|
|
||||||
// Tutorial 02
|
// Tutorial 02
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkEnumerateDeviceExtensionProperties )
|
VK_INSTANCE_LEVEL_FUNCTION( vkEnumerateDeviceExtensionProperties )
|
||||||
#if defined(USE_SWAPCHAIN_EXTENSIONS)
|
#if defined(USE_SWAPCHAIN_EXTENSIONS)
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceSupportKHR )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceSupportKHR )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceCapabilitiesKHR )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceCapabilitiesKHR )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceFormatsKHR )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceFormatsKHR )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfacePresentModesKHR )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfacePresentModesKHR )
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkDestroySurfaceKHR )
|
VK_INSTANCE_LEVEL_FUNCTION( vkDestroySurfaceKHR )
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkCreateWin32SurfaceKHR )
|
VK_INSTANCE_LEVEL_FUNCTION( vkCreateWin32SurfaceKHR )
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkCreateXcbSurfaceKHR )
|
VK_INSTANCE_LEVEL_FUNCTION( vkCreateXcbSurfaceKHR )
|
||||||
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkCreateXlibSurfaceKHR )
|
VK_INSTANCE_LEVEL_FUNCTION( vkCreateXlibSurfaceKHR )
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Tutorial 04
|
// Tutorial 04
|
||||||
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceMemoryProperties )
|
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceMemoryProperties )
|
||||||
|
|
||||||
#undef VK_INSTANCE_LEVEL_FUNCTION
|
#undef VK_INSTANCE_LEVEL_FUNCTION
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Device level functions //
|
// Device level functions //
|
||||||
// //
|
// //
|
||||||
// These functions are used mainly for drawing //
|
// These functions are used mainly for drawing //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
|
|
||||||
#if !defined(VK_DEVICE_LEVEL_FUNCTION)
|
#if !defined(VK_DEVICE_LEVEL_FUNCTION)
|
||||||
#define VK_DEVICE_LEVEL_FUNCTION( fun )
|
#define VK_DEVICE_LEVEL_FUNCTION( fun )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Tutorial 01
|
// Tutorial 01
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkGetDeviceQueue )
|
VK_DEVICE_LEVEL_FUNCTION( vkGetDeviceQueue )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDeviceWaitIdle )
|
VK_DEVICE_LEVEL_FUNCTION( vkDeviceWaitIdle )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDevice )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDevice )
|
||||||
|
|
||||||
// Tutorial 02
|
// Tutorial 02
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateSemaphore )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateSemaphore )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateCommandPool )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateCommandPool )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkAllocateCommandBuffers )
|
VK_DEVICE_LEVEL_FUNCTION( vkAllocateCommandBuffers )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkBeginCommandBuffer )
|
VK_DEVICE_LEVEL_FUNCTION( vkBeginCommandBuffer )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdPipelineBarrier )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdPipelineBarrier )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdClearColorImage )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdClearColorImage )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkEndCommandBuffer )
|
VK_DEVICE_LEVEL_FUNCTION( vkEndCommandBuffer )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkQueueSubmit )
|
VK_DEVICE_LEVEL_FUNCTION( vkQueueSubmit )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkFreeCommandBuffers )
|
VK_DEVICE_LEVEL_FUNCTION( vkFreeCommandBuffers )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyCommandPool )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyCommandPool )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroySemaphore )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroySemaphore )
|
||||||
#if defined(USE_SWAPCHAIN_EXTENSIONS)
|
#if defined(USE_SWAPCHAIN_EXTENSIONS)
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateSwapchainKHR )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateSwapchainKHR )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkGetSwapchainImagesKHR )
|
VK_DEVICE_LEVEL_FUNCTION( vkGetSwapchainImagesKHR )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkAcquireNextImageKHR )
|
VK_DEVICE_LEVEL_FUNCTION( vkAcquireNextImageKHR )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkQueuePresentKHR )
|
VK_DEVICE_LEVEL_FUNCTION( vkQueuePresentKHR )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroySwapchainKHR )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroySwapchainKHR )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Tutorial 03
|
// Tutorial 03
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateImageView )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateImageView )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateRenderPass )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateRenderPass )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateFramebuffer )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateFramebuffer )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateShaderModule )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateShaderModule )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreatePipelineLayout )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreatePipelineLayout )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateGraphicsPipelines )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateGraphicsPipelines )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdBeginRenderPass )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdBeginRenderPass )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindPipeline )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindPipeline )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdDraw )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdDraw )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdEndRenderPass )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdEndRenderPass )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyShaderModule )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyShaderModule )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyPipelineLayout )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyPipelineLayout )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyPipeline )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyPipeline )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyRenderPass )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyRenderPass )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyFramebuffer )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyFramebuffer )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyImageView )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyImageView )
|
||||||
|
|
||||||
// Tutorial 04
|
// Tutorial 04
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateFence )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateFence )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateBuffer )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateBuffer )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkGetBufferMemoryRequirements )
|
VK_DEVICE_LEVEL_FUNCTION( vkGetBufferMemoryRequirements )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkAllocateMemory )
|
VK_DEVICE_LEVEL_FUNCTION( vkAllocateMemory )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkBindBufferMemory )
|
VK_DEVICE_LEVEL_FUNCTION( vkBindBufferMemory )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkMapMemory )
|
VK_DEVICE_LEVEL_FUNCTION( vkMapMemory )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkFlushMappedMemoryRanges )
|
VK_DEVICE_LEVEL_FUNCTION( vkFlushMappedMemoryRanges )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkUnmapMemory )
|
VK_DEVICE_LEVEL_FUNCTION( vkUnmapMemory )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdSetViewport )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdSetViewport )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdSetScissor )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdSetScissor )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindVertexBuffers )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindVertexBuffers )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkWaitForFences )
|
VK_DEVICE_LEVEL_FUNCTION( vkWaitForFences )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkResetFences )
|
VK_DEVICE_LEVEL_FUNCTION( vkResetFences )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkFreeMemory )
|
VK_DEVICE_LEVEL_FUNCTION( vkFreeMemory )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyBuffer )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyBuffer )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyFence )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyFence )
|
||||||
|
|
||||||
// Tutorial 05
|
// Tutorial 05
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdCopyBuffer )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdCopyBuffer )
|
||||||
|
|
||||||
// Tutorial 06
|
// Tutorial 06
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateImage )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateImage )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkGetImageMemoryRequirements )
|
VK_DEVICE_LEVEL_FUNCTION( vkGetImageMemoryRequirements )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkBindImageMemory )
|
VK_DEVICE_LEVEL_FUNCTION( vkBindImageMemory )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateSampler )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateSampler )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdCopyBufferToImage )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdCopyBufferToImage )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateDescriptorSetLayout )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateDescriptorSetLayout )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCreateDescriptorPool )
|
VK_DEVICE_LEVEL_FUNCTION( vkCreateDescriptorPool )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkAllocateDescriptorSets )
|
VK_DEVICE_LEVEL_FUNCTION( vkAllocateDescriptorSets )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkUpdateDescriptorSets )
|
VK_DEVICE_LEVEL_FUNCTION( vkUpdateDescriptorSets )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindDescriptorSets )
|
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindDescriptorSets )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDescriptorPool )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDescriptorPool )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDescriptorSetLayout )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDescriptorSetLayout )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroySampler )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroySampler )
|
||||||
VK_DEVICE_LEVEL_FUNCTION( vkDestroyImage )
|
VK_DEVICE_LEVEL_FUNCTION( vkDestroyImage )
|
||||||
|
|
||||||
#undef VK_DEVICE_LEVEL_FUNCTION
|
#undef VK_DEVICE_LEVEL_FUNCTION
|
||||||
@@ -1,385 +1,385 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include "OperatingSystem.h"
|
#include "OperatingSystem.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
namespace OS {
|
namespace OS {
|
||||||
|
|
||||||
Window::Window() :
|
Window::Window() :
|
||||||
Parameters() {
|
Parameters() {
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowParameters Window::GetParameters() const {
|
WindowParameters Window::GetParameters() const {
|
||||||
return Parameters;
|
return Parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
|
|
||||||
#define TUTORIAL_NAME "API without Secrets: Introduction to Vulkan"
|
#define TUTORIAL_NAME "API without Secrets: Introduction to Vulkan"
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {
|
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {
|
||||||
switch( message ) {
|
switch( message ) {
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
case WM_EXITSIZEMOVE:
|
case WM_EXITSIZEMOVE:
|
||||||
PostMessage( hWnd, WM_USER + 1, wParam, lParam );
|
PostMessage( hWnd, WM_USER + 1, wParam, lParam );
|
||||||
break;
|
break;
|
||||||
case WM_KEYDOWN:
|
case WM_KEYDOWN:
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
PostMessage( hWnd, WM_USER + 2, wParam, lParam );
|
PostMessage( hWnd, WM_USER + 2, wParam, lParam );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return DefWindowProc( hWnd, message, wParam, lParam );
|
return DefWindowProc( hWnd, message, wParam, lParam );
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
if( Parameters.Handle ) {
|
if( Parameters.Handle ) {
|
||||||
DestroyWindow( Parameters.Handle );
|
DestroyWindow( Parameters.Handle );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Parameters.Instance ) {
|
if( Parameters.Instance ) {
|
||||||
UnregisterClass( TUTORIAL_NAME, Parameters.Instance );
|
UnregisterClass( TUTORIAL_NAME, Parameters.Instance );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::Create( const char *title ) {
|
bool Window::Create( const char *title ) {
|
||||||
Parameters.Instance = GetModuleHandle( nullptr );
|
Parameters.Instance = GetModuleHandle( nullptr );
|
||||||
|
|
||||||
// Register window class
|
// Register window class
|
||||||
WNDCLASSEX wcex;
|
WNDCLASSEX wcex;
|
||||||
|
|
||||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||||
|
|
||||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
wcex.lpfnWndProc = WndProc;
|
wcex.lpfnWndProc = WndProc;
|
||||||
wcex.cbClsExtra = 0;
|
wcex.cbClsExtra = 0;
|
||||||
wcex.cbWndExtra = 0;
|
wcex.cbWndExtra = 0;
|
||||||
wcex.hInstance = Parameters.Instance;
|
wcex.hInstance = Parameters.Instance;
|
||||||
wcex.hIcon = NULL;
|
wcex.hIcon = NULL;
|
||||||
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
|
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
|
||||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||||
wcex.lpszMenuName = NULL;
|
wcex.lpszMenuName = NULL;
|
||||||
wcex.lpszClassName = TUTORIAL_NAME;
|
wcex.lpszClassName = TUTORIAL_NAME;
|
||||||
wcex.hIconSm = NULL;
|
wcex.hIconSm = NULL;
|
||||||
|
|
||||||
if( !RegisterClassEx( &wcex ) ) {
|
if( !RegisterClassEx( &wcex ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
Parameters.Handle = CreateWindow( TUTORIAL_NAME, title, WS_OVERLAPPEDWINDOW, 20, 20, 500, 500, nullptr, nullptr, Parameters.Instance, nullptr );
|
Parameters.Handle = CreateWindow( TUTORIAL_NAME, title, WS_OVERLAPPEDWINDOW, 20, 20, 500, 500, nullptr, nullptr, Parameters.Instance, nullptr );
|
||||||
if( !Parameters.Handle ) {
|
if( !Parameters.Handle ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
|
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
|
||||||
// Display window
|
// Display window
|
||||||
ShowWindow( Parameters.Handle, SW_SHOWNORMAL );
|
ShowWindow( Parameters.Handle, SW_SHOWNORMAL );
|
||||||
UpdateWindow( Parameters.Handle );
|
UpdateWindow( Parameters.Handle );
|
||||||
|
|
||||||
// Main message loop
|
// Main message loop
|
||||||
MSG message;
|
MSG message;
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
bool resize = false;
|
bool resize = false;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
while( loop ) {
|
while( loop ) {
|
||||||
if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) ) {
|
if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) ) {
|
||||||
// Process events
|
// Process events
|
||||||
switch( message.message ) {
|
switch( message.message ) {
|
||||||
// Resize
|
// Resize
|
||||||
case WM_USER + 1:
|
case WM_USER + 1:
|
||||||
resize = true;
|
resize = true;
|
||||||
break;
|
break;
|
||||||
// Close
|
// Close
|
||||||
case WM_USER + 2:
|
case WM_USER + 2:
|
||||||
loop = false;
|
loop = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
TranslateMessage( &message );
|
TranslateMessage( &message );
|
||||||
DispatchMessage( &message );
|
DispatchMessage( &message );
|
||||||
} else {
|
} else {
|
||||||
// Draw
|
// Draw
|
||||||
if( resize ) {
|
if( resize ) {
|
||||||
resize = false;
|
resize = false;
|
||||||
if( !tutorial.OnWindowSizeChanged() ) {
|
if( !tutorial.OnWindowSizeChanged() ) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( tutorial.ReadyToDraw() ) {
|
if( tutorial.ReadyToDraw() ) {
|
||||||
if( !tutorial.Draw() ) {
|
if( !tutorial.Draw() ) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
xcb_destroy_window( Parameters.Connection, Parameters.Handle );
|
xcb_destroy_window( Parameters.Connection, Parameters.Handle );
|
||||||
xcb_disconnect( Parameters.Connection );
|
xcb_disconnect( Parameters.Connection );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::Create( const char *title ) {
|
bool Window::Create( const char *title ) {
|
||||||
int screen_index;
|
int screen_index;
|
||||||
Parameters.Connection = xcb_connect( nullptr, &screen_index );
|
Parameters.Connection = xcb_connect( nullptr, &screen_index );
|
||||||
|
|
||||||
if( !Parameters.Connection ) {
|
if( !Parameters.Connection ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const xcb_setup_t *setup = xcb_get_setup( Parameters.Connection );
|
const xcb_setup_t *setup = xcb_get_setup( Parameters.Connection );
|
||||||
xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator( setup );
|
xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator( setup );
|
||||||
|
|
||||||
while( screen_index-- > 0 ) {
|
while( screen_index-- > 0 ) {
|
||||||
xcb_screen_next( &screen_iterator );
|
xcb_screen_next( &screen_iterator );
|
||||||
}
|
}
|
||||||
|
|
||||||
xcb_screen_t *screen = screen_iterator.data;
|
xcb_screen_t *screen = screen_iterator.data;
|
||||||
|
|
||||||
Parameters.Handle = xcb_generate_id( Parameters.Connection );
|
Parameters.Handle = xcb_generate_id( Parameters.Connection );
|
||||||
|
|
||||||
uint32_t value_list[] = {
|
uint32_t value_list[] = {
|
||||||
screen->white_pixel,
|
screen->white_pixel,
|
||||||
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY
|
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY
|
||||||
};
|
};
|
||||||
|
|
||||||
xcb_create_window(
|
xcb_create_window(
|
||||||
Parameters.Connection,
|
Parameters.Connection,
|
||||||
XCB_COPY_FROM_PARENT,
|
XCB_COPY_FROM_PARENT,
|
||||||
Parameters.Handle,
|
Parameters.Handle,
|
||||||
screen->root,
|
screen->root,
|
||||||
20,
|
20,
|
||||||
20,
|
20,
|
||||||
500,
|
500,
|
||||||
500,
|
500,
|
||||||
0,
|
0,
|
||||||
XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
||||||
screen->root_visual,
|
screen->root_visual,
|
||||||
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
|
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
|
||||||
value_list );
|
value_list );
|
||||||
|
|
||||||
xcb_flush( Parameters.Connection );
|
xcb_flush( Parameters.Connection );
|
||||||
|
|
||||||
xcb_change_property(
|
xcb_change_property(
|
||||||
Parameters.Connection,
|
Parameters.Connection,
|
||||||
XCB_PROP_MODE_REPLACE,
|
XCB_PROP_MODE_REPLACE,
|
||||||
Parameters.Handle,
|
Parameters.Handle,
|
||||||
XCB_ATOM_WM_NAME,
|
XCB_ATOM_WM_NAME,
|
||||||
XCB_ATOM_STRING,
|
XCB_ATOM_STRING,
|
||||||
8,
|
8,
|
||||||
strlen( title ),
|
strlen( title ),
|
||||||
title );
|
title );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
|
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
|
||||||
// Prepare notification for window destruction
|
// Prepare notification for window destruction
|
||||||
xcb_intern_atom_cookie_t protocols_cookie = xcb_intern_atom( Parameters.Connection, 1, 12, "WM_PROTOCOLS" );
|
xcb_intern_atom_cookie_t protocols_cookie = xcb_intern_atom( Parameters.Connection, 1, 12, "WM_PROTOCOLS" );
|
||||||
xcb_intern_atom_reply_t *protocols_reply = xcb_intern_atom_reply( Parameters.Connection, protocols_cookie, 0 );
|
xcb_intern_atom_reply_t *protocols_reply = xcb_intern_atom_reply( Parameters.Connection, protocols_cookie, 0 );
|
||||||
xcb_intern_atom_cookie_t delete_cookie = xcb_intern_atom( Parameters.Connection, 0, 16, "WM_DELETE_WINDOW" );
|
xcb_intern_atom_cookie_t delete_cookie = xcb_intern_atom( Parameters.Connection, 0, 16, "WM_DELETE_WINDOW" );
|
||||||
xcb_intern_atom_reply_t *delete_reply = xcb_intern_atom_reply( Parameters.Connection, delete_cookie, 0 );
|
xcb_intern_atom_reply_t *delete_reply = xcb_intern_atom_reply( Parameters.Connection, delete_cookie, 0 );
|
||||||
xcb_change_property( Parameters.Connection, XCB_PROP_MODE_REPLACE, Parameters.Handle, (*protocols_reply).atom, 4, 32, 1, &(*delete_reply).atom );
|
xcb_change_property( Parameters.Connection, XCB_PROP_MODE_REPLACE, Parameters.Handle, (*protocols_reply).atom, 4, 32, 1, &(*delete_reply).atom );
|
||||||
free( protocols_reply );
|
free( protocols_reply );
|
||||||
|
|
||||||
// Display window
|
// Display window
|
||||||
xcb_map_window( Parameters.Connection, Parameters.Handle );
|
xcb_map_window( Parameters.Connection, Parameters.Handle );
|
||||||
xcb_flush( Parameters.Connection );
|
xcb_flush( Parameters.Connection );
|
||||||
|
|
||||||
// Main message loop
|
// Main message loop
|
||||||
xcb_generic_event_t *event;
|
xcb_generic_event_t *event;
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
bool resize = false;
|
bool resize = false;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
while( loop ) {
|
while( loop ) {
|
||||||
event = xcb_poll_for_event( Parameters.Connection );
|
event = xcb_poll_for_event( Parameters.Connection );
|
||||||
|
|
||||||
if( event ) {
|
if( event ) {
|
||||||
// Process events
|
// Process events
|
||||||
switch (event->response_type & 0x7f) {
|
switch (event->response_type & 0x7f) {
|
||||||
// Resize
|
// Resize
|
||||||
case XCB_CONFIGURE_NOTIFY: {
|
case XCB_CONFIGURE_NOTIFY: {
|
||||||
xcb_configure_notify_event_t *configure_event = (xcb_configure_notify_event_t*)event;
|
xcb_configure_notify_event_t *configure_event = (xcb_configure_notify_event_t*)event;
|
||||||
static uint16_t width = configure_event->width;
|
static uint16_t width = configure_event->width;
|
||||||
static uint16_t height = configure_event->height;
|
static uint16_t height = configure_event->height;
|
||||||
|
|
||||||
if( ((configure_event->width > 0) && (width != configure_event->width)) ||
|
if( ((configure_event->width > 0) && (width != configure_event->width)) ||
|
||||||
((configure_event->height > 0) && (height != configure_event->height)) ) {
|
((configure_event->height > 0) && (height != configure_event->height)) ) {
|
||||||
resize = true;
|
resize = true;
|
||||||
width = configure_event->width;
|
width = configure_event->width;
|
||||||
height = configure_event->height;
|
height = configure_event->height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Close
|
// Close
|
||||||
case XCB_CLIENT_MESSAGE:
|
case XCB_CLIENT_MESSAGE:
|
||||||
if( (*(xcb_client_message_event_t*)event).data.data32[0] == (*delete_reply).atom ) {
|
if( (*(xcb_client_message_event_t*)event).data.data32[0] == (*delete_reply).atom ) {
|
||||||
loop = false;
|
loop = false;
|
||||||
free( delete_reply );
|
free( delete_reply );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XCB_KEY_PRESS:
|
case XCB_KEY_PRESS:
|
||||||
loop = false;
|
loop = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free( event );
|
free( event );
|
||||||
} else {
|
} else {
|
||||||
// Draw
|
// Draw
|
||||||
if( resize ) {
|
if( resize ) {
|
||||||
resize = false;
|
resize = false;
|
||||||
if( !tutorial.OnWindowSizeChanged() ) {
|
if( !tutorial.OnWindowSizeChanged() ) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( tutorial.ReadyToDraw() ) {
|
if( tutorial.ReadyToDraw() ) {
|
||||||
if( !tutorial.Draw() ) {
|
if( !tutorial.Draw() ) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
XDestroyWindow( Parameters.DisplayPtr, Parameters.Handle );
|
XDestroyWindow( Parameters.DisplayPtr, Parameters.Handle );
|
||||||
XCloseDisplay( Parameters.DisplayPtr );
|
XCloseDisplay( Parameters.DisplayPtr );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::Create( const char *title ) {
|
bool Window::Create( const char *title ) {
|
||||||
Parameters.DisplayPtr = XOpenDisplay( nullptr );
|
Parameters.DisplayPtr = XOpenDisplay( nullptr );
|
||||||
if( !Parameters.DisplayPtr ) {
|
if( !Parameters.DisplayPtr ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int default_screen = DefaultScreen( Parameters.DisplayPtr );
|
int default_screen = DefaultScreen( Parameters.DisplayPtr );
|
||||||
|
|
||||||
Parameters.Handle = XCreateSimpleWindow(
|
Parameters.Handle = XCreateSimpleWindow(
|
||||||
Parameters.DisplayPtr,
|
Parameters.DisplayPtr,
|
||||||
DefaultRootWindow( Parameters.DisplayPtr ),
|
DefaultRootWindow( Parameters.DisplayPtr ),
|
||||||
20,
|
20,
|
||||||
20,
|
20,
|
||||||
500,
|
500,
|
||||||
500,
|
500,
|
||||||
1,
|
1,
|
||||||
BlackPixel( Parameters.DisplayPtr, default_screen ),
|
BlackPixel( Parameters.DisplayPtr, default_screen ),
|
||||||
WhitePixel( Parameters.DisplayPtr, default_screen ) );
|
WhitePixel( Parameters.DisplayPtr, default_screen ) );
|
||||||
|
|
||||||
// XSync( Parameters.DisplayPtr, false );
|
// XSync( Parameters.DisplayPtr, false );
|
||||||
XSetStandardProperties( Parameters.DisplayPtr, Parameters.Handle, title, title, None, nullptr, 0, nullptr );
|
XSetStandardProperties( Parameters.DisplayPtr, Parameters.Handle, title, title, None, nullptr, 0, nullptr );
|
||||||
XSelectInput( Parameters.DisplayPtr, Parameters.Handle, ExposureMask | KeyPressMask | StructureNotifyMask );
|
XSelectInput( Parameters.DisplayPtr, Parameters.Handle, ExposureMask | KeyPressMask | StructureNotifyMask );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
|
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
|
||||||
// Prepare notification for window destruction
|
// Prepare notification for window destruction
|
||||||
Atom delete_window_atom;
|
Atom delete_window_atom;
|
||||||
delete_window_atom = XInternAtom( Parameters.DisplayPtr, "WM_DELETE_WINDOW", false );
|
delete_window_atom = XInternAtom( Parameters.DisplayPtr, "WM_DELETE_WINDOW", false );
|
||||||
XSetWMProtocols( Parameters.DisplayPtr, Parameters.Handle, &delete_window_atom, 1);
|
XSetWMProtocols( Parameters.DisplayPtr, Parameters.Handle, &delete_window_atom, 1);
|
||||||
|
|
||||||
// Display window
|
// Display window
|
||||||
XClearWindow( Parameters.DisplayPtr, Parameters.Handle );
|
XClearWindow( Parameters.DisplayPtr, Parameters.Handle );
|
||||||
XMapWindow( Parameters.DisplayPtr, Parameters.Handle );
|
XMapWindow( Parameters.DisplayPtr, Parameters.Handle );
|
||||||
|
|
||||||
// Main message loop
|
// Main message loop
|
||||||
XEvent event;
|
XEvent event;
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
bool resize = false;
|
bool resize = false;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
while( loop ) {
|
while( loop ) {
|
||||||
if( XPending( Parameters.DisplayPtr ) ) {
|
if( XPending( Parameters.DisplayPtr ) ) {
|
||||||
XNextEvent( Parameters.DisplayPtr, &event );
|
XNextEvent( Parameters.DisplayPtr, &event );
|
||||||
switch( event.type ) {
|
switch( event.type ) {
|
||||||
//Process events
|
//Process events
|
||||||
case ConfigureNotify: {
|
case ConfigureNotify: {
|
||||||
static int width = event.xconfigure.width;
|
static int width = event.xconfigure.width;
|
||||||
static int height = event.xconfigure.height;
|
static int height = event.xconfigure.height;
|
||||||
|
|
||||||
if( ((event.xconfigure.width > 0) && (event.xconfigure.width != width)) ||
|
if( ((event.xconfigure.width > 0) && (event.xconfigure.width != width)) ||
|
||||||
((event.xconfigure.height > 0) && (event.xconfigure.width != height)) ) {
|
((event.xconfigure.height > 0) && (event.xconfigure.width != height)) ) {
|
||||||
width = event.xconfigure.width;
|
width = event.xconfigure.width;
|
||||||
height = event.xconfigure.height;
|
height = event.xconfigure.height;
|
||||||
resize = true;
|
resize = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
loop = false;
|
loop = false;
|
||||||
break;
|
break;
|
||||||
case DestroyNotify:
|
case DestroyNotify:
|
||||||
loop = false;
|
loop = false;
|
||||||
break;
|
break;
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
if( static_cast<unsigned int>(event.xclient.data.l[0]) == delete_window_atom ) {
|
if( static_cast<unsigned int>(event.xclient.data.l[0]) == delete_window_atom ) {
|
||||||
loop = false;
|
loop = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Draw
|
// Draw
|
||||||
if( resize ) {
|
if( resize ) {
|
||||||
resize = false;
|
resize = false;
|
||||||
if( !tutorial.OnWindowSizeChanged() ) {
|
if( !tutorial.OnWindowSizeChanged() ) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( tutorial.ReadyToDraw() ) {
|
if( tutorial.ReadyToDraw() ) {
|
||||||
if( !tutorial.Draw() ) {
|
if( !tutorial.Draw() ) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace OS
|
} // namespace OS
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|||||||
@@ -1,140 +1,140 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(OPERATING_SYSTEM_HEADER)
|
#if !defined(OPERATING_SYSTEM_HEADER)
|
||||||
#define OPERATING_SYSTEM_HEADER
|
#define OPERATING_SYSTEM_HEADER
|
||||||
|
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
namespace OS {
|
namespace OS {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// LibraryHandle //
|
// LibraryHandle //
|
||||||
// //
|
// //
|
||||||
// Dynamic Library OS dependent type //
|
// Dynamic Library OS dependent type //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
//
|
//
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
typedef HMODULE LibraryHandle;
|
typedef HMODULE LibraryHandle;
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||||
typedef void* LibraryHandle;
|
typedef void* LibraryHandle;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// OnWindowSizeChanged //
|
// OnWindowSizeChanged //
|
||||||
// //
|
// //
|
||||||
// Base class for handling window size changes //
|
// Base class for handling window size changes //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class TutorialBase {
|
class TutorialBase {
|
||||||
public:
|
public:
|
||||||
virtual bool OnWindowSizeChanged() = 0;
|
virtual bool OnWindowSizeChanged() = 0;
|
||||||
virtual bool Draw() = 0;
|
virtual bool Draw() = 0;
|
||||||
|
|
||||||
virtual bool ReadyToDraw() const final {
|
virtual bool ReadyToDraw() const final {
|
||||||
return CanRender;
|
return CanRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
TutorialBase() :
|
TutorialBase() :
|
||||||
CanRender( false ) {
|
CanRender( false ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~TutorialBase() {
|
virtual ~TutorialBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool CanRender;
|
bool CanRender;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// WindowParameters //
|
// WindowParameters //
|
||||||
// //
|
// //
|
||||||
// OS dependent window parameters //
|
// OS dependent window parameters //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct WindowParameters {
|
struct WindowParameters {
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
HINSTANCE Instance;
|
HINSTANCE Instance;
|
||||||
HWND Handle;
|
HWND Handle;
|
||||||
|
|
||||||
WindowParameters() :
|
WindowParameters() :
|
||||||
Instance(),
|
Instance(),
|
||||||
Handle() {
|
Handle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||||
xcb_connection_t *Connection;
|
xcb_connection_t *Connection;
|
||||||
xcb_window_t Handle;
|
xcb_window_t Handle;
|
||||||
|
|
||||||
WindowParameters() :
|
WindowParameters() :
|
||||||
Connection(),
|
Connection(),
|
||||||
Handle() {
|
Handle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||||
Display *DisplayPtr;
|
Display *DisplayPtr;
|
||||||
Window Handle;
|
Window Handle;
|
||||||
|
|
||||||
WindowParameters() :
|
WindowParameters() :
|
||||||
DisplayPtr(),
|
DisplayPtr(),
|
||||||
Handle() {
|
Handle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Window //
|
// Window //
|
||||||
// //
|
// //
|
||||||
// OS dependent window creation and destruction class //
|
// OS dependent window creation and destruction class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class Window {
|
class Window {
|
||||||
public:
|
public:
|
||||||
Window();
|
Window();
|
||||||
~Window();
|
~Window();
|
||||||
|
|
||||||
bool Create( const char *title );
|
bool Create( const char *title );
|
||||||
bool RenderingLoop( TutorialBase &tutorial ) const;
|
bool RenderingLoop( TutorialBase &tutorial ) const;
|
||||||
WindowParameters GetParameters() const;
|
WindowParameters GetParameters() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WindowParameters Parameters;
|
WindowParameters Parameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace OS
|
} // namespace OS
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // OPERATING_SYSTEM_HEADER
|
#endif // OPERATING_SYSTEM_HEADER
|
||||||
@@ -1,158 +1,158 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
namespace Tools {
|
namespace Tools {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// GetBinaryFileContents //
|
// GetBinaryFileContents //
|
||||||
// //
|
// //
|
||||||
// Function reading binary contents of a file //
|
// Function reading binary contents of a file //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
std::vector<char> GetBinaryFileContents( std::string const &filename ) {
|
std::vector<char> GetBinaryFileContents( std::string const &filename ) {
|
||||||
|
|
||||||
std::ifstream file( filename, std::ios::binary );
|
std::ifstream file( filename, std::ios::binary );
|
||||||
if( file.fail() ) {
|
if( file.fail() ) {
|
||||||
std::cout << "Could not open \"" << filename << "\" file!" << std::endl;
|
std::cout << "Could not open \"" << filename << "\" file!" << std::endl;
|
||||||
return std::vector<char>();
|
return std::vector<char>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::streampos begin, end;
|
std::streampos begin, end;
|
||||||
begin = file.tellg();
|
begin = file.tellg();
|
||||||
file.seekg( 0, std::ios::end );
|
file.seekg( 0, std::ios::end );
|
||||||
end = file.tellg();
|
end = file.tellg();
|
||||||
|
|
||||||
std::vector<char> result( static_cast<size_t>(end - begin) );
|
std::vector<char> result( static_cast<size_t>(end - begin) );
|
||||||
file.seekg( 0, std::ios::beg );
|
file.seekg( 0, std::ios::beg );
|
||||||
file.read( &result[0], end - begin );
|
file.read( &result[0], end - begin );
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// GetImageData //
|
// GetImageData //
|
||||||
// //
|
// //
|
||||||
// Function loading image (texture) data from a specified file //
|
// Function loading image (texture) data from a specified file //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
std::vector<char> GetImageData( std::string const &filename, int requested_components, int *width, int *height, int *components, int *data_size ) {
|
std::vector<char> GetImageData( std::string const &filename, int requested_components, int *width, int *height, int *components, int *data_size ) {
|
||||||
std::vector<char> file_data = Tools::GetBinaryFileContents( filename );
|
std::vector<char> file_data = Tools::GetBinaryFileContents( filename );
|
||||||
if( file_data.size() == 0 ) {
|
if( file_data.size() == 0 ) {
|
||||||
return std::vector<char>();
|
return std::vector<char>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int tmp_width = 0, tmp_height = 0, tmp_components = 0;
|
int tmp_width = 0, tmp_height = 0, tmp_components = 0;
|
||||||
unsigned char *image_data = stbi_load_from_memory( reinterpret_cast<unsigned char*>(&file_data[0]), static_cast<int>(file_data.size()), &tmp_width, &tmp_height, &tmp_components, requested_components );
|
unsigned char *image_data = stbi_load_from_memory( reinterpret_cast<unsigned char*>(&file_data[0]), static_cast<int>(file_data.size()), &tmp_width, &tmp_height, &tmp_components, requested_components );
|
||||||
if( (image_data == nullptr) ||
|
if( (image_data == nullptr) ||
|
||||||
(tmp_width <= 0) ||
|
(tmp_width <= 0) ||
|
||||||
(tmp_height <= 0) ||
|
(tmp_height <= 0) ||
|
||||||
(tmp_components <= 0) ) {
|
(tmp_components <= 0) ) {
|
||||||
std::cout << "Could not read image data!" << std::endl;
|
std::cout << "Could not read image data!" << std::endl;
|
||||||
return std::vector<char>();
|
return std::vector<char>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = (tmp_width) * (tmp_height) * (requested_components <= 0 ? tmp_components : requested_components);
|
int size = (tmp_width) * (tmp_height) * (requested_components <= 0 ? tmp_components : requested_components);
|
||||||
if( data_size ) {
|
if( data_size ) {
|
||||||
*data_size = size;
|
*data_size = size;
|
||||||
}
|
}
|
||||||
if( width ) {
|
if( width ) {
|
||||||
*width = tmp_width;
|
*width = tmp_width;
|
||||||
}
|
}
|
||||||
if( height ) {
|
if( height ) {
|
||||||
*height = tmp_height;
|
*height = tmp_height;
|
||||||
}
|
}
|
||||||
if( components ) {
|
if( components ) {
|
||||||
*components = tmp_components;
|
*components = tmp_components;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> output(size);
|
std::vector<char> output(size);
|
||||||
memcpy( &output[0], image_data, size );
|
memcpy( &output[0], image_data, size );
|
||||||
|
|
||||||
stbi_image_free( image_data );
|
stbi_image_free( image_data );
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// GetPerspectiveProjectionMatrix //
|
// GetPerspectiveProjectionMatrix //
|
||||||
// //
|
// //
|
||||||
// Function calculating perspective projection matrix //
|
// Function calculating perspective projection matrix //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
std::array<float, 16> GetPerspectiveProjectionMatrix( float const aspect_ratio, float const field_of_view, float const near_clip, float const far_clip ) {
|
std::array<float, 16> GetPerspectiveProjectionMatrix( float const aspect_ratio, float const field_of_view, float const near_clip, float const far_clip ) {
|
||||||
float f = 1.0f / std::tan( field_of_view * 0.5f * 0.01745329251994329576923690768489f );
|
float f = 1.0f / std::tan( field_of_view * 0.5f * 0.01745329251994329576923690768489f );
|
||||||
|
|
||||||
return {
|
return {
|
||||||
f / aspect_ratio,
|
f / aspect_ratio,
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
0.0f,
|
0.0f,
|
||||||
f,
|
f,
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
(near_clip + far_clip) / (near_clip - far_clip),
|
(near_clip + far_clip) / (near_clip - far_clip),
|
||||||
-1.0f,
|
-1.0f,
|
||||||
|
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
(2.0f * near_clip * far_clip) / (near_clip - far_clip),
|
(2.0f * near_clip * far_clip) / (near_clip - far_clip),
|
||||||
0.0f
|
0.0f
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// GetOrthographicsProjectionMatrix //
|
// GetOrthographicsProjectionMatrix //
|
||||||
// //
|
// //
|
||||||
// Function calculating orthographic projection matrix //
|
// Function calculating orthographic projection matrix //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
std::array<float, 16> GetOrthographicProjectionMatrix( float const left_plane, float const right_plane, float const top_plane, float const bottom_plane, float const near_plane, float const far_plane ) {
|
std::array<float, 16> GetOrthographicProjectionMatrix( float const left_plane, float const right_plane, float const top_plane, float const bottom_plane, float const near_plane, float const far_plane ) {
|
||||||
return {
|
return {
|
||||||
2.0f / (right_plane - left_plane),
|
2.0f / (right_plane - left_plane),
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
0.0f,
|
0.0f,
|
||||||
2.0f / (bottom_plane - top_plane),
|
2.0f / (bottom_plane - top_plane),
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
-2.0f / (far_plane - near_plane),
|
-2.0f / (far_plane - near_plane),
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
-(right_plane + left_plane) / (right_plane - left_plane),
|
-(right_plane + left_plane) / (right_plane - left_plane),
|
||||||
-(bottom_plane + top_plane) / (bottom_plane - top_plane),
|
-(bottom_plane + top_plane) / (bottom_plane - top_plane),
|
||||||
-(far_plane + near_plane) / (far_plane - near_plane),
|
-(far_plane + near_plane) / (far_plane - near_plane),
|
||||||
1.0f
|
1.0f
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Tools
|
} // namespace Tools
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
@@ -1,119 +1,119 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(TOOLS_HEADER)
|
#if !defined(TOOLS_HEADER)
|
||||||
#define TOOLS_HEADER
|
#define TOOLS_HEADER
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "vulkan.h"
|
#include "vulkan.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
namespace Tools {
|
namespace Tools {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// AutoDeleter //
|
// AutoDeleter //
|
||||||
// //
|
// //
|
||||||
// Auto-deleter helper template class responsible for calling //
|
// Auto-deleter helper template class responsible for calling //
|
||||||
// provided function which deletes given object of type T //
|
// provided function which deletes given object of type T //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
template<class T, class F>
|
template<class T, class F>
|
||||||
class AutoDeleter {
|
class AutoDeleter {
|
||||||
public:
|
public:
|
||||||
AutoDeleter() :
|
AutoDeleter() :
|
||||||
Object( VK_NULL_HANDLE ),
|
Object( VK_NULL_HANDLE ),
|
||||||
Deleter( nullptr ),
|
Deleter( nullptr ),
|
||||||
Device( VK_NULL_HANDLE ) {
|
Device( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoDeleter( T object, F deleter, VkDevice device ) :
|
AutoDeleter( T object, F deleter, VkDevice device ) :
|
||||||
Object( object ),
|
Object( object ),
|
||||||
Deleter( deleter ),
|
Deleter( deleter ),
|
||||||
Device( device ) {
|
Device( device ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoDeleter( AutoDeleter&& other ) {
|
AutoDeleter( AutoDeleter&& other ) {
|
||||||
*this = std::move( other );
|
*this = std::move( other );
|
||||||
}
|
}
|
||||||
|
|
||||||
~AutoDeleter() {
|
~AutoDeleter() {
|
||||||
if( (Object != VK_NULL_HANDLE) && (Deleter != nullptr) && (Device != VK_NULL_HANDLE) ) {
|
if( (Object != VK_NULL_HANDLE) && (Deleter != nullptr) && (Device != VK_NULL_HANDLE) ) {
|
||||||
Deleter( Device, Object, nullptr );
|
Deleter( Device, Object, nullptr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoDeleter& operator=(AutoDeleter&& other) {
|
AutoDeleter& operator=(AutoDeleter&& other) {
|
||||||
if( this != &other ) {
|
if( this != &other ) {
|
||||||
Object = other.Object;
|
Object = other.Object;
|
||||||
Deleter = other.Deleter;
|
Deleter = other.Deleter;
|
||||||
Device = other.Device;
|
Device = other.Device;
|
||||||
other.Object = VK_NULL_HANDLE;
|
other.Object = VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
T Get() {
|
T Get() {
|
||||||
return Object;
|
return Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator !() const {
|
bool operator !() const {
|
||||||
return Object == VK_NULL_HANDLE;
|
return Object == VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AutoDeleter( const AutoDeleter& );
|
AutoDeleter( const AutoDeleter& );
|
||||||
AutoDeleter& operator=( const AutoDeleter& );
|
AutoDeleter& operator=( const AutoDeleter& );
|
||||||
T Object;
|
T Object;
|
||||||
F Deleter;
|
F Deleter;
|
||||||
VkDevice Device;
|
VkDevice Device;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// GetBinaryFileContents //
|
// GetBinaryFileContents //
|
||||||
// //
|
// //
|
||||||
// Function reading binary contents of a file //
|
// Function reading binary contents of a file //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
std::vector<char> GetBinaryFileContents( std::string const &filename );
|
std::vector<char> GetBinaryFileContents( std::string const &filename );
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// GetImageData //
|
// GetImageData //
|
||||||
// //
|
// //
|
||||||
// Function loading image (texture) data from a specified file //
|
// Function loading image (texture) data from a specified file //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
std::vector<char> GetImageData( std::string const &filename, int requested_components, int *width, int *height, int *components, int *data_size );
|
std::vector<char> GetImageData( std::string const &filename, int requested_components, int *width, int *height, int *components, int *data_size );
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// GetPerspectiveProjectionMatrix //
|
// GetPerspectiveProjectionMatrix //
|
||||||
// //
|
// //
|
||||||
// Function calculating perspective projection matrix //
|
// Function calculating perspective projection matrix //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
std::array<float, 16> GetPerspectiveProjectionMatrix( float const aspect_ratio, float const field_of_view, float const near_clip, float const far_clip );
|
std::array<float, 16> GetPerspectiveProjectionMatrix( float const aspect_ratio, float const field_of_view, float const near_clip, float const far_clip );
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// GetOrthographicsProjectionMatrix //
|
// GetOrthographicsProjectionMatrix //
|
||||||
// //
|
// //
|
||||||
// Function calculating orthographic projection matrix //
|
// Function calculating orthographic projection matrix //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
std::array<float, 16> GetOrthographicProjectionMatrix( float const left_plane, float const right_plane, float const top_plane, float const bottom_plane, float const near_plane, float const far_plane );
|
std::array<float, 16> GetOrthographicProjectionMatrix( float const left_plane, float const right_plane, float const top_plane, float const bottom_plane, float const near_plane, float const far_plane );
|
||||||
|
|
||||||
} // namespace Tools
|
} // namespace Tools
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
|
|
||||||
#endif // TOOLS_HEADER
|
#endif // TOOLS_HEADER
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,157 +1,157 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(VULKAN_COMMON_HEADER)
|
#if !defined(VULKAN_COMMON_HEADER)
|
||||||
#define VULKAN_COMMON_HEADER
|
#define VULKAN_COMMON_HEADER
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "vulkan.h"
|
#include "vulkan.h"
|
||||||
#include "OperatingSystem.h"
|
#include "OperatingSystem.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// QueueParameters //
|
// QueueParameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan Queue's parameters container class //
|
// Vulkan Queue's parameters container class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct QueueParameters {
|
struct QueueParameters {
|
||||||
VkQueue Handle;
|
VkQueue Handle;
|
||||||
uint32_t FamilyIndex;
|
uint32_t FamilyIndex;
|
||||||
|
|
||||||
QueueParameters() :
|
QueueParameters() :
|
||||||
Handle( VK_NULL_HANDLE ),
|
Handle( VK_NULL_HANDLE ),
|
||||||
FamilyIndex( 0 ) {
|
FamilyIndex( 0 ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// ImageParameters //
|
// ImageParameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan Image's parameters container class //
|
// Vulkan Image's parameters container class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct ImageParameters {
|
struct ImageParameters {
|
||||||
VkImage Handle;
|
VkImage Handle;
|
||||||
VkImageView View;
|
VkImageView View;
|
||||||
VkSampler Sampler;
|
VkSampler Sampler;
|
||||||
VkDeviceMemory Memory;
|
VkDeviceMemory Memory;
|
||||||
|
|
||||||
ImageParameters() :
|
ImageParameters() :
|
||||||
Handle( VK_NULL_HANDLE ),
|
Handle( VK_NULL_HANDLE ),
|
||||||
View( VK_NULL_HANDLE ),
|
View( VK_NULL_HANDLE ),
|
||||||
Sampler( VK_NULL_HANDLE ),
|
Sampler( VK_NULL_HANDLE ),
|
||||||
Memory( VK_NULL_HANDLE ) {
|
Memory( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// SwapChainParameters //
|
// SwapChainParameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan SwapChain's parameters container class //
|
// Vulkan SwapChain's parameters container class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct SwapChainParameters {
|
struct SwapChainParameters {
|
||||||
VkSwapchainKHR Handle;
|
VkSwapchainKHR Handle;
|
||||||
VkFormat Format;
|
VkFormat Format;
|
||||||
std::vector<ImageParameters> Images;
|
std::vector<ImageParameters> Images;
|
||||||
VkExtent2D Extent;
|
VkExtent2D Extent;
|
||||||
|
|
||||||
SwapChainParameters() :
|
SwapChainParameters() :
|
||||||
Handle( VK_NULL_HANDLE ),
|
Handle( VK_NULL_HANDLE ),
|
||||||
Format( VK_FORMAT_UNDEFINED ),
|
Format( VK_FORMAT_UNDEFINED ),
|
||||||
Images(),
|
Images(),
|
||||||
Extent() {
|
Extent() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanCommonParameters //
|
// VulkanCommonParameters //
|
||||||
// //
|
// //
|
||||||
// General Vulkan parameters' container class //
|
// General Vulkan parameters' container class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VulkanCommonParameters {
|
struct VulkanCommonParameters {
|
||||||
VkInstance Instance;
|
VkInstance Instance;
|
||||||
VkPhysicalDevice PhysicalDevice;
|
VkPhysicalDevice PhysicalDevice;
|
||||||
VkDevice Device;
|
VkDevice Device;
|
||||||
QueueParameters GraphicsQueue;
|
QueueParameters GraphicsQueue;
|
||||||
QueueParameters PresentQueue;
|
QueueParameters PresentQueue;
|
||||||
VkSurfaceKHR PresentationSurface;
|
VkSurfaceKHR PresentationSurface;
|
||||||
SwapChainParameters SwapChain;
|
SwapChainParameters SwapChain;
|
||||||
|
|
||||||
VulkanCommonParameters() :
|
VulkanCommonParameters() :
|
||||||
Instance( VK_NULL_HANDLE ),
|
Instance( VK_NULL_HANDLE ),
|
||||||
PhysicalDevice( VK_NULL_HANDLE ),
|
PhysicalDevice( VK_NULL_HANDLE ),
|
||||||
Device( VK_NULL_HANDLE ),
|
Device( VK_NULL_HANDLE ),
|
||||||
GraphicsQueue(),
|
GraphicsQueue(),
|
||||||
PresentQueue(),
|
PresentQueue(),
|
||||||
PresentationSurface( VK_NULL_HANDLE ),
|
PresentationSurface( VK_NULL_HANDLE ),
|
||||||
SwapChain() {
|
SwapChain() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanCommon //
|
// VulkanCommon //
|
||||||
// //
|
// //
|
||||||
// Base class for Vulkan more advanced tutorial classes //
|
// Base class for Vulkan more advanced tutorial classes //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class VulkanCommon : public OS::TutorialBase {
|
class VulkanCommon : public OS::TutorialBase {
|
||||||
public:
|
public:
|
||||||
VulkanCommon();
|
VulkanCommon();
|
||||||
virtual ~VulkanCommon();
|
virtual ~VulkanCommon();
|
||||||
|
|
||||||
bool PrepareVulkan( OS::WindowParameters parameters );
|
bool PrepareVulkan( OS::WindowParameters parameters );
|
||||||
virtual bool OnWindowSizeChanged() final override;
|
virtual bool OnWindowSizeChanged() final override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
VkPhysicalDevice GetPhysicalDevice() const;
|
VkPhysicalDevice GetPhysicalDevice() const;
|
||||||
VkDevice GetDevice() const;
|
VkDevice GetDevice() const;
|
||||||
|
|
||||||
const QueueParameters GetGraphicsQueue() const;
|
const QueueParameters GetGraphicsQueue() const;
|
||||||
const QueueParameters GetPresentQueue() const;
|
const QueueParameters GetPresentQueue() const;
|
||||||
|
|
||||||
const SwapChainParameters GetSwapChain() const;
|
const SwapChainParameters GetSwapChain() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OS::LibraryHandle VulkanLibrary;
|
OS::LibraryHandle VulkanLibrary;
|
||||||
OS::WindowParameters Window;
|
OS::WindowParameters Window;
|
||||||
VulkanCommonParameters Vulkan;
|
VulkanCommonParameters Vulkan;
|
||||||
|
|
||||||
bool LoadVulkanLibrary();
|
bool LoadVulkanLibrary();
|
||||||
bool LoadExportedEntryPoints();
|
bool LoadExportedEntryPoints();
|
||||||
bool LoadGlobalLevelEntryPoints();
|
bool LoadGlobalLevelEntryPoints();
|
||||||
bool CreateInstance();
|
bool CreateInstance();
|
||||||
bool LoadInstanceLevelEntryPoints();
|
bool LoadInstanceLevelEntryPoints();
|
||||||
bool CreatePresentationSurface();
|
bool CreatePresentationSurface();
|
||||||
bool CreateDevice();
|
bool CreateDevice();
|
||||||
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
|
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
|
||||||
bool LoadDeviceLevelEntryPoints();
|
bool LoadDeviceLevelEntryPoints();
|
||||||
bool GetDeviceQueue();
|
bool GetDeviceQueue();
|
||||||
bool CreateSwapChain();
|
bool CreateSwapChain();
|
||||||
bool CreateSwapChainImageViews();
|
bool CreateSwapChainImageViews();
|
||||||
virtual bool ChildOnWindowSizeChanged() = 0;
|
virtual bool ChildOnWindowSizeChanged() = 0;
|
||||||
virtual void ChildClear() = 0;
|
virtual void ChildClear() = 0;
|
||||||
|
|
||||||
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
|
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
|
||||||
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||||
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
|
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
|
||||||
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||||
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||||
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||||
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
|
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // VULKAN_COMMON_HEADER
|
#endif // VULKAN_COMMON_HEADER
|
||||||
@@ -1,28 +1,28 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "vulkan.h"
|
#include "vulkan.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
#define VK_EXPORTED_FUNCTION( fun ) PFN_##fun fun;
|
#define VK_EXPORTED_FUNCTION( fun ) PFN_##fun fun;
|
||||||
#define VK_GLOBAL_LEVEL_FUNCTION( fun ) PFN_##fun fun;
|
#define VK_GLOBAL_LEVEL_FUNCTION( fun ) PFN_##fun fun;
|
||||||
#define VK_INSTANCE_LEVEL_FUNCTION( fun ) PFN_##fun fun;
|
#define VK_INSTANCE_LEVEL_FUNCTION( fun ) PFN_##fun fun;
|
||||||
#define VK_DEVICE_LEVEL_FUNCTION( fun ) PFN_##fun fun;
|
#define VK_DEVICE_LEVEL_FUNCTION( fun ) PFN_##fun fun;
|
||||||
|
|
||||||
#include "ListOfFunctions.inl"
|
#include "ListOfFunctions.inl"
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
@@ -1,33 +1,33 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(VULKAN_FUNCTIONS_HEADER)
|
#if !defined(VULKAN_FUNCTIONS_HEADER)
|
||||||
#define VULKAN_FUNCTIONS_HEADER
|
#define VULKAN_FUNCTIONS_HEADER
|
||||||
|
|
||||||
#include "vulkan.h"
|
#include "vulkan.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
#define VK_EXPORTED_FUNCTION( fun ) extern PFN_##fun fun;
|
#define VK_EXPORTED_FUNCTION( fun ) extern PFN_##fun fun;
|
||||||
#define VK_GLOBAL_LEVEL_FUNCTION( fun) extern PFN_##fun fun;
|
#define VK_GLOBAL_LEVEL_FUNCTION( fun) extern PFN_##fun fun;
|
||||||
#define VK_INSTANCE_LEVEL_FUNCTION( fun ) extern PFN_##fun fun;
|
#define VK_INSTANCE_LEVEL_FUNCTION( fun ) extern PFN_##fun fun;
|
||||||
#define VK_DEVICE_LEVEL_FUNCTION( fun ) extern PFN_##fun fun;
|
#define VK_DEVICE_LEVEL_FUNCTION( fun ) extern PFN_##fun fun;
|
||||||
|
|
||||||
#include "ListOfFunctions.inl"
|
#include "ListOfFunctions.inl"
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,284 +1,284 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Tutorial01.h"
|
#include "Tutorial01.h"
|
||||||
#include "VulkanFunctions.h"
|
#include "VulkanFunctions.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
Tutorial01::Tutorial01() :
|
Tutorial01::Tutorial01() :
|
||||||
VulkanLibrary(),
|
VulkanLibrary(),
|
||||||
Vulkan() {
|
Vulkan() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::OnWindowSizeChanged() {
|
bool Tutorial01::OnWindowSizeChanged() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::Draw() {
|
bool Tutorial01::Draw() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::PrepareVulkan() {
|
bool Tutorial01::PrepareVulkan() {
|
||||||
if( !LoadVulkanLibrary() ) {
|
if( !LoadVulkanLibrary() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( !LoadExportedEntryPoints() ) {
|
if( !LoadExportedEntryPoints() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( !LoadGlobalLevelEntryPoints() ) {
|
if( !LoadGlobalLevelEntryPoints() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( !CreateInstance() ) {
|
if( !CreateInstance() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( !LoadInstanceLevelEntryPoints() ) {
|
if( !LoadInstanceLevelEntryPoints() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( !CreateDevice() ) {
|
if( !CreateDevice() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( !LoadDeviceLevelEntryPoints() ) {
|
if( !LoadDeviceLevelEntryPoints() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( !GetDeviceQueue() ) {
|
if( !GetDeviceQueue() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::LoadVulkanLibrary() {
|
bool Tutorial01::LoadVulkanLibrary() {
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
VulkanLibrary = LoadLibrary( "vulkan-1.dll" );
|
VulkanLibrary = LoadLibrary( "vulkan-1.dll" );
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||||
VulkanLibrary = dlopen( "libvulkan.so.1", RTLD_NOW );
|
VulkanLibrary = dlopen( "libvulkan.so.1", RTLD_NOW );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( VulkanLibrary == nullptr ) {
|
if( VulkanLibrary == nullptr ) {
|
||||||
std::cout << "Could not load Vulkan library!" << std::endl;
|
std::cout << "Could not load Vulkan library!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::LoadExportedEntryPoints() {
|
bool Tutorial01::LoadExportedEntryPoints() {
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
#define LoadProcAddress GetProcAddress
|
#define LoadProcAddress GetProcAddress
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||||
#define LoadProcAddress dlsym
|
#define LoadProcAddress dlsym
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define VK_EXPORTED_FUNCTION( fun ) \
|
#define VK_EXPORTED_FUNCTION( fun ) \
|
||||||
if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \
|
if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \
|
||||||
std::cout << "Could not load exported function: " << #fun << "!" << std::endl; \
|
std::cout << "Could not load exported function: " << #fun << "!" << std::endl; \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "ListOfFunctions.inl"
|
#include "ListOfFunctions.inl"
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::LoadGlobalLevelEntryPoints() {
|
bool Tutorial01::LoadGlobalLevelEntryPoints() {
|
||||||
#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \
|
#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \
|
||||||
if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \
|
if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \
|
||||||
std::cout << "Could not load global level function: " << #fun << "!" << std::endl; \
|
std::cout << "Could not load global level function: " << #fun << "!" << std::endl; \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "ListOfFunctions.inl"
|
#include "ListOfFunctions.inl"
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::CreateInstance() {
|
bool Tutorial01::CreateInstance() {
|
||||||
VkApplicationInfo application_info = {
|
VkApplicationInfo application_info = {
|
||||||
VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType
|
VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType
|
||||||
nullptr, // const void *pNext
|
nullptr, // const void *pNext
|
||||||
"API without Secrets: Introduction to Vulkan", // const char *pApplicationName
|
"API without Secrets: Introduction to Vulkan", // const char *pApplicationName
|
||||||
VK_MAKE_VERSION( 1, 0, 0 ), // uint32_t applicationVersion
|
VK_MAKE_VERSION( 1, 0, 0 ), // uint32_t applicationVersion
|
||||||
"Vulkan Tutorial by Intel", // const char *pEngineName
|
"Vulkan Tutorial by Intel", // const char *pEngineName
|
||||||
VK_MAKE_VERSION( 1, 0, 0 ), // uint32_t engineVersion
|
VK_MAKE_VERSION( 1, 0, 0 ), // uint32_t engineVersion
|
||||||
VK_MAKE_VERSION( 1, 0, 0 ) // uint32_t apiVersion
|
VK_MAKE_VERSION( 1, 0, 0 ) // uint32_t apiVersion
|
||||||
};
|
};
|
||||||
|
|
||||||
VkInstanceCreateInfo instance_create_info = {
|
VkInstanceCreateInfo instance_create_info = {
|
||||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType
|
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType
|
||||||
nullptr, // const void* pNext
|
nullptr, // const void* pNext
|
||||||
0, // VkInstanceCreateFlags flags
|
0, // VkInstanceCreateFlags flags
|
||||||
&application_info, // const VkApplicationInfo *pApplicationInfo
|
&application_info, // const VkApplicationInfo *pApplicationInfo
|
||||||
0, // uint32_t enabledLayerCount
|
0, // uint32_t enabledLayerCount
|
||||||
nullptr, // const char * const *ppEnabledLayerNames
|
nullptr, // const char * const *ppEnabledLayerNames
|
||||||
0, // uint32_t enabledExtensionCount
|
0, // uint32_t enabledExtensionCount
|
||||||
nullptr // const char * const *ppEnabledExtensionNames
|
nullptr // const char * const *ppEnabledExtensionNames
|
||||||
};
|
};
|
||||||
|
|
||||||
if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) {
|
if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) {
|
||||||
std::cout << "Could not create Vulkan instance!" << std::endl;
|
std::cout << "Could not create Vulkan instance!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::LoadInstanceLevelEntryPoints() {
|
bool Tutorial01::LoadInstanceLevelEntryPoints() {
|
||||||
#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \
|
#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \
|
||||||
if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \
|
if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \
|
||||||
std::cout << "Could not load instance level function: " << #fun << "!" << std::endl; \
|
std::cout << "Could not load instance level function: " << #fun << "!" << std::endl; \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "ListOfFunctions.inl"
|
#include "ListOfFunctions.inl"
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::CreateDevice() {
|
bool Tutorial01::CreateDevice() {
|
||||||
uint32_t num_devices = 0;
|
uint32_t num_devices = 0;
|
||||||
if( (vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, nullptr ) != VK_SUCCESS) ||
|
if( (vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, nullptr ) != VK_SUCCESS) ||
|
||||||
(num_devices == 0) ) {
|
(num_devices == 0) ) {
|
||||||
std::cout << "Error occurred during physical devices enumeration!" << std::endl;
|
std::cout << "Error occurred during physical devices enumeration!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<VkPhysicalDevice> physical_devices( num_devices );
|
std::vector<VkPhysicalDevice> physical_devices( num_devices );
|
||||||
if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) {
|
if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) {
|
||||||
std::cout << "Error occurred during physical devices enumeration!" << std::endl;
|
std::cout << "Error occurred during physical devices enumeration!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPhysicalDevice selected_physical_device = VK_NULL_HANDLE;
|
VkPhysicalDevice selected_physical_device = VK_NULL_HANDLE;
|
||||||
uint32_t selected_queue_family_index = UINT32_MAX;
|
uint32_t selected_queue_family_index = UINT32_MAX;
|
||||||
for( uint32_t i = 0; i < num_devices; ++i ) {
|
for( uint32_t i = 0; i < num_devices; ++i ) {
|
||||||
if( CheckPhysicalDeviceProperties( physical_devices[i], selected_queue_family_index ) ) {
|
if( CheckPhysicalDeviceProperties( physical_devices[i], selected_queue_family_index ) ) {
|
||||||
selected_physical_device = physical_devices[i];
|
selected_physical_device = physical_devices[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( selected_physical_device == VK_NULL_HANDLE ) {
|
if( selected_physical_device == VK_NULL_HANDLE ) {
|
||||||
std::cout << "Could not select physical device based on the chosen properties!" << std::endl;
|
std::cout << "Could not select physical device based on the chosen properties!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> queue_priorities = { 1.0f };
|
std::vector<float> queue_priorities = { 1.0f };
|
||||||
|
|
||||||
VkDeviceQueueCreateInfo queue_create_info = {
|
VkDeviceQueueCreateInfo queue_create_info = {
|
||||||
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType
|
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType
|
||||||
nullptr, // const void *pNext
|
nullptr, // const void *pNext
|
||||||
0, // VkDeviceQueueCreateFlags flags
|
0, // VkDeviceQueueCreateFlags flags
|
||||||
selected_queue_family_index, // uint32_t queueFamilyIndex
|
selected_queue_family_index, // uint32_t queueFamilyIndex
|
||||||
static_cast<uint32_t>(queue_priorities.size()), // uint32_t queueCount
|
static_cast<uint32_t>(queue_priorities.size()), // uint32_t queueCount
|
||||||
&queue_priorities[0] // const float *pQueuePriorities
|
&queue_priorities[0] // const float *pQueuePriorities
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDeviceCreateInfo device_create_info = {
|
VkDeviceCreateInfo device_create_info = {
|
||||||
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // VkStructureType sType
|
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // VkStructureType sType
|
||||||
nullptr, // const void *pNext
|
nullptr, // const void *pNext
|
||||||
0, // VkDeviceCreateFlags flags
|
0, // VkDeviceCreateFlags flags
|
||||||
1, // uint32_t queueCreateInfoCount
|
1, // uint32_t queueCreateInfoCount
|
||||||
&queue_create_info, // const VkDeviceQueueCreateInfo *pQueueCreateInfos
|
&queue_create_info, // const VkDeviceQueueCreateInfo *pQueueCreateInfos
|
||||||
0, // uint32_t enabledLayerCount
|
0, // uint32_t enabledLayerCount
|
||||||
nullptr, // const char * const *ppEnabledLayerNames
|
nullptr, // const char * const *ppEnabledLayerNames
|
||||||
0, // uint32_t enabledExtensionCount
|
0, // uint32_t enabledExtensionCount
|
||||||
nullptr, // const char * const *ppEnabledExtensionNames
|
nullptr, // const char * const *ppEnabledExtensionNames
|
||||||
nullptr // const VkPhysicalDeviceFeatures *pEnabledFeatures
|
nullptr // const VkPhysicalDeviceFeatures *pEnabledFeatures
|
||||||
};
|
};
|
||||||
|
|
||||||
if( vkCreateDevice( selected_physical_device, &device_create_info, nullptr, &Vulkan.Device ) != VK_SUCCESS ) {
|
if( vkCreateDevice( selected_physical_device, &device_create_info, nullptr, &Vulkan.Device ) != VK_SUCCESS ) {
|
||||||
std::cout << "Could not create Vulkan device!" << std::endl;
|
std::cout << "Could not create Vulkan device!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vulkan.QueueFamilyIndex = selected_queue_family_index;
|
Vulkan.QueueFamilyIndex = selected_queue_family_index;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &queue_family_index ) {
|
bool Tutorial01::CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &queue_family_index ) {
|
||||||
VkPhysicalDeviceProperties device_properties;
|
VkPhysicalDeviceProperties device_properties;
|
||||||
VkPhysicalDeviceFeatures device_features;
|
VkPhysicalDeviceFeatures device_features;
|
||||||
|
|
||||||
vkGetPhysicalDeviceProperties( physical_device, &device_properties );
|
vkGetPhysicalDeviceProperties( physical_device, &device_properties );
|
||||||
vkGetPhysicalDeviceFeatures( physical_device, &device_features );
|
vkGetPhysicalDeviceFeatures( physical_device, &device_features );
|
||||||
|
|
||||||
uint32_t major_version = VK_VERSION_MAJOR( device_properties.apiVersion );
|
uint32_t major_version = VK_VERSION_MAJOR( device_properties.apiVersion );
|
||||||
uint32_t minor_version = VK_VERSION_MINOR( device_properties.apiVersion );
|
uint32_t minor_version = VK_VERSION_MINOR( device_properties.apiVersion );
|
||||||
uint32_t patch_version = VK_VERSION_PATCH( device_properties.apiVersion );
|
uint32_t patch_version = VK_VERSION_PATCH( device_properties.apiVersion );
|
||||||
|
|
||||||
if( (major_version < 1) ||
|
if( (major_version < 1) ||
|
||||||
(device_properties.limits.maxImageDimension2D < 4096) ) {
|
(device_properties.limits.maxImageDimension2D < 4096) ) {
|
||||||
std::cout << "Physical device " << physical_device << " doesn't support required parameters!" << std::endl;
|
std::cout << "Physical device " << physical_device << " doesn't support required parameters!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t queue_families_count = 0;
|
uint32_t queue_families_count = 0;
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, nullptr );
|
vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, nullptr );
|
||||||
if( queue_families_count == 0 ) {
|
if( queue_families_count == 0 ) {
|
||||||
std::cout << "Physical device " << physical_device << " doesn't have any queue families!" << std::endl;
|
std::cout << "Physical device " << physical_device << " doesn't have any queue families!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<VkQueueFamilyProperties> queue_family_properties( queue_families_count );
|
std::vector<VkQueueFamilyProperties> queue_family_properties( queue_families_count );
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, &queue_family_properties[0] );
|
vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, &queue_family_properties[0] );
|
||||||
for( uint32_t i = 0; i < queue_families_count; ++i ) {
|
for( uint32_t i = 0; i < queue_families_count; ++i ) {
|
||||||
if( (queue_family_properties[i].queueCount > 0) &&
|
if( (queue_family_properties[i].queueCount > 0) &&
|
||||||
(queue_family_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) ) {
|
(queue_family_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) ) {
|
||||||
queue_family_index = i;
|
queue_family_index = i;
|
||||||
std::cout << "Selected device: " << device_properties.deviceName << std::endl;
|
std::cout << "Selected device: " << device_properties.deviceName << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Could not find queue family with required properties on physical device " << physical_device << "!" << std::endl;
|
std::cout << "Could not find queue family with required properties on physical device " << physical_device << "!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::LoadDeviceLevelEntryPoints() {
|
bool Tutorial01::LoadDeviceLevelEntryPoints() {
|
||||||
#define VK_DEVICE_LEVEL_FUNCTION( fun ) \
|
#define VK_DEVICE_LEVEL_FUNCTION( fun ) \
|
||||||
if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \
|
if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \
|
||||||
std::cout << "Could not load device level function: " << #fun << "!" << std::endl; \
|
std::cout << "Could not load device level function: " << #fun << "!" << std::endl; \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "ListOfFunctions.inl"
|
#include "ListOfFunctions.inl"
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tutorial01::GetDeviceQueue() {
|
bool Tutorial01::GetDeviceQueue() {
|
||||||
vkGetDeviceQueue( Vulkan.Device, Vulkan.QueueFamilyIndex, 0, &Vulkan.Queue );
|
vkGetDeviceQueue( Vulkan.Device, Vulkan.QueueFamilyIndex, 0, &Vulkan.Queue );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tutorial01::~Tutorial01() {
|
Tutorial01::~Tutorial01() {
|
||||||
if( Vulkan.Device != VK_NULL_HANDLE ) {
|
if( Vulkan.Device != VK_NULL_HANDLE ) {
|
||||||
vkDeviceWaitIdle( Vulkan.Device );
|
vkDeviceWaitIdle( Vulkan.Device );
|
||||||
vkDestroyDevice( Vulkan.Device, nullptr );
|
vkDestroyDevice( Vulkan.Device, nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Vulkan.Instance != VK_NULL_HANDLE ) {
|
if( Vulkan.Instance != VK_NULL_HANDLE ) {
|
||||||
vkDestroyInstance( Vulkan.Instance, nullptr );
|
vkDestroyInstance( Vulkan.Instance, nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( VulkanLibrary ) {
|
if( VulkanLibrary ) {
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
FreeLibrary( VulkanLibrary );
|
FreeLibrary( VulkanLibrary );
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||||
dlclose( VulkanLibrary );
|
dlclose( VulkanLibrary );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
@@ -1,76 +1,76 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(TUTORIAL_01_HEADER)
|
#if !defined(TUTORIAL_01_HEADER)
|
||||||
#define TUTORIAL_01_HEADER
|
#define TUTORIAL_01_HEADER
|
||||||
|
|
||||||
#include "vulkan.h"
|
#include "vulkan.h"
|
||||||
#include "OperatingSystem.h"
|
#include "OperatingSystem.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanTutorial01Parameters //
|
// VulkanTutorial01Parameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan specific parameters //
|
// Vulkan specific parameters //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VulkanTutorial01Parameters {
|
struct VulkanTutorial01Parameters {
|
||||||
VkInstance Instance;
|
VkInstance Instance;
|
||||||
VkDevice Device;
|
VkDevice Device;
|
||||||
uint32_t QueueFamilyIndex;
|
uint32_t QueueFamilyIndex;
|
||||||
VkQueue Queue;
|
VkQueue Queue;
|
||||||
|
|
||||||
VulkanTutorial01Parameters() :
|
VulkanTutorial01Parameters() :
|
||||||
Instance( VK_NULL_HANDLE ),
|
Instance( VK_NULL_HANDLE ),
|
||||||
Device( VK_NULL_HANDLE ),
|
Device( VK_NULL_HANDLE ),
|
||||||
QueueFamilyIndex( 0 ),
|
QueueFamilyIndex( 0 ),
|
||||||
Queue( VK_NULL_HANDLE ) {
|
Queue( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Tutorial01 //
|
// Tutorial01 //
|
||||||
// //
|
// //
|
||||||
// Class for presenting Vulkan usage topics //
|
// Class for presenting Vulkan usage topics //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class Tutorial01 : public OS::TutorialBase {
|
class Tutorial01 : public OS::TutorialBase {
|
||||||
public:
|
public:
|
||||||
Tutorial01();
|
Tutorial01();
|
||||||
~Tutorial01();
|
~Tutorial01();
|
||||||
|
|
||||||
bool OnWindowSizeChanged() override;
|
bool OnWindowSizeChanged() override;
|
||||||
bool Draw() override;
|
bool Draw() override;
|
||||||
|
|
||||||
bool PrepareVulkan();
|
bool PrepareVulkan();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OS::LibraryHandle VulkanLibrary;
|
OS::LibraryHandle VulkanLibrary;
|
||||||
VulkanTutorial01Parameters Vulkan;
|
VulkanTutorial01Parameters Vulkan;
|
||||||
|
|
||||||
bool LoadVulkanLibrary();
|
bool LoadVulkanLibrary();
|
||||||
bool LoadExportedEntryPoints();
|
bool LoadExportedEntryPoints();
|
||||||
bool LoadGlobalLevelEntryPoints();
|
bool LoadGlobalLevelEntryPoints();
|
||||||
bool CreateInstance();
|
bool CreateInstance();
|
||||||
bool LoadInstanceLevelEntryPoints();
|
bool LoadInstanceLevelEntryPoints();
|
||||||
bool CreateDevice();
|
bool CreateDevice();
|
||||||
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &queue_family_index );
|
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &queue_family_index );
|
||||||
bool LoadDeviceLevelEntryPoints();
|
bool LoadDeviceLevelEntryPoints();
|
||||||
bool GetDeviceQueue();
|
bool GetDeviceQueue();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // TUTORIAL_01_HEADER
|
#endif // TUTORIAL_01_HEADER
|
||||||
@@ -1,39 +1,39 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Tutorial01.h"
|
#include "Tutorial01.h"
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
ApiWithoutSecrets::OS::Window window;
|
ApiWithoutSecrets::OS::Window window;
|
||||||
ApiWithoutSecrets::Tutorial01 tutorial01;
|
ApiWithoutSecrets::Tutorial01 tutorial01;
|
||||||
|
|
||||||
// Window creation
|
// Window creation
|
||||||
if( !window.Create( "01 - The Beginning" ) ) {
|
if( !window.Create( "01 - The Beginning" ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vulkan preparations and initialization
|
// Vulkan preparations and initialization
|
||||||
if( !tutorial01.PrepareVulkan() ) {
|
if( !tutorial01.PrepareVulkan() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendering loop
|
// Rendering loop
|
||||||
if( !window.RenderingLoop( tutorial01 ) ) {
|
if( !window.RenderingLoop( tutorial01 ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,107 +1,107 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(TUTORIAL_02_HEADER)
|
#if !defined(TUTORIAL_02_HEADER)
|
||||||
#define TUTORIAL_02_HEADER
|
#define TUTORIAL_02_HEADER
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "vulkan.h"
|
#include "vulkan.h"
|
||||||
#include "OperatingSystem.h"
|
#include "OperatingSystem.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanTutorial02Parameters //
|
// VulkanTutorial02Parameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan specific parameters //
|
// Vulkan specific parameters //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VulkanTutorial02Parameters {
|
struct VulkanTutorial02Parameters {
|
||||||
VkInstance Instance;
|
VkInstance Instance;
|
||||||
VkPhysicalDevice PhysicalDevice;
|
VkPhysicalDevice PhysicalDevice;
|
||||||
VkDevice Device;
|
VkDevice Device;
|
||||||
VkQueue GraphicsQueue;
|
VkQueue GraphicsQueue;
|
||||||
VkQueue PresentQueue;
|
VkQueue PresentQueue;
|
||||||
uint32_t GraphicsQueueFamilyIndex;
|
uint32_t GraphicsQueueFamilyIndex;
|
||||||
uint32_t PresentQueueFamilyIndex;
|
uint32_t PresentQueueFamilyIndex;
|
||||||
VkSurfaceKHR PresentationSurface;
|
VkSurfaceKHR PresentationSurface;
|
||||||
VkSwapchainKHR SwapChain;
|
VkSwapchainKHR SwapChain;
|
||||||
std::vector<VkCommandBuffer> PresentQueueCmdBuffers;
|
std::vector<VkCommandBuffer> PresentQueueCmdBuffers;
|
||||||
VkCommandPool PresentQueueCmdPool;
|
VkCommandPool PresentQueueCmdPool;
|
||||||
VkSemaphore ImageAvailableSemaphore;
|
VkSemaphore ImageAvailableSemaphore;
|
||||||
VkSemaphore RenderingFinishedSemaphore;
|
VkSemaphore RenderingFinishedSemaphore;
|
||||||
|
|
||||||
VulkanTutorial02Parameters() :
|
VulkanTutorial02Parameters() :
|
||||||
Instance( VK_NULL_HANDLE ),
|
Instance( VK_NULL_HANDLE ),
|
||||||
PhysicalDevice( VK_NULL_HANDLE ),
|
PhysicalDevice( VK_NULL_HANDLE ),
|
||||||
Device( VK_NULL_HANDLE ),
|
Device( VK_NULL_HANDLE ),
|
||||||
GraphicsQueue( VK_NULL_HANDLE ),
|
GraphicsQueue( VK_NULL_HANDLE ),
|
||||||
PresentQueue( VK_NULL_HANDLE ),
|
PresentQueue( VK_NULL_HANDLE ),
|
||||||
GraphicsQueueFamilyIndex( 0 ),
|
GraphicsQueueFamilyIndex( 0 ),
|
||||||
PresentQueueFamilyIndex( 0 ),
|
PresentQueueFamilyIndex( 0 ),
|
||||||
PresentationSurface( VK_NULL_HANDLE ),
|
PresentationSurface( VK_NULL_HANDLE ),
|
||||||
SwapChain( VK_NULL_HANDLE ),
|
SwapChain( VK_NULL_HANDLE ),
|
||||||
PresentQueueCmdBuffers( 0 ),
|
PresentQueueCmdBuffers( 0 ),
|
||||||
PresentQueueCmdPool( VK_NULL_HANDLE ) {
|
PresentQueueCmdPool( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Tutorial02 //
|
// Tutorial02 //
|
||||||
// //
|
// //
|
||||||
// Class for presenting Vulkan usage topics //
|
// Class for presenting Vulkan usage topics //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class Tutorial02 : public OS::TutorialBase {
|
class Tutorial02 : public OS::TutorialBase {
|
||||||
public:
|
public:
|
||||||
Tutorial02();
|
Tutorial02();
|
||||||
~Tutorial02();
|
~Tutorial02();
|
||||||
|
|
||||||
bool PrepareVulkan( OS::WindowParameters parameters );
|
bool PrepareVulkan( OS::WindowParameters parameters );
|
||||||
bool CreateSwapChain();
|
bool CreateSwapChain();
|
||||||
bool OnWindowSizeChanged() override;
|
bool OnWindowSizeChanged() override;
|
||||||
bool CreateCommandBuffers();
|
bool CreateCommandBuffers();
|
||||||
bool Draw() override;
|
bool Draw() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OS::LibraryHandle VulkanLibrary;
|
OS::LibraryHandle VulkanLibrary;
|
||||||
OS::WindowParameters Window;
|
OS::WindowParameters Window;
|
||||||
VulkanTutorial02Parameters Vulkan;
|
VulkanTutorial02Parameters Vulkan;
|
||||||
|
|
||||||
bool LoadVulkanLibrary();
|
bool LoadVulkanLibrary();
|
||||||
bool LoadExportedEntryPoints();
|
bool LoadExportedEntryPoints();
|
||||||
bool LoadGlobalLevelEntryPoints();
|
bool LoadGlobalLevelEntryPoints();
|
||||||
bool CreateInstance();
|
bool CreateInstance();
|
||||||
bool LoadInstanceLevelEntryPoints();
|
bool LoadInstanceLevelEntryPoints();
|
||||||
bool CreatePresentationSurface();
|
bool CreatePresentationSurface();
|
||||||
bool CreateDevice();
|
bool CreateDevice();
|
||||||
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
|
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
|
||||||
bool LoadDeviceLevelEntryPoints();
|
bool LoadDeviceLevelEntryPoints();
|
||||||
bool GetDeviceQueue();
|
bool GetDeviceQueue();
|
||||||
bool CreateSemaphores();
|
bool CreateSemaphores();
|
||||||
bool RecordCommandBuffers();
|
bool RecordCommandBuffers();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
|
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
|
||||||
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||||
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
|
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
|
||||||
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||||
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||||
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||||
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
|
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // TUTORIAL_02_HEADER
|
#endif // TUTORIAL_02_HEADER
|
||||||
@@ -1,45 +1,45 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Tutorial02.h"
|
#include "Tutorial02.h"
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
ApiWithoutSecrets::OS::Window window;
|
ApiWithoutSecrets::OS::Window window;
|
||||||
ApiWithoutSecrets::Tutorial02 tutorial02;
|
ApiWithoutSecrets::Tutorial02 tutorial02;
|
||||||
|
|
||||||
// Window creation
|
// Window creation
|
||||||
if( !window.Create( "02 - Swap chain" ) ) {
|
if( !window.Create( "02 - Swap chain" ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vulkan preparations and initialization
|
// Vulkan preparations and initialization
|
||||||
if( !tutorial02.PrepareVulkan( window.GetParameters() ) ) {
|
if( !tutorial02.PrepareVulkan( window.GetParameters() ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial02.CreateSwapChain() ) {
|
if( !tutorial02.CreateSwapChain() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial02.CreateCommandBuffers() ) {
|
if( !tutorial02.CreateCommandBuffers() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendering loop
|
// Rendering loop
|
||||||
if( !window.RenderingLoop( tutorial02 ) ) {
|
if( !window.RenderingLoop( tutorial02 ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,83 +1,83 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(TUTORIAL_03_HEADER)
|
#if !defined(TUTORIAL_03_HEADER)
|
||||||
#define TUTORIAL_03_HEADER
|
#define TUTORIAL_03_HEADER
|
||||||
|
|
||||||
#include "VulkanCommon.h"
|
#include "VulkanCommon.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanTutorial03Parameters //
|
// VulkanTutorial03Parameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan specific parameters //
|
// Vulkan specific parameters //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VulkanTutorial03Parameters {
|
struct VulkanTutorial03Parameters {
|
||||||
VkRenderPass RenderPass;
|
VkRenderPass RenderPass;
|
||||||
std::vector<VkFramebuffer> Framebuffers;
|
std::vector<VkFramebuffer> Framebuffers;
|
||||||
VkPipeline GraphicsPipeline;
|
VkPipeline GraphicsPipeline;
|
||||||
VkSemaphore ImageAvailableSemaphore;
|
VkSemaphore ImageAvailableSemaphore;
|
||||||
VkSemaphore RenderingFinishedSemaphore;
|
VkSemaphore RenderingFinishedSemaphore;
|
||||||
VkCommandPool GraphicsCommandPool;
|
VkCommandPool GraphicsCommandPool;
|
||||||
std::vector<VkCommandBuffer> GraphicsCommandBuffers;
|
std::vector<VkCommandBuffer> GraphicsCommandBuffers;
|
||||||
|
|
||||||
VulkanTutorial03Parameters() :
|
VulkanTutorial03Parameters() :
|
||||||
RenderPass( VK_NULL_HANDLE ),
|
RenderPass( VK_NULL_HANDLE ),
|
||||||
Framebuffers(),
|
Framebuffers(),
|
||||||
GraphicsCommandPool( VK_NULL_HANDLE ),
|
GraphicsCommandPool( VK_NULL_HANDLE ),
|
||||||
GraphicsCommandBuffers(),
|
GraphicsCommandBuffers(),
|
||||||
GraphicsPipeline( VK_NULL_HANDLE ),
|
GraphicsPipeline( VK_NULL_HANDLE ),
|
||||||
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
||||||
RenderingFinishedSemaphore( VK_NULL_HANDLE ) {
|
RenderingFinishedSemaphore( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Tutorial03 //
|
// Tutorial03 //
|
||||||
// //
|
// //
|
||||||
// Class for presenting Vulkan usage topics //
|
// Class for presenting Vulkan usage topics //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class Tutorial03 : public VulkanCommon {
|
class Tutorial03 : public VulkanCommon {
|
||||||
public:
|
public:
|
||||||
Tutorial03();
|
Tutorial03();
|
||||||
~Tutorial03();
|
~Tutorial03();
|
||||||
|
|
||||||
bool CreateRenderPass();
|
bool CreateRenderPass();
|
||||||
bool CreateFramebuffers();
|
bool CreateFramebuffers();
|
||||||
bool CreatePipeline();
|
bool CreatePipeline();
|
||||||
bool CreateSemaphores();
|
bool CreateSemaphores();
|
||||||
bool CreateCommandBuffers();
|
bool CreateCommandBuffers();
|
||||||
bool RecordCommandBuffers();
|
bool RecordCommandBuffers();
|
||||||
|
|
||||||
bool Draw() override;
|
bool Draw() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VulkanTutorial03Parameters Vulkan;
|
VulkanTutorial03Parameters Vulkan;
|
||||||
|
|
||||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
||||||
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
|
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
|
||||||
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
|
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
|
||||||
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
|
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
|
||||||
|
|
||||||
void ChildClear() override;
|
void ChildClear() override;
|
||||||
bool ChildOnWindowSizeChanged() override;
|
bool ChildOnWindowSizeChanged() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // TUTORIAL_03_HEADER
|
#endif // TUTORIAL_03_HEADER
|
||||||
@@ -1,59 +1,59 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Tutorial03.h"
|
#include "Tutorial03.h"
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
ApiWithoutSecrets::OS::Window window;
|
ApiWithoutSecrets::OS::Window window;
|
||||||
ApiWithoutSecrets::Tutorial03 tutorial03;
|
ApiWithoutSecrets::Tutorial03 tutorial03;
|
||||||
|
|
||||||
// Window creation
|
// Window creation
|
||||||
if( !window.Create( "03 - First Triangle" ) ) {
|
if( !window.Create( "03 - First Triangle" ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vulkan preparations and initialization
|
// Vulkan preparations and initialization
|
||||||
if( !tutorial03.PrepareVulkan( window.GetParameters() ) ) {
|
if( !tutorial03.PrepareVulkan( window.GetParameters() ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tutorial 03
|
// Tutorial 03
|
||||||
if( !tutorial03.CreateRenderPass() ) {
|
if( !tutorial03.CreateRenderPass() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial03.CreateFramebuffers() ) {
|
if( !tutorial03.CreateFramebuffers() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial03.CreatePipeline() ) {
|
if( !tutorial03.CreatePipeline() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial03.CreateSemaphores() ) {
|
if( !tutorial03.CreateSemaphores() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial03.CreateCommandBuffers() ) {
|
if( !tutorial03.CreateCommandBuffers() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial03.RecordCommandBuffers() ) {
|
if( !tutorial03.RecordCommandBuffers() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendering loop
|
// Rendering loop
|
||||||
if( !window.RenderingLoop( tutorial03 ) ) {
|
if( !window.RenderingLoop( tutorial03 ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,133 +1,133 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(TUTORIAL_04_HEADER)
|
#if !defined(TUTORIAL_04_HEADER)
|
||||||
#define TUTORIAL_04_HEADER
|
#define TUTORIAL_04_HEADER
|
||||||
|
|
||||||
#include "VulkanCommon.h"
|
#include "VulkanCommon.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// BufferParameters //
|
// BufferParameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan Buffer's parameters container class //
|
// Vulkan Buffer's parameters container class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct BufferParameters {
|
struct BufferParameters {
|
||||||
VkBuffer Handle;
|
VkBuffer Handle;
|
||||||
VkDeviceMemory Memory;
|
VkDeviceMemory Memory;
|
||||||
uint32_t Size;
|
uint32_t Size;
|
||||||
|
|
||||||
BufferParameters() :
|
BufferParameters() :
|
||||||
Handle( VK_NULL_HANDLE ),
|
Handle( VK_NULL_HANDLE ),
|
||||||
Memory( VK_NULL_HANDLE ),
|
Memory( VK_NULL_HANDLE ),
|
||||||
Size( 0 ) {
|
Size( 0 ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VertexData //
|
// VertexData //
|
||||||
// //
|
// //
|
||||||
// Struct describing data type and format of vertex attributes //
|
// Struct describing data type and format of vertex attributes //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VertexData {
|
struct VertexData {
|
||||||
float x, y, z, w;
|
float x, y, z, w;
|
||||||
float r, g, b, a;
|
float r, g, b, a;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// RenderingResourcesData //
|
// RenderingResourcesData //
|
||||||
// //
|
// //
|
||||||
// Struct containing data used during rendering process //
|
// Struct containing data used during rendering process //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct RenderingResourcesData {
|
struct RenderingResourcesData {
|
||||||
VkFramebuffer Framebuffer;
|
VkFramebuffer Framebuffer;
|
||||||
VkCommandBuffer CommandBuffer;
|
VkCommandBuffer CommandBuffer;
|
||||||
VkSemaphore ImageAvailableSemaphore;
|
VkSemaphore ImageAvailableSemaphore;
|
||||||
VkSemaphore FinishedRenderingSemaphore;
|
VkSemaphore FinishedRenderingSemaphore;
|
||||||
VkFence Fence;
|
VkFence Fence;
|
||||||
|
|
||||||
RenderingResourcesData() :
|
RenderingResourcesData() :
|
||||||
Framebuffer( VK_NULL_HANDLE ),
|
Framebuffer( VK_NULL_HANDLE ),
|
||||||
CommandBuffer( VK_NULL_HANDLE ),
|
CommandBuffer( VK_NULL_HANDLE ),
|
||||||
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
||||||
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
|
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
|
||||||
Fence( VK_NULL_HANDLE ) {
|
Fence( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanTutorial04Parameters //
|
// VulkanTutorial04Parameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan specific parameters //
|
// Vulkan specific parameters //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VulkanTutorial04Parameters {
|
struct VulkanTutorial04Parameters {
|
||||||
VkRenderPass RenderPass;
|
VkRenderPass RenderPass;
|
||||||
VkPipeline GraphicsPipeline;
|
VkPipeline GraphicsPipeline;
|
||||||
BufferParameters VertexBuffer;
|
BufferParameters VertexBuffer;
|
||||||
VkCommandPool CommandPool;
|
VkCommandPool CommandPool;
|
||||||
std::vector<RenderingResourcesData> RenderingResources;
|
std::vector<RenderingResourcesData> RenderingResources;
|
||||||
|
|
||||||
static const size_t ResourcesCount = 3;
|
static const size_t ResourcesCount = 3;
|
||||||
|
|
||||||
VulkanTutorial04Parameters() :
|
VulkanTutorial04Parameters() :
|
||||||
RenderPass( VK_NULL_HANDLE ),
|
RenderPass( VK_NULL_HANDLE ),
|
||||||
GraphicsPipeline( VK_NULL_HANDLE ),
|
GraphicsPipeline( VK_NULL_HANDLE ),
|
||||||
VertexBuffer(),
|
VertexBuffer(),
|
||||||
CommandPool( VK_NULL_HANDLE ),
|
CommandPool( VK_NULL_HANDLE ),
|
||||||
RenderingResources( ResourcesCount ) {
|
RenderingResources( ResourcesCount ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Tutorial04 //
|
// Tutorial04 //
|
||||||
// //
|
// //
|
||||||
// Class for presenting Vulkan usage topics //
|
// Class for presenting Vulkan usage topics //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class Tutorial04 : public VulkanCommon {
|
class Tutorial04 : public VulkanCommon {
|
||||||
public:
|
public:
|
||||||
Tutorial04();
|
Tutorial04();
|
||||||
~Tutorial04();
|
~Tutorial04();
|
||||||
|
|
||||||
bool CreateRenderPass();
|
bool CreateRenderPass();
|
||||||
bool CreatePipeline();
|
bool CreatePipeline();
|
||||||
bool CreateVertexBuffer();
|
bool CreateVertexBuffer();
|
||||||
bool CreateRenderingResources();
|
bool CreateRenderingResources();
|
||||||
|
|
||||||
bool Draw() override;
|
bool Draw() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VulkanTutorial04Parameters Vulkan;
|
VulkanTutorial04Parameters Vulkan;
|
||||||
|
|
||||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
||||||
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
|
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
|
||||||
bool AllocateBufferMemory( VkBuffer buffer, VkDeviceMemory *memory );
|
bool AllocateBufferMemory( VkBuffer buffer, VkDeviceMemory *memory );
|
||||||
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
|
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
|
||||||
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
|
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
|
||||||
bool CreateCommandBuffers();
|
bool CreateCommandBuffers();
|
||||||
bool CreateSemaphores();
|
bool CreateSemaphores();
|
||||||
bool CreateFences();
|
bool CreateFences();
|
||||||
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
|
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
|
||||||
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
|
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
|
||||||
|
|
||||||
void ChildClear() override;
|
void ChildClear() override;
|
||||||
bool ChildOnWindowSizeChanged() override;
|
bool ChildOnWindowSizeChanged() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // TUTORIAL_04_HEADER
|
#endif // TUTORIAL_04_HEADER
|
||||||
@@ -1,53 +1,53 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Tutorial04.h"
|
#include "Tutorial04.h"
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
ApiWithoutSecrets::OS::Window window;
|
ApiWithoutSecrets::OS::Window window;
|
||||||
ApiWithoutSecrets::Tutorial04 tutorial04;
|
ApiWithoutSecrets::Tutorial04 tutorial04;
|
||||||
|
|
||||||
// Window creation
|
// Window creation
|
||||||
if( !window.Create( "04 - Vertex Attributes" ) ) {
|
if( !window.Create( "04 - Vertex Attributes" ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vulkan preparations and initialization
|
// Vulkan preparations and initialization
|
||||||
if( !tutorial04.PrepareVulkan( window.GetParameters() ) ) {
|
if( !tutorial04.PrepareVulkan( window.GetParameters() ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tutorial 04
|
// Tutorial 04
|
||||||
if( !tutorial04.CreateRenderPass() ) {
|
if( !tutorial04.CreateRenderPass() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial04.CreatePipeline() ) {
|
if( !tutorial04.CreatePipeline() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial04.CreateVertexBuffer() ) {
|
if( !tutorial04.CreateVertexBuffer() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial04.CreateRenderingResources() ) {
|
if( !tutorial04.CreateRenderingResources() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendering loop
|
// Rendering loop
|
||||||
if( !window.RenderingLoop( tutorial04 ) ) {
|
if( !window.RenderingLoop( tutorial04 ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,139 +1,139 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(TUTORIAL_05_HEADER)
|
#if !defined(TUTORIAL_05_HEADER)
|
||||||
#define TUTORIAL_05_HEADER
|
#define TUTORIAL_05_HEADER
|
||||||
|
|
||||||
#include "VulkanCommon.h"
|
#include "VulkanCommon.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// BufferParameters //
|
// BufferParameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan Buffer's parameters container class //
|
// Vulkan Buffer's parameters container class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct BufferParameters {
|
struct BufferParameters {
|
||||||
VkBuffer Handle;
|
VkBuffer Handle;
|
||||||
VkDeviceMemory Memory;
|
VkDeviceMemory Memory;
|
||||||
uint32_t Size;
|
uint32_t Size;
|
||||||
|
|
||||||
BufferParameters() :
|
BufferParameters() :
|
||||||
Handle( VK_NULL_HANDLE ),
|
Handle( VK_NULL_HANDLE ),
|
||||||
Memory( VK_NULL_HANDLE ),
|
Memory( VK_NULL_HANDLE ),
|
||||||
Size( 0 ) {
|
Size( 0 ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VertexData //
|
// VertexData //
|
||||||
// //
|
// //
|
||||||
// Struct describing data type and format of vertex attributes //
|
// Struct describing data type and format of vertex attributes //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VertexData {
|
struct VertexData {
|
||||||
float x, y, z, w;
|
float x, y, z, w;
|
||||||
float r, g, b, a;
|
float r, g, b, a;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// RenderingResourcesData //
|
// RenderingResourcesData //
|
||||||
// //
|
// //
|
||||||
// Struct containing data used during rendering process //
|
// Struct containing data used during rendering process //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct RenderingResourcesData {
|
struct RenderingResourcesData {
|
||||||
VkFramebuffer Framebuffer;
|
VkFramebuffer Framebuffer;
|
||||||
VkCommandBuffer CommandBuffer;
|
VkCommandBuffer CommandBuffer;
|
||||||
VkSemaphore ImageAvailableSemaphore;
|
VkSemaphore ImageAvailableSemaphore;
|
||||||
VkSemaphore FinishedRenderingSemaphore;
|
VkSemaphore FinishedRenderingSemaphore;
|
||||||
VkFence Fence;
|
VkFence Fence;
|
||||||
|
|
||||||
RenderingResourcesData() :
|
RenderingResourcesData() :
|
||||||
Framebuffer( VK_NULL_HANDLE ),
|
Framebuffer( VK_NULL_HANDLE ),
|
||||||
CommandBuffer( VK_NULL_HANDLE ),
|
CommandBuffer( VK_NULL_HANDLE ),
|
||||||
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
||||||
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
|
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
|
||||||
Fence( VK_NULL_HANDLE ) {
|
Fence( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanTutorial04Parameters //
|
// VulkanTutorial04Parameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan specific parameters //
|
// Vulkan specific parameters //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VulkanTutorial05Parameters {
|
struct VulkanTutorial05Parameters {
|
||||||
VkRenderPass RenderPass;
|
VkRenderPass RenderPass;
|
||||||
VkPipeline GraphicsPipeline;
|
VkPipeline GraphicsPipeline;
|
||||||
BufferParameters VertexBuffer;
|
BufferParameters VertexBuffer;
|
||||||
BufferParameters StagingBuffer;
|
BufferParameters StagingBuffer;
|
||||||
VkCommandPool CommandPool;
|
VkCommandPool CommandPool;
|
||||||
std::vector<RenderingResourcesData> RenderingResources;
|
std::vector<RenderingResourcesData> RenderingResources;
|
||||||
|
|
||||||
static const size_t ResourcesCount = 3;
|
static const size_t ResourcesCount = 3;
|
||||||
|
|
||||||
VulkanTutorial05Parameters() :
|
VulkanTutorial05Parameters() :
|
||||||
RenderPass( VK_NULL_HANDLE ),
|
RenderPass( VK_NULL_HANDLE ),
|
||||||
GraphicsPipeline( VK_NULL_HANDLE ),
|
GraphicsPipeline( VK_NULL_HANDLE ),
|
||||||
VertexBuffer(),
|
VertexBuffer(),
|
||||||
StagingBuffer(),
|
StagingBuffer(),
|
||||||
CommandPool( VK_NULL_HANDLE ),
|
CommandPool( VK_NULL_HANDLE ),
|
||||||
RenderingResources( ResourcesCount ) {
|
RenderingResources( ResourcesCount ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Tutorial04 //
|
// Tutorial04 //
|
||||||
// //
|
// //
|
||||||
// Class for presenting Vulkan usage topics //
|
// Class for presenting Vulkan usage topics //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class Tutorial05 : public VulkanCommon {
|
class Tutorial05 : public VulkanCommon {
|
||||||
public:
|
public:
|
||||||
Tutorial05();
|
Tutorial05();
|
||||||
~Tutorial05();
|
~Tutorial05();
|
||||||
|
|
||||||
bool CreateRenderingResources();
|
bool CreateRenderingResources();
|
||||||
bool CreateRenderPass();
|
bool CreateRenderPass();
|
||||||
bool CreatePipeline();
|
bool CreatePipeline();
|
||||||
bool CreateVertexBuffer();
|
bool CreateVertexBuffer();
|
||||||
bool CreateStagingBuffer();
|
bool CreateStagingBuffer();
|
||||||
bool CopyVertexData();
|
bool CopyVertexData();
|
||||||
|
|
||||||
bool Draw() override;
|
bool Draw() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VulkanTutorial05Parameters Vulkan;
|
VulkanTutorial05Parameters Vulkan;
|
||||||
|
|
||||||
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
|
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
|
||||||
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
|
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
|
||||||
bool CreateSemaphore( VkSemaphore *semaphore );
|
bool CreateSemaphore( VkSemaphore *semaphore );
|
||||||
bool CreateFence( VkFenceCreateFlags flags, VkFence *fence );
|
bool CreateFence( VkFenceCreateFlags flags, VkFence *fence );
|
||||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
||||||
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
|
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
|
||||||
bool CreateBuffer( VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer );
|
bool CreateBuffer( VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer );
|
||||||
bool AllocateBufferMemory( VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
|
bool AllocateBufferMemory( VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
|
||||||
const std::vector<float>& GetVertexData() const;
|
const std::vector<float>& GetVertexData() const;
|
||||||
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
|
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
|
||||||
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
|
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
|
||||||
void DestroyBuffer( BufferParameters& buffer );
|
void DestroyBuffer( BufferParameters& buffer );
|
||||||
|
|
||||||
void ChildClear() override;
|
void ChildClear() override;
|
||||||
bool ChildOnWindowSizeChanged() override;
|
bool ChildOnWindowSizeChanged() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // TUTORIAL_05_HEADER
|
#endif // TUTORIAL_05_HEADER
|
||||||
@@ -1,59 +1,59 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Tutorial05.h"
|
#include "Tutorial05.h"
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
ApiWithoutSecrets::OS::Window window;
|
ApiWithoutSecrets::OS::Window window;
|
||||||
ApiWithoutSecrets::Tutorial05 tutorial05;
|
ApiWithoutSecrets::Tutorial05 tutorial05;
|
||||||
|
|
||||||
// Window creation
|
// Window creation
|
||||||
if( !window.Create( "05 - Staging Resources" ) ) {
|
if( !window.Create( "05 - Staging Resources" ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vulkan preparations and initialization
|
// Vulkan preparations and initialization
|
||||||
if( !tutorial05.PrepareVulkan( window.GetParameters() ) ) {
|
if( !tutorial05.PrepareVulkan( window.GetParameters() ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tutorial 05
|
// Tutorial 05
|
||||||
if( !tutorial05.CreateRenderingResources() ) {
|
if( !tutorial05.CreateRenderingResources() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial05.CreateRenderPass() ) {
|
if( !tutorial05.CreateRenderPass() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial05.CreatePipeline() ) {
|
if( !tutorial05.CreatePipeline() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial05.CreateVertexBuffer() ) {
|
if( !tutorial05.CreateVertexBuffer() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial05.CreateStagingBuffer() ) {
|
if( !tutorial05.CreateStagingBuffer() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial05.CopyVertexData() ) {
|
if( !tutorial05.CopyVertexData() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendering loop
|
// Rendering loop
|
||||||
if( !window.RenderingLoop( tutorial05 ) ) {
|
if( !window.RenderingLoop( tutorial05 ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,173 +1,173 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(TUTORIAL_06_HEADER)
|
#if !defined(TUTORIAL_06_HEADER)
|
||||||
#define TUTORIAL_06_HEADER
|
#define TUTORIAL_06_HEADER
|
||||||
|
|
||||||
#include "VulkanCommon.h"
|
#include "VulkanCommon.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// BufferParameters //
|
// BufferParameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan Buffer's parameters container class //
|
// Vulkan Buffer's parameters container class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct BufferParameters {
|
struct BufferParameters {
|
||||||
VkBuffer Handle;
|
VkBuffer Handle;
|
||||||
VkDeviceMemory Memory;
|
VkDeviceMemory Memory;
|
||||||
uint32_t Size;
|
uint32_t Size;
|
||||||
|
|
||||||
BufferParameters() :
|
BufferParameters() :
|
||||||
Handle( VK_NULL_HANDLE ),
|
Handle( VK_NULL_HANDLE ),
|
||||||
Memory( VK_NULL_HANDLE ),
|
Memory( VK_NULL_HANDLE ),
|
||||||
Size( 0 ) {
|
Size( 0 ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// DescriptorParameters //
|
// DescriptorParameters //
|
||||||
// //
|
// //
|
||||||
// Container class for descriptor related resources //
|
// Container class for descriptor related resources //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct DescriptorSetParameters {
|
struct DescriptorSetParameters {
|
||||||
VkDescriptorPool Pool;
|
VkDescriptorPool Pool;
|
||||||
VkDescriptorSetLayout Layout;
|
VkDescriptorSetLayout Layout;
|
||||||
VkDescriptorSet Handle;
|
VkDescriptorSet Handle;
|
||||||
|
|
||||||
DescriptorSetParameters() :
|
DescriptorSetParameters() :
|
||||||
Pool( VK_NULL_HANDLE ),
|
Pool( VK_NULL_HANDLE ),
|
||||||
Layout( VK_NULL_HANDLE ),
|
Layout( VK_NULL_HANDLE ),
|
||||||
Handle( VK_NULL_HANDLE ) {
|
Handle( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VertexData //
|
// VertexData //
|
||||||
// //
|
// //
|
||||||
// Struct describing data type and format of vertex attributes //
|
// Struct describing data type and format of vertex attributes //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VertexData {
|
struct VertexData {
|
||||||
float x, y, z, w;
|
float x, y, z, w;
|
||||||
float u, v;
|
float u, v;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// RenderingResourcesData //
|
// RenderingResourcesData //
|
||||||
// //
|
// //
|
||||||
// Struct containing data used during rendering process //
|
// Struct containing data used during rendering process //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct RenderingResourcesData {
|
struct RenderingResourcesData {
|
||||||
VkFramebuffer Framebuffer;
|
VkFramebuffer Framebuffer;
|
||||||
VkCommandBuffer CommandBuffer;
|
VkCommandBuffer CommandBuffer;
|
||||||
VkSemaphore ImageAvailableSemaphore;
|
VkSemaphore ImageAvailableSemaphore;
|
||||||
VkSemaphore FinishedRenderingSemaphore;
|
VkSemaphore FinishedRenderingSemaphore;
|
||||||
VkFence Fence;
|
VkFence Fence;
|
||||||
|
|
||||||
RenderingResourcesData() :
|
RenderingResourcesData() :
|
||||||
Framebuffer( VK_NULL_HANDLE ),
|
Framebuffer( VK_NULL_HANDLE ),
|
||||||
CommandBuffer( VK_NULL_HANDLE ),
|
CommandBuffer( VK_NULL_HANDLE ),
|
||||||
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
||||||
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
|
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
|
||||||
Fence( VK_NULL_HANDLE ) {
|
Fence( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanTutorial04Parameters //
|
// VulkanTutorial04Parameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan specific parameters //
|
// Vulkan specific parameters //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VulkanTutorial06Parameters {
|
struct VulkanTutorial06Parameters {
|
||||||
VkRenderPass RenderPass;
|
VkRenderPass RenderPass;
|
||||||
ImageParameters Image;
|
ImageParameters Image;
|
||||||
DescriptorSetParameters DescriptorSet;
|
DescriptorSetParameters DescriptorSet;
|
||||||
VkPipelineLayout PipelineLayout;
|
VkPipelineLayout PipelineLayout;
|
||||||
VkPipeline GraphicsPipeline;
|
VkPipeline GraphicsPipeline;
|
||||||
BufferParameters VertexBuffer;
|
BufferParameters VertexBuffer;
|
||||||
BufferParameters StagingBuffer;
|
BufferParameters StagingBuffer;
|
||||||
VkCommandPool CommandPool;
|
VkCommandPool CommandPool;
|
||||||
std::vector<RenderingResourcesData> RenderingResources;
|
std::vector<RenderingResourcesData> RenderingResources;
|
||||||
|
|
||||||
static const size_t ResourcesCount = 3;
|
static const size_t ResourcesCount = 3;
|
||||||
|
|
||||||
VulkanTutorial06Parameters() :
|
VulkanTutorial06Parameters() :
|
||||||
RenderPass( VK_NULL_HANDLE ),
|
RenderPass( VK_NULL_HANDLE ),
|
||||||
Image(),
|
Image(),
|
||||||
DescriptorSet(),
|
DescriptorSet(),
|
||||||
PipelineLayout(),
|
PipelineLayout(),
|
||||||
GraphicsPipeline( VK_NULL_HANDLE ),
|
GraphicsPipeline( VK_NULL_HANDLE ),
|
||||||
VertexBuffer(),
|
VertexBuffer(),
|
||||||
StagingBuffer(),
|
StagingBuffer(),
|
||||||
CommandPool( VK_NULL_HANDLE ),
|
CommandPool( VK_NULL_HANDLE ),
|
||||||
RenderingResources( ResourcesCount ) {
|
RenderingResources( ResourcesCount ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Tutorial04 //
|
// Tutorial04 //
|
||||||
// //
|
// //
|
||||||
// Class for presenting Vulkan usage topics //
|
// Class for presenting Vulkan usage topics //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class Tutorial06 : public VulkanCommon {
|
class Tutorial06 : public VulkanCommon {
|
||||||
public:
|
public:
|
||||||
Tutorial06();
|
Tutorial06();
|
||||||
~Tutorial06();
|
~Tutorial06();
|
||||||
|
|
||||||
bool CreateRenderingResources();
|
bool CreateRenderingResources();
|
||||||
bool CreateStagingBuffer();
|
bool CreateStagingBuffer();
|
||||||
bool CreateTexture();
|
bool CreateTexture();
|
||||||
bool CreateDescriptorSetLayout();
|
bool CreateDescriptorSetLayout();
|
||||||
bool CreateDescriptorPool();
|
bool CreateDescriptorPool();
|
||||||
bool AllocateDescriptorSet();
|
bool AllocateDescriptorSet();
|
||||||
bool UpdateDescriptorSet();
|
bool UpdateDescriptorSet();
|
||||||
bool CreateRenderPass();
|
bool CreateRenderPass();
|
||||||
bool CreatePipelineLayout();
|
bool CreatePipelineLayout();
|
||||||
bool CreatePipeline();
|
bool CreatePipeline();
|
||||||
bool CreateVertexBuffer();
|
bool CreateVertexBuffer();
|
||||||
|
|
||||||
bool Draw() override;
|
bool Draw() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VulkanTutorial06Parameters Vulkan;
|
VulkanTutorial06Parameters Vulkan;
|
||||||
|
|
||||||
bool CreateCommandBuffers();
|
bool CreateCommandBuffers();
|
||||||
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
|
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
|
||||||
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
|
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
|
||||||
bool CreateSemaphores();
|
bool CreateSemaphores();
|
||||||
bool CreateFences();
|
bool CreateFences();
|
||||||
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
|
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
|
||||||
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
|
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
|
||||||
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
|
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
|
||||||
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
|
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
|
||||||
bool CreateImageView( ImageParameters &image_parameters );
|
bool CreateImageView( ImageParameters &image_parameters );
|
||||||
bool CreateSampler( VkSampler *sampler );
|
bool CreateSampler( VkSampler *sampler );
|
||||||
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
|
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
|
||||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
||||||
const std::vector<float>& GetVertexData() const;
|
const std::vector<float>& GetVertexData() const;
|
||||||
bool CopyVertexData();
|
bool CopyVertexData();
|
||||||
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
|
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
|
||||||
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
|
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
|
||||||
void DestroyBuffer( BufferParameters& buffer );
|
void DestroyBuffer( BufferParameters& buffer );
|
||||||
|
|
||||||
bool ChildOnWindowSizeChanged() override;
|
bool ChildOnWindowSizeChanged() override;
|
||||||
void ChildClear() override;
|
void ChildClear() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // TUTORIAL_06_HEADER
|
#endif // TUTORIAL_06_HEADER
|
||||||
@@ -1,74 +1,74 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Tutorial06.h"
|
#include "Tutorial06.h"
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
ApiWithoutSecrets::OS::Window window;
|
ApiWithoutSecrets::OS::Window window;
|
||||||
ApiWithoutSecrets::Tutorial06 tutorial06;
|
ApiWithoutSecrets::Tutorial06 tutorial06;
|
||||||
|
|
||||||
// Window creation
|
// Window creation
|
||||||
if( !window.Create( "06 - Descriptor Sets" ) ) {
|
if( !window.Create( "06 - Descriptor Sets" ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vulkan preparations and initialization
|
// Vulkan preparations and initialization
|
||||||
if( !tutorial06.PrepareVulkan( window.GetParameters() ) ) {
|
if( !tutorial06.PrepareVulkan( window.GetParameters() ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tutorial 06
|
// Tutorial 06
|
||||||
if( !tutorial06.CreateRenderingResources() ) {
|
if( !tutorial06.CreateRenderingResources() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.CreateStagingBuffer() ) {
|
if( !tutorial06.CreateStagingBuffer() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.CreateTexture() ) {
|
if( !tutorial06.CreateTexture() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.CreateDescriptorSetLayout() ) {
|
if( !tutorial06.CreateDescriptorSetLayout() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.CreateDescriptorPool() ) {
|
if( !tutorial06.CreateDescriptorPool() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.AllocateDescriptorSet() ) {
|
if( !tutorial06.AllocateDescriptorSet() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.UpdateDescriptorSet() ) {
|
if( !tutorial06.UpdateDescriptorSet() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.CreateRenderPass() ) {
|
if( !tutorial06.CreateRenderPass() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.CreatePipelineLayout() ) {
|
if( !tutorial06.CreatePipelineLayout() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.CreatePipeline() ) {
|
if( !tutorial06.CreatePipeline() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial06.CreateVertexBuffer() ) {
|
if( !tutorial06.CreateVertexBuffer() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendering loop
|
// Rendering loop
|
||||||
if( !window.RenderingLoop( tutorial06 ) ) {
|
if( !window.RenderingLoop( tutorial06 ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,177 +1,177 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if !defined(TUTORIAL_07_HEADER)
|
#if !defined(TUTORIAL_07_HEADER)
|
||||||
#define TUTORIAL_07_HEADER
|
#define TUTORIAL_07_HEADER
|
||||||
|
|
||||||
#include "VulkanCommon.h"
|
#include "VulkanCommon.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
|
||||||
namespace ApiWithoutSecrets {
|
namespace ApiWithoutSecrets {
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// BufferParameters //
|
// BufferParameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan Buffer's parameters container class //
|
// Vulkan Buffer's parameters container class //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct BufferParameters {
|
struct BufferParameters {
|
||||||
VkBuffer Handle;
|
VkBuffer Handle;
|
||||||
VkDeviceMemory Memory;
|
VkDeviceMemory Memory;
|
||||||
uint32_t Size;
|
uint32_t Size;
|
||||||
|
|
||||||
BufferParameters() :
|
BufferParameters() :
|
||||||
Handle( VK_NULL_HANDLE ),
|
Handle( VK_NULL_HANDLE ),
|
||||||
Memory( VK_NULL_HANDLE ),
|
Memory( VK_NULL_HANDLE ),
|
||||||
Size( 0 ) {
|
Size( 0 ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// DescriptorParameters //
|
// DescriptorParameters //
|
||||||
// //
|
// //
|
||||||
// Container class for descriptor related resources //
|
// Container class for descriptor related resources //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct DescriptorSetParameters {
|
struct DescriptorSetParameters {
|
||||||
VkDescriptorPool Pool;
|
VkDescriptorPool Pool;
|
||||||
VkDescriptorSetLayout Layout;
|
VkDescriptorSetLayout Layout;
|
||||||
VkDescriptorSet Handle;
|
VkDescriptorSet Handle;
|
||||||
|
|
||||||
DescriptorSetParameters() :
|
DescriptorSetParameters() :
|
||||||
Pool( VK_NULL_HANDLE ),
|
Pool( VK_NULL_HANDLE ),
|
||||||
Layout( VK_NULL_HANDLE ),
|
Layout( VK_NULL_HANDLE ),
|
||||||
Handle( VK_NULL_HANDLE ) {
|
Handle( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VertexData //
|
// VertexData //
|
||||||
// //
|
// //
|
||||||
// Struct describing data type and format of vertex attributes //
|
// Struct describing data type and format of vertex attributes //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VertexData {
|
struct VertexData {
|
||||||
float x, y, z, w;
|
float x, y, z, w;
|
||||||
float u, v;
|
float u, v;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// RenderingResourcesData //
|
// RenderingResourcesData //
|
||||||
// //
|
// //
|
||||||
// Struct containing data used during rendering process //
|
// Struct containing data used during rendering process //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct RenderingResourcesData {
|
struct RenderingResourcesData {
|
||||||
VkFramebuffer Framebuffer;
|
VkFramebuffer Framebuffer;
|
||||||
VkCommandBuffer CommandBuffer;
|
VkCommandBuffer CommandBuffer;
|
||||||
VkSemaphore ImageAvailableSemaphore;
|
VkSemaphore ImageAvailableSemaphore;
|
||||||
VkSemaphore FinishedRenderingSemaphore;
|
VkSemaphore FinishedRenderingSemaphore;
|
||||||
VkFence Fence;
|
VkFence Fence;
|
||||||
|
|
||||||
RenderingResourcesData() :
|
RenderingResourcesData() :
|
||||||
Framebuffer( VK_NULL_HANDLE ),
|
Framebuffer( VK_NULL_HANDLE ),
|
||||||
CommandBuffer( VK_NULL_HANDLE ),
|
CommandBuffer( VK_NULL_HANDLE ),
|
||||||
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
ImageAvailableSemaphore( VK_NULL_HANDLE ),
|
||||||
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
|
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
|
||||||
Fence( VK_NULL_HANDLE ) {
|
Fence( VK_NULL_HANDLE ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// VulkanTutorial04Parameters //
|
// VulkanTutorial04Parameters //
|
||||||
// //
|
// //
|
||||||
// Vulkan specific parameters //
|
// Vulkan specific parameters //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
struct VulkanTutorial07Parameters {
|
struct VulkanTutorial07Parameters {
|
||||||
VkRenderPass RenderPass;
|
VkRenderPass RenderPass;
|
||||||
ImageParameters Image;
|
ImageParameters Image;
|
||||||
BufferParameters UniformBuffer;
|
BufferParameters UniformBuffer;
|
||||||
DescriptorSetParameters DescriptorSet;
|
DescriptorSetParameters DescriptorSet;
|
||||||
VkPipelineLayout PipelineLayout;
|
VkPipelineLayout PipelineLayout;
|
||||||
VkPipeline GraphicsPipeline;
|
VkPipeline GraphicsPipeline;
|
||||||
BufferParameters VertexBuffer;
|
BufferParameters VertexBuffer;
|
||||||
BufferParameters StagingBuffer;
|
BufferParameters StagingBuffer;
|
||||||
VkCommandPool CommandPool;
|
VkCommandPool CommandPool;
|
||||||
std::vector<RenderingResourcesData> RenderingResources;
|
std::vector<RenderingResourcesData> RenderingResources;
|
||||||
|
|
||||||
static const size_t ResourcesCount = 3;
|
static const size_t ResourcesCount = 3;
|
||||||
|
|
||||||
VulkanTutorial07Parameters() :
|
VulkanTutorial07Parameters() :
|
||||||
RenderPass( VK_NULL_HANDLE ),
|
RenderPass( VK_NULL_HANDLE ),
|
||||||
Image(),
|
Image(),
|
||||||
DescriptorSet(),
|
DescriptorSet(),
|
||||||
PipelineLayout(),
|
PipelineLayout(),
|
||||||
GraphicsPipeline( VK_NULL_HANDLE ),
|
GraphicsPipeline( VK_NULL_HANDLE ),
|
||||||
VertexBuffer(),
|
VertexBuffer(),
|
||||||
StagingBuffer(),
|
StagingBuffer(),
|
||||||
CommandPool( VK_NULL_HANDLE ),
|
CommandPool( VK_NULL_HANDLE ),
|
||||||
RenderingResources( ResourcesCount ) {
|
RenderingResources( ResourcesCount ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// Tutorial04 //
|
// Tutorial04 //
|
||||||
// //
|
// //
|
||||||
// Class for presenting Vulkan usage topics //
|
// Class for presenting Vulkan usage topics //
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
class Tutorial07 : public VulkanCommon {
|
class Tutorial07 : public VulkanCommon {
|
||||||
public:
|
public:
|
||||||
Tutorial07();
|
Tutorial07();
|
||||||
~Tutorial07();
|
~Tutorial07();
|
||||||
|
|
||||||
bool CreateRenderingResources();
|
bool CreateRenderingResources();
|
||||||
bool CreateStagingBuffer();
|
bool CreateStagingBuffer();
|
||||||
bool CreateTexture();
|
bool CreateTexture();
|
||||||
bool CreateUniformBuffer();
|
bool CreateUniformBuffer();
|
||||||
bool CreateDescriptorSetLayout();
|
bool CreateDescriptorSetLayout();
|
||||||
bool CreateDescriptorPool();
|
bool CreateDescriptorPool();
|
||||||
bool AllocateDescriptorSet();
|
bool AllocateDescriptorSet();
|
||||||
bool UpdateDescriptorSet();
|
bool UpdateDescriptorSet();
|
||||||
bool CreateRenderPass();
|
bool CreateRenderPass();
|
||||||
bool CreatePipelineLayout();
|
bool CreatePipelineLayout();
|
||||||
bool CreatePipeline();
|
bool CreatePipeline();
|
||||||
bool CreateVertexBuffer();
|
bool CreateVertexBuffer();
|
||||||
|
|
||||||
bool Draw() override;
|
bool Draw() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VulkanTutorial07Parameters Vulkan;
|
VulkanTutorial07Parameters Vulkan;
|
||||||
|
|
||||||
bool CreateCommandBuffers();
|
bool CreateCommandBuffers();
|
||||||
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
|
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
|
||||||
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
|
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
|
||||||
bool CreateSemaphores();
|
bool CreateSemaphores();
|
||||||
bool CreateFences();
|
bool CreateFences();
|
||||||
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
|
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
|
||||||
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
|
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
|
||||||
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
|
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
|
||||||
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
|
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
|
||||||
bool CreateImageView( ImageParameters &image_parameters );
|
bool CreateImageView( ImageParameters &image_parameters );
|
||||||
bool CreateSampler( VkSampler *sampler );
|
bool CreateSampler( VkSampler *sampler );
|
||||||
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
|
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
|
||||||
const std::array<float, 16> GetUniformBufferData() const;
|
const std::array<float, 16> GetUniformBufferData() const;
|
||||||
bool CopyUniformBufferData();
|
bool CopyUniformBufferData();
|
||||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
||||||
const std::vector<float>& GetVertexData() const;
|
const std::vector<float>& GetVertexData() const;
|
||||||
bool CopyVertexData();
|
bool CopyVertexData();
|
||||||
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
|
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
|
||||||
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
|
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
|
||||||
void DestroyBuffer( BufferParameters& buffer );
|
void DestroyBuffer( BufferParameters& buffer );
|
||||||
|
|
||||||
bool ChildOnWindowSizeChanged() override;
|
bool ChildOnWindowSizeChanged() override;
|
||||||
void ChildClear() override;
|
void ChildClear() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ApiWithoutSecrets
|
} // namespace ApiWithoutSecrets
|
||||||
|
|
||||||
#endif // TUTORIAL_07_HEADER
|
#endif // TUTORIAL_07_HEADER
|
||||||
@@ -1,77 +1,77 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 2017 Intel Corporation
|
// Copyright 2017 Intel Corporation
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
// use this file except in compliance with the License. You may obtain a copy
|
// use this file except in compliance with the License. You may obtain a copy
|
||||||
// of the License at
|
// of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
// License for the specific language governing permissions and limitations
|
// License for the specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Tutorial07.h"
|
#include "Tutorial07.h"
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
ApiWithoutSecrets::OS::Window window;
|
ApiWithoutSecrets::OS::Window window;
|
||||||
ApiWithoutSecrets::Tutorial07 tutorial07;
|
ApiWithoutSecrets::Tutorial07 tutorial07;
|
||||||
|
|
||||||
// Window creation
|
// Window creation
|
||||||
if( !window.Create( "07 - Uniform Buffers" ) ) {
|
if( !window.Create( "07 - Uniform Buffers" ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vulkan preparations and initialization
|
// Vulkan preparations and initialization
|
||||||
if( !tutorial07.PrepareVulkan( window.GetParameters() ) ) {
|
if( !tutorial07.PrepareVulkan( window.GetParameters() ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tutorial 06
|
// Tutorial 06
|
||||||
if( !tutorial07.CreateRenderingResources() ) {
|
if( !tutorial07.CreateRenderingResources() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreateStagingBuffer() ) {
|
if( !tutorial07.CreateStagingBuffer() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreateTexture() ) {
|
if( !tutorial07.CreateTexture() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreateUniformBuffer() ) {
|
if( !tutorial07.CreateUniformBuffer() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreateDescriptorSetLayout() ) {
|
if( !tutorial07.CreateDescriptorSetLayout() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreateDescriptorPool() ) {
|
if( !tutorial07.CreateDescriptorPool() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.AllocateDescriptorSet() ) {
|
if( !tutorial07.AllocateDescriptorSet() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.UpdateDescriptorSet() ) {
|
if( !tutorial07.UpdateDescriptorSet() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreateRenderPass() ) {
|
if( !tutorial07.CreateRenderPass() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreatePipelineLayout() ) {
|
if( !tutorial07.CreatePipelineLayout() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreatePipeline() ) {
|
if( !tutorial07.CreatePipeline() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( !tutorial07.CreateVertexBuffer() ) {
|
if( !tutorial07.CreateVertexBuffer() ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendering loop
|
// Rendering loop
|
||||||
if( !window.RenderingLoop( tutorial07 ) ) {
|
if( !window.RenderingLoop( tutorial07 ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,42 @@
|
|||||||
@ECHO OFF
|
@ECHO OFF
|
||||||
SETLOCAL
|
SETLOCAL
|
||||||
|
|
||||||
REM /////////////////////////////////////////////////////////////////////////////////////////////
|
REM /////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
REM // Copyright 2017 Intel Corporation
|
REM // Copyright 2017 Intel Corporation
|
||||||
REM //
|
REM //
|
||||||
REM // Licensed under the Apache License, Version 2.0 (the "License");
|
REM // Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
REM // you may not use this file except in compliance with the License.
|
REM // you may not use this file except in compliance with the License.
|
||||||
REM // You may obtain a copy of the License at
|
REM // You may obtain a copy of the License at
|
||||||
REM //
|
REM //
|
||||||
REM // http://www.apache.org/licenses/LICENSE-2.0
|
REM // http://www.apache.org/licenses/LICENSE-2.0
|
||||||
REM //
|
REM //
|
||||||
REM // Unless required by applicable law or agreed to in writing, software
|
REM // Unless required by applicable law or agreed to in writing, software
|
||||||
REM // distributed under the License is distributed on an "AS IS" BASIS,
|
REM // distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
REM // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
REM // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
REM // See the License for the specific language governing permissions and
|
REM // See the License for the specific language governing permissions and
|
||||||
REM // limitations under the License.
|
REM // limitations under the License.
|
||||||
REM /////////////////////////////////////////////////////////////////////////////////////////////
|
REM /////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
if [%1] == [] (
|
if [%1] == [] (
|
||||||
echo No arguments provided! Please specify folder number.
|
echo No arguments provided! Please specify folder number.
|
||||||
echo Example usage: compile_shaders.bat 03
|
echo Example usage: compile_shaders.bat 03
|
||||||
goto end
|
goto end
|
||||||
)
|
)
|
||||||
|
|
||||||
if exist glslangValidator.exe (
|
if exist glslangValidator.exe (
|
||||||
goto convert
|
goto convert
|
||||||
)
|
)
|
||||||
for %%X in (glslangValidator.exe) do (set glslangValidator=%%~$PATH:X)
|
for %%X in (glslangValidator.exe) do (set glslangValidator=%%~$PATH:X)
|
||||||
if defined glslangValidator (
|
if defined glslangValidator (
|
||||||
goto convert
|
goto convert
|
||||||
)
|
)
|
||||||
|
|
||||||
echo Could not find "glslangValidator.exe" file.
|
echo Could not find "glslangValidator.exe" file.
|
||||||
goto end
|
goto end
|
||||||
|
|
||||||
:convert
|
:convert
|
||||||
|
|
||||||
set folder=Tutorial%1/Data%1
|
set folder=Tutorial%1/Data%1
|
||||||
echo Converting GLSL shaders into SPIR-V assembly in the "%folder%" folder.
|
echo Converting GLSL shaders into SPIR-V assembly in the "%folder%" folder.
|
||||||
|
|
||||||
if exist %folder%/shader.vert (
|
if exist %folder%/shader.vert (
|
||||||
Reference in New Issue
Block a user