summaryrefslogtreecommitdiffstats
path: root/src/state.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.h')
-rw-r--r--src/state.h69
1 files changed, 52 insertions, 17 deletions
diff --git a/src/state.h b/src/state.h
index cd5f44e..3890694 100644
--- a/src/state.h
+++ b/src/state.h
@@ -1,29 +1,55 @@
#include <SDL2/SDL.h>
-#include "cq.h"
#include "../lib/cglm/include/cglm/cglm.h"
+#include <vulkan/vulkan.h>
#pragma once
#define MAX_FRAMES_IN_FLIGHT 2
typedef struct {
+ vec3 pos;
+ vec3 front;
+ vec3 up;
+ float yaw;
+ float pitch;
+ float lastX;
+ float lastY;
+ float fov;
+} camera3d;
+
+typedef struct {
mat4 model;
mat4 view;
mat4 proj;
} UniformBufferObject;
typedef struct {
+ VkCommandBuffer vk_command_buffer;
+
+ VkSemaphore image_available_semaphore;
+ VkSemaphore render_finished_semaphore;
+ VkFence in_flight_fence;
+
+ VkBuffer vk_uniform_buffer;
+ VkDeviceMemory vk_uniform_buffer_memory;
+ void * vk_uniform_buffer_mapped;
+ VkDescriptorSet vk_descriptor_set;
} frame_data;
typedef struct state {
+ camera3d camera;
+
int window_w, window_h;
int cell_w, cell_h;
int grid_w, grid_h;
int char_w, char_h;
int char_x, char_y;
+ int rotate;
+ int mouse_pressed;
+
UniformBufferObject ubo;
float x;
@@ -35,7 +61,7 @@ typedef struct state {
VkDebugUtilsMessengerEXT vk_debug_messenger;
PFN_vkCreateDebugUtilsMessengerEXT pfnCreateDebugUtilsMessengerEXT;
PFN_vkDestroyDebugUtilsMessengerEXT pfnDestroyDebugUtilsMessengerEXT;
-
+
VkPhysicalDevice vk_physical_device;
VkDevice vk_device;
VkQueue vk_graphics_queue;
@@ -62,15 +88,8 @@ typedef struct state {
uint32_t vk_swap_chain_framebuffers_count;
VkCommandPool vk_command_pool;
- VkCommandBuffer vk_command_buffers[MAX_FRAMES_IN_FLIGHT];
-
- VkSemaphore imageAvailableSemaphores[MAX_FRAMES_IN_FLIGHT];
- VkSemaphore renderFinishedSemaphores[MAX_FRAMES_IN_FLIGHT];
- VkFence inFlightFences[MAX_FRAMES_IN_FLIGHT];
- VkBuffer vk_uniform_buffers[MAX_FRAMES_IN_FLIGHT];
- VkDeviceMemory vk_uniform_buffers_memory[MAX_FRAMES_IN_FLIGHT];
- void * vk_uniform_buffers_mapped[MAX_FRAMES_IN_FLIGHT];
+ frame_data frames[MAX_FRAMES_IN_FLIGHT];
VkBuffer vk_vertex_buffer;
VkDeviceMemory vk_vertex_buffer_memory;
@@ -79,14 +98,32 @@ typedef struct state {
VkDeviceMemory vk_index_buffer_memory;
VkDescriptorPool vk_descriptor_pool;
- VkDescriptorSet vk_descriptor_sets[MAX_FRAMES_IN_FLIGHT];
-
- LIST test;
} state_t ;
-void
+static void
init_state(state_t * s)
{
+ s->camera.pos[0] = 1.0f;
+ s->camera.pos[1] = 1.0f;
+ s->camera.pos[2] = 1.0f;
+
+ s->camera.front[0] = 0.0f;
+ s->camera.front[1] = 0.0f;
+ s->camera.front[2] = 0.0f;
+
+ s->camera.up[0] = 0.0f;
+ s->camera.up[1] = 0.0f;
+ s->camera.up[2] = 1.0f;
+
+ s->camera.yaw = 0.0f;
+ s->camera.pitch = -90.0f;
+ s->camera.lastX = 400.0f;
+ s->camera.lastY = 300.0f;
+ s->camera.fov = 45.0f;
+
+ s->rotate = 0;
+ s->mouse_pressed = 0;
+
s->window_w = 800;
s->window_h = 600;
s->cell_w = 10;
@@ -100,13 +137,11 @@ init_state(state_t * s)
s->zoom = 10;
s->x = 0.0f;
-
+
s->sdl_window = NULL;
s->vk_swap_chain_image_count = 0;
s->vk_physical_device = VK_NULL_HANDLE;
s->vk_swap_chain_framebuffers_count = 0;
-
- list_init(VkImage *, s->test, 1024);
}