vulkan_test2

view src/vkgl.c @ 7:20eb42197ab8

clear color ...
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Jun 2018 05:57:34 +0300
parents
children f8bd29f124a8
line source
1 #include <string.h>
2 #include "vkgl.h"
3 #include "vku.h"
5 static struct vkgl_state {
6 VkClearValue clear;
7 } st;
9 void vkgl_clear_color(float r, float g, float b, float a)
10 {
11 st.clear.color.float32[0] = r;
12 st.clear.color.float32[1] = g;
13 st.clear.color.float32[2] = b;
14 st.clear.color.float32[3] = a;
15 }
17 void vkgl_clear_depth(float z)
18 {
19 st.clear.depthStencil.depth = z;
20 }
22 void vkgl_clear_stencil(int s)
23 {
24 st.clear.depthStencil.stencil = s;
25 }
27 void vkgl_clear(unsigned int flags)
28 {
29 VkImageSubresourceRange wtf;
30 VkSubmitInfo si;
32 memset(&wtf, 0, sizeof wtf);
34 if(flags & VKGL_COLOR_BUFFER_BIT) {
35 wtf.aspectMask |= VK_IMAGE_ASPECT_COLOR_BIT;
36 }
37 if(flags & VKGL_DEPTH_BUFFER_BIT) {
38 wtf.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
39 }
40 if(flags & VKGL_STENCIL_BUFFER_BIT) {
41 wtf.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
42 }
43 wtf.levelCount = 1;
44 wtf.layerCount = 1;
46 vku_begin_cmdbuf(vkcmdbuf, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT);
47 if(flags & VKGL_COLOR_BUFFER_BIT) {
48 vkCmdClearColorImage(vkcmdbuf, swapchain_images[next_swapchain_image],
49 VK_IMAGE_LAYOUT_GENERAL, &st.clear.color, 1, &wtf);
50 }
51 if(flags & (VKGL_DEPTH_BUFFER_BIT | VKGL_STENCIL_BUFFER_BIT)) {
52 vkCmdClearDepthStencilImage(vkcmdbuf, swapchain_images[next_swapchain_image],
53 VK_IMAGE_LAYOUT_GENERAL, &st.clear.depthStencil, 1, &wtf);
54 }
55 vku_end_cmdbuf(vkcmdbuf);
57 memset(&si, 0, sizeof si);
58 si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
59 si.commandBufferCount = 1;
60 si.pCommandBuffers = &vkcmdbuf;
62 vkQueueSubmit(vkq, 1, &si, 0);
63 }