mirror of
https://github.com/opus-tango/IntroductionToVulkan.git
synced 2026-03-20 12:05:20 +00:00
Renamed "Tutorial" namespace to "ApiWithoutSecrets". Added ApiWithoutSecrets namescape to all files. Placed function pointers in an ApiWithoutSecrets namespace to fix errors on Linux.
This commit is contained in:
@@ -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
|
||||
} // namespace OS
|
||||
|
||||
} // namespace ApiWithoutSecrets
|
||||
@@ -30,90 +30,94 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
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
|
||||
@@ -12,27 +12,31 @@
|
||||
#include <iostream>
|
||||
#include "Tools.h"
|
||||
|
||||
namespace Tools {
|
||||
namespace ApiWithoutSecrets {
|
||||
|
||||
std::vector<char> 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<char>();
|
||||
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;
|
||||
}
|
||||
|
||||
std::streampos begin, end;
|
||||
begin = file.tellg();
|
||||
file.seekg( 0, std::ios::end );
|
||||
end = file.tellg();
|
||||
} // namespace Tools
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace ApiWithoutSecrets
|
||||
@@ -15,73 +15,77 @@
|
||||
#include <vector>
|
||||
#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 T, class F>
|
||||
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 T, class F>
|
||||
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<char> 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<char> GetBinaryFileContents( std::string const &filename );
|
||||
|
||||
} // namespace Tools
|
||||
|
||||
} // namespace ApiWithoutSecrets
|
||||
|
||||
|
||||
#endif // TOOLS_HEADER
|
||||
@@ -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
|
||||
} // namespace ApiWithoutSecrets
|
||||
@@ -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<VkPresentModeKHR> &present_modes );
|
||||
};
|
||||
|
||||
} // namespace Tutorial
|
||||
} // namespace ApiWithoutSecrets
|
||||
|
||||
#endif // VULKAN_COMMON_HEADER
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "Tutorial01.h"
|
||||
#include "VulkanFunctions.h"
|
||||
|
||||
namespace Tutorial {
|
||||
namespace ApiWithoutSecrets {
|
||||
|
||||
Tutorial01::Tutorial01() :
|
||||
VulkanLibrary(),
|
||||
|
||||
@@ -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
|
||||
@@ -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" ) ) {
|
||||
|
||||
@@ -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
|
||||
} // namespace ApiWithoutSecrets
|
||||
@@ -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<VkPresentModeKHR> &present_modes );
|
||||
};
|
||||
|
||||
} // namespace Tutorial
|
||||
} // namespace ApiWithoutSecrets
|
||||
|
||||
#endif // TUTORIAL_02_HEADER
|
||||
@@ -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" ) ) {
|
||||
|
||||
@@ -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
|
||||
} // namespace ApiWithoutSecrets
|
||||
@@ -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
|
||||
@@ -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" ) ) {
|
||||
|
||||
@@ -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
|
||||
} // namespace ApiWithoutSecrets
|
||||
@@ -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
|
||||
@@ -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" ) ) {
|
||||
|
||||
Reference in New Issue
Block a user