From 95675bd12539cc7da9a03201cb4a085283bc28f1 Mon Sep 17 00:00:00 2001 From: plapins Date: Wed, 13 Apr 2016 09:27:27 +0200 Subject: [PATCH] Renamed "Tutorial" namespace to "ApiWithoutSecrets". Added ApiWithoutSecrets namescape to all files. Placed function pointers in an ApiWithoutSecrets namespace to fix errors on Linux. --- Project/Common/OperatingSystem.cpp | 472 +++++++++++++++-------------- Project/Common/OperatingSystem.h | 128 ++++---- Project/Common/Tools.cpp | 42 +-- Project/Common/Tools.h | 118 ++++---- Project/Common/VulkanCommon.cpp | 4 +- Project/Common/VulkanCommon.h | 4 +- Project/Common/VulkanFunctions.cpp | 4 + Project/Common/VulkanFunctions.h | 4 + Project/Tutorial01/Tutorial01.cpp | 2 +- Project/Tutorial01/Tutorial01.h | 4 +- Project/Tutorial01/main.cpp | 4 +- Project/Tutorial02/Tutorial02.cpp | 4 +- Project/Tutorial02/Tutorial02.h | 4 +- Project/Tutorial02/main.cpp | 4 +- Project/Tutorial03/Tutorial03.cpp | 4 +- Project/Tutorial03/Tutorial03.h | 4 +- Project/Tutorial03/main.cpp | 4 +- Project/Tutorial04/Tutorial04.cpp | 4 +- Project/Tutorial04/Tutorial04.h | 4 +- Project/Tutorial04/main.cpp | 4 +- 20 files changed, 423 insertions(+), 399 deletions(-) diff --git a/Project/Common/OperatingSystem.cpp b/Project/Common/OperatingSystem.cpp index 348d543..cae80d6 100644 --- a/Project/Common/OperatingSystem.cpp +++ b/Project/Common/OperatingSystem.cpp @@ -10,22 +10,24 @@ #include "OperatingSystem.h" -namespace OS { +namespace ApiWithoutSecrets { - Window::Window() : - Parameters() { - } + namespace OS { - WindowParameters Window::GetParameters() const { - return Parameters; - } + 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 ) { + 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 ); @@ -36,68 +38,68 @@ namespace OS { break; default: return DefWindowProc( hWnd, message, wParam, lParam ); - } - return 0; - } - - Window::~Window() { - if( Parameters.Handle ) { - DestroyWindow( Parameters.Handle ); + } + return 0; } - if( Parameters.Instance ) { - UnregisterClass( TUTORIAL_NAME, Parameters.Instance ); - } - } + Window::~Window() { + if( Parameters.Handle ) { + DestroyWindow( Parameters.Handle ); + } - 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; + if( Parameters.Instance ) { + UnregisterClass( TUTORIAL_NAME, Parameters.Instance ); + } } - // Create window - Parameters.Handle = CreateWindow( TUTORIAL_NAME, title, WS_OVERLAPPEDWINDOW, 20, 20, 500, 500, nullptr, nullptr, Parameters.Instance, nullptr ); - if( !Parameters.Handle ) { - return false; + 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; } - return true; - } + bool Window::RenderingLoop( TutorialBase &tutorial ) const { + // Display window + ShowWindow( Parameters.Handle, SW_SHOWNORMAL ); + UpdateWindow( Parameters.Handle ); - 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; - // Main message loop - MSG message; - bool loop = true; - bool resize = false; - - while( loop ) { - if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) ) { - // Process events - switch( message.message ) { - // Resize + while( loop ) { + if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) ) { + // Process events + switch( message.message ) { + // Resize case WM_USER + 1: resize = true; break; @@ -105,124 +107,124 @@ namespace OS { case WM_USER + 2: loop = false; break; - } - TranslateMessage( &message ); - DispatchMessage( &message ); - } else { - // Draw - if( resize ) { - resize = false; - if( !tutorial.OnWindowSizeChanged() ) { + } + TranslateMessage( &message ); + DispatchMessage( &message ); + } else { + // Draw + if( resize ) { + resize = false; + if( !tutorial.OnWindowSizeChanged() ) { + loop = false; + } + } + if( !tutorial.Draw() ) { loop = false; } } - if( !tutorial.Draw() ) { - loop = false; - } } - } - return true; - } + return true; + } #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; + Window::~Window() { + xcb_destroy_window( Parameters.Connection, Parameters.Handle ); + xcb_disconnect( Parameters.Connection ); } - const xcb_setup_t *setup = xcb_get_setup( Parameters.Connection ); - xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator( setup ); + bool Window::Create( const char *title ) { + int screen_index; + Parameters.Connection = xcb_connect( nullptr, &screen_index ); - while( screen_index-- > 0 ) { - xcb_screen_next( &screen_iterator ); + 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_change_property( + Parameters.Connection, + XCB_PROP_MODE_REPLACE, + Parameters.Handle, + XCB_ATOM_WM_NAME, + XCB_ATOM_STRING, + 8, + strlen( title ), + title ); + + return true; } - xcb_screen_t *screen = screen_iterator.data; + 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 ); - Parameters.Handle = xcb_generate_id( Parameters.Connection ); + // Display window + xcb_map_window( Parameters.Connection, Parameters.Handle ); + xcb_flush( Parameters.Connection ); - uint32_t value_list[] = { - screen->white_pixel, - XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY - }; + // Main message loop + xcb_generic_event_t *event; + bool loop = true; + bool resize = false; - 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 ); + while( loop ) { + event = xcb_poll_for_event( 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; - - while( loop ) { - event = xcb_poll_for_event( Parameters.Connection ); - - if( event ) { - // Process events - switch (event->response_type & 0x7f) { - // Resize + 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; + 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)) || + 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; + resize = true; + width = configure_event->width; + height = configure_event->height; + } } - } - break; - // Close + break; + // Close case XCB_CLIENT_MESSAGE: if( (*(xcb_client_message_event_t*)event).data.data32[0] == (*delete_reply).atom ) { loop = false; @@ -232,89 +234,89 @@ namespace OS { case XCB_KEY_PRESS: loop = false; break; - } - free( event ); - } else { - // Draw - if( resize ) { - resize = false; - if( !tutorial.OnWindowSizeChanged() ) { + } + free( event ); + } else { + // Draw + if( resize ) { + resize = false; + if( !tutorial.OnWindowSizeChanged() ) { + loop = false; + } + } + if( !tutorial.Draw() ) { loop = false; } } - if( !tutorial.Draw() ) { - loop = false; - } } - } - return true; - } + return true; + } #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; + Window::~Window() { + XDestroyWindow( Parameters.DisplayPtr, Parameters.Handle ); + XCloseDisplay( Parameters.DisplayPtr ); } - int default_screen = DefaultScreen( Parameters.DisplayPtr ); + bool Window::Create( const char *title ) { + Parameters.DisplayPtr = XOpenDisplay( nullptr ); + if( !Parameters.DisplayPtr ) { + return false; + } - Parameters.Handle = XCreateSimpleWindow( - Parameters.DisplayPtr, - DefaultRootWindow( Parameters.DisplayPtr ), - 20, - 20, - 500, - 500, - 1, - BlackPixel( Parameters.DisplayPtr, default_screen ), - WhitePixel( Parameters.DisplayPtr, default_screen ) ); + int default_screen = DefaultScreen( Parameters.DisplayPtr ); - XSetStandardProperties( Parameters.DisplayPtr, Parameters.Handle, title, title, None, nullptr, 0, nullptr ); - XSelectInput( Parameters.DisplayPtr, Parameters.Handle, ExposureMask | KeyPressMask | StructureNotifyMask ); + Parameters.Handle = XCreateSimpleWindow( + Parameters.DisplayPtr, + DefaultRootWindow( Parameters.DisplayPtr ), + 20, + 20, + 500, + 500, + 1, + BlackPixel( Parameters.DisplayPtr, default_screen ), + WhitePixel( Parameters.DisplayPtr, default_screen ) ); - return true; - } + XSetStandardProperties( Parameters.DisplayPtr, Parameters.Handle, title, title, None, nullptr, 0, nullptr ); + XSelectInput( Parameters.DisplayPtr, Parameters.Handle, ExposureMask | KeyPressMask | StructureNotifyMask ); - 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); + return true; + } - // Display window - XClearWindow( Parameters.DisplayPtr, Parameters.Handle ); - XMapWindow( Parameters.DisplayPtr, Parameters.Handle ); + 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); - // Main message loop - XEvent event; - bool loop = true; - bool resize = false; + // Display window + XClearWindow( Parameters.DisplayPtr, Parameters.Handle ); + XMapWindow( Parameters.DisplayPtr, Parameters.Handle ); - while( loop ) { - if( XPending( Parameters.DisplayPtr ) ) { - XNextEvent( Parameters.DisplayPtr, &event ); - switch( event.type ) { - //Process events + // Main message loop + XEvent event; + bool loop = true; + bool resize = false; + + 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; + static int width = event.xconfigure.width; + static int height = event.xconfigure.height; - if( ((event.xconfigure.width > 0) && (event.xconfigure.width != width)) || + if( ((event.xconfigure.width > 0) && (event.xconfigure.width != width)) || ((event.xconfigure.height > 0) && (event.xconfigure.width != height)) ) { - width = event.xconfigure.width; - height = event.xconfigure.height; - resize = true; + width = event.xconfigure.width; + height = event.xconfigure.height; + resize = true; + } } - } - break; + break; case KeyPress: loop = false; break; @@ -326,24 +328,26 @@ namespace OS { loop = false; } break; - } - } else { - // Draw - if( resize ) { - resize = false; - if( !tutorial.OnWindowSizeChanged() ) { + } + } else { + // Draw + if( resize ) { + resize = false; + if( !tutorial.OnWindowSizeChanged() ) { + loop = false; + } + } + if( !tutorial.Draw() ) { loop = false; } } - if( !tutorial.Draw() ) { - loop = false; - } } - } - return true; - } + return true; + } #endif -} // namespace OS \ No newline at end of file + } // namespace OS + +} // namespace ApiWithoutSecrets \ No newline at end of file diff --git a/Project/Common/OperatingSystem.h b/Project/Common/OperatingSystem.h index e870eba..0b27360 100644 --- a/Project/Common/OperatingSystem.h +++ b/Project/Common/OperatingSystem.h @@ -30,90 +30,94 @@ #include #include -namespace OS { +namespace ApiWithoutSecrets { - // ************************************************************ // - // LibraryHandle // - // // - // Dynamic Library OS dependent type // - // ************************************************************ // - // + namespace OS { + + // ************************************************************ // + // LibraryHandle // + // // + // Dynamic Library OS dependent type // + // ************************************************************ // + // #if defined(VK_USE_PLATFORM_WIN32_KHR) - typedef HMODULE LibraryHandle; + typedef HMODULE LibraryHandle; #elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) - typedef void* LibraryHandle; + typedef void* LibraryHandle; #endif - // ************************************************************ // - // OnWindowSizeChanged // - // // - // Base class for handling window size changes // - // ************************************************************ // - class TutorialBase { - public: - virtual bool OnWindowSizeChanged() = 0; - virtual bool Draw() = 0; + // ************************************************************ // + // OnWindowSizeChanged // + // // + // Base class for handling window size changes // + // ************************************************************ // + class TutorialBase { + public: + virtual bool OnWindowSizeChanged() = 0; + virtual bool Draw() = 0; - virtual ~TutorialBase( ) { - } - }; + virtual ~TutorialBase() { + } + }; - // ************************************************************ // - // WindowParameters // - // // - // OS dependent window parameters // - // ************************************************************ // - struct WindowParameters { + // ************************************************************ // + // WindowParameters // + // // + // OS dependent window parameters // + // ************************************************************ // + struct WindowParameters { #if defined(VK_USE_PLATFORM_WIN32_KHR) - HINSTANCE Instance; - HWND Handle; + HINSTANCE Instance; + HWND Handle; - WindowParameters() : - Instance(), - Handle() { - } + WindowParameters() : + Instance(), + Handle() { + } #elif defined(VK_USE_PLATFORM_XCB_KHR) - xcb_connection_t *Connection; - xcb_window_t Handle; + xcb_connection_t *Connection; + xcb_window_t Handle; - WindowParameters() : - Connection(), - Handle() { - } + WindowParameters() : + Connection(), + Handle() { + } #elif defined(VK_USE_PLATFORM_XLIB_KHR) - Display *DisplayPtr; - Window Handle; + Display *DisplayPtr; + Window Handle; - WindowParameters() : - DisplayPtr(), - Handle() { - } + WindowParameters() : + DisplayPtr(), + Handle() { + } #endif - }; + }; - // ************************************************************ // - // Window // - // // - // OS dependent window creation and destruction class // - // ************************************************************ // - class Window { - public: - Window(); - ~Window(); + // ************************************************************ // + // 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; + bool Create( const char *title ); + bool RenderingLoop( TutorialBase &tutorial ) const; + WindowParameters GetParameters() const; - private: - WindowParameters Parameters; - }; + private: + WindowParameters Parameters; + }; -} + } // namespace OS + +} // namespace ApiWithoutSecrets #endif // OPERATING_SYSTEM_HEADER \ No newline at end of file diff --git a/Project/Common/Tools.cpp b/Project/Common/Tools.cpp index 43a3b63..5d8e5d4 100644 --- a/Project/Common/Tools.cpp +++ b/Project/Common/Tools.cpp @@ -12,27 +12,31 @@ #include #include "Tools.h" -namespace Tools { +namespace ApiWithoutSecrets { - std::vector GetBinaryFileContents( std::string const &filename ) { + namespace Tools { - std::ifstream file( filename, std::ios::binary ); - if( file.fail() ) { - std::cout << "Could not open \"" << filename << "\" file!" << std::endl; - return std::vector(); + std::vector 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(); + } + + std::streampos begin, end; + begin = file.tellg(); + file.seekg( 0, std::ios::end ); + end = file.tellg(); + + std::vector result( static_cast(end - begin) ); + file.seekg( 0, std::ios::beg ); + file.read( &result[0], end - begin ); + file.close(); + + return result; } - std::streampos begin, end; - begin = file.tellg(); - file.seekg( 0, std::ios::end ); - end = file.tellg(); + } // namespace Tools - std::vector result( static_cast(end - begin) ); - file.seekg( 0, std::ios::beg ); - file.read( &result[0], end - begin ); - file.close(); - - return result; - } - -} \ No newline at end of file +} // namespace ApiWithoutSecrets \ No newline at end of file diff --git a/Project/Common/Tools.h b/Project/Common/Tools.h index 3ebe1e6..bc054b1 100644 --- a/Project/Common/Tools.h +++ b/Project/Common/Tools.h @@ -15,73 +15,77 @@ #include #include "vulkan.h" -namespace Tools { +namespace ApiWithoutSecrets { - // ************************************************************ // - // AutoDeleter // - // // - // Auto-deleter helper template class responsible for calling // - // provided function which deletes given object of type T // - // ************************************************************ // - template - class AutoDeleter { - public: - AutoDeleter() : - Object( VK_NULL_HANDLE ), - Deleter( nullptr ), - Device( VK_NULL_HANDLE ) { - } + namespace Tools { - 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 // + // // + // Auto-deleter helper template class responsible for calling // + // provided function which deletes given object of type T // + // ************************************************************ // + template + class AutoDeleter { + public: + AutoDeleter() : + Object( VK_NULL_HANDLE ), + Deleter( nullptr ), + Device( VK_NULL_HANDLE ) { } - } - AutoDeleter& operator=( AutoDeleter&& other ) { - if( this != &other ) { - Object = other.Object; - Deleter = other.Deleter; - Device = other.Device; - other.Object = VK_NULL_HANDLE; + AutoDeleter( T object, F deleter, VkDevice device ) : + Object( object ), + Deleter( deleter ), + Device( device ) { } - return *this; - } - T Get() { - return Object; - } + AutoDeleter( AutoDeleter&& other ) { + *this = std::move( other ); + } - bool operator !() const { - return Object == VK_NULL_HANDLE; - } + ~AutoDeleter() { + if( (Object != VK_NULL_HANDLE) && (Deleter != nullptr) && (Device != VK_NULL_HANDLE) ) { + Deleter( Device, Object, nullptr ); + } + } - private: - AutoDeleter( const AutoDeleter& ); - AutoDeleter& operator=( const AutoDeleter& ); - T Object; - F Deleter; - VkDevice Device; - }; + AutoDeleter& operator=(AutoDeleter&& other) { + if( this != &other ) { + Object = other.Object; + Deleter = other.Deleter; + Device = other.Device; + other.Object = VK_NULL_HANDLE; + } + return *this; + } - // ************************************************************ // - // GetBinaryFileContents // - // // - // Function reading binary contents of a file // - // ************************************************************ // - std::vector GetBinaryFileContents( std::string const &filename ); + 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 GetBinaryFileContents( std::string const &filename ); + + } // namespace Tools + +} // namespace ApiWithoutSecrets #endif // TOOLS_HEADER \ No newline at end of file diff --git a/Project/Common/VulkanCommon.cpp b/Project/Common/VulkanCommon.cpp index c6d276b..180776d 100644 --- a/Project/Common/VulkanCommon.cpp +++ b/Project/Common/VulkanCommon.cpp @@ -11,7 +11,7 @@ #include "VulkanCommon.h" #include "VulkanFunctions.h" -namespace Tutorial { +namespace ApiWithoutSecrets { VulkanCommon::VulkanCommon() : VulkanLibrary(), @@ -707,4 +707,4 @@ namespace Tutorial { } } -} // namespace Tutorial \ No newline at end of file +} // namespace ApiWithoutSecrets \ No newline at end of file diff --git a/Project/Common/VulkanCommon.h b/Project/Common/VulkanCommon.h index c10d6a5..d00d26b 100644 --- a/Project/Common/VulkanCommon.h +++ b/Project/Common/VulkanCommon.h @@ -15,7 +15,7 @@ #include "vulkan.h" #include "OperatingSystem.h" -namespace Tutorial { +namespace ApiWithoutSecrets { // ************************************************************ // // QueueParameters // @@ -129,6 +129,6 @@ namespace Tutorial { VkPresentModeKHR GetSwapChainPresentMode( std::vector &present_modes ); }; -} // namespace Tutorial +} // namespace ApiWithoutSecrets #endif // VULKAN_COMMON_HEADER \ No newline at end of file diff --git a/Project/Common/VulkanFunctions.cpp b/Project/Common/VulkanFunctions.cpp index bd19818..3d7a1e3 100644 --- a/Project/Common/VulkanFunctions.cpp +++ b/Project/Common/VulkanFunctions.cpp @@ -10,9 +10,13 @@ #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 \ No newline at end of file diff --git a/Project/Common/VulkanFunctions.h b/Project/Common/VulkanFunctions.h index b8bc9a8..f438daa 100644 --- a/Project/Common/VulkanFunctions.h +++ b/Project/Common/VulkanFunctions.h @@ -13,6 +13,8 @@ #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; @@ -20,4 +22,6 @@ #include "ListOfFunctions.inl" +} // namespace ApiWithoutSecrets + #endif \ No newline at end of file diff --git a/Project/Tutorial01/Tutorial01.cpp b/Project/Tutorial01/Tutorial01.cpp index 2a456e7..ba82306 100644 --- a/Project/Tutorial01/Tutorial01.cpp +++ b/Project/Tutorial01/Tutorial01.cpp @@ -12,7 +12,7 @@ #include "Tutorial01.h" #include "VulkanFunctions.h" -namespace Tutorial { +namespace ApiWithoutSecrets { Tutorial01::Tutorial01() : VulkanLibrary(), diff --git a/Project/Tutorial01/Tutorial01.h b/Project/Tutorial01/Tutorial01.h index 380c94e..42909d7 100644 --- a/Project/Tutorial01/Tutorial01.h +++ b/Project/Tutorial01/Tutorial01.h @@ -14,7 +14,7 @@ #include "vulkan.h" #include "OperatingSystem.h" -namespace Tutorial { +namespace ApiWithoutSecrets { // ************************************************************ // // VulkanTutorial01Parameters // @@ -65,6 +65,6 @@ namespace Tutorial { bool GetDeviceQueue(); }; -} // namespace Tutorial +} // namespace ApiWithoutSecrets #endif // TUTORIAL_01_HEADER \ No newline at end of file diff --git a/Project/Tutorial01/main.cpp b/Project/Tutorial01/main.cpp index b7119fb..79060a7 100644 --- a/Project/Tutorial01/main.cpp +++ b/Project/Tutorial01/main.cpp @@ -11,8 +11,8 @@ #include "Tutorial01.h" int main( int argc, char **argv ) { - OS::Window window; - Tutorial::Tutorial01 tutorial01; + ApiWithoutSecrets::OS::Window window; + ApiWithoutSecrets::Tutorial01 tutorial01; // Window creation if( !window.Create( "01 - The Beginning" ) ) { diff --git a/Project/Tutorial02/Tutorial02.cpp b/Project/Tutorial02/Tutorial02.cpp index 361479e..6d0227a 100644 --- a/Project/Tutorial02/Tutorial02.cpp +++ b/Project/Tutorial02/Tutorial02.cpp @@ -11,7 +11,7 @@ #include "Tutorial02.h" #include "VulkanFunctions.h" -namespace Tutorial { +namespace ApiWithoutSecrets { Tutorial02::Tutorial02() : VulkanLibrary(), @@ -851,4 +851,4 @@ namespace Tutorial { } } -} // namespace Tutorial \ No newline at end of file +} // namespace ApiWithoutSecrets \ No newline at end of file diff --git a/Project/Tutorial02/Tutorial02.h b/Project/Tutorial02/Tutorial02.h index 39dd7ce..9e67847 100644 --- a/Project/Tutorial02/Tutorial02.h +++ b/Project/Tutorial02/Tutorial02.h @@ -15,7 +15,7 @@ #include "vulkan.h" #include "OperatingSystem.h" -namespace Tutorial { +namespace ApiWithoutSecrets { // ************************************************************ // // VulkanTutorial02Parameters // @@ -96,6 +96,6 @@ namespace Tutorial { VkPresentModeKHR GetSwapChainPresentMode( std::vector &present_modes ); }; -} // namespace Tutorial +} // namespace ApiWithoutSecrets #endif // TUTORIAL_02_HEADER \ No newline at end of file diff --git a/Project/Tutorial02/main.cpp b/Project/Tutorial02/main.cpp index a77914b..ff5a252 100644 --- a/Project/Tutorial02/main.cpp +++ b/Project/Tutorial02/main.cpp @@ -11,8 +11,8 @@ #include "Tutorial02.h" int main( int argc, char **argv ) { - OS::Window window; - Tutorial::Tutorial02 tutorial02; + ApiWithoutSecrets::OS::Window window; + ApiWithoutSecrets::Tutorial02 tutorial02; // Window creation if( !window.Create( "02 - Swap chain" ) ) { diff --git a/Project/Tutorial03/Tutorial03.cpp b/Project/Tutorial03/Tutorial03.cpp index c51cc17..1c69439 100644 --- a/Project/Tutorial03/Tutorial03.cpp +++ b/Project/Tutorial03/Tutorial03.cpp @@ -11,7 +11,7 @@ #include "Tutorial03.h" #include "VulkanFunctions.h" -namespace Tutorial { +namespace ApiWithoutSecrets { Tutorial03::Tutorial03() : Vulkan() { @@ -593,4 +593,4 @@ namespace Tutorial { ChildClear(); } -} // namespace Tutorial \ No newline at end of file +} // namespace ApiWithoutSecrets \ No newline at end of file diff --git a/Project/Tutorial03/Tutorial03.h b/Project/Tutorial03/Tutorial03.h index eb0e3dc..8029f75 100644 --- a/Project/Tutorial03/Tutorial03.h +++ b/Project/Tutorial03/Tutorial03.h @@ -14,7 +14,7 @@ #include "VulkanCommon.h" #include "Tools.h" -namespace Tutorial { +namespace ApiWithoutSecrets { // ************************************************************ // // FramebufferObject // @@ -77,6 +77,6 @@ namespace Tutorial { bool ChildOnWindowSizeChanged() override; }; -} // namespace Tutorial +} // namespace ApiWithoutSecrets #endif // TUTORIAL_03_HEADER \ No newline at end of file diff --git a/Project/Tutorial03/main.cpp b/Project/Tutorial03/main.cpp index b235e92..f558423 100644 --- a/Project/Tutorial03/main.cpp +++ b/Project/Tutorial03/main.cpp @@ -11,8 +11,8 @@ #include "Tutorial03.h" int main( int argc, char **argv ) { - OS::Window window; - Tutorial::Tutorial03 tutorial03; + ApiWithoutSecrets::OS::Window window; + ApiWithoutSecrets::Tutorial03 tutorial03; // Window creation if( !window.Create( "03 - First Triangle" ) ) { diff --git a/Project/Tutorial04/Tutorial04.cpp b/Project/Tutorial04/Tutorial04.cpp index 6d12260..7c3d8f8 100644 --- a/Project/Tutorial04/Tutorial04.cpp +++ b/Project/Tutorial04/Tutorial04.cpp @@ -11,7 +11,7 @@ #include "Tutorial04.h" #include "VulkanFunctions.h" -namespace Tutorial { +namespace ApiWithoutSecrets { Tutorial04::Tutorial04() : Vulkan() { @@ -915,4 +915,4 @@ namespace Tutorial { } } -} // namespace Tutorial \ No newline at end of file +} // namespace ApiWithoutSecrets \ No newline at end of file diff --git a/Project/Tutorial04/Tutorial04.h b/Project/Tutorial04/Tutorial04.h index 419c80c..acc0352 100644 --- a/Project/Tutorial04/Tutorial04.h +++ b/Project/Tutorial04/Tutorial04.h @@ -14,7 +14,7 @@ #include "VulkanCommon.h" #include "Tools.h" -namespace Tutorial { +namespace ApiWithoutSecrets { // ************************************************************ // // ImageParameters // @@ -127,6 +127,6 @@ namespace Tutorial { bool ChildOnWindowSizeChanged() override; }; -} // namespace Tutorial +} // namespace ApiWithoutSecrets #endif // TUTORIAL_03_HEADER \ No newline at end of file diff --git a/Project/Tutorial04/main.cpp b/Project/Tutorial04/main.cpp index afe8fd8..9c4301b 100644 --- a/Project/Tutorial04/main.cpp +++ b/Project/Tutorial04/main.cpp @@ -11,8 +11,8 @@ #include "Tutorial04.h" int main( int argc, char **argv ) { - OS::Window window; - Tutorial::Tutorial04 tutorial04; + ApiWithoutSecrets::OS::Window window; + ApiWithoutSecrets::Tutorial04 tutorial04; // Window creation if( !window.Create( "04 - Vertex Attributes" ) ) {