int win_width, win_height;
-static int rpass, pipeln, fb;
+static int rpass, pipeln, *fb, num_swap_img;
static VkSemaphore sem_getimg, sem_draw;
static VkQueue queue;
int app_init(void)
{
+ int i;
unsigned int flags;
if(vk_init(VKINIT_DEPTH, &flags) == -1) {
return -1;
}
+ /* force swapchain creation, to find out how many framebuffers to create */
+ vk_reshape(win_width, win_height);
+ if((num_swap_img = vk_num_swap_images()) <= 0) {
+ return -1;
+ }
+ if(!(fb = malloc(num_swap_img * sizeof *fb))) {
+ return -1;
+ }
+
rpass = vk_create_rpass();
- fb = vk_create_fb();
- vk_fb_size(fb, win_width, win_height);
- vk_fb_rpass(fb, rpass);
+ for(i=0; i<num_swap_img; i++) {
+ fb[i] = vk_create_fb();
+ vk_fb_size(fb[i], win_width, win_height);
+ vk_fb_rpass(fb[i], rpass);
+ vk_fb_images(fb[i], 1, vk_swap_image(i));
+ }
pipeln = vk_create_pipeln();
- vk_pipeln_
+ vk_pipeln_rpass(pipeln, vk_rpass(rpass));
+ vk_pipeln_viewport(pipeln, 0, 0, win_width, win_height);
sem_getimg = vk_create_sem();
sem_draw = vk_create_sem();
VkCommandBuffer cmdbuf;
/* get the next image from the swap chain */
- imgid = vk_next_image(sem_getimg);
+ imgid = vk_next_swap_image(sem_getimg);
cmdbuf = vk_get_cmdbuf(imgid);
{
VkCommandBufferBeginInfo cmdbegin = {0};
VkRenderPassBeginInfo rpbegin = {0};
- VkClearValue clear;
+ VkClearValue clear[2];
cmdbegin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
cmdbegin.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
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;
+ clear[0].color.float32[0] = 0.5f;
+ clear[0].color.float32[1] = 0.1f;
+ clear[0].color.float32[2] = 0.2f;
+ clear[0].color.float32[3] = 1.0f;
+ clear[1].depthStencil.depth = 1.0f;
+ clear[1].depthStencil.stencil = 0;
rpbegin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
- rpbegin.renderPass =
+ rpbegin.renderPass = vk_rpass(rpass);
+ rpbegin.framebuffer = vk_fb(fb[imgid]);
+ vk_rect(&rpbegin.renderArea, 0, 0, win_width, win_height);
+ rpbegin.pClearValues = clear;
+ rpbegin.clearValueCount = 1;
+
+ vkCmdBeginRenderPass(cmdbuf, &rpbegin, VK_SUBPASS_CONTENTS_INLINE);
+
+ /* ... */
+
+ vkCmdEndRenderPass(cmdbuf);
+ vkEndCommandBuffer(cmdbuf);
}
/* submit the command buffer, wait for one semaphore, signal another */
/* swap buffers after drawing is finished */
vk_present(queue, imgid, sem_draw);
+
+ usleep(10000);
}
void app_reshape(int x, int y)
{
+ int i;
+
+ return; /* XXX */
+
if(vk_reshape(x, y) == -1) {
abort();
}
+
+ for(i=0; i<vk_num_swap_images(); i++) {
+ vk_fb_size(fb[i], x, y);
+ vk_fb_images(fb[i], 1, vk_swap_image(i));
+ }
}
void app_keyboard(int key, int press)