From 02fcf66ef77a47088d411bc00a5ebee2d6ae43e0 Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Thu, 10 Jun 2021 22:18:08 +0200 Subject: [PATCH] Create surface for GLFW window and fixed logging for window functions. --- src/main.c | 25 +++++-------------------- src/window.c | 18 +++++++++++++++--- src/window.h | 4 ++++ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main.c b/src/main.c index 2213f4c..68ee68d 100644 --- a/src/main.c +++ b/src/main.c @@ -121,7 +121,7 @@ int vkeCreateLogicalDeviceAndQueues(VKEContext* ctx, VKEConfig* config, VKEQueue }; float queuePriority = 1.0f; queueCreateInfo.pQueuePriorities = &queuePriority; - //VkPhysicalDeviceFeatures deviceFeatures; + //VkPhysicalDeviceFeatures deviceFeatures; TODO VkDeviceCreateInfo createInfo = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pQueueCreateInfos = &queueCreateInfo, @@ -146,21 +146,7 @@ int vkeCreateLogicalDeviceAndQueues(VKEContext* ctx, VKEConfig* config, VKEQueue return 0; } -int vkeCreateSurface(VKEContext* ctx) { - VkDisplaySurfaceCreateInfoKHR surfaceCreateInfo = { - .sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR - // TODO - }; - - if(vkCreateDisplayPlaneSurfaceKHR(ctx->instance, &surfaceCreateInfo, NULL, &ctx->surface) != VK_SUCCESS) { - vkeLogError("error creating surface"); - return -1; - } - - return 0; -} - -int vkeInit(VKEContext* ctx, VKEConfig* config) { +int vkeInit(VKEContext* ctx, VKEConfig* config, GLFWwindow* window) { if(!vkeCheckValidationLayerSupport(config->validationLayers, config->validationLayerCount)) { vkeLogError("validation layer not supported"); return -1; @@ -209,10 +195,9 @@ int vkeInit(VKEContext* ctx, VKEConfig* config) { return -5; } - // TODO - /*if(vkeCreateSurface(ctx) != 0) { + if(vkeCreateWindowSurface(ctx->instance, window, &ctx->surface) != 0) { return -6; - }*/ + } return 0; } @@ -249,7 +234,7 @@ int main(int argc, const char *argv[]) { .validationLayers = validationLayers }; - if(vkeInit(&ctx, &config) != 0) { + if(vkeInit(&ctx, &config, window) != 0) { return -1; } diff --git a/src/window.c b/src/window.c index fab7b53..882bd85 100644 --- a/src/window.c +++ b/src/window.c @@ -1,17 +1,20 @@ +#define GLFW_INCLUDE_VULKAN + #include "window.h" -#include +#include #include +#include "log.h" GLFWwindow* vkeCreateWindow(const char* title, int width, int height) { int err = glfwInit(); if(err != GLFW_TRUE) { - perror("error initializing glfw"); + vkeLogError("error initializing glfw"); return NULL; } if(glfwVulkanSupported() != GLFW_TRUE) { - perror("vulkan not supported"); + vkeLogError("vulkan not supported"); return NULL; } @@ -25,3 +28,12 @@ void vkeDestroyWindow(GLFWwindow* window) { glfwDestroyWindow(window); glfwTerminate(); } + +int vkeCreateWindowSurface(VkInstance instance, GLFWwindow* window, VkSurfaceKHR* surface) { + if(glfwCreateWindowSurface(instance, window, NULL, surface) != VK_SUCCESS) { + vkeLogError("error creating surface"); + return -1; + } + + return 0; +} diff --git a/src/window.h b/src/window.h index f609b0a..dc1e2c0 100644 --- a/src/window.h +++ b/src/window.h @@ -1,6 +1,7 @@ #ifndef VKE_WINDOW_H #define VKE_WINDOW_H +#include #include // Creates a new window for given title and dimensions. @@ -10,4 +11,7 @@ GLFWwindow* vkeCreateWindow(const char* title, int width, int height); // Destroys given window. void vkeDestroyWindow(GLFWwindow* window); +// Create a Vulkan surface for given window. +int vkeCreateWindowSurface(VkInstance instance, GLFWwindow* window, VkSurfaceKHR* surface); + #endif