SimpleGL  1.1.0
A framework for platform independent rendering
glfw_window_vk.cpp
Go to the documentation of this file.
1 
10 
11 #include <stdexcept>
12 
13 #define GLFW_INCLUDE_VULKAN
14 #include <GLFW/glfw3.h>
15 
17 
18 using namespace std;
19 
20 namespace sgl {
21 
22  WindowVK::WindowVK(int width, int height, std::string title) : Window() {
23  size.x = width;
24  size.y = height;
25  this->title = title;
26 
27  /* Reset to default window hints */
28  glfwDefaultWindowHints();
29 
30  /* Not resizeable */
31  glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
32 
33  /* Disable OpenGL context creation */
34  glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
35 
36  /* Creating the GLFW window */
37  handle = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
38  if (!handle) {
39  throw runtime_error("Could not create window!");
40  }
41 
42  /* Create Vulkan context and set it current */
43  context = new VulkanContext();
45 
46  /* Setup a debug callback */
47  context->setupDebugCallback();
48 
49  /* Create a Vulkan surface */
50  surface = new Surface(this);
51 
52  /* Initialize the Vulkan device */
53  context->pickPhysicalDevice(surface);
54  context->createLogicalDevice();
55 
56  /* Create the swapchain */
57  context->createSwapchain(surface, size);
58 
59  /* Center window to screen */
60  centerWindow();
61 
62  /* Set default callbacks */
63  KeyCallback* keyCallback = new KeyCallback();
64  setKeyCallback(keyCallback);
65  MouseButtonCallback* mouseButtonCallback = new MouseButtonCallback();
66  setMouseButtonCallback(mouseButtonCallback);
67  }
68 
70  /* Delete the window surface */
71  delete surface;
72 
73  /* Delete the Vulkan context */
74  delete context;
75  }
76 
78  context->getSwapchain()->present();
79  context->getSwapchain()->acquireNextImage();
80  }
81 }
void present()
Presents the swapchain image.
Definition: swapchain.cpp:182
void setKeyCallback(KeyCallback *callback)
Set the key callback.
Definition: glfw_window.cpp:89
Swapchain * getSwapchain()
Returns the swapchain of this context.
void swapBuffers() override
Swaps the framebuffers of this window.
This class contains all relevant Vulkan objects to setup a Vulkan application.
This class provides a basic GLFW window.
Definition: glfw_window.hpp:29
Generic namespace for the SimpleGL framework.
Definition: application.hpp:18
This class wraps a GLFW mouse button callback.
~WindowVK(void)
Destroys the window.
This class wraps a GLFW key callback.
void createSwapchain(Surface *surface, glm::ivec2 size)
Creates a swapchain for this context.
GLFWwindow * handle
The handle for the GLFW window.
Definition: glfw_window.hpp:33
std::string title
The title for the GLFW window.
Definition: glfw_window.hpp:39
static void setCurrent(VulkanContext *context)
Sets the current Vulkan context.
void setMouseButtonCallback(MouseButtonCallback *callback)
Set the mouse button callback.
Definition: glfw_window.cpp:94
void setupDebugCallback()
Creates a debug report callback, if compiled in debug mode.
void createLogicalDevice()
Creates the logical device for rendering.
void centerWindow()
Centers the window on the primary screen.
Definition: glfw_window.cpp:84
void acquireNextImage()
Updates the index for the swapchain images.
Definition: swapchain.cpp:163
void pickPhysicalDevice(Surface *surface)
Enumerates all available physical devices and picks a suitable physical device.
This class wraps a Vulkan surface.
Definition: surface.hpp:25
glm::ivec2 size
The size of the drawing area.
Definition: glfw_window.hpp:36