foo
[vktest3] / src / app.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include "app.h"
5 #include "vk.h"
6
7 int win_width, win_height;
8
9 static int rpass, pipeln, fb;
10 static VkSemaphore sem_getimg, sem_draw;
11 static VkQueue queue;
12
13 int app_init(void)
14 {
15         unsigned int flags;
16
17         if(vk_init(VKINIT_DEPTH, &flags) == -1) {
18                 return -1;
19         }
20
21         if(!(queue = vk_getq(VKQ_GFX | VKQ_PRESENT, 0))) {
22                 return -1;
23         }
24
25         rpass = vk_create_rpass();
26
27         fb = vk_create_fb();
28         vk_fb_size(fb, win_width, win_height);
29         vk_fb_rpass(fb, rpass);
30
31         pipeln = vk_create_pipeln();
32         vk_pipeln_
33
34         sem_getimg = vk_create_sem();
35         sem_draw = vk_create_sem();
36         return 0;
37 }
38
39 void app_cleanup(void)
40 {
41         vk_free_sem(sem_getimg);
42         vk_free_sem(sem_draw);
43         vk_cleanup();
44 }
45
46
47 void app_display(void)
48 {
49         int imgid;
50         VkCommandBuffer cmdbuf;
51
52         /* get the next image from the swap chain */
53         imgid = vk_next_image(sem_getimg);
54         cmdbuf = vk_get_cmdbuf(imgid);
55
56         {
57                 VkCommandBufferBeginInfo cmdbegin = {0};
58                 VkRenderPassBeginInfo rpbegin = {0};
59                 VkClearValue clear;
60
61                 cmdbegin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
62                 cmdbegin.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
63
64                 if(vkBeginCommandBuffer(cmdbuf, &cmdbegin) != 0) {
65                         fprintf(stderr, "failed to begin command buffer recording\n");
66                         abort();
67                 }
68
69                 clear.color.float32[0] = 0.5f;
70                 clear.color.float32[1] = 0.1f;
71                 clear.color.float32[2] = 0.2f;
72                 clear.color.float32[3] = 1.0f;
73
74                 rpbegin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
75                 rpbegin.renderPass = 
76         }
77
78         /* submit the command buffer, wait for one semaphore, signal another */
79         vk_submit(queue, cmdbuf, sem_getimg, sem_draw);
80
81         /* swap buffers after drawing is finished */
82         vk_present(queue, imgid, sem_draw);
83 }
84
85 void app_reshape(int x, int y)
86 {
87         if(vk_reshape(x, y) == -1) {
88                 abort();
89         }
90 }
91
92 void app_keyboard(int key, int press)
93 {
94         if(!press) return;
95
96         switch(key) {
97         case 27:
98                 app_quit();
99                 break;
100         }
101 }
102
103 void app_mouse(int bn, int press, int x, int y)
104 {
105 }
106
107 void app_motion(int x, int y)
108 {
109 }