aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/window.hpp8
-rw-r--r--src/main.cpp3
-rw-r--r--src/utils.cpp2
-rw-r--r--src/vk-renderer.cpp15
-rw-r--r--src/window.cpp50
5 files changed, 75 insertions, 3 deletions
diff --git a/include/window.hpp b/include/window.hpp
index 4b3d37b..44d6501 100644
--- a/include/window.hpp
+++ b/include/window.hpp
@@ -24,6 +24,8 @@ class window {
uint32_t width;
uint32_t height;
+
+ bool isOpen;
};
#elif defined(WINDOWS)
#include <Windows.h>
@@ -32,8 +34,14 @@ class window {
public:
window(uint32_t width, uint32_t height);
+ static LRESULT CALLBACK window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam);
+
+ HWND win_handle;
+
uint32_t width;
uint32_t height;
+
+ bool isOpen;
};
#endif
diff --git a/src/main.cpp b/src/main.cpp
index cbaa798..ff352c5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -171,6 +171,9 @@ int main() {
// stop the capture
if(rdoc_api) rdoc_api->EndFrameCapture(NULL, NULL);
+ while(wnd.isOpen) {
+ }
+
//-------------------------
// GPU path tracer
//-------------------------
diff --git a/src/utils.cpp b/src/utils.cpp
index 9aaf93a..e7aef1d 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -5,7 +5,7 @@
#include <iostream>
std::vector<uint8_t> get_shader_code(const char* path) {
- FILE* f = fopen(path, "r");
+ FILE* f = fopen(path, "rb");
if (f == nullptr) {
std::cerr << "Cannot open compute shader file !" << std::endl;
diff --git a/src/vk-renderer.cpp b/src/vk-renderer.cpp
index 26b2ff3..a733d49 100644
--- a/src/vk-renderer.cpp
+++ b/src/vk-renderer.cpp
@@ -150,8 +150,10 @@ void vkrenderer::create_instance() {
std::vector<const char*> extensions = {
VK_EXT_DEBUG_UTILS_EXTENSION_NAME,
"VK_KHR_surface",
-#ifdef LINUX
+#if defined(LINUX)
"VK_KHR_xcb_surface"
+#elif defined(WINDOWS)
+ "VK_KHR_win32_surface"
#endif
};
@@ -194,7 +196,7 @@ void vkrenderer::create_debugger() {
}
void vkrenderer::create_surface(window& wnd) {
-#ifdef LINUX
+#if defined(LINUX)
VkXcbSurfaceCreateInfoKHR create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
create_info.pNext = nullptr;
@@ -203,6 +205,15 @@ void vkrenderer::create_surface(window& wnd) {
create_info.window = wnd.win;
VKRESULT(vkCreateXcbSurfaceKHR(instance, &create_info, nullptr, &platform_surface))
+#elif defined(WINDOWS)
+ VkWin32SurfaceCreateInfoKHR create_info = {};
+ create_info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
+ create_info.pNext = nullptr;
+ create_info.flags = 0;
+ create_info.hinstance = GetModuleHandle(NULL);
+ create_info.hwnd = wnd.win_handle;
+
+ VKRESULT(vkCreateWin32SurfaceKHR(instance, &create_info, nullptr, &platform_surface))
#endif
}
diff --git a/src/window.cpp b/src/window.cpp
index d901e66..a55a439 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -27,9 +27,59 @@ window::window(uint32_t width, uint32_t height)
xcb_map_window(connection, win);
xcb_flush(connection);
+
+ isOpen = true;
}
#elif defined(WINDOWS)
+LRESULT CALLBACK window::window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam) {
+ window* win = nullptr;
+
+ if (umsg == WM_CREATE) {
+ LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lparam;
+ win = (window*)lpcs->lpCreateParams;
+
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)win);
+ } else {
+ win = (window*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ }
+
+ return DefWindowProc(hwnd, umsg, wparam, lparam);
+}
+
window::window(uint32_t width, uint32_t height)
:width(width), height(height) {
+ auto process_handle = GetModuleHandle(NULL);
+
+ WNDCLASS window_class = {};
+ window_class.style = 0;
+ window_class.lpfnWndProc = &window::window_procedure;
+ window_class.cbClsExtra = 0;
+ window_class.cbWndExtra = 0;
+ window_class.hInstance = process_handle;
+ window_class.hIcon = NULL;
+ window_class.hCursor = NULL;
+ window_class.hbrBackground = NULL;
+ window_class.lpszMenuName = NULL;
+ window_class.lpszClassName = "default-window";
+
+ RegisterClass(&window_class);
+
+ win_handle = CreateWindow(
+ "default-window",
+ "path-tracer",
+ WS_OVERLAPPEDWINDOW,
+ 10,
+ 10,
+ width,
+ height,
+ NULL,
+ NULL,
+ process_handle,
+ this
+ );
+
+ ShowWindow(win_handle, SW_SHOW);
+
+ isOpen = true;
}
#endif