vulkan_test2

changeset 7:20eb42197ab8

clear color ...
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Jun 2018 05:57:34 +0300
parents 1dd2c7398afc
children 633b522539a1 8eb3126cc2f1
files src/main.c src/vkgl.c src/vkgl.h src/vku.h src/wsys_x11.c
diffstat 5 files changed, 86 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/main.c	Fri Sep 22 18:13:03 2017 +0300
     1.2 +++ b/src/main.c	Wed Jun 20 05:57:34 2018 +0300
     1.3 @@ -1,6 +1,7 @@
     1.4  #include <stdio.h>
     1.5  #include "wsys.h"
     1.6  #include "vku.h"
     1.7 +#include "vkgl.h"
     1.8  
     1.9  static void display(void);
    1.10  static void reshape(int x, int y);
    1.11 @@ -30,6 +31,9 @@
    1.12  
    1.13  static void display(void)
    1.14  {
    1.15 +	vkgl_clear_color(1, 0, 0, 1);
    1.16 +	vkgl_clear(VKGL_COLOR_BUFFER_BIT);
    1.17 +
    1.18  	wsys_swap_buffers();
    1.19  }
    1.20  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/vkgl.c	Wed Jun 20 05:57:34 2018 +0300
     2.3 @@ -0,0 +1,63 @@
     2.4 +#include <string.h>
     2.5 +#include "vkgl.h"
     2.6 +#include "vku.h"
     2.7 +
     2.8 +static struct vkgl_state {
     2.9 +	VkClearValue clear;
    2.10 +} st;
    2.11 +
    2.12 +void vkgl_clear_color(float r, float g, float b, float a)
    2.13 +{
    2.14 +	st.clear.color.float32[0] = r;
    2.15 +	st.clear.color.float32[1] = g;
    2.16 +	st.clear.color.float32[2] = b;
    2.17 +	st.clear.color.float32[3] = a;
    2.18 +}
    2.19 +
    2.20 +void vkgl_clear_depth(float z)
    2.21 +{
    2.22 +	st.clear.depthStencil.depth = z;
    2.23 +}
    2.24 +
    2.25 +void vkgl_clear_stencil(int s)
    2.26 +{
    2.27 +	st.clear.depthStencil.stencil = s;
    2.28 +}
    2.29 +
    2.30 +void vkgl_clear(unsigned int flags)
    2.31 +{
    2.32 +	VkImageSubresourceRange wtf;
    2.33 +	VkSubmitInfo si;
    2.34 +
    2.35 +	memset(&wtf, 0, sizeof wtf);
    2.36 +
    2.37 +	if(flags & VKGL_COLOR_BUFFER_BIT) {
    2.38 +		wtf.aspectMask |= VK_IMAGE_ASPECT_COLOR_BIT;
    2.39 +	}
    2.40 +	if(flags & VKGL_DEPTH_BUFFER_BIT) {
    2.41 +		wtf.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
    2.42 +	}
    2.43 +	if(flags & VKGL_STENCIL_BUFFER_BIT) {
    2.44 +		wtf.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
    2.45 +	}
    2.46 +	wtf.levelCount = 1;
    2.47 +	wtf.layerCount = 1;
    2.48 +
    2.49 +	vku_begin_cmdbuf(vkcmdbuf, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT);
    2.50 +	if(flags & VKGL_COLOR_BUFFER_BIT) {
    2.51 +		vkCmdClearColorImage(vkcmdbuf, swapchain_images[next_swapchain_image],
    2.52 +				VK_IMAGE_LAYOUT_GENERAL, &st.clear.color, 1, &wtf);
    2.53 +	}
    2.54 +	if(flags & (VKGL_DEPTH_BUFFER_BIT | VKGL_STENCIL_BUFFER_BIT)) {
    2.55 +		vkCmdClearDepthStencilImage(vkcmdbuf, swapchain_images[next_swapchain_image],
    2.56 +				VK_IMAGE_LAYOUT_GENERAL, &st.clear.depthStencil, 1, &wtf);
    2.57 +	}
    2.58 +	vku_end_cmdbuf(vkcmdbuf);
    2.59 +
    2.60 +	memset(&si, 0, sizeof si);
    2.61 +	si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
    2.62 +	si.commandBufferCount = 1;
    2.63 +	si.pCommandBuffers = &vkcmdbuf;
    2.64 +
    2.65 +	vkQueueSubmit(vkq, 1, &si, 0);
    2.66 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/vkgl.h	Wed Jun 20 05:57:34 2018 +0300
     3.3 @@ -0,0 +1,15 @@
     3.4 +#ifndef VKGL_H_
     3.5 +#define VKGL_H_
     3.6 +
     3.7 +enum {
     3.8 +	VKGL_COLOR_BUFFER_BIT = 1,
     3.9 +	VKGL_DEPTH_BUFFER_BIT = 2,
    3.10 +	VKGL_STENCIL_BUFFER_BIT = 4
    3.11 +};
    3.12 +
    3.13 +void vkgl_clear_color(float r, float g, float b, float a);
    3.14 +void vkgl_clear_depth(float z);
    3.15 +void vkgl_clear_stencil(int s);
    3.16 +void vkgl_clear(unsigned int flags);
    3.17 +
    3.18 +#endif	/* VKGL_H_ */
     4.1 --- a/src/vku.h	Fri Sep 22 18:13:03 2017 +0300
     4.2 +++ b/src/vku.h	Wed Jun 20 05:57:34 2018 +0300
     4.3 @@ -13,6 +13,10 @@
     4.4  VkCommandPool vkcmdpool;
     4.5  VkCommandBuffer vkcmdbuf;	/* primary command buffer */
     4.6  
     4.7 +VkImage *swapchain_images;
     4.8 +int next_swapchain_image;
     4.9 +
    4.10 +
    4.11  struct vku_buffer {
    4.12  	VkBuffer buf;
    4.13  	VkDeviceMemory mem_pool;
     5.1 --- a/src/wsys_x11.c	Fri Sep 22 18:13:03 2017 +0300
     5.2 +++ b/src/wsys_x11.c	Wed Jun 20 05:57:34 2018 +0300
     5.3 @@ -26,8 +26,6 @@
     5.4  static Window win;
     5.5  static VkSurfaceKHR surf;
     5.6  static VkSwapchainKHR swapchain;
     5.7 -static VkImage *swapchain_images;
     5.8 -static int next_swapchain_image;
     5.9  static Atom xa_wm_delete;
    5.10  static int win_width, win_height;
    5.11  static int win_mapped;