summaryrefslogtreecommitdiffstats
path: root/src/game.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/game.c b/src/game.c
index f469122..32fe268 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1,4 +1,3 @@
-#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
@@ -8,7 +7,6 @@
#define SDL_MAIN_HANDLED
#define VK_USE_PLATFORM_XCB_KHR
#include <SDL2/SDL.h>
-#include <SDL2/SDL_image.h>
#include <SDL2/SDL_vulkan.h>
#include <vulkan/vulkan.h>
@@ -23,9 +21,6 @@
#include "state.h"
// embedded clgm library
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-#include "../lib/cglm/include/cglm/cglm.h"
-
uint32_t currentFrame = 0;
state_t s;
@@ -727,11 +722,21 @@ vulkan_create_graphics_pipeline()
shaderc_compilation_result_t vert_result = load_compile_shader_data("src/shader.vert", shaderc_vertex_shader);
if (!vert_result) {
vk_log(VK_ERROR, "Can't load vertex shader\n");
+ if (s.prev_vert_result) {
+ vert_result = s.prev_vert_result;
+ }
}
+ if (s.prev_vert_result && vert_result != s.prev_vert_result) shaderc_result_release(s.prev_vert_result);
+ s.prev_vert_result = vert_result;
shaderc_compilation_result_t frag_result = load_compile_shader_data("src/shader.frag", shaderc_fragment_shader);
if (!frag_result) {
vk_log(VK_ERROR, "Can't load fragment shader\n");
+ if (s.prev_frag_result) {
+ frag_result = s.prev_frag_result;
+ }
}
+ if (s.prev_frag_result && frag_result != s.prev_frag_result) shaderc_result_release(s.prev_frag_result);
+ s.prev_frag_result = frag_result;
const char * vert_data = shaderc_result_get_bytes(vert_result);
long vert_size = shaderc_result_get_length(vert_result);
@@ -857,7 +862,7 @@ vulkan_create_graphics_pipeline()
VkPipelineColorBlendStateCreateInfo colorBlending = {0};
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
- colorBlending.logicOpEnable = VK_FALSE;
+ colorBlending.logicOpEnable = VK_TRUE;
colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional
colorBlending.attachmentCount = 1;
colorBlending.pAttachments = &colorBlendAttachment;
@@ -900,8 +905,12 @@ vulkan_create_graphics_pipeline()
vk_log(VK_ERROR, "failed to create graphics pipeline!\n");
}
- shaderc_result_release(vert_result);
- shaderc_result_release(frag_result);
+ if (s.prev_vert_result != vert_result) {
+ shaderc_result_release(vert_result);
+ }
+ if (s.prev_frag_result != frag_result) {
+ shaderc_result_release(frag_result);
+ }
vkDestroyShaderModule(s.vk_device, fragShaderModule, NULL);
vkDestroyShaderModule(s.vk_device, vertShaderModule, NULL);
@@ -1233,7 +1242,8 @@ vulkan_create_descriptor_set_layout()
uboLayoutBinding.binding = 0;
uboLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
uboLayoutBinding.descriptorCount = 1;
- uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
+ uboLayoutBinding.stageFlags = VK_SHADER_STAGE_ALL;
+ //uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
uboLayoutBinding.pImmutableSamplers = NULL; // optional
VkDescriptorSetLayoutCreateInfo layoutInfo = {0};
@@ -1479,6 +1489,13 @@ close_vulkan()
/* DestroyDebugUtilsMessengerEXT(s.vk_instance, s.vk_debug_messenger, NULL); */
/* } */
vkDestroyInstance(s.vk_instance, NULL);
+
+ if (s.prev_vert_result) {
+ shaderc_result_release(s.prev_vert_result);
+ }
+ if (s.prev_frag_result) {
+ shaderc_result_release(s.prev_frag_result);
+ }
}
float
@@ -1504,6 +1521,10 @@ updateUniformBuffer(uint32_t currentImage)
float time = current_time();
UniformBufferObject ubo = {0};
+
+ ubo.resolution[0] = s.vk_swap_chain_extent.width;
+ ubo.resolution[1] = s.vk_swap_chain_extent.height;
+
glm_mat4_identity(ubo.model);
if (s.rotate)
@@ -1627,7 +1648,7 @@ main(int argc, char* args[])
while (!quit) {
handle_input(&quit);
draw_frame();
- //SDL_Delay(16);
+ SDL_Delay(16);
}
close_vulkan();