vulkan_test2

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/vkgl.c	Wed Jun 20 05:57:34 2018 +0300
     1.3 @@ -0,0 +1,63 @@
     1.4 +#include <string.h>
     1.5 +#include "vkgl.h"
     1.6 +#include "vku.h"
     1.7 +
     1.8 +static struct vkgl_state {
     1.9 +	VkClearValue clear;
    1.10 +} st;
    1.11 +
    1.12 +void vkgl_clear_color(float r, float g, float b, float a)
    1.13 +{
    1.14 +	st.clear.color.float32[0] = r;
    1.15 +	st.clear.color.float32[1] = g;
    1.16 +	st.clear.color.float32[2] = b;
    1.17 +	st.clear.color.float32[3] = a;
    1.18 +}
    1.19 +
    1.20 +void vkgl_clear_depth(float z)
    1.21 +{
    1.22 +	st.clear.depthStencil.depth = z;
    1.23 +}
    1.24 +
    1.25 +void vkgl_clear_stencil(int s)
    1.26 +{
    1.27 +	st.clear.depthStencil.stencil = s;
    1.28 +}
    1.29 +
    1.30 +void vkgl_clear(unsigned int flags)
    1.31 +{
    1.32 +	VkImageSubresourceRange wtf;
    1.33 +	VkSubmitInfo si;
    1.34 +
    1.35 +	memset(&wtf, 0, sizeof wtf);
    1.36 +
    1.37 +	if(flags & VKGL_COLOR_BUFFER_BIT) {
    1.38 +		wtf.aspectMask |= VK_IMAGE_ASPECT_COLOR_BIT;
    1.39 +	}
    1.40 +	if(flags & VKGL_DEPTH_BUFFER_BIT) {
    1.41 +		wtf.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
    1.42 +	}
    1.43 +	if(flags & VKGL_STENCIL_BUFFER_BIT) {
    1.44 +		wtf.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
    1.45 +	}
    1.46 +	wtf.levelCount = 1;
    1.47 +	wtf.layerCount = 1;
    1.48 +
    1.49 +	vku_begin_cmdbuf(vkcmdbuf, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT);
    1.50 +	if(flags & VKGL_COLOR_BUFFER_BIT) {
    1.51 +		vkCmdClearColorImage(vkcmdbuf, swapchain_images[next_swapchain_image],
    1.52 +				VK_IMAGE_LAYOUT_GENERAL, &st.clear.color, 1, &wtf);
    1.53 +	}
    1.54 +	if(flags & (VKGL_DEPTH_BUFFER_BIT | VKGL_STENCIL_BUFFER_BIT)) {
    1.55 +		vkCmdClearDepthStencilImage(vkcmdbuf, swapchain_images[next_swapchain_image],
    1.56 +				VK_IMAGE_LAYOUT_GENERAL, &st.clear.depthStencil, 1, &wtf);
    1.57 +	}
    1.58 +	vku_end_cmdbuf(vkcmdbuf);
    1.59 +
    1.60 +	memset(&si, 0, sizeof si);
    1.61 +	si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
    1.62 +	si.commandBufferCount = 1;
    1.63 +	si.pCommandBuffers = &vkcmdbuf;
    1.64 +
    1.65 +	vkQueueSubmit(vkq, 1, &si, 0);
    1.66 +}