summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Halase <jordan@halase.me>2019-10-27 14:01:43 -0500
committerJordan Halase <jordan@halase.me>2019-10-27 14:01:43 -0500
commitb9b804e59c983f9f21f695f51577da93b92ebb0f (patch)
tree4dc5f62ade027392bcedee331664108ba27b4c9c
parentd225f774017c5900c42ec0ec018e5f45853d6831 (diff)
Add #ifdefs for windows
-rw-r--r--main.c73
1 files changed, 55 insertions, 18 deletions
diff --git a/main.c b/main.c
index 37c8c92..98863b1 100644
--- a/main.c
+++ b/main.c
@@ -19,11 +19,21 @@ PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <math.h>
-#include <X11/Xlib.h>
-
#include <vulkan/vulkan.h>
+
+#if defined(__linux__)
+#include <X11/Xlib.h>
#include <vulkan/vulkan_xlib.h>
+#include "pugl/detail/x11.h"
+
+#elif defined (__WIN32)
+#include <windows.h>
+#include <vulkan/vulkan_win32.h>
+#else
+#error "This platform is not supported"
+#endif
+
#include "pugl/pugl.h"
#include "vk_mem_alloc.h"
@@ -57,22 +67,31 @@ static const VkFormat depthFormat = VK_FORMAT_D24_UNORM_S8_UINT;
#define TIMER_INTERVAL 500
+#if defined(__WIN32)
+#include <io.h>
static ssize_t get_file_size(FILE *fp)
{
-#if defined(__linux__)
-
+ const int fd = fileno(fp);
+ const HANDLE hFile = (HANDLE)_get_osfhandle(fd);
+ DWORD fileSizeHigh = 0;
+ const DWORD fileSizeLow = GetFileSize(hFile, &fileSizeHigh);
+ ssize_t fileSize = fileSizeHigh;
+ fileSize <<= 32;
+ fileSize += fileSizeLow;
+ return fileSize;
+}
+#else
#include <sys/stat.h>
+static ssize_t get_file_size(FILE *fp)
+{
const int fd = fileno(fp);
struct stat st;
if (fstat(fd, &st) == -1) {
return -1;
}
return st.st_size;
-
-#else
-#error "Cannot get file sizes on this system"
-#endif
}
+#endif
uint8_t *read_file(const char *path, size_t *size)
{
@@ -949,7 +968,33 @@ static void destroySwapchainFramebuffers()
swapchainFramebuffers = NULL;
}
-#include "pugl/detail/x11.h"
+#if defined(__linux__)
+static void createSurface()
+{
+ const VkXlibSurfaceCreateInfoKHR createInfo = {
+ .sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
+ .dpy = ((struct PuglWorldImpl*)world)->impl->display,
+ .window = puglGetNativeWindow(view)
+ };
+ VkResult result;
+ if ((result = vkCreateXlibSurfaceKHR(instance, &createInfo, NULL, &surface))) {
+ ERRFQ("Could not create Xlib surface: %d\n", result);
+ }
+}
+#elif defined(__WIN32)
+static void createSurface()
+{
+ const VkWin32SurfaceCreateInfoKHR createInfo = {
+ .sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
+ .hinstance = GetModuleHandle(NULL), // FIXME: whole process scope
+ .hwnd = puglGetNativeWindow(view)
+ };
+ VkResult result;
+ if ((result = vkCreateWin32SurfaceKHR(instance, &createInfo, NULL, &surface))) {
+ ERRFQ("Could not create Win32 surface: %d\n", result);
+ }
+}
+#endif
void initVulkan()
{
@@ -971,15 +1016,7 @@ void initVulkan()
// However, it should do it differently than how SDL does it, because SDL loads the Vulkan Loader
// using hidden global state, which goes against Pugl's embedded model.
// This could be negotiated at a later time.
- const VkXlibSurfaceCreateInfoKHR createInfo = {
- .sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
- .dpy = ((struct PuglWorldImpl*)world)->impl->display,
- .window = puglGetNativeWindow(view)
- };
- VkResult result;
- if ((result = vkCreateXlibSurfaceKHR(instance, &createInfo, NULL, &surface))) {
- ERRFQ("Could not create Xlib surface: %d\n", result);
- }
+ createSurface();
#endif
selectPhysicalDevice(NULL);
createLogicalDevice();