vulkan_test2

annotate src/vkgl.c @ 8:633b522539a1

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