nuclear@7: #include nuclear@7: #include "vkgl.h" nuclear@7: #include "vku.h" nuclear@7: nuclear@7: static struct vkgl_state { nuclear@7: VkClearValue clear; nuclear@7: } st; nuclear@7: nuclear@7: void vkgl_clear_color(float r, float g, float b, float a) nuclear@7: { nuclear@7: st.clear.color.float32[0] = r; nuclear@7: st.clear.color.float32[1] = g; nuclear@7: st.clear.color.float32[2] = b; nuclear@7: st.clear.color.float32[3] = a; nuclear@7: } nuclear@7: nuclear@7: void vkgl_clear_depth(float z) nuclear@7: { nuclear@7: st.clear.depthStencil.depth = z; nuclear@7: } nuclear@7: nuclear@7: void vkgl_clear_stencil(int s) nuclear@7: { nuclear@7: st.clear.depthStencil.stencil = s; nuclear@7: } nuclear@7: nuclear@7: void vkgl_clear(unsigned int flags) nuclear@7: { nuclear@7: VkImageSubresourceRange wtf; nuclear@7: VkSubmitInfo si; nuclear@7: nuclear@7: memset(&wtf, 0, sizeof wtf); nuclear@7: nuclear@7: if(flags & VKGL_COLOR_BUFFER_BIT) { nuclear@7: wtf.aspectMask |= VK_IMAGE_ASPECT_COLOR_BIT; nuclear@7: } nuclear@7: if(flags & VKGL_DEPTH_BUFFER_BIT) { nuclear@7: wtf.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT; nuclear@7: } nuclear@7: if(flags & VKGL_STENCIL_BUFFER_BIT) { nuclear@7: wtf.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; nuclear@7: } nuclear@7: wtf.levelCount = 1; nuclear@7: wtf.layerCount = 1; nuclear@7: nuclear@7: vku_begin_cmdbuf(vkcmdbuf, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT); nuclear@7: if(flags & VKGL_COLOR_BUFFER_BIT) { nuclear@7: vkCmdClearColorImage(vkcmdbuf, swapchain_images[next_swapchain_image], nuclear@7: VK_IMAGE_LAYOUT_GENERAL, &st.clear.color, 1, &wtf); nuclear@7: } nuclear@7: if(flags & (VKGL_DEPTH_BUFFER_BIT | VKGL_STENCIL_BUFFER_BIT)) { nuclear@7: vkCmdClearDepthStencilImage(vkcmdbuf, swapchain_images[next_swapchain_image], nuclear@7: VK_IMAGE_LAYOUT_GENERAL, &st.clear.depthStencil, 1, &wtf); nuclear@7: } nuclear@7: vku_end_cmdbuf(vkcmdbuf); nuclear@7: nuclear@7: memset(&si, 0, sizeof si); nuclear@7: si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; nuclear@7: si.commandBufferCount = 1; nuclear@7: si.pCommandBuffers = &vkcmdbuf; nuclear@7: nuclear@7: vkQueueSubmit(vkq, 1, &si, 0); nuclear@7: }