Changed line endings from Windows (\r\n) to Linux (\n) style.

This commit is contained in:
Pawel Lapinski
2017-11-14 09:57:36 +01:00
parent 340a7a664a
commit 9af5bc6d35
31 changed files with 9266 additions and 9266 deletions

View File

@@ -1,185 +1,185 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
// ************************************************************ //
// Exported functions //
// //
// These functions are always exposed by vulkan libraries. //
// ************************************************************ //
#if !defined(VK_EXPORTED_FUNCTION)
#define VK_EXPORTED_FUNCTION( fun )
#endif
VK_EXPORTED_FUNCTION( vkGetInstanceProcAddr )
#undef VK_EXPORTED_FUNCTION
// ************************************************************ //
// Global level functions //
// //
// They allow checking what instance extensions are available //
// and allow creation of a Vulkan Instance. //
// ************************************************************ //
#if !defined(VK_GLOBAL_LEVEL_FUNCTION)
#define VK_GLOBAL_LEVEL_FUNCTION( fun )
#endif
// Tutorial 01
VK_GLOBAL_LEVEL_FUNCTION( vkCreateInstance )
// Tutorial 02
VK_GLOBAL_LEVEL_FUNCTION( vkEnumerateInstanceExtensionProperties )
#undef VK_GLOBAL_LEVEL_FUNCTION
// ************************************************************ //
// Instance level functions //
// //
// These functions allow for device queries and creation. //
// They help choose which device is well suited for our needs. //
// ************************************************************ //
#if !defined(VK_INSTANCE_LEVEL_FUNCTION)
#define VK_INSTANCE_LEVEL_FUNCTION( fun )
#endif
// Tutorial 01
VK_INSTANCE_LEVEL_FUNCTION( vkEnumeratePhysicalDevices )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceProperties )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceFeatures )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceQueueFamilyProperties )
VK_INSTANCE_LEVEL_FUNCTION( vkCreateDevice )
VK_INSTANCE_LEVEL_FUNCTION( vkGetDeviceProcAddr )
VK_INSTANCE_LEVEL_FUNCTION( vkDestroyInstance )
// Tutorial 02
VK_INSTANCE_LEVEL_FUNCTION( vkEnumerateDeviceExtensionProperties )
#if defined(USE_SWAPCHAIN_EXTENSIONS)
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceSupportKHR )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceCapabilitiesKHR )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceFormatsKHR )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfacePresentModesKHR )
VK_INSTANCE_LEVEL_FUNCTION( vkDestroySurfaceKHR )
#if defined(VK_USE_PLATFORM_WIN32_KHR)
VK_INSTANCE_LEVEL_FUNCTION( vkCreateWin32SurfaceKHR )
#elif defined(VK_USE_PLATFORM_XCB_KHR)
VK_INSTANCE_LEVEL_FUNCTION( vkCreateXcbSurfaceKHR )
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
VK_INSTANCE_LEVEL_FUNCTION( vkCreateXlibSurfaceKHR )
#endif
#endif
// Tutorial 04
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceMemoryProperties )
#undef VK_INSTANCE_LEVEL_FUNCTION
// ************************************************************ //
// Device level functions //
// //
// These functions are used mainly for drawing //
// ************************************************************ //
#if !defined(VK_DEVICE_LEVEL_FUNCTION)
#define VK_DEVICE_LEVEL_FUNCTION( fun )
#endif
// Tutorial 01
VK_DEVICE_LEVEL_FUNCTION( vkGetDeviceQueue )
VK_DEVICE_LEVEL_FUNCTION( vkDeviceWaitIdle )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDevice )
// Tutorial 02
VK_DEVICE_LEVEL_FUNCTION( vkCreateSemaphore )
VK_DEVICE_LEVEL_FUNCTION( vkCreateCommandPool )
VK_DEVICE_LEVEL_FUNCTION( vkAllocateCommandBuffers )
VK_DEVICE_LEVEL_FUNCTION( vkBeginCommandBuffer )
VK_DEVICE_LEVEL_FUNCTION( vkCmdPipelineBarrier )
VK_DEVICE_LEVEL_FUNCTION( vkCmdClearColorImage )
VK_DEVICE_LEVEL_FUNCTION( vkEndCommandBuffer )
VK_DEVICE_LEVEL_FUNCTION( vkQueueSubmit )
VK_DEVICE_LEVEL_FUNCTION( vkFreeCommandBuffers )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyCommandPool )
VK_DEVICE_LEVEL_FUNCTION( vkDestroySemaphore )
#if defined(USE_SWAPCHAIN_EXTENSIONS)
VK_DEVICE_LEVEL_FUNCTION( vkCreateSwapchainKHR )
VK_DEVICE_LEVEL_FUNCTION( vkGetSwapchainImagesKHR )
VK_DEVICE_LEVEL_FUNCTION( vkAcquireNextImageKHR )
VK_DEVICE_LEVEL_FUNCTION( vkQueuePresentKHR )
VK_DEVICE_LEVEL_FUNCTION( vkDestroySwapchainKHR )
#endif
// Tutorial 03
VK_DEVICE_LEVEL_FUNCTION( vkCreateImageView )
VK_DEVICE_LEVEL_FUNCTION( vkCreateRenderPass )
VK_DEVICE_LEVEL_FUNCTION( vkCreateFramebuffer )
VK_DEVICE_LEVEL_FUNCTION( vkCreateShaderModule )
VK_DEVICE_LEVEL_FUNCTION( vkCreatePipelineLayout )
VK_DEVICE_LEVEL_FUNCTION( vkCreateGraphicsPipelines )
VK_DEVICE_LEVEL_FUNCTION( vkCmdBeginRenderPass )
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindPipeline )
VK_DEVICE_LEVEL_FUNCTION( vkCmdDraw )
VK_DEVICE_LEVEL_FUNCTION( vkCmdEndRenderPass )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyShaderModule )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyPipelineLayout )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyPipeline )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyRenderPass )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyFramebuffer )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyImageView )
// Tutorial 04
VK_DEVICE_LEVEL_FUNCTION( vkCreateFence )
VK_DEVICE_LEVEL_FUNCTION( vkCreateBuffer )
VK_DEVICE_LEVEL_FUNCTION( vkGetBufferMemoryRequirements )
VK_DEVICE_LEVEL_FUNCTION( vkAllocateMemory )
VK_DEVICE_LEVEL_FUNCTION( vkBindBufferMemory )
VK_DEVICE_LEVEL_FUNCTION( vkMapMemory )
VK_DEVICE_LEVEL_FUNCTION( vkFlushMappedMemoryRanges )
VK_DEVICE_LEVEL_FUNCTION( vkUnmapMemory )
VK_DEVICE_LEVEL_FUNCTION( vkCmdSetViewport )
VK_DEVICE_LEVEL_FUNCTION( vkCmdSetScissor )
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindVertexBuffers )
VK_DEVICE_LEVEL_FUNCTION( vkWaitForFences )
VK_DEVICE_LEVEL_FUNCTION( vkResetFences )
VK_DEVICE_LEVEL_FUNCTION( vkFreeMemory )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyBuffer )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyFence )
// Tutorial 05
VK_DEVICE_LEVEL_FUNCTION( vkCmdCopyBuffer )
// Tutorial 06
VK_DEVICE_LEVEL_FUNCTION( vkCreateImage )
VK_DEVICE_LEVEL_FUNCTION( vkGetImageMemoryRequirements )
VK_DEVICE_LEVEL_FUNCTION( vkBindImageMemory )
VK_DEVICE_LEVEL_FUNCTION( vkCreateSampler )
VK_DEVICE_LEVEL_FUNCTION( vkCmdCopyBufferToImage )
VK_DEVICE_LEVEL_FUNCTION( vkCreateDescriptorSetLayout )
VK_DEVICE_LEVEL_FUNCTION( vkCreateDescriptorPool )
VK_DEVICE_LEVEL_FUNCTION( vkAllocateDescriptorSets )
VK_DEVICE_LEVEL_FUNCTION( vkUpdateDescriptorSets )
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindDescriptorSets )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDescriptorPool )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDescriptorSetLayout )
VK_DEVICE_LEVEL_FUNCTION( vkDestroySampler )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyImage )
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
// ************************************************************ //
// Exported functions //
// //
// These functions are always exposed by vulkan libraries. //
// ************************************************************ //
#if !defined(VK_EXPORTED_FUNCTION)
#define VK_EXPORTED_FUNCTION( fun )
#endif
VK_EXPORTED_FUNCTION( vkGetInstanceProcAddr )
#undef VK_EXPORTED_FUNCTION
// ************************************************************ //
// Global level functions //
// //
// They allow checking what instance extensions are available //
// and allow creation of a Vulkan Instance. //
// ************************************************************ //
#if !defined(VK_GLOBAL_LEVEL_FUNCTION)
#define VK_GLOBAL_LEVEL_FUNCTION( fun )
#endif
// Tutorial 01
VK_GLOBAL_LEVEL_FUNCTION( vkCreateInstance )
// Tutorial 02
VK_GLOBAL_LEVEL_FUNCTION( vkEnumerateInstanceExtensionProperties )
#undef VK_GLOBAL_LEVEL_FUNCTION
// ************************************************************ //
// Instance level functions //
// //
// These functions allow for device queries and creation. //
// They help choose which device is well suited for our needs. //
// ************************************************************ //
#if !defined(VK_INSTANCE_LEVEL_FUNCTION)
#define VK_INSTANCE_LEVEL_FUNCTION( fun )
#endif
// Tutorial 01
VK_INSTANCE_LEVEL_FUNCTION( vkEnumeratePhysicalDevices )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceProperties )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceFeatures )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceQueueFamilyProperties )
VK_INSTANCE_LEVEL_FUNCTION( vkCreateDevice )
VK_INSTANCE_LEVEL_FUNCTION( vkGetDeviceProcAddr )
VK_INSTANCE_LEVEL_FUNCTION( vkDestroyInstance )
// Tutorial 02
VK_INSTANCE_LEVEL_FUNCTION( vkEnumerateDeviceExtensionProperties )
#if defined(USE_SWAPCHAIN_EXTENSIONS)
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceSupportKHR )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceCapabilitiesKHR )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfaceFormatsKHR )
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceSurfacePresentModesKHR )
VK_INSTANCE_LEVEL_FUNCTION( vkDestroySurfaceKHR )
#if defined(VK_USE_PLATFORM_WIN32_KHR)
VK_INSTANCE_LEVEL_FUNCTION( vkCreateWin32SurfaceKHR )
#elif defined(VK_USE_PLATFORM_XCB_KHR)
VK_INSTANCE_LEVEL_FUNCTION( vkCreateXcbSurfaceKHR )
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
VK_INSTANCE_LEVEL_FUNCTION( vkCreateXlibSurfaceKHR )
#endif
#endif
// Tutorial 04
VK_INSTANCE_LEVEL_FUNCTION( vkGetPhysicalDeviceMemoryProperties )
#undef VK_INSTANCE_LEVEL_FUNCTION
// ************************************************************ //
// Device level functions //
// //
// These functions are used mainly for drawing //
// ************************************************************ //
#if !defined(VK_DEVICE_LEVEL_FUNCTION)
#define VK_DEVICE_LEVEL_FUNCTION( fun )
#endif
// Tutorial 01
VK_DEVICE_LEVEL_FUNCTION( vkGetDeviceQueue )
VK_DEVICE_LEVEL_FUNCTION( vkDeviceWaitIdle )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDevice )
// Tutorial 02
VK_DEVICE_LEVEL_FUNCTION( vkCreateSemaphore )
VK_DEVICE_LEVEL_FUNCTION( vkCreateCommandPool )
VK_DEVICE_LEVEL_FUNCTION( vkAllocateCommandBuffers )
VK_DEVICE_LEVEL_FUNCTION( vkBeginCommandBuffer )
VK_DEVICE_LEVEL_FUNCTION( vkCmdPipelineBarrier )
VK_DEVICE_LEVEL_FUNCTION( vkCmdClearColorImage )
VK_DEVICE_LEVEL_FUNCTION( vkEndCommandBuffer )
VK_DEVICE_LEVEL_FUNCTION( vkQueueSubmit )
VK_DEVICE_LEVEL_FUNCTION( vkFreeCommandBuffers )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyCommandPool )
VK_DEVICE_LEVEL_FUNCTION( vkDestroySemaphore )
#if defined(USE_SWAPCHAIN_EXTENSIONS)
VK_DEVICE_LEVEL_FUNCTION( vkCreateSwapchainKHR )
VK_DEVICE_LEVEL_FUNCTION( vkGetSwapchainImagesKHR )
VK_DEVICE_LEVEL_FUNCTION( vkAcquireNextImageKHR )
VK_DEVICE_LEVEL_FUNCTION( vkQueuePresentKHR )
VK_DEVICE_LEVEL_FUNCTION( vkDestroySwapchainKHR )
#endif
// Tutorial 03
VK_DEVICE_LEVEL_FUNCTION( vkCreateImageView )
VK_DEVICE_LEVEL_FUNCTION( vkCreateRenderPass )
VK_DEVICE_LEVEL_FUNCTION( vkCreateFramebuffer )
VK_DEVICE_LEVEL_FUNCTION( vkCreateShaderModule )
VK_DEVICE_LEVEL_FUNCTION( vkCreatePipelineLayout )
VK_DEVICE_LEVEL_FUNCTION( vkCreateGraphicsPipelines )
VK_DEVICE_LEVEL_FUNCTION( vkCmdBeginRenderPass )
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindPipeline )
VK_DEVICE_LEVEL_FUNCTION( vkCmdDraw )
VK_DEVICE_LEVEL_FUNCTION( vkCmdEndRenderPass )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyShaderModule )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyPipelineLayout )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyPipeline )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyRenderPass )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyFramebuffer )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyImageView )
// Tutorial 04
VK_DEVICE_LEVEL_FUNCTION( vkCreateFence )
VK_DEVICE_LEVEL_FUNCTION( vkCreateBuffer )
VK_DEVICE_LEVEL_FUNCTION( vkGetBufferMemoryRequirements )
VK_DEVICE_LEVEL_FUNCTION( vkAllocateMemory )
VK_DEVICE_LEVEL_FUNCTION( vkBindBufferMemory )
VK_DEVICE_LEVEL_FUNCTION( vkMapMemory )
VK_DEVICE_LEVEL_FUNCTION( vkFlushMappedMemoryRanges )
VK_DEVICE_LEVEL_FUNCTION( vkUnmapMemory )
VK_DEVICE_LEVEL_FUNCTION( vkCmdSetViewport )
VK_DEVICE_LEVEL_FUNCTION( vkCmdSetScissor )
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindVertexBuffers )
VK_DEVICE_LEVEL_FUNCTION( vkWaitForFences )
VK_DEVICE_LEVEL_FUNCTION( vkResetFences )
VK_DEVICE_LEVEL_FUNCTION( vkFreeMemory )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyBuffer )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyFence )
// Tutorial 05
VK_DEVICE_LEVEL_FUNCTION( vkCmdCopyBuffer )
// Tutorial 06
VK_DEVICE_LEVEL_FUNCTION( vkCreateImage )
VK_DEVICE_LEVEL_FUNCTION( vkGetImageMemoryRequirements )
VK_DEVICE_LEVEL_FUNCTION( vkBindImageMemory )
VK_DEVICE_LEVEL_FUNCTION( vkCreateSampler )
VK_DEVICE_LEVEL_FUNCTION( vkCmdCopyBufferToImage )
VK_DEVICE_LEVEL_FUNCTION( vkCreateDescriptorSetLayout )
VK_DEVICE_LEVEL_FUNCTION( vkCreateDescriptorPool )
VK_DEVICE_LEVEL_FUNCTION( vkAllocateDescriptorSets )
VK_DEVICE_LEVEL_FUNCTION( vkUpdateDescriptorSets )
VK_DEVICE_LEVEL_FUNCTION( vkCmdBindDescriptorSets )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDescriptorPool )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyDescriptorSetLayout )
VK_DEVICE_LEVEL_FUNCTION( vkDestroySampler )
VK_DEVICE_LEVEL_FUNCTION( vkDestroyImage )
#undef VK_DEVICE_LEVEL_FUNCTION

View File

@@ -1,385 +1,385 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include <thread>
#include <chrono>
#include "OperatingSystem.h"
namespace ApiWithoutSecrets {
namespace OS {
Window::Window() :
Parameters() {
}
WindowParameters Window::GetParameters() const {
return Parameters;
}
#if defined(VK_USE_PLATFORM_WIN32_KHR)
#define TUTORIAL_NAME "API without Secrets: Introduction to Vulkan"
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {
switch( message ) {
case WM_SIZE:
case WM_EXITSIZEMOVE:
PostMessage( hWnd, WM_USER + 1, wParam, lParam );
break;
case WM_KEYDOWN:
case WM_CLOSE:
PostMessage( hWnd, WM_USER + 2, wParam, lParam );
break;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
return 0;
}
Window::~Window() {
if( Parameters.Handle ) {
DestroyWindow( Parameters.Handle );
}
if( Parameters.Instance ) {
UnregisterClass( TUTORIAL_NAME, Parameters.Instance );
}
}
bool Window::Create( const char *title ) {
Parameters.Instance = GetModuleHandle( nullptr );
// Register window class
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = Parameters.Instance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TUTORIAL_NAME;
wcex.hIconSm = NULL;
if( !RegisterClassEx( &wcex ) ) {
return false;
}
// Create window
Parameters.Handle = CreateWindow( TUTORIAL_NAME, title, WS_OVERLAPPEDWINDOW, 20, 20, 500, 500, nullptr, nullptr, Parameters.Instance, nullptr );
if( !Parameters.Handle ) {
return false;
}
return true;
}
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
// Display window
ShowWindow( Parameters.Handle, SW_SHOWNORMAL );
UpdateWindow( Parameters.Handle );
// Main message loop
MSG message;
bool loop = true;
bool resize = false;
bool result = true;
while( loop ) {
if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) ) {
// Process events
switch( message.message ) {
// Resize
case WM_USER + 1:
resize = true;
break;
// Close
case WM_USER + 2:
loop = false;
break;
}
TranslateMessage( &message );
DispatchMessage( &message );
} else {
// Draw
if( resize ) {
resize = false;
if( !tutorial.OnWindowSizeChanged() ) {
result = false;
break;
}
}
if( tutorial.ReadyToDraw() ) {
if( !tutorial.Draw() ) {
result = false;
break;
}
} else {
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
}
}
}
return result;
}
#elif defined(VK_USE_PLATFORM_XCB_KHR)
Window::~Window() {
xcb_destroy_window( Parameters.Connection, Parameters.Handle );
xcb_disconnect( Parameters.Connection );
}
bool Window::Create( const char *title ) {
int screen_index;
Parameters.Connection = xcb_connect( nullptr, &screen_index );
if( !Parameters.Connection ) {
return false;
}
const xcb_setup_t *setup = xcb_get_setup( Parameters.Connection );
xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator( setup );
while( screen_index-- > 0 ) {
xcb_screen_next( &screen_iterator );
}
xcb_screen_t *screen = screen_iterator.data;
Parameters.Handle = xcb_generate_id( Parameters.Connection );
uint32_t value_list[] = {
screen->white_pixel,
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY
};
xcb_create_window(
Parameters.Connection,
XCB_COPY_FROM_PARENT,
Parameters.Handle,
screen->root,
20,
20,
500,
500,
0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual,
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
value_list );
xcb_flush( Parameters.Connection );
xcb_change_property(
Parameters.Connection,
XCB_PROP_MODE_REPLACE,
Parameters.Handle,
XCB_ATOM_WM_NAME,
XCB_ATOM_STRING,
8,
strlen( title ),
title );
return true;
}
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
// Prepare notification for window destruction
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_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_change_property( Parameters.Connection, XCB_PROP_MODE_REPLACE, Parameters.Handle, (*protocols_reply).atom, 4, 32, 1, &(*delete_reply).atom );
free( protocols_reply );
// Display window
xcb_map_window( Parameters.Connection, Parameters.Handle );
xcb_flush( Parameters.Connection );
// Main message loop
xcb_generic_event_t *event;
bool loop = true;
bool resize = false;
bool result = true;
while( loop ) {
event = xcb_poll_for_event( Parameters.Connection );
if( event ) {
// Process events
switch (event->response_type & 0x7f) {
// Resize
case XCB_CONFIGURE_NOTIFY: {
xcb_configure_notify_event_t *configure_event = (xcb_configure_notify_event_t*)event;
static uint16_t width = configure_event->width;
static uint16_t height = configure_event->height;
if( ((configure_event->width > 0) && (width != configure_event->width)) ||
((configure_event->height > 0) && (height != configure_event->height)) ) {
resize = true;
width = configure_event->width;
height = configure_event->height;
}
}
break;
// Close
case XCB_CLIENT_MESSAGE:
if( (*(xcb_client_message_event_t*)event).data.data32[0] == (*delete_reply).atom ) {
loop = false;
free( delete_reply );
}
break;
case XCB_KEY_PRESS:
loop = false;
break;
}
free( event );
} else {
// Draw
if( resize ) {
resize = false;
if( !tutorial.OnWindowSizeChanged() ) {
result = false;
break;
}
}
if( tutorial.ReadyToDraw() ) {
if( !tutorial.Draw() ) {
result = false;
break;
}
} else {
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
}
}
}
return result;
}
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
Window::~Window() {
XDestroyWindow( Parameters.DisplayPtr, Parameters.Handle );
XCloseDisplay( Parameters.DisplayPtr );
}
bool Window::Create( const char *title ) {
Parameters.DisplayPtr = XOpenDisplay( nullptr );
if( !Parameters.DisplayPtr ) {
return false;
}
int default_screen = DefaultScreen( Parameters.DisplayPtr );
Parameters.Handle = XCreateSimpleWindow(
Parameters.DisplayPtr,
DefaultRootWindow( Parameters.DisplayPtr ),
20,
20,
500,
500,
1,
BlackPixel( Parameters.DisplayPtr, default_screen ),
WhitePixel( Parameters.DisplayPtr, default_screen ) );
// XSync( Parameters.DisplayPtr, false );
XSetStandardProperties( Parameters.DisplayPtr, Parameters.Handle, title, title, None, nullptr, 0, nullptr );
XSelectInput( Parameters.DisplayPtr, Parameters.Handle, ExposureMask | KeyPressMask | StructureNotifyMask );
return true;
}
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
// Prepare notification for window destruction
Atom delete_window_atom;
delete_window_atom = XInternAtom( Parameters.DisplayPtr, "WM_DELETE_WINDOW", false );
XSetWMProtocols( Parameters.DisplayPtr, Parameters.Handle, &delete_window_atom, 1);
// Display window
XClearWindow( Parameters.DisplayPtr, Parameters.Handle );
XMapWindow( Parameters.DisplayPtr, Parameters.Handle );
// Main message loop
XEvent event;
bool loop = true;
bool resize = false;
bool result = true;
while( loop ) {
if( XPending( Parameters.DisplayPtr ) ) {
XNextEvent( Parameters.DisplayPtr, &event );
switch( event.type ) {
//Process events
case ConfigureNotify: {
static int width = event.xconfigure.width;
static int height = event.xconfigure.height;
if( ((event.xconfigure.width > 0) && (event.xconfigure.width != width)) ||
((event.xconfigure.height > 0) && (event.xconfigure.width != height)) ) {
width = event.xconfigure.width;
height = event.xconfigure.height;
resize = true;
}
}
break;
case KeyPress:
loop = false;
break;
case DestroyNotify:
loop = false;
break;
case ClientMessage:
if( static_cast<unsigned int>(event.xclient.data.l[0]) == delete_window_atom ) {
loop = false;
}
break;
}
} else {
// Draw
if( resize ) {
resize = false;
if( !tutorial.OnWindowSizeChanged() ) {
result = false;
break;
}
}
if( tutorial.ReadyToDraw() ) {
if( !tutorial.Draw() ) {
result = false;
break;
}
} else {
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
}
}
}
return result;
}
#endif
} // namespace OS
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include <thread>
#include <chrono>
#include "OperatingSystem.h"
namespace ApiWithoutSecrets {
namespace OS {
Window::Window() :
Parameters() {
}
WindowParameters Window::GetParameters() const {
return Parameters;
}
#if defined(VK_USE_PLATFORM_WIN32_KHR)
#define TUTORIAL_NAME "API without Secrets: Introduction to Vulkan"
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {
switch( message ) {
case WM_SIZE:
case WM_EXITSIZEMOVE:
PostMessage( hWnd, WM_USER + 1, wParam, lParam );
break;
case WM_KEYDOWN:
case WM_CLOSE:
PostMessage( hWnd, WM_USER + 2, wParam, lParam );
break;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
return 0;
}
Window::~Window() {
if( Parameters.Handle ) {
DestroyWindow( Parameters.Handle );
}
if( Parameters.Instance ) {
UnregisterClass( TUTORIAL_NAME, Parameters.Instance );
}
}
bool Window::Create( const char *title ) {
Parameters.Instance = GetModuleHandle( nullptr );
// Register window class
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = Parameters.Instance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TUTORIAL_NAME;
wcex.hIconSm = NULL;
if( !RegisterClassEx( &wcex ) ) {
return false;
}
// Create window
Parameters.Handle = CreateWindow( TUTORIAL_NAME, title, WS_OVERLAPPEDWINDOW, 20, 20, 500, 500, nullptr, nullptr, Parameters.Instance, nullptr );
if( !Parameters.Handle ) {
return false;
}
return true;
}
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
// Display window
ShowWindow( Parameters.Handle, SW_SHOWNORMAL );
UpdateWindow( Parameters.Handle );
// Main message loop
MSG message;
bool loop = true;
bool resize = false;
bool result = true;
while( loop ) {
if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) ) {
// Process events
switch( message.message ) {
// Resize
case WM_USER + 1:
resize = true;
break;
// Close
case WM_USER + 2:
loop = false;
break;
}
TranslateMessage( &message );
DispatchMessage( &message );
} else {
// Draw
if( resize ) {
resize = false;
if( !tutorial.OnWindowSizeChanged() ) {
result = false;
break;
}
}
if( tutorial.ReadyToDraw() ) {
if( !tutorial.Draw() ) {
result = false;
break;
}
} else {
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
}
}
}
return result;
}
#elif defined(VK_USE_PLATFORM_XCB_KHR)
Window::~Window() {
xcb_destroy_window( Parameters.Connection, Parameters.Handle );
xcb_disconnect( Parameters.Connection );
}
bool Window::Create( const char *title ) {
int screen_index;
Parameters.Connection = xcb_connect( nullptr, &screen_index );
if( !Parameters.Connection ) {
return false;
}
const xcb_setup_t *setup = xcb_get_setup( Parameters.Connection );
xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator( setup );
while( screen_index-- > 0 ) {
xcb_screen_next( &screen_iterator );
}
xcb_screen_t *screen = screen_iterator.data;
Parameters.Handle = xcb_generate_id( Parameters.Connection );
uint32_t value_list[] = {
screen->white_pixel,
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY
};
xcb_create_window(
Parameters.Connection,
XCB_COPY_FROM_PARENT,
Parameters.Handle,
screen->root,
20,
20,
500,
500,
0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual,
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
value_list );
xcb_flush( Parameters.Connection );
xcb_change_property(
Parameters.Connection,
XCB_PROP_MODE_REPLACE,
Parameters.Handle,
XCB_ATOM_WM_NAME,
XCB_ATOM_STRING,
8,
strlen( title ),
title );
return true;
}
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
// Prepare notification for window destruction
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_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_change_property( Parameters.Connection, XCB_PROP_MODE_REPLACE, Parameters.Handle, (*protocols_reply).atom, 4, 32, 1, &(*delete_reply).atom );
free( protocols_reply );
// Display window
xcb_map_window( Parameters.Connection, Parameters.Handle );
xcb_flush( Parameters.Connection );
// Main message loop
xcb_generic_event_t *event;
bool loop = true;
bool resize = false;
bool result = true;
while( loop ) {
event = xcb_poll_for_event( Parameters.Connection );
if( event ) {
// Process events
switch (event->response_type & 0x7f) {
// Resize
case XCB_CONFIGURE_NOTIFY: {
xcb_configure_notify_event_t *configure_event = (xcb_configure_notify_event_t*)event;
static uint16_t width = configure_event->width;
static uint16_t height = configure_event->height;
if( ((configure_event->width > 0) && (width != configure_event->width)) ||
((configure_event->height > 0) && (height != configure_event->height)) ) {
resize = true;
width = configure_event->width;
height = configure_event->height;
}
}
break;
// Close
case XCB_CLIENT_MESSAGE:
if( (*(xcb_client_message_event_t*)event).data.data32[0] == (*delete_reply).atom ) {
loop = false;
free( delete_reply );
}
break;
case XCB_KEY_PRESS:
loop = false;
break;
}
free( event );
} else {
// Draw
if( resize ) {
resize = false;
if( !tutorial.OnWindowSizeChanged() ) {
result = false;
break;
}
}
if( tutorial.ReadyToDraw() ) {
if( !tutorial.Draw() ) {
result = false;
break;
}
} else {
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
}
}
}
return result;
}
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
Window::~Window() {
XDestroyWindow( Parameters.DisplayPtr, Parameters.Handle );
XCloseDisplay( Parameters.DisplayPtr );
}
bool Window::Create( const char *title ) {
Parameters.DisplayPtr = XOpenDisplay( nullptr );
if( !Parameters.DisplayPtr ) {
return false;
}
int default_screen = DefaultScreen( Parameters.DisplayPtr );
Parameters.Handle = XCreateSimpleWindow(
Parameters.DisplayPtr,
DefaultRootWindow( Parameters.DisplayPtr ),
20,
20,
500,
500,
1,
BlackPixel( Parameters.DisplayPtr, default_screen ),
WhitePixel( Parameters.DisplayPtr, default_screen ) );
// XSync( Parameters.DisplayPtr, false );
XSetStandardProperties( Parameters.DisplayPtr, Parameters.Handle, title, title, None, nullptr, 0, nullptr );
XSelectInput( Parameters.DisplayPtr, Parameters.Handle, ExposureMask | KeyPressMask | StructureNotifyMask );
return true;
}
bool Window::RenderingLoop( TutorialBase &tutorial ) const {
// Prepare notification for window destruction
Atom delete_window_atom;
delete_window_atom = XInternAtom( Parameters.DisplayPtr, "WM_DELETE_WINDOW", false );
XSetWMProtocols( Parameters.DisplayPtr, Parameters.Handle, &delete_window_atom, 1);
// Display window
XClearWindow( Parameters.DisplayPtr, Parameters.Handle );
XMapWindow( Parameters.DisplayPtr, Parameters.Handle );
// Main message loop
XEvent event;
bool loop = true;
bool resize = false;
bool result = true;
while( loop ) {
if( XPending( Parameters.DisplayPtr ) ) {
XNextEvent( Parameters.DisplayPtr, &event );
switch( event.type ) {
//Process events
case ConfigureNotify: {
static int width = event.xconfigure.width;
static int height = event.xconfigure.height;
if( ((event.xconfigure.width > 0) && (event.xconfigure.width != width)) ||
((event.xconfigure.height > 0) && (event.xconfigure.width != height)) ) {
width = event.xconfigure.width;
height = event.xconfigure.height;
resize = true;
}
}
break;
case KeyPress:
loop = false;
break;
case DestroyNotify:
loop = false;
break;
case ClientMessage:
if( static_cast<unsigned int>(event.xclient.data.l[0]) == delete_window_atom ) {
loop = false;
}
break;
}
} else {
// Draw
if( resize ) {
resize = false;
if( !tutorial.OnWindowSizeChanged() ) {
result = false;
break;
}
}
if( tutorial.ReadyToDraw() ) {
if( !tutorial.Draw() ) {
result = false;
break;
}
} else {
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
}
}
}
return result;
}
#endif
} // namespace OS
} // namespace ApiWithoutSecrets

View File

@@ -1,140 +1,140 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(OPERATING_SYSTEM_HEADER)
#define OPERATING_SYSTEM_HEADER
#if defined(VK_USE_PLATFORM_WIN32_KHR)
#include <Windows.h>
#elif defined(VK_USE_PLATFORM_XCB_KHR)
#include <xcb/xcb.h>
#include <dlfcn.h>
#include <cstdlib>
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <dlfcn.h>
#include <cstdlib>
#endif
#include <cstring>
#include <iostream>
namespace ApiWithoutSecrets {
namespace OS {
// ************************************************************ //
// LibraryHandle //
// //
// Dynamic Library OS dependent type //
// ************************************************************ //
//
#if defined(VK_USE_PLATFORM_WIN32_KHR)
typedef HMODULE LibraryHandle;
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
typedef void* LibraryHandle;
#endif
// ************************************************************ //
// OnWindowSizeChanged //
// //
// Base class for handling window size changes //
// ************************************************************ //
class TutorialBase {
public:
virtual bool OnWindowSizeChanged() = 0;
virtual bool Draw() = 0;
virtual bool ReadyToDraw() const final {
return CanRender;
}
TutorialBase() :
CanRender( false ) {
}
virtual ~TutorialBase() {
}
protected:
bool CanRender;
};
// ************************************************************ //
// WindowParameters //
// //
// OS dependent window parameters //
// ************************************************************ //
struct WindowParameters {
#if defined(VK_USE_PLATFORM_WIN32_KHR)
HINSTANCE Instance;
HWND Handle;
WindowParameters() :
Instance(),
Handle() {
}
#elif defined(VK_USE_PLATFORM_XCB_KHR)
xcb_connection_t *Connection;
xcb_window_t Handle;
WindowParameters() :
Connection(),
Handle() {
}
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
Display *DisplayPtr;
Window Handle;
WindowParameters() :
DisplayPtr(),
Handle() {
}
#endif
};
// ************************************************************ //
// Window //
// //
// OS dependent window creation and destruction class //
// ************************************************************ //
class Window {
public:
Window();
~Window();
bool Create( const char *title );
bool RenderingLoop( TutorialBase &tutorial ) const;
WindowParameters GetParameters() const;
private:
WindowParameters Parameters;
};
} // namespace OS
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(OPERATING_SYSTEM_HEADER)
#define OPERATING_SYSTEM_HEADER
#if defined(VK_USE_PLATFORM_WIN32_KHR)
#include <Windows.h>
#elif defined(VK_USE_PLATFORM_XCB_KHR)
#include <xcb/xcb.h>
#include <dlfcn.h>
#include <cstdlib>
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <dlfcn.h>
#include <cstdlib>
#endif
#include <cstring>
#include <iostream>
namespace ApiWithoutSecrets {
namespace OS {
// ************************************************************ //
// LibraryHandle //
// //
// Dynamic Library OS dependent type //
// ************************************************************ //
//
#if defined(VK_USE_PLATFORM_WIN32_KHR)
typedef HMODULE LibraryHandle;
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
typedef void* LibraryHandle;
#endif
// ************************************************************ //
// OnWindowSizeChanged //
// //
// Base class for handling window size changes //
// ************************************************************ //
class TutorialBase {
public:
virtual bool OnWindowSizeChanged() = 0;
virtual bool Draw() = 0;
virtual bool ReadyToDraw() const final {
return CanRender;
}
TutorialBase() :
CanRender( false ) {
}
virtual ~TutorialBase() {
}
protected:
bool CanRender;
};
// ************************************************************ //
// WindowParameters //
// //
// OS dependent window parameters //
// ************************************************************ //
struct WindowParameters {
#if defined(VK_USE_PLATFORM_WIN32_KHR)
HINSTANCE Instance;
HWND Handle;
WindowParameters() :
Instance(),
Handle() {
}
#elif defined(VK_USE_PLATFORM_XCB_KHR)
xcb_connection_t *Connection;
xcb_window_t Handle;
WindowParameters() :
Connection(),
Handle() {
}
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
Display *DisplayPtr;
Window Handle;
WindowParameters() :
DisplayPtr(),
Handle() {
}
#endif
};
// ************************************************************ //
// Window //
// //
// OS dependent window creation and destruction class //
// ************************************************************ //
class Window {
public:
Window();
~Window();
bool Create( const char *title );
bool RenderingLoop( TutorialBase &tutorial ) const;
WindowParameters GetParameters() const;
private:
WindowParameters Parameters;
};
} // namespace OS
} // namespace ApiWithoutSecrets
#endif // OPERATING_SYSTEM_HEADER

View File

@@ -1,158 +1,158 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include <cmath>
#include <fstream>
#include <iostream>
#include "Tools.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
namespace ApiWithoutSecrets {
namespace Tools {
// ************************************************************ //
// GetBinaryFileContents //
// //
// Function reading binary contents of a file //
// ************************************************************ //
std::vector<char> GetBinaryFileContents( std::string const &filename ) {
std::ifstream file( filename, std::ios::binary );
if( file.fail() ) {
std::cout << "Could not open \"" << filename << "\" file!" << std::endl;
return std::vector<char>();
}
std::streampos begin, end;
begin = file.tellg();
file.seekg( 0, std::ios::end );
end = file.tellg();
std::vector<char> result( static_cast<size_t>(end - begin) );
file.seekg( 0, std::ios::beg );
file.read( &result[0], end - begin );
file.close();
return result;
}
// ************************************************************ //
// GetImageData //
// //
// 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> file_data = Tools::GetBinaryFileContents( filename );
if( file_data.size() == 0 ) {
return std::vector<char>();
}
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 );
if( (image_data == nullptr) ||
(tmp_width <= 0) ||
(tmp_height <= 0) ||
(tmp_components <= 0) ) {
std::cout << "Could not read image data!" << std::endl;
return std::vector<char>();
}
int size = (tmp_width) * (tmp_height) * (requested_components <= 0 ? tmp_components : requested_components);
if( data_size ) {
*data_size = size;
}
if( width ) {
*width = tmp_width;
}
if( height ) {
*height = tmp_height;
}
if( components ) {
*components = tmp_components;
}
std::vector<char> output(size);
memcpy( &output[0], image_data, size );
stbi_image_free( image_data );
return output;
}
// ************************************************************ //
// GetPerspectiveProjectionMatrix //
// //
// 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 ) {
float f = 1.0f / std::tan( field_of_view * 0.5f * 0.01745329251994329576923690768489f );
return {
f / aspect_ratio,
0.0f,
0.0f,
0.0f,
0.0f,
f,
0.0f,
0.0f,
0.0f,
0.0f,
(near_clip + far_clip) / (near_clip - far_clip),
-1.0f,
0.0f,
0.0f,
(2.0f * near_clip * far_clip) / (near_clip - far_clip),
0.0f
};
}
// ************************************************************ //
// GetOrthographicsProjectionMatrix //
// //
// 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 ) {
return {
2.0f / (right_plane - left_plane),
0.0f,
0.0f,
0.0f,
0.0f,
2.0f / (bottom_plane - top_plane),
0.0f,
0.0f,
0.0f,
0.0f,
-2.0f / (far_plane - near_plane),
0.0f,
-(right_plane + left_plane) / (right_plane - left_plane),
-(bottom_plane + top_plane) / (bottom_plane - top_plane),
-(far_plane + near_plane) / (far_plane - near_plane),
1.0f
};
}
} // namespace Tools
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include <cmath>
#include <fstream>
#include <iostream>
#include "Tools.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
namespace ApiWithoutSecrets {
namespace Tools {
// ************************************************************ //
// GetBinaryFileContents //
// //
// Function reading binary contents of a file //
// ************************************************************ //
std::vector<char> GetBinaryFileContents( std::string const &filename ) {
std::ifstream file( filename, std::ios::binary );
if( file.fail() ) {
std::cout << "Could not open \"" << filename << "\" file!" << std::endl;
return std::vector<char>();
}
std::streampos begin, end;
begin = file.tellg();
file.seekg( 0, std::ios::end );
end = file.tellg();
std::vector<char> result( static_cast<size_t>(end - begin) );
file.seekg( 0, std::ios::beg );
file.read( &result[0], end - begin );
file.close();
return result;
}
// ************************************************************ //
// GetImageData //
// //
// 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> file_data = Tools::GetBinaryFileContents( filename );
if( file_data.size() == 0 ) {
return std::vector<char>();
}
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 );
if( (image_data == nullptr) ||
(tmp_width <= 0) ||
(tmp_height <= 0) ||
(tmp_components <= 0) ) {
std::cout << "Could not read image data!" << std::endl;
return std::vector<char>();
}
int size = (tmp_width) * (tmp_height) * (requested_components <= 0 ? tmp_components : requested_components);
if( data_size ) {
*data_size = size;
}
if( width ) {
*width = tmp_width;
}
if( height ) {
*height = tmp_height;
}
if( components ) {
*components = tmp_components;
}
std::vector<char> output(size);
memcpy( &output[0], image_data, size );
stbi_image_free( image_data );
return output;
}
// ************************************************************ //
// GetPerspectiveProjectionMatrix //
// //
// 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 ) {
float f = 1.0f / std::tan( field_of_view * 0.5f * 0.01745329251994329576923690768489f );
return {
f / aspect_ratio,
0.0f,
0.0f,
0.0f,
0.0f,
f,
0.0f,
0.0f,
0.0f,
0.0f,
(near_clip + far_clip) / (near_clip - far_clip),
-1.0f,
0.0f,
0.0f,
(2.0f * near_clip * far_clip) / (near_clip - far_clip),
0.0f
};
}
// ************************************************************ //
// GetOrthographicsProjectionMatrix //
// //
// 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 ) {
return {
2.0f / (right_plane - left_plane),
0.0f,
0.0f,
0.0f,
0.0f,
2.0f / (bottom_plane - top_plane),
0.0f,
0.0f,
0.0f,
0.0f,
-2.0f / (far_plane - near_plane),
0.0f,
-(right_plane + left_plane) / (right_plane - left_plane),
-(bottom_plane + top_plane) / (bottom_plane - top_plane),
-(far_plane + near_plane) / (far_plane - near_plane),
1.0f
};
}
} // namespace Tools
} // namespace ApiWithoutSecrets

View File

@@ -1,119 +1,119 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TOOLS_HEADER)
#define TOOLS_HEADER
#include <string>
#include <vector>
#include <array>
#include "vulkan.h"
namespace ApiWithoutSecrets {
namespace Tools {
// ************************************************************ //
// AutoDeleter //
// //
// Auto-deleter helper template class responsible for calling //
// provided function which deletes given object of type T //
// ************************************************************ //
template<class T, class F>
class AutoDeleter {
public:
AutoDeleter() :
Object( VK_NULL_HANDLE ),
Deleter( nullptr ),
Device( VK_NULL_HANDLE ) {
}
AutoDeleter( T object, F deleter, VkDevice device ) :
Object( object ),
Deleter( deleter ),
Device( device ) {
}
AutoDeleter( AutoDeleter&& other ) {
*this = std::move( other );
}
~AutoDeleter() {
if( (Object != VK_NULL_HANDLE) && (Deleter != nullptr) && (Device != VK_NULL_HANDLE) ) {
Deleter( Device, Object, nullptr );
}
}
AutoDeleter& operator=(AutoDeleter&& other) {
if( this != &other ) {
Object = other.Object;
Deleter = other.Deleter;
Device = other.Device;
other.Object = VK_NULL_HANDLE;
}
return *this;
}
T Get() {
return Object;
}
bool operator !() const {
return Object == VK_NULL_HANDLE;
}
private:
AutoDeleter( const AutoDeleter& );
AutoDeleter& operator=( const AutoDeleter& );
T Object;
F Deleter;
VkDevice Device;
};
// ************************************************************ //
// GetBinaryFileContents //
// //
// Function reading binary contents of a file //
// ************************************************************ //
std::vector<char> GetBinaryFileContents( std::string const &filename );
// ************************************************************ //
// GetImageData //
// //
// 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 );
// ************************************************************ //
// GetPerspectiveProjectionMatrix //
// //
// 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 );
// ************************************************************ //
// GetOrthographicsProjectionMatrix //
// //
// 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 );
} // namespace Tools
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TOOLS_HEADER)
#define TOOLS_HEADER
#include <string>
#include <vector>
#include <array>
#include "vulkan.h"
namespace ApiWithoutSecrets {
namespace Tools {
// ************************************************************ //
// AutoDeleter //
// //
// Auto-deleter helper template class responsible for calling //
// provided function which deletes given object of type T //
// ************************************************************ //
template<class T, class F>
class AutoDeleter {
public:
AutoDeleter() :
Object( VK_NULL_HANDLE ),
Deleter( nullptr ),
Device( VK_NULL_HANDLE ) {
}
AutoDeleter( T object, F deleter, VkDevice device ) :
Object( object ),
Deleter( deleter ),
Device( device ) {
}
AutoDeleter( AutoDeleter&& other ) {
*this = std::move( other );
}
~AutoDeleter() {
if( (Object != VK_NULL_HANDLE) && (Deleter != nullptr) && (Device != VK_NULL_HANDLE) ) {
Deleter( Device, Object, nullptr );
}
}
AutoDeleter& operator=(AutoDeleter&& other) {
if( this != &other ) {
Object = other.Object;
Deleter = other.Deleter;
Device = other.Device;
other.Object = VK_NULL_HANDLE;
}
return *this;
}
T Get() {
return Object;
}
bool operator !() const {
return Object == VK_NULL_HANDLE;
}
private:
AutoDeleter( const AutoDeleter& );
AutoDeleter& operator=( const AutoDeleter& );
T Object;
F Deleter;
VkDevice Device;
};
// ************************************************************ //
// GetBinaryFileContents //
// //
// Function reading binary contents of a file //
// ************************************************************ //
std::vector<char> GetBinaryFileContents( std::string const &filename );
// ************************************************************ //
// GetImageData //
// //
// 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 );
// ************************************************************ //
// GetPerspectiveProjectionMatrix //
// //
// 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 );
// ************************************************************ //
// GetOrthographicsProjectionMatrix //
// //
// 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 );
} // namespace Tools
} // namespace ApiWithoutSecrets
#endif // TOOLS_HEADER

File diff suppressed because it is too large Load Diff

View File

@@ -1,157 +1,157 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(VULKAN_COMMON_HEADER)
#define VULKAN_COMMON_HEADER
#include <vector>
#include "vulkan.h"
#include "OperatingSystem.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// QueueParameters //
// //
// Vulkan Queue's parameters container class //
// ************************************************************ //
struct QueueParameters {
VkQueue Handle;
uint32_t FamilyIndex;
QueueParameters() :
Handle( VK_NULL_HANDLE ),
FamilyIndex( 0 ) {
}
};
// ************************************************************ //
// ImageParameters //
// //
// Vulkan Image's parameters container class //
// ************************************************************ //
struct ImageParameters {
VkImage Handle;
VkImageView View;
VkSampler Sampler;
VkDeviceMemory Memory;
ImageParameters() :
Handle( VK_NULL_HANDLE ),
View( VK_NULL_HANDLE ),
Sampler( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// SwapChainParameters //
// //
// Vulkan SwapChain's parameters container class //
// ************************************************************ //
struct SwapChainParameters {
VkSwapchainKHR Handle;
VkFormat Format;
std::vector<ImageParameters> Images;
VkExtent2D Extent;
SwapChainParameters() :
Handle( VK_NULL_HANDLE ),
Format( VK_FORMAT_UNDEFINED ),
Images(),
Extent() {
}
};
// ************************************************************ //
// VulkanCommonParameters //
// //
// General Vulkan parameters' container class //
// ************************************************************ //
struct VulkanCommonParameters {
VkInstance Instance;
VkPhysicalDevice PhysicalDevice;
VkDevice Device;
QueueParameters GraphicsQueue;
QueueParameters PresentQueue;
VkSurfaceKHR PresentationSurface;
SwapChainParameters SwapChain;
VulkanCommonParameters() :
Instance( VK_NULL_HANDLE ),
PhysicalDevice( VK_NULL_HANDLE ),
Device( VK_NULL_HANDLE ),
GraphicsQueue(),
PresentQueue(),
PresentationSurface( VK_NULL_HANDLE ),
SwapChain() {
}
};
// ************************************************************ //
// VulkanCommon //
// //
// Base class for Vulkan more advanced tutorial classes //
// ************************************************************ //
class VulkanCommon : public OS::TutorialBase {
public:
VulkanCommon();
virtual ~VulkanCommon();
bool PrepareVulkan( OS::WindowParameters parameters );
virtual bool OnWindowSizeChanged() final override;
protected:
VkPhysicalDevice GetPhysicalDevice() const;
VkDevice GetDevice() const;
const QueueParameters GetGraphicsQueue() const;
const QueueParameters GetPresentQueue() const;
const SwapChainParameters GetSwapChain() const;
private:
OS::LibraryHandle VulkanLibrary;
OS::WindowParameters Window;
VulkanCommonParameters Vulkan;
bool LoadVulkanLibrary();
bool LoadExportedEntryPoints();
bool LoadGlobalLevelEntryPoints();
bool CreateInstance();
bool LoadInstanceLevelEntryPoints();
bool CreatePresentationSurface();
bool CreateDevice();
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
bool LoadDeviceLevelEntryPoints();
bool GetDeviceQueue();
bool CreateSwapChain();
bool CreateSwapChainImageViews();
virtual bool ChildOnWindowSizeChanged() = 0;
virtual void ChildClear() = 0;
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
};
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(VULKAN_COMMON_HEADER)
#define VULKAN_COMMON_HEADER
#include <vector>
#include "vulkan.h"
#include "OperatingSystem.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// QueueParameters //
// //
// Vulkan Queue's parameters container class //
// ************************************************************ //
struct QueueParameters {
VkQueue Handle;
uint32_t FamilyIndex;
QueueParameters() :
Handle( VK_NULL_HANDLE ),
FamilyIndex( 0 ) {
}
};
// ************************************************************ //
// ImageParameters //
// //
// Vulkan Image's parameters container class //
// ************************************************************ //
struct ImageParameters {
VkImage Handle;
VkImageView View;
VkSampler Sampler;
VkDeviceMemory Memory;
ImageParameters() :
Handle( VK_NULL_HANDLE ),
View( VK_NULL_HANDLE ),
Sampler( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// SwapChainParameters //
// //
// Vulkan SwapChain's parameters container class //
// ************************************************************ //
struct SwapChainParameters {
VkSwapchainKHR Handle;
VkFormat Format;
std::vector<ImageParameters> Images;
VkExtent2D Extent;
SwapChainParameters() :
Handle( VK_NULL_HANDLE ),
Format( VK_FORMAT_UNDEFINED ),
Images(),
Extent() {
}
};
// ************************************************************ //
// VulkanCommonParameters //
// //
// General Vulkan parameters' container class //
// ************************************************************ //
struct VulkanCommonParameters {
VkInstance Instance;
VkPhysicalDevice PhysicalDevice;
VkDevice Device;
QueueParameters GraphicsQueue;
QueueParameters PresentQueue;
VkSurfaceKHR PresentationSurface;
SwapChainParameters SwapChain;
VulkanCommonParameters() :
Instance( VK_NULL_HANDLE ),
PhysicalDevice( VK_NULL_HANDLE ),
Device( VK_NULL_HANDLE ),
GraphicsQueue(),
PresentQueue(),
PresentationSurface( VK_NULL_HANDLE ),
SwapChain() {
}
};
// ************************************************************ //
// VulkanCommon //
// //
// Base class for Vulkan more advanced tutorial classes //
// ************************************************************ //
class VulkanCommon : public OS::TutorialBase {
public:
VulkanCommon();
virtual ~VulkanCommon();
bool PrepareVulkan( OS::WindowParameters parameters );
virtual bool OnWindowSizeChanged() final override;
protected:
VkPhysicalDevice GetPhysicalDevice() const;
VkDevice GetDevice() const;
const QueueParameters GetGraphicsQueue() const;
const QueueParameters GetPresentQueue() const;
const SwapChainParameters GetSwapChain() const;
private:
OS::LibraryHandle VulkanLibrary;
OS::WindowParameters Window;
VulkanCommonParameters Vulkan;
bool LoadVulkanLibrary();
bool LoadExportedEntryPoints();
bool LoadGlobalLevelEntryPoints();
bool CreateInstance();
bool LoadInstanceLevelEntryPoints();
bool CreatePresentationSurface();
bool CreateDevice();
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
bool LoadDeviceLevelEntryPoints();
bool GetDeviceQueue();
bool CreateSwapChain();
bool CreateSwapChainImageViews();
virtual bool ChildOnWindowSizeChanged() = 0;
virtual void ChildClear() = 0;
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
};
} // namespace ApiWithoutSecrets
#endif // VULKAN_COMMON_HEADER

View File

@@ -1,28 +1,28 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "vulkan.h"
namespace ApiWithoutSecrets {
#define VK_EXPORTED_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_DEVICE_LEVEL_FUNCTION( fun ) PFN_##fun fun;
#include "ListOfFunctions.inl"
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "vulkan.h"
namespace ApiWithoutSecrets {
#define VK_EXPORTED_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_DEVICE_LEVEL_FUNCTION( fun ) PFN_##fun fun;
#include "ListOfFunctions.inl"
} // namespace ApiWithoutSecrets

View File

@@ -1,33 +1,33 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(VULKAN_FUNCTIONS_HEADER)
#define VULKAN_FUNCTIONS_HEADER
#include "vulkan.h"
namespace ApiWithoutSecrets {
#define VK_EXPORTED_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_DEVICE_LEVEL_FUNCTION( fun ) extern PFN_##fun fun;
#include "ListOfFunctions.inl"
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(VULKAN_FUNCTIONS_HEADER)
#define VULKAN_FUNCTIONS_HEADER
#include "vulkan.h"
namespace ApiWithoutSecrets {
#define VK_EXPORTED_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_DEVICE_LEVEL_FUNCTION( fun ) extern PFN_##fun fun;
#include "ListOfFunctions.inl"
} // namespace ApiWithoutSecrets
#endif

View File

@@ -1,284 +1,284 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include <vector>
#include "Tutorial01.h"
#include "VulkanFunctions.h"
namespace ApiWithoutSecrets {
Tutorial01::Tutorial01() :
VulkanLibrary(),
Vulkan() {
}
bool Tutorial01::OnWindowSizeChanged() {
return true;
}
bool Tutorial01::Draw() {
return true;
}
bool Tutorial01::PrepareVulkan() {
if( !LoadVulkanLibrary() ) {
return false;
}
if( !LoadExportedEntryPoints() ) {
return false;
}
if( !LoadGlobalLevelEntryPoints() ) {
return false;
}
if( !CreateInstance() ) {
return false;
}
if( !LoadInstanceLevelEntryPoints() ) {
return false;
}
if( !CreateDevice() ) {
return false;
}
if( !LoadDeviceLevelEntryPoints() ) {
return false;
}
if( !GetDeviceQueue() ) {
return false;
}
return true;
}
bool Tutorial01::LoadVulkanLibrary() {
#if defined(VK_USE_PLATFORM_WIN32_KHR)
VulkanLibrary = LoadLibrary( "vulkan-1.dll" );
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
VulkanLibrary = dlopen( "libvulkan.so.1", RTLD_NOW );
#endif
if( VulkanLibrary == nullptr ) {
std::cout << "Could not load Vulkan library!" << std::endl;
return false;
}
return true;
}
bool Tutorial01::LoadExportedEntryPoints() {
#if defined(VK_USE_PLATFORM_WIN32_KHR)
#define LoadProcAddress GetProcAddress
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
#define LoadProcAddress dlsym
#endif
#define VK_EXPORTED_FUNCTION( fun ) \
if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \
std::cout << "Could not load exported function: " << #fun << "!" << std::endl; \
return false; \
}
#include "ListOfFunctions.inl"
return true;
}
bool Tutorial01::LoadGlobalLevelEntryPoints() {
#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \
if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \
std::cout << "Could not load global level function: " << #fun << "!" << std::endl; \
return false; \
}
#include "ListOfFunctions.inl"
return true;
}
bool Tutorial01::CreateInstance() {
VkApplicationInfo application_info = {
VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType
nullptr, // const void *pNext
"API without Secrets: Introduction to Vulkan", // const char *pApplicationName
VK_MAKE_VERSION( 1, 0, 0 ), // uint32_t applicationVersion
"Vulkan Tutorial by Intel", // const char *pEngineName
VK_MAKE_VERSION( 1, 0, 0 ), // uint32_t engineVersion
VK_MAKE_VERSION( 1, 0, 0 ) // uint32_t apiVersion
};
VkInstanceCreateInfo instance_create_info = {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType
nullptr, // const void* pNext
0, // VkInstanceCreateFlags flags
&application_info, // const VkApplicationInfo *pApplicationInfo
0, // uint32_t enabledLayerCount
nullptr, // const char * const *ppEnabledLayerNames
0, // uint32_t enabledExtensionCount
nullptr // const char * const *ppEnabledExtensionNames
};
if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) {
std::cout << "Could not create Vulkan instance!" << std::endl;
return false;
}
return true;
}
bool Tutorial01::LoadInstanceLevelEntryPoints() {
#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \
if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \
std::cout << "Could not load instance level function: " << #fun << "!" << std::endl; \
return false; \
}
#include "ListOfFunctions.inl"
return true;
}
bool Tutorial01::CreateDevice() {
uint32_t num_devices = 0;
if( (vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, nullptr ) != VK_SUCCESS) ||
(num_devices == 0) ) {
std::cout << "Error occurred during physical devices enumeration!" << std::endl;
return false;
}
std::vector<VkPhysicalDevice> physical_devices( num_devices );
if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) {
std::cout << "Error occurred during physical devices enumeration!" << std::endl;
return false;
}
VkPhysicalDevice selected_physical_device = VK_NULL_HANDLE;
uint32_t selected_queue_family_index = UINT32_MAX;
for( uint32_t i = 0; i < num_devices; ++i ) {
if( CheckPhysicalDeviceProperties( physical_devices[i], selected_queue_family_index ) ) {
selected_physical_device = physical_devices[i];
break;
}
}
if( selected_physical_device == VK_NULL_HANDLE ) {
std::cout << "Could not select physical device based on the chosen properties!" << std::endl;
return false;
}
std::vector<float> queue_priorities = { 1.0f };
VkDeviceQueueCreateInfo queue_create_info = {
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType
nullptr, // const void *pNext
0, // VkDeviceQueueCreateFlags flags
selected_queue_family_index, // uint32_t queueFamilyIndex
static_cast<uint32_t>(queue_priorities.size()), // uint32_t queueCount
&queue_priorities[0] // const float *pQueuePriorities
};
VkDeviceCreateInfo device_create_info = {
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // VkStructureType sType
nullptr, // const void *pNext
0, // VkDeviceCreateFlags flags
1, // uint32_t queueCreateInfoCount
&queue_create_info, // const VkDeviceQueueCreateInfo *pQueueCreateInfos
0, // uint32_t enabledLayerCount
nullptr, // const char * const *ppEnabledLayerNames
0, // uint32_t enabledExtensionCount
nullptr, // const char * const *ppEnabledExtensionNames
nullptr // const VkPhysicalDeviceFeatures *pEnabledFeatures
};
if( vkCreateDevice( selected_physical_device, &device_create_info, nullptr, &Vulkan.Device ) != VK_SUCCESS ) {
std::cout << "Could not create Vulkan device!" << std::endl;
return false;
}
Vulkan.QueueFamilyIndex = selected_queue_family_index;
return true;
}
bool Tutorial01::CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &queue_family_index ) {
VkPhysicalDeviceProperties device_properties;
VkPhysicalDeviceFeatures device_features;
vkGetPhysicalDeviceProperties( physical_device, &device_properties );
vkGetPhysicalDeviceFeatures( physical_device, &device_features );
uint32_t major_version = VK_VERSION_MAJOR( device_properties.apiVersion );
uint32_t minor_version = VK_VERSION_MINOR( device_properties.apiVersion );
uint32_t patch_version = VK_VERSION_PATCH( device_properties.apiVersion );
if( (major_version < 1) ||
(device_properties.limits.maxImageDimension2D < 4096) ) {
std::cout << "Physical device " << physical_device << " doesn't support required parameters!" << std::endl;
return false;
}
uint32_t queue_families_count = 0;
vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, nullptr );
if( queue_families_count == 0 ) {
std::cout << "Physical device " << physical_device << " doesn't have any queue families!" << std::endl;
return false;
}
std::vector<VkQueueFamilyProperties> queue_family_properties( queue_families_count );
vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, &queue_family_properties[0] );
for( uint32_t i = 0; i < queue_families_count; ++i ) {
if( (queue_family_properties[i].queueCount > 0) &&
(queue_family_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) ) {
queue_family_index = i;
std::cout << "Selected device: " << device_properties.deviceName << std::endl;
return true;
}
}
std::cout << "Could not find queue family with required properties on physical device " << physical_device << "!" << std::endl;
return false;
}
bool Tutorial01::LoadDeviceLevelEntryPoints() {
#define VK_DEVICE_LEVEL_FUNCTION( fun ) \
if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \
std::cout << "Could not load device level function: " << #fun << "!" << std::endl; \
return false; \
}
#include "ListOfFunctions.inl"
return true;
}
bool Tutorial01::GetDeviceQueue() {
vkGetDeviceQueue( Vulkan.Device, Vulkan.QueueFamilyIndex, 0, &Vulkan.Queue );
return true;
}
Tutorial01::~Tutorial01() {
if( Vulkan.Device != VK_NULL_HANDLE ) {
vkDeviceWaitIdle( Vulkan.Device );
vkDestroyDevice( Vulkan.Device, nullptr );
}
if( Vulkan.Instance != VK_NULL_HANDLE ) {
vkDestroyInstance( Vulkan.Instance, nullptr );
}
if( VulkanLibrary ) {
#if defined(VK_USE_PLATFORM_WIN32_KHR)
FreeLibrary( VulkanLibrary );
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
dlclose( VulkanLibrary );
#endif
}
}
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include <vector>
#include "Tutorial01.h"
#include "VulkanFunctions.h"
namespace ApiWithoutSecrets {
Tutorial01::Tutorial01() :
VulkanLibrary(),
Vulkan() {
}
bool Tutorial01::OnWindowSizeChanged() {
return true;
}
bool Tutorial01::Draw() {
return true;
}
bool Tutorial01::PrepareVulkan() {
if( !LoadVulkanLibrary() ) {
return false;
}
if( !LoadExportedEntryPoints() ) {
return false;
}
if( !LoadGlobalLevelEntryPoints() ) {
return false;
}
if( !CreateInstance() ) {
return false;
}
if( !LoadInstanceLevelEntryPoints() ) {
return false;
}
if( !CreateDevice() ) {
return false;
}
if( !LoadDeviceLevelEntryPoints() ) {
return false;
}
if( !GetDeviceQueue() ) {
return false;
}
return true;
}
bool Tutorial01::LoadVulkanLibrary() {
#if defined(VK_USE_PLATFORM_WIN32_KHR)
VulkanLibrary = LoadLibrary( "vulkan-1.dll" );
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
VulkanLibrary = dlopen( "libvulkan.so.1", RTLD_NOW );
#endif
if( VulkanLibrary == nullptr ) {
std::cout << "Could not load Vulkan library!" << std::endl;
return false;
}
return true;
}
bool Tutorial01::LoadExportedEntryPoints() {
#if defined(VK_USE_PLATFORM_WIN32_KHR)
#define LoadProcAddress GetProcAddress
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
#define LoadProcAddress dlsym
#endif
#define VK_EXPORTED_FUNCTION( fun ) \
if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \
std::cout << "Could not load exported function: " << #fun << "!" << std::endl; \
return false; \
}
#include "ListOfFunctions.inl"
return true;
}
bool Tutorial01::LoadGlobalLevelEntryPoints() {
#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \
if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \
std::cout << "Could not load global level function: " << #fun << "!" << std::endl; \
return false; \
}
#include "ListOfFunctions.inl"
return true;
}
bool Tutorial01::CreateInstance() {
VkApplicationInfo application_info = {
VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType
nullptr, // const void *pNext
"API without Secrets: Introduction to Vulkan", // const char *pApplicationName
VK_MAKE_VERSION( 1, 0, 0 ), // uint32_t applicationVersion
"Vulkan Tutorial by Intel", // const char *pEngineName
VK_MAKE_VERSION( 1, 0, 0 ), // uint32_t engineVersion
VK_MAKE_VERSION( 1, 0, 0 ) // uint32_t apiVersion
};
VkInstanceCreateInfo instance_create_info = {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType
nullptr, // const void* pNext
0, // VkInstanceCreateFlags flags
&application_info, // const VkApplicationInfo *pApplicationInfo
0, // uint32_t enabledLayerCount
nullptr, // const char * const *ppEnabledLayerNames
0, // uint32_t enabledExtensionCount
nullptr // const char * const *ppEnabledExtensionNames
};
if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) {
std::cout << "Could not create Vulkan instance!" << std::endl;
return false;
}
return true;
}
bool Tutorial01::LoadInstanceLevelEntryPoints() {
#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \
if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \
std::cout << "Could not load instance level function: " << #fun << "!" << std::endl; \
return false; \
}
#include "ListOfFunctions.inl"
return true;
}
bool Tutorial01::CreateDevice() {
uint32_t num_devices = 0;
if( (vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, nullptr ) != VK_SUCCESS) ||
(num_devices == 0) ) {
std::cout << "Error occurred during physical devices enumeration!" << std::endl;
return false;
}
std::vector<VkPhysicalDevice> physical_devices( num_devices );
if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) {
std::cout << "Error occurred during physical devices enumeration!" << std::endl;
return false;
}
VkPhysicalDevice selected_physical_device = VK_NULL_HANDLE;
uint32_t selected_queue_family_index = UINT32_MAX;
for( uint32_t i = 0; i < num_devices; ++i ) {
if( CheckPhysicalDeviceProperties( physical_devices[i], selected_queue_family_index ) ) {
selected_physical_device = physical_devices[i];
break;
}
}
if( selected_physical_device == VK_NULL_HANDLE ) {
std::cout << "Could not select physical device based on the chosen properties!" << std::endl;
return false;
}
std::vector<float> queue_priorities = { 1.0f };
VkDeviceQueueCreateInfo queue_create_info = {
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType
nullptr, // const void *pNext
0, // VkDeviceQueueCreateFlags flags
selected_queue_family_index, // uint32_t queueFamilyIndex
static_cast<uint32_t>(queue_priorities.size()), // uint32_t queueCount
&queue_priorities[0] // const float *pQueuePriorities
};
VkDeviceCreateInfo device_create_info = {
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // VkStructureType sType
nullptr, // const void *pNext
0, // VkDeviceCreateFlags flags
1, // uint32_t queueCreateInfoCount
&queue_create_info, // const VkDeviceQueueCreateInfo *pQueueCreateInfos
0, // uint32_t enabledLayerCount
nullptr, // const char * const *ppEnabledLayerNames
0, // uint32_t enabledExtensionCount
nullptr, // const char * const *ppEnabledExtensionNames
nullptr // const VkPhysicalDeviceFeatures *pEnabledFeatures
};
if( vkCreateDevice( selected_physical_device, &device_create_info, nullptr, &Vulkan.Device ) != VK_SUCCESS ) {
std::cout << "Could not create Vulkan device!" << std::endl;
return false;
}
Vulkan.QueueFamilyIndex = selected_queue_family_index;
return true;
}
bool Tutorial01::CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &queue_family_index ) {
VkPhysicalDeviceProperties device_properties;
VkPhysicalDeviceFeatures device_features;
vkGetPhysicalDeviceProperties( physical_device, &device_properties );
vkGetPhysicalDeviceFeatures( physical_device, &device_features );
uint32_t major_version = VK_VERSION_MAJOR( device_properties.apiVersion );
uint32_t minor_version = VK_VERSION_MINOR( device_properties.apiVersion );
uint32_t patch_version = VK_VERSION_PATCH( device_properties.apiVersion );
if( (major_version < 1) ||
(device_properties.limits.maxImageDimension2D < 4096) ) {
std::cout << "Physical device " << physical_device << " doesn't support required parameters!" << std::endl;
return false;
}
uint32_t queue_families_count = 0;
vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, nullptr );
if( queue_families_count == 0 ) {
std::cout << "Physical device " << physical_device << " doesn't have any queue families!" << std::endl;
return false;
}
std::vector<VkQueueFamilyProperties> queue_family_properties( queue_families_count );
vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, &queue_family_properties[0] );
for( uint32_t i = 0; i < queue_families_count; ++i ) {
if( (queue_family_properties[i].queueCount > 0) &&
(queue_family_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) ) {
queue_family_index = i;
std::cout << "Selected device: " << device_properties.deviceName << std::endl;
return true;
}
}
std::cout << "Could not find queue family with required properties on physical device " << physical_device << "!" << std::endl;
return false;
}
bool Tutorial01::LoadDeviceLevelEntryPoints() {
#define VK_DEVICE_LEVEL_FUNCTION( fun ) \
if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \
std::cout << "Could not load device level function: " << #fun << "!" << std::endl; \
return false; \
}
#include "ListOfFunctions.inl"
return true;
}
bool Tutorial01::GetDeviceQueue() {
vkGetDeviceQueue( Vulkan.Device, Vulkan.QueueFamilyIndex, 0, &Vulkan.Queue );
return true;
}
Tutorial01::~Tutorial01() {
if( Vulkan.Device != VK_NULL_HANDLE ) {
vkDeviceWaitIdle( Vulkan.Device );
vkDestroyDevice( Vulkan.Device, nullptr );
}
if( Vulkan.Instance != VK_NULL_HANDLE ) {
vkDestroyInstance( Vulkan.Instance, nullptr );
}
if( VulkanLibrary ) {
#if defined(VK_USE_PLATFORM_WIN32_KHR)
FreeLibrary( VulkanLibrary );
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
dlclose( VulkanLibrary );
#endif
}
}
} // namespace ApiWithoutSecrets

View File

@@ -1,76 +1,76 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_01_HEADER)
#define TUTORIAL_01_HEADER
#include "vulkan.h"
#include "OperatingSystem.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// VulkanTutorial01Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial01Parameters {
VkInstance Instance;
VkDevice Device;
uint32_t QueueFamilyIndex;
VkQueue Queue;
VulkanTutorial01Parameters() :
Instance( VK_NULL_HANDLE ),
Device( VK_NULL_HANDLE ),
QueueFamilyIndex( 0 ),
Queue( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// Tutorial01 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial01 : public OS::TutorialBase {
public:
Tutorial01();
~Tutorial01();
bool OnWindowSizeChanged() override;
bool Draw() override;
bool PrepareVulkan();
private:
OS::LibraryHandle VulkanLibrary;
VulkanTutorial01Parameters Vulkan;
bool LoadVulkanLibrary();
bool LoadExportedEntryPoints();
bool LoadGlobalLevelEntryPoints();
bool CreateInstance();
bool LoadInstanceLevelEntryPoints();
bool CreateDevice();
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &queue_family_index );
bool LoadDeviceLevelEntryPoints();
bool GetDeviceQueue();
};
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_01_HEADER)
#define TUTORIAL_01_HEADER
#include "vulkan.h"
#include "OperatingSystem.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// VulkanTutorial01Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial01Parameters {
VkInstance Instance;
VkDevice Device;
uint32_t QueueFamilyIndex;
VkQueue Queue;
VulkanTutorial01Parameters() :
Instance( VK_NULL_HANDLE ),
Device( VK_NULL_HANDLE ),
QueueFamilyIndex( 0 ),
Queue( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// Tutorial01 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial01 : public OS::TutorialBase {
public:
Tutorial01();
~Tutorial01();
bool OnWindowSizeChanged() override;
bool Draw() override;
bool PrepareVulkan();
private:
OS::LibraryHandle VulkanLibrary;
VulkanTutorial01Parameters Vulkan;
bool LoadVulkanLibrary();
bool LoadExportedEntryPoints();
bool LoadGlobalLevelEntryPoints();
bool CreateInstance();
bool LoadInstanceLevelEntryPoints();
bool CreateDevice();
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &queue_family_index );
bool LoadDeviceLevelEntryPoints();
bool GetDeviceQueue();
};
} // namespace ApiWithoutSecrets
#endif // TUTORIAL_01_HEADER

View File

@@ -1,39 +1,39 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial01.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial01 tutorial01;
// Window creation
if( !window.Create( "01 - The Beginning" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial01.PrepareVulkan() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial01 ) ) {
return -1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial01.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial01 tutorial01;
// Window creation
if( !window.Create( "01 - The Beginning" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial01.PrepareVulkan() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial01 ) ) {
return -1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,107 +1,107 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_02_HEADER)
#define TUTORIAL_02_HEADER
#include <vector>
#include "vulkan.h"
#include "OperatingSystem.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// VulkanTutorial02Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial02Parameters {
VkInstance Instance;
VkPhysicalDevice PhysicalDevice;
VkDevice Device;
VkQueue GraphicsQueue;
VkQueue PresentQueue;
uint32_t GraphicsQueueFamilyIndex;
uint32_t PresentQueueFamilyIndex;
VkSurfaceKHR PresentationSurface;
VkSwapchainKHR SwapChain;
std::vector<VkCommandBuffer> PresentQueueCmdBuffers;
VkCommandPool PresentQueueCmdPool;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore RenderingFinishedSemaphore;
VulkanTutorial02Parameters() :
Instance( VK_NULL_HANDLE ),
PhysicalDevice( VK_NULL_HANDLE ),
Device( VK_NULL_HANDLE ),
GraphicsQueue( VK_NULL_HANDLE ),
PresentQueue( VK_NULL_HANDLE ),
GraphicsQueueFamilyIndex( 0 ),
PresentQueueFamilyIndex( 0 ),
PresentationSurface( VK_NULL_HANDLE ),
SwapChain( VK_NULL_HANDLE ),
PresentQueueCmdBuffers( 0 ),
PresentQueueCmdPool( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// Tutorial02 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial02 : public OS::TutorialBase {
public:
Tutorial02();
~Tutorial02();
bool PrepareVulkan( OS::WindowParameters parameters );
bool CreateSwapChain();
bool OnWindowSizeChanged() override;
bool CreateCommandBuffers();
bool Draw() override;
private:
OS::LibraryHandle VulkanLibrary;
OS::WindowParameters Window;
VulkanTutorial02Parameters Vulkan;
bool LoadVulkanLibrary();
bool LoadExportedEntryPoints();
bool LoadGlobalLevelEntryPoints();
bool CreateInstance();
bool LoadInstanceLevelEntryPoints();
bool CreatePresentationSurface();
bool CreateDevice();
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
bool LoadDeviceLevelEntryPoints();
bool GetDeviceQueue();
bool CreateSemaphores();
bool RecordCommandBuffers();
void Clear();
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
};
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_02_HEADER)
#define TUTORIAL_02_HEADER
#include <vector>
#include "vulkan.h"
#include "OperatingSystem.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// VulkanTutorial02Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial02Parameters {
VkInstance Instance;
VkPhysicalDevice PhysicalDevice;
VkDevice Device;
VkQueue GraphicsQueue;
VkQueue PresentQueue;
uint32_t GraphicsQueueFamilyIndex;
uint32_t PresentQueueFamilyIndex;
VkSurfaceKHR PresentationSurface;
VkSwapchainKHR SwapChain;
std::vector<VkCommandBuffer> PresentQueueCmdBuffers;
VkCommandPool PresentQueueCmdPool;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore RenderingFinishedSemaphore;
VulkanTutorial02Parameters() :
Instance( VK_NULL_HANDLE ),
PhysicalDevice( VK_NULL_HANDLE ),
Device( VK_NULL_HANDLE ),
GraphicsQueue( VK_NULL_HANDLE ),
PresentQueue( VK_NULL_HANDLE ),
GraphicsQueueFamilyIndex( 0 ),
PresentQueueFamilyIndex( 0 ),
PresentationSurface( VK_NULL_HANDLE ),
SwapChain( VK_NULL_HANDLE ),
PresentQueueCmdBuffers( 0 ),
PresentQueueCmdPool( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// Tutorial02 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial02 : public OS::TutorialBase {
public:
Tutorial02();
~Tutorial02();
bool PrepareVulkan( OS::WindowParameters parameters );
bool CreateSwapChain();
bool OnWindowSizeChanged() override;
bool CreateCommandBuffers();
bool Draw() override;
private:
OS::LibraryHandle VulkanLibrary;
OS::WindowParameters Window;
VulkanTutorial02Parameters Vulkan;
bool LoadVulkanLibrary();
bool LoadExportedEntryPoints();
bool LoadGlobalLevelEntryPoints();
bool CreateInstance();
bool LoadInstanceLevelEntryPoints();
bool CreatePresentationSurface();
bool CreateDevice();
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
bool LoadDeviceLevelEntryPoints();
bool GetDeviceQueue();
bool CreateSemaphores();
bool RecordCommandBuffers();
void Clear();
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
};
} // namespace ApiWithoutSecrets
#endif // TUTORIAL_02_HEADER

View File

@@ -1,45 +1,45 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial02.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial02 tutorial02;
// Window creation
if( !window.Create( "02 - Swap chain" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial02.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
if( !tutorial02.CreateSwapChain() ) {
return -1;
}
if( !tutorial02.CreateCommandBuffers() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial02 ) ) {
return -1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial02.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial02 tutorial02;
// Window creation
if( !window.Create( "02 - Swap chain" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial02.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
if( !tutorial02.CreateSwapChain() ) {
return -1;
}
if( !tutorial02.CreateCommandBuffers() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial02 ) ) {
return -1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,83 +1,83 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_03_HEADER)
#define TUTORIAL_03_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// VulkanTutorial03Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial03Parameters {
VkRenderPass RenderPass;
std::vector<VkFramebuffer> Framebuffers;
VkPipeline GraphicsPipeline;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore RenderingFinishedSemaphore;
VkCommandPool GraphicsCommandPool;
std::vector<VkCommandBuffer> GraphicsCommandBuffers;
VulkanTutorial03Parameters() :
RenderPass( VK_NULL_HANDLE ),
Framebuffers(),
GraphicsCommandPool( VK_NULL_HANDLE ),
GraphicsCommandBuffers(),
GraphicsPipeline( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
RenderingFinishedSemaphore( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// Tutorial03 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial03 : public VulkanCommon {
public:
Tutorial03();
~Tutorial03();
bool CreateRenderPass();
bool CreateFramebuffers();
bool CreatePipeline();
bool CreateSemaphores();
bool CreateCommandBuffers();
bool RecordCommandBuffers();
bool Draw() override;
private:
VulkanTutorial03Parameters Vulkan;
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
void ChildClear() override;
bool ChildOnWindowSizeChanged() override;
};
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_03_HEADER)
#define TUTORIAL_03_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// VulkanTutorial03Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial03Parameters {
VkRenderPass RenderPass;
std::vector<VkFramebuffer> Framebuffers;
VkPipeline GraphicsPipeline;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore RenderingFinishedSemaphore;
VkCommandPool GraphicsCommandPool;
std::vector<VkCommandBuffer> GraphicsCommandBuffers;
VulkanTutorial03Parameters() :
RenderPass( VK_NULL_HANDLE ),
Framebuffers(),
GraphicsCommandPool( VK_NULL_HANDLE ),
GraphicsCommandBuffers(),
GraphicsPipeline( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
RenderingFinishedSemaphore( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// Tutorial03 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial03 : public VulkanCommon {
public:
Tutorial03();
~Tutorial03();
bool CreateRenderPass();
bool CreateFramebuffers();
bool CreatePipeline();
bool CreateSemaphores();
bool CreateCommandBuffers();
bool RecordCommandBuffers();
bool Draw() override;
private:
VulkanTutorial03Parameters Vulkan;
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
void ChildClear() override;
bool ChildOnWindowSizeChanged() override;
};
} // namespace ApiWithoutSecrets
#endif // TUTORIAL_03_HEADER

View File

@@ -1,59 +1,59 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial03.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial03 tutorial03;
// Window creation
if( !window.Create( "03 - First Triangle" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial03.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 03
if( !tutorial03.CreateRenderPass() ) {
return -1;
}
if( !tutorial03.CreateFramebuffers() ) {
return -1;
}
if( !tutorial03.CreatePipeline() ) {
return -1;
}
if( !tutorial03.CreateSemaphores() ) {
return -1;
}
if( !tutorial03.CreateCommandBuffers() ) {
return -1;
}
if( !tutorial03.RecordCommandBuffers() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial03 ) ) {
return -1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial03.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial03 tutorial03;
// Window creation
if( !window.Create( "03 - First Triangle" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial03.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 03
if( !tutorial03.CreateRenderPass() ) {
return -1;
}
if( !tutorial03.CreateFramebuffers() ) {
return -1;
}
if( !tutorial03.CreatePipeline() ) {
return -1;
}
if( !tutorial03.CreateSemaphores() ) {
return -1;
}
if( !tutorial03.CreateCommandBuffers() ) {
return -1;
}
if( !tutorial03.RecordCommandBuffers() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial03 ) ) {
return -1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,133 +1,133 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_04_HEADER)
#define TUTORIAL_04_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float r, g, b, a;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial04Parameters {
VkRenderPass RenderPass;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial04Parameters() :
RenderPass( VK_NULL_HANDLE ),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial04 : public VulkanCommon {
public:
Tutorial04();
~Tutorial04();
bool CreateRenderPass();
bool CreatePipeline();
bool CreateVertexBuffer();
bool CreateRenderingResources();
bool Draw() override;
private:
VulkanTutorial04Parameters Vulkan;
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
bool AllocateBufferMemory( VkBuffer buffer, VkDeviceMemory *memory );
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
bool CreateCommandBuffers();
bool CreateSemaphores();
bool CreateFences();
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void ChildClear() override;
bool ChildOnWindowSizeChanged() override;
};
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_04_HEADER)
#define TUTORIAL_04_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float r, g, b, a;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial04Parameters {
VkRenderPass RenderPass;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial04Parameters() :
RenderPass( VK_NULL_HANDLE ),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial04 : public VulkanCommon {
public:
Tutorial04();
~Tutorial04();
bool CreateRenderPass();
bool CreatePipeline();
bool CreateVertexBuffer();
bool CreateRenderingResources();
bool Draw() override;
private:
VulkanTutorial04Parameters Vulkan;
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
bool AllocateBufferMemory( VkBuffer buffer, VkDeviceMemory *memory );
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
bool CreateCommandBuffers();
bool CreateSemaphores();
bool CreateFences();
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void ChildClear() override;
bool ChildOnWindowSizeChanged() override;
};
} // namespace ApiWithoutSecrets
#endif // TUTORIAL_04_HEADER

View File

@@ -1,53 +1,53 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial04.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial04 tutorial04;
// Window creation
if( !window.Create( "04 - Vertex Attributes" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial04.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 04
if( !tutorial04.CreateRenderPass() ) {
return -1;
}
if( !tutorial04.CreatePipeline() ) {
return -1;
}
if( !tutorial04.CreateVertexBuffer() ) {
return -1;
}
if( !tutorial04.CreateRenderingResources() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial04 ) ) {
return -1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial04.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial04 tutorial04;
// Window creation
if( !window.Create( "04 - Vertex Attributes" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial04.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 04
if( !tutorial04.CreateRenderPass() ) {
return -1;
}
if( !tutorial04.CreatePipeline() ) {
return -1;
}
if( !tutorial04.CreateVertexBuffer() ) {
return -1;
}
if( !tutorial04.CreateRenderingResources() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial04 ) ) {
return -1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,139 +1,139 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_05_HEADER)
#define TUTORIAL_05_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float r, g, b, a;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial05Parameters {
VkRenderPass RenderPass;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
BufferParameters StagingBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial05Parameters() :
RenderPass( VK_NULL_HANDLE ),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
StagingBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial05 : public VulkanCommon {
public:
Tutorial05();
~Tutorial05();
bool CreateRenderingResources();
bool CreateRenderPass();
bool CreatePipeline();
bool CreateVertexBuffer();
bool CreateStagingBuffer();
bool CopyVertexData();
bool Draw() override;
private:
VulkanTutorial05Parameters Vulkan;
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
bool CreateSemaphore( VkSemaphore *semaphore );
bool CreateFence( VkFenceCreateFlags flags, VkFence *fence );
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
bool CreateBuffer( VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer );
bool AllocateBufferMemory( VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
const std::vector<float>& GetVertexData() const;
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void DestroyBuffer( BufferParameters& buffer );
void ChildClear() override;
bool ChildOnWindowSizeChanged() override;
};
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_05_HEADER)
#define TUTORIAL_05_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float r, g, b, a;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial05Parameters {
VkRenderPass RenderPass;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
BufferParameters StagingBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial05Parameters() :
RenderPass( VK_NULL_HANDLE ),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
StagingBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial05 : public VulkanCommon {
public:
Tutorial05();
~Tutorial05();
bool CreateRenderingResources();
bool CreateRenderPass();
bool CreatePipeline();
bool CreateVertexBuffer();
bool CreateStagingBuffer();
bool CopyVertexData();
bool Draw() override;
private:
VulkanTutorial05Parameters Vulkan;
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
bool CreateSemaphore( VkSemaphore *semaphore );
bool CreateFence( VkFenceCreateFlags flags, VkFence *fence );
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
bool CreateBuffer( VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer );
bool AllocateBufferMemory( VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
const std::vector<float>& GetVertexData() const;
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void DestroyBuffer( BufferParameters& buffer );
void ChildClear() override;
bool ChildOnWindowSizeChanged() override;
};
} // namespace ApiWithoutSecrets
#endif // TUTORIAL_05_HEADER

View File

@@ -1,59 +1,59 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial05.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial05 tutorial05;
// Window creation
if( !window.Create( "05 - Staging Resources" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial05.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 05
if( !tutorial05.CreateRenderingResources() ) {
return -1;
}
if( !tutorial05.CreateRenderPass() ) {
return -1;
}
if( !tutorial05.CreatePipeline() ) {
return -1;
}
if( !tutorial05.CreateVertexBuffer() ) {
return -1;
}
if( !tutorial05.CreateStagingBuffer() ) {
return -1;
}
if( !tutorial05.CopyVertexData() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial05 ) ) {
return -1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial05.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial05 tutorial05;
// Window creation
if( !window.Create( "05 - Staging Resources" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial05.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 05
if( !tutorial05.CreateRenderingResources() ) {
return -1;
}
if( !tutorial05.CreateRenderPass() ) {
return -1;
}
if( !tutorial05.CreatePipeline() ) {
return -1;
}
if( !tutorial05.CreateVertexBuffer() ) {
return -1;
}
if( !tutorial05.CreateStagingBuffer() ) {
return -1;
}
if( !tutorial05.CopyVertexData() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial05 ) ) {
return -1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,173 +1,173 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_06_HEADER)
#define TUTORIAL_06_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// DescriptorParameters //
// //
// Container class for descriptor related resources //
// ************************************************************ //
struct DescriptorSetParameters {
VkDescriptorPool Pool;
VkDescriptorSetLayout Layout;
VkDescriptorSet Handle;
DescriptorSetParameters() :
Pool( VK_NULL_HANDLE ),
Layout( VK_NULL_HANDLE ),
Handle( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float u, v;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial06Parameters {
VkRenderPass RenderPass;
ImageParameters Image;
DescriptorSetParameters DescriptorSet;
VkPipelineLayout PipelineLayout;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
BufferParameters StagingBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial06Parameters() :
RenderPass( VK_NULL_HANDLE ),
Image(),
DescriptorSet(),
PipelineLayout(),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
StagingBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial06 : public VulkanCommon {
public:
Tutorial06();
~Tutorial06();
bool CreateRenderingResources();
bool CreateStagingBuffer();
bool CreateTexture();
bool CreateDescriptorSetLayout();
bool CreateDescriptorPool();
bool AllocateDescriptorSet();
bool UpdateDescriptorSet();
bool CreateRenderPass();
bool CreatePipelineLayout();
bool CreatePipeline();
bool CreateVertexBuffer();
bool Draw() override;
private:
VulkanTutorial06Parameters Vulkan;
bool CreateCommandBuffers();
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
bool CreateSemaphores();
bool CreateFences();
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
bool CreateImageView( ImageParameters &image_parameters );
bool CreateSampler( VkSampler *sampler );
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
const std::vector<float>& GetVertexData() const;
bool CopyVertexData();
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void DestroyBuffer( BufferParameters& buffer );
bool ChildOnWindowSizeChanged() override;
void ChildClear() override;
};
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_06_HEADER)
#define TUTORIAL_06_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// DescriptorParameters //
// //
// Container class for descriptor related resources //
// ************************************************************ //
struct DescriptorSetParameters {
VkDescriptorPool Pool;
VkDescriptorSetLayout Layout;
VkDescriptorSet Handle;
DescriptorSetParameters() :
Pool( VK_NULL_HANDLE ),
Layout( VK_NULL_HANDLE ),
Handle( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float u, v;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial06Parameters {
VkRenderPass RenderPass;
ImageParameters Image;
DescriptorSetParameters DescriptorSet;
VkPipelineLayout PipelineLayout;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
BufferParameters StagingBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial06Parameters() :
RenderPass( VK_NULL_HANDLE ),
Image(),
DescriptorSet(),
PipelineLayout(),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
StagingBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial06 : public VulkanCommon {
public:
Tutorial06();
~Tutorial06();
bool CreateRenderingResources();
bool CreateStagingBuffer();
bool CreateTexture();
bool CreateDescriptorSetLayout();
bool CreateDescriptorPool();
bool AllocateDescriptorSet();
bool UpdateDescriptorSet();
bool CreateRenderPass();
bool CreatePipelineLayout();
bool CreatePipeline();
bool CreateVertexBuffer();
bool Draw() override;
private:
VulkanTutorial06Parameters Vulkan;
bool CreateCommandBuffers();
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
bool CreateSemaphores();
bool CreateFences();
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
bool CreateImageView( ImageParameters &image_parameters );
bool CreateSampler( VkSampler *sampler );
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
const std::vector<float>& GetVertexData() const;
bool CopyVertexData();
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void DestroyBuffer( BufferParameters& buffer );
bool ChildOnWindowSizeChanged() override;
void ChildClear() override;
};
} // namespace ApiWithoutSecrets
#endif // TUTORIAL_06_HEADER

View File

@@ -1,74 +1,74 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial06.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial06 tutorial06;
// Window creation
if( !window.Create( "06 - Descriptor Sets" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial06.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 06
if( !tutorial06.CreateRenderingResources() ) {
return -1;
}
if( !tutorial06.CreateStagingBuffer() ) {
return -1;
}
if( !tutorial06.CreateTexture() ) {
return -1;
}
if( !tutorial06.CreateDescriptorSetLayout() ) {
return -1;
}
if( !tutorial06.CreateDescriptorPool() ) {
return -1;
}
if( !tutorial06.AllocateDescriptorSet() ) {
return -1;
}
if( !tutorial06.UpdateDescriptorSet() ) {
return -1;
}
if( !tutorial06.CreateRenderPass() ) {
return -1;
}
if( !tutorial06.CreatePipelineLayout() ) {
return -1;
}
if( !tutorial06.CreatePipeline() ) {
return -1;
}
if( !tutorial06.CreateVertexBuffer() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial06 ) ) {
return -1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial06.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial06 tutorial06;
// Window creation
if( !window.Create( "06 - Descriptor Sets" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial06.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 06
if( !tutorial06.CreateRenderingResources() ) {
return -1;
}
if( !tutorial06.CreateStagingBuffer() ) {
return -1;
}
if( !tutorial06.CreateTexture() ) {
return -1;
}
if( !tutorial06.CreateDescriptorSetLayout() ) {
return -1;
}
if( !tutorial06.CreateDescriptorPool() ) {
return -1;
}
if( !tutorial06.AllocateDescriptorSet() ) {
return -1;
}
if( !tutorial06.UpdateDescriptorSet() ) {
return -1;
}
if( !tutorial06.CreateRenderPass() ) {
return -1;
}
if( !tutorial06.CreatePipelineLayout() ) {
return -1;
}
if( !tutorial06.CreatePipeline() ) {
return -1;
}
if( !tutorial06.CreateVertexBuffer() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial06 ) ) {
return -1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,177 +1,177 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_07_HEADER)
#define TUTORIAL_07_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// DescriptorParameters //
// //
// Container class for descriptor related resources //
// ************************************************************ //
struct DescriptorSetParameters {
VkDescriptorPool Pool;
VkDescriptorSetLayout Layout;
VkDescriptorSet Handle;
DescriptorSetParameters() :
Pool( VK_NULL_HANDLE ),
Layout( VK_NULL_HANDLE ),
Handle( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float u, v;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial07Parameters {
VkRenderPass RenderPass;
ImageParameters Image;
BufferParameters UniformBuffer;
DescriptorSetParameters DescriptorSet;
VkPipelineLayout PipelineLayout;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
BufferParameters StagingBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial07Parameters() :
RenderPass( VK_NULL_HANDLE ),
Image(),
DescriptorSet(),
PipelineLayout(),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
StagingBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial07 : public VulkanCommon {
public:
Tutorial07();
~Tutorial07();
bool CreateRenderingResources();
bool CreateStagingBuffer();
bool CreateTexture();
bool CreateUniformBuffer();
bool CreateDescriptorSetLayout();
bool CreateDescriptorPool();
bool AllocateDescriptorSet();
bool UpdateDescriptorSet();
bool CreateRenderPass();
bool CreatePipelineLayout();
bool CreatePipeline();
bool CreateVertexBuffer();
bool Draw() override;
private:
VulkanTutorial07Parameters Vulkan;
bool CreateCommandBuffers();
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
bool CreateSemaphores();
bool CreateFences();
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
bool CreateImageView( ImageParameters &image_parameters );
bool CreateSampler( VkSampler *sampler );
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
const std::array<float, 16> GetUniformBufferData() const;
bool CopyUniformBufferData();
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
const std::vector<float>& GetVertexData() const;
bool CopyVertexData();
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void DestroyBuffer( BufferParameters& buffer );
bool ChildOnWindowSizeChanged() override;
void ChildClear() override;
};
} // namespace ApiWithoutSecrets
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#if !defined(TUTORIAL_07_HEADER)
#define TUTORIAL_07_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// DescriptorParameters //
// //
// Container class for descriptor related resources //
// ************************************************************ //
struct DescriptorSetParameters {
VkDescriptorPool Pool;
VkDescriptorSetLayout Layout;
VkDescriptorSet Handle;
DescriptorSetParameters() :
Pool( VK_NULL_HANDLE ),
Layout( VK_NULL_HANDLE ),
Handle( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float u, v;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial07Parameters {
VkRenderPass RenderPass;
ImageParameters Image;
BufferParameters UniformBuffer;
DescriptorSetParameters DescriptorSet;
VkPipelineLayout PipelineLayout;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
BufferParameters StagingBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial07Parameters() :
RenderPass( VK_NULL_HANDLE ),
Image(),
DescriptorSet(),
PipelineLayout(),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
StagingBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial07 : public VulkanCommon {
public:
Tutorial07();
~Tutorial07();
bool CreateRenderingResources();
bool CreateStagingBuffer();
bool CreateTexture();
bool CreateUniformBuffer();
bool CreateDescriptorSetLayout();
bool CreateDescriptorPool();
bool AllocateDescriptorSet();
bool UpdateDescriptorSet();
bool CreateRenderPass();
bool CreatePipelineLayout();
bool CreatePipeline();
bool CreateVertexBuffer();
bool Draw() override;
private:
VulkanTutorial07Parameters Vulkan;
bool CreateCommandBuffers();
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
bool CreateSemaphores();
bool CreateFences();
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
bool CreateImageView( ImageParameters &image_parameters );
bool CreateSampler( VkSampler *sampler );
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
const std::array<float, 16> GetUniformBufferData() const;
bool CopyUniformBufferData();
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
const std::vector<float>& GetVertexData() const;
bool CopyVertexData();
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void DestroyBuffer( BufferParameters& buffer );
bool ChildOnWindowSizeChanged() override;
void ChildClear() override;
};
} // namespace ApiWithoutSecrets
#endif // TUTORIAL_07_HEADER

View File

@@ -1,77 +1,77 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial07.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial07 tutorial07;
// Window creation
if( !window.Create( "07 - Uniform Buffers" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial07.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 06
if( !tutorial07.CreateRenderingResources() ) {
return -1;
}
if( !tutorial07.CreateStagingBuffer() ) {
return -1;
}
if( !tutorial07.CreateTexture() ) {
return -1;
}
if( !tutorial07.CreateUniformBuffer() ) {
return -1;
}
if( !tutorial07.CreateDescriptorSetLayout() ) {
return -1;
}
if( !tutorial07.CreateDescriptorPool() ) {
return -1;
}
if( !tutorial07.AllocateDescriptorSet() ) {
return -1;
}
if( !tutorial07.UpdateDescriptorSet() ) {
return -1;
}
if( !tutorial07.CreateRenderPass() ) {
return -1;
}
if( !tutorial07.CreatePipelineLayout() ) {
return -1;
}
if( !tutorial07.CreatePipeline() ) {
return -1;
}
if( !tutorial07.CreateVertexBuffer() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial07 ) ) {
return -1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// 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
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "Tutorial07.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial07 tutorial07;
// Window creation
if( !window.Create( "07 - Uniform Buffers" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial07.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 06
if( !tutorial07.CreateRenderingResources() ) {
return -1;
}
if( !tutorial07.CreateStagingBuffer() ) {
return -1;
}
if( !tutorial07.CreateTexture() ) {
return -1;
}
if( !tutorial07.CreateUniformBuffer() ) {
return -1;
}
if( !tutorial07.CreateDescriptorSetLayout() ) {
return -1;
}
if( !tutorial07.CreateDescriptorPool() ) {
return -1;
}
if( !tutorial07.AllocateDescriptorSet() ) {
return -1;
}
if( !tutorial07.UpdateDescriptorSet() ) {
return -1;
}
if( !tutorial07.CreateRenderPass() ) {
return -1;
}
if( !tutorial07.CreatePipelineLayout() ) {
return -1;
}
if( !tutorial07.CreatePipeline() ) {
return -1;
}
if( !tutorial07.CreateVertexBuffer() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial07 ) ) {
return -1;
}
return 0;
}

View File

@@ -1,42 +1,42 @@
@ECHO OFF
SETLOCAL
REM /////////////////////////////////////////////////////////////////////////////////////////////
REM // Copyright 2017 Intel Corporation
REM //
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 obtain a copy of the License at
REM //
REM // http://www.apache.org/licenses/LICENSE-2.0
REM //
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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM // See the License for the specific language governing permissions and
REM // limitations under the License.
REM /////////////////////////////////////////////////////////////////////////////////////////////
if [%1] == [] (
echo No arguments provided! Please specify folder number.
echo Example usage: compile_shaders.bat 03
goto end
)
if exist glslangValidator.exe (
goto convert
)
for %%X in (glslangValidator.exe) do (set glslangValidator=%%~$PATH:X)
if defined glslangValidator (
goto convert
)
echo Could not find "glslangValidator.exe" file.
goto end
:convert
set folder=Tutorial%1/Data%1
echo Converting GLSL shaders into SPIR-V assembly in the "%folder%" folder.
@ECHO OFF
SETLOCAL
REM /////////////////////////////////////////////////////////////////////////////////////////////
REM // Copyright 2017 Intel Corporation
REM //
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 obtain a copy of the License at
REM //
REM // http://www.apache.org/licenses/LICENSE-2.0
REM //
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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM // See the License for the specific language governing permissions and
REM // limitations under the License.
REM /////////////////////////////////////////////////////////////////////////////////////////////
if [%1] == [] (
echo No arguments provided! Please specify folder number.
echo Example usage: compile_shaders.bat 03
goto end
)
if exist glslangValidator.exe (
goto convert
)
for %%X in (glslangValidator.exe) do (set glslangValidator=%%~$PATH:X)
if defined glslangValidator (
goto convert
)
echo Could not find "glslangValidator.exe" file.
goto end
:convert
set folder=Tutorial%1/Data%1
echo Converting GLSL shaders into SPIR-V assembly in the "%folder%" folder.
if exist %folder%/shader.vert (