#include <string.h>
#include "vk.h"
+#include "util.h"
/* static glfw callbacks */
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;
+static struct vk_image_attachment vk_color_att;
+static struct vk_image_attachment vk_depth_att;
+static struct vk_image_props vk_depth_att_props;
+
+/* 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)
{
static bool
init()
{
+ char *vsdr, *fsdr;
+
/* initialize GLFW */
if (!glfwInit()) {
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);
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 depth attachment (for the moment we are going to use this
+ * for all images */
+ if (!vk_fill_image_props(&vk_core,
+ win_w, win_h, 1,
+ 1, 1, 1,
+ VK_FORMAT_D24_UNORM_S8_UINT,
+ VK_IMAGE_TILING_OPTIMAL,
+ VK_IMAGE_LAYOUT_UNDEFINED,
+ VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
+ false, &vk_depth_att_props)) {
+ fprintf(stderr, "Unsupported depth image properties\n");
+ return false;
+ }
+ if (!vk_create_image(&vk_core, &vk_depth_att_props, &vk_depth_att.obj)) {
+ fprintf(stderr, "Failed to create depth attachment.\n");
+ return false;
+ }
/* create renderer */
+ if (!vk_create_renderer(&vk_core, vsdr, vsz, fsdr, fsz,
+ false, false, 0, &vk_depth_att,
+ &vk_vert_info, &vk_rnd)) {
+ fprintf(stderr, "Failed to create renderer.\n");
+ return false;
+ }
/* set GLFW callbacks */
static void
cleanup()
{
+ vk_destroy_renderer(&vk_core, &vk_rnd);
+
vk_cleanup_ctx(&vk_core);
+
glfwTerminate();
}