foo
[vktest3] / src / app.c
index 044a885..ae0a1f1 100644 (file)
--- a/src/app.c
+++ b/src/app.c
@@ -1,8 +1,15 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include "app.h"
 #include "vk.h"
 
+int win_width, win_height;
+
+static int rpass, pipeln, fb;
+static VkSemaphore sem_getimg, sem_draw;
+static VkQueue queue;
+
 int app_init(void)
 {
        unsigned int flags;
@@ -10,17 +17,69 @@ int app_init(void)
        if(vk_init(VKINIT_DEPTH, &flags) == -1) {
                return -1;
        }
+
+       if(!(queue = vk_getq(VKQ_GFX | VKQ_PRESENT, 0))) {
+               return -1;
+       }
+
+       rpass = vk_create_rpass();
+
+       fb = vk_create_fb();
+       vk_fb_size(fb, win_width, win_height);
+       vk_fb_rpass(fb, rpass);
+
+       pipeln = vk_create_pipeln();
+       vk_pipeln_
+
+       sem_getimg = vk_create_sem();
+       sem_draw = vk_create_sem();
        return 0;
 }
 
 void app_cleanup(void)
 {
+       vk_free_sem(sem_getimg);
+       vk_free_sem(sem_draw);
        vk_cleanup();
 }
 
 
 void app_display(void)
 {
+       int imgid;
+       VkCommandBuffer cmdbuf;
+
+       /* get the next image from the swap chain */
+       imgid = vk_next_image(sem_getimg);
+       cmdbuf = vk_get_cmdbuf(imgid);
+
+       {
+               VkCommandBufferBeginInfo cmdbegin = {0};
+               VkRenderPassBeginInfo rpbegin = {0};
+               VkClearValue clear;
+
+               cmdbegin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+               cmdbegin.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
+
+               if(vkBeginCommandBuffer(cmdbuf, &cmdbegin) != 0) {
+                       fprintf(stderr, "failed to begin command buffer recording\n");
+                       abort();
+               }
+
+               clear.color.float32[0] = 0.5f;
+               clear.color.float32[1] = 0.1f;
+               clear.color.float32[2] = 0.2f;
+               clear.color.float32[3] = 1.0f;
+
+               rpbegin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
+               rpbegin.renderPass = 
+       }
+
+       /* submit the command buffer, wait for one semaphore, signal another */
+       vk_submit(queue, cmdbuf, sem_getimg, sem_draw);
+
+       /* swap buffers after drawing is finished */
+       vk_present(queue, imgid, sem_draw);
 }
 
 void app_reshape(int x, int y)