X-Git-Url: https://eleni.mutantstargoat.com/git/?p=vkrt;a=blobdiff_plain;f=src%2Fmain.c;fp=src%2Fmain.c;h=b0a5ec4223e0872e3a2801969a8a7fe28d9fb36c;hp=07af1ef65718d6e8c959e281b6bab6fa635fac0d;hb=9c5fa12eb2c6db6c8a3fbd280bab8951cf51f0a0;hpb=c5fcb12273c24f6e24d459ad184f662ef9abefea diff --git a/src/main.c b/src/main.c index 07af1ef..b0a5ec4 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,7 @@ #include #include "vk.h" +#include "util.h" /* static glfw callbacks */ @@ -36,7 +37,15 @@ static int win_w = 800; static int win_h = 600; static struct vk_ctx vk_core; -static struct vk_swapchain vk_swap; +static VkSurfaceKHR vk_surf; +static int vsz, fsz; +static struct vk_renderer vk_rnd; +static struct vk_swapchain vk_chain; + +static struct vk_semaphores vk_sema; + +/* empty for as long as we hardcode the vertices in the vertex shader */ +static struct vk_vertex_info vk_vert_info; int main(int argc, char** argv) { @@ -66,6 +75,8 @@ int main(int argc, char** argv) static bool init() { + char *vsdr, *fsdr; + /* initialize GLFW */ if (!glfwInit()) { @@ -78,15 +89,6 @@ init() return false; } - /* initialize Vulkan context */ - - if (!vk_init_ctx_for_rendering(&vk_core)) { - fprintf(stderr, "Failed to initialize Vulkan context.\n"); - return false; - } - - memset(&vk_swap, 0, sizeof vk_swap); - /* create window */ glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); @@ -97,24 +99,41 @@ init() return false; } + /* initialize Vulkan context (instance) */ + + if (!vk_init_ctx_for_rendering(&vk_core)) { + fprintf(stderr, "Failed to initialize Vulkan context.\n"); + return false; + } + /* create (Xcb) surface */ glfwGetFramebufferSize(win, &win_h, &win_h); - if (glfwCreateWindowSurface(vk_core.inst, win, 0, &vk_swap.surface) + if (glfwCreateWindowSurface(vk_core.inst, win, 0, &vk_surf) != VK_SUCCESS) { fprintf(stderr, "Failed to create XCB surface.\n"); + glfwTerminate(); + return false; } - /* create Vulkan swapchain */ + /* create semaphores */ + vk_create_semaphores(&vk_core, false, &vk_sema); - /* aquire images? */ + /* create swapchain */ + vk_create_swapchain(&vk_core, win_w, win_h, false, vk_surf, VK_NULL_HANDLE, &vk_chain); /* create shaders */ - - /* create semaphores? */ + vsdr = sdr_load("data/main.vert.spv", &vsz); + fsdr = sdr_load("data/main.frag.spv", &fsz); /* create renderer */ + if (!vk_create_renderer(&vk_core, vsdr, vsz, fsdr, fsz, + false, false, 0, 0, + &vk_vert_info, &vk_rnd)) { + fprintf(stderr, "Failed to create renderer.\n"); + return false; + } /* set GLFW callbacks */ @@ -137,7 +156,10 @@ display() static void cleanup() { + vk_destroy_renderer(&vk_core, &vk_rnd); + vk_cleanup_ctx(&vk_core); + glfwTerminate(); }