summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.h3
-rw-r--r--src/defines.h2
-rw-r--r--src/logos/jobs.h3
-rw-r--r--src/renderer/backends/backend_opengl.c4
-rw-r--r--src/renderer/backends/backend_vulkan.c4
-rw-r--r--src/renderer/cleanroom/backend_vulkan.c65
-rw-r--r--src/renderer/cleanroom/backend_vulkan.h27
-rw-r--r--src/renderer/cleanroom/ral.h86
-rw-r--r--src/renderer/cleanroom/renderer.c4
-rw-r--r--src/renderer/cleanroom/renderer.h14
-rw-r--r--src/renderer/cleanroom/simda.h18
-rw-r--r--src/renderer/cleanroom/types.h120
-rw-r--r--src/renderer/render_types.h245
-rw-r--r--src/resources/gltf.c1
-rw-r--r--src/systems/physics.c1
-rw-r--r--src/systems/physics.h33
-rw-r--r--src/systems/screenspace.h2
-rw-r--r--src/systems/text.h4
-rw-r--r--src/transform_hierarchy.c2
-rw-r--r--src/transform_hierarchy.h1
20 files changed, 443 insertions, 196 deletions
diff --git a/src/core.h b/src/core.h
index 05e3aed..68bf957 100644
--- a/src/core.h
+++ b/src/core.h
@@ -2,7 +2,8 @@
#include "defines.h"
#include "input.h"
-#include "render_types.h"
+#include "ral.h"
+// #include "render_types.h"
#include "screenspace.h"
#include "text.h"
#include "threadpool.h"
diff --git a/src/defines.h b/src/defines.h
index 5110f5a..8cd4f98 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -1,6 +1,6 @@
/**
* @file defines.h
- * @brief
+ * @brief Typedefs for common integer/floating point types and very basic macros
* @date 2024-02-24
* @copyright Copyright (c) 2024
*/
diff --git a/src/logos/jobs.h b/src/logos/jobs.h
new file mode 100644
index 0000000..cc2c8fa
--- /dev/null
+++ b/src/logos/jobs.h
@@ -0,0 +1,3 @@
+/**
+ * Common jobs that get run
+*/ \ No newline at end of file
diff --git a/src/renderer/backends/backend_opengl.c b/src/renderer/backends/backend_opengl.c
index b769002..7467416 100644
--- a/src/renderer/backends/backend_opengl.c
+++ b/src/renderer/backends/backend_opengl.c
@@ -6,7 +6,9 @@
#include "file.h"
#include "log.h"
#include "maths_types.h"
-#include "render_types.h"
+// #include "render_types.h"
+#include "cleanroom/types.h"
+#include "ral.h"
#if CEL_REND_BACKEND_OPENGL
diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c
index e0b0e4e..4d3a14e 100644
--- a/src/renderer/backends/backend_vulkan.c
+++ b/src/renderer/backends/backend_vulkan.c
@@ -923,6 +923,10 @@ void vulkan_image_transition_layout(vulkan_context* context, vulkan_command_buff
vulkan_image* image, VkFormat format, VkImageLayout old_layout,
VkImageLayout new_layout) {
VkImageMemoryBarrier barrier = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
+void vulkan_image_transition_layout(vulkan_context* context, vulkan_command_buffer* command_buffer,
+ vulkan_image* image, VkFormat format, VkImageLayout old_layout,
+ VkImageLayout new_layout) {
+ VkImageMemoryBarrier barrier = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
barrier.oldLayout = old_layout;
barrier.newLayout = new_layout;
barrier.srcQueueFamilyIndex = context->device.graphics_queue_index;
diff --git a/src/renderer/cleanroom/backend_vulkan.c b/src/renderer/cleanroom/backend_vulkan.c
new file mode 100644
index 0000000..71a09f3
--- /dev/null
+++ b/src/renderer/cleanroom/backend_vulkan.c
@@ -0,0 +1,65 @@
+#include <stdlib.h>
+#include "ral.h"
+#include "types.h"
+// #include "render_types.h"
+
+#define VULKAN_QUEUES_COUNT 2
+const char* queue_names[VULKAN_QUEUES_COUNT] = { "GRAPHICS", "TRANSFER" };
+
+typedef struct gpu_device {
+} gpu_device;
+
+typedef struct vulkan_context {
+ gpu_device device;
+
+ VkInstance instance;
+
+} vulkan_context;
+
+static vulkan_context context;
+
+static bool select_physical_device(gpu_device* out_device) {}
+
+bool gpu_device_create(gpu_device* out_device) {
+ // Physical device
+ if (!select_physical_device(out_device)) {
+ return false;
+ }
+ INFO("Physical device selected");
+
+ // Logical device
+ VkDeviceQueueCreateInfo queue_create_info[2];
+ //..
+ VkDeviceCreateInfo device_create_info = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
+
+ VkResult result = vkCreateDevice();
+ if (result != VK_SUCCESS) {
+ FATAL("Error creating logical device with status %u\n", result);
+ exit(1);
+ }
+ INFO("Logical device created");
+
+ // Queues
+
+ // Create the command pool
+}
+
+gpu_renderpass* gpu_renderpass_create() {
+ // Allocate it
+ // sets everything up
+ // return pointer to it
+}
+
+void encode_set_pipeline(gpu_cmd_encoder* encoder, pipeline_type kind, gpu_pipeline* pipeline) {
+ // VK_PIPELINE_BIND_POINT_GRAPHICS, &shader->pipeline);
+ if (kind == PIPELINE_GRAPHICS) {
+ // ...
+ } else {
+ // ...
+ }
+}
+
+// --- Drawing
+inline void encode_draw_indexed(gpu_cmd_encoder* encoder, u64 index_count) {
+ vkCmdDrawIndexed(encoder->cmd_buffer, index_count, 1, 0, 0, 0);
+} \ No newline at end of file
diff --git a/src/renderer/cleanroom/backend_vulkan.h b/src/renderer/cleanroom/backend_vulkan.h
new file mode 100644
index 0000000..6798b13
--- /dev/null
+++ b/src/renderer/cleanroom/backend_vulkan.h
@@ -0,0 +1,27 @@
+#pragma once
+#include "cleanroom/ral.h"
+
+#define GPU_SWAPCHAIN_IMG_COUNT 2
+
+typedef struct gpu_swapchain {} gpu_swapchain;
+typedef struct gpu_device {
+ // In Vulkan we store both physical and logical device here
+ VkPhysicalDevice physical_device;
+ VkDevice logical_device;
+ VkPhysicalDeviceProperties properties;
+ VkPhysicalDeviceFeatures features;
+ VkPhysicalDeviceMemoryProperties memory;
+ VkCommandPool pool;
+} gpu_device;
+typedef struct gpu_pipeline {} gpu_pipeline;
+
+typedef struct gpu_renderpass {
+ VkRenderPass vk_handle;
+ VkFramebuffer framebuffers[GPU_SWAPCHAIN_IMG_COUNT];
+ u32
+} gpu_renderpass;
+
+
+typedef struct gpu_cmd_encoder {
+ VkCommandBuffer cmd_buffer;
+} gpu_cmd_encoder; \ No newline at end of file
diff --git a/src/renderer/cleanroom/ral.h b/src/renderer/cleanroom/ral.h
new file mode 100644
index 0000000..a1e9929
--- /dev/null
+++ b/src/renderer/cleanroom/ral.h
@@ -0,0 +1,86 @@
+/**
+ * @file ral.h
+ * @author your name (you@domain.com)
+ * @brief Render Abstraction Layer
+ * @details API that a graphics backend *must* implement
+ * @version 0.1
+ * @date 2024-03-31
+ *
+ * @copyright Copyright (c) 2024
+ *
+ */
+#pragma once
+
+#include "cleanroom/types.h"
+#include "defines.h"
+
+// Forward declare structs
+typedef struct gpu_swapchain gpu_swapchain;
+typedef struct gpu_device gpu_device;
+typedef struct gpu_pipeline gpu_pipeline;
+typedef struct gpu_renderpass gpu_renderpass;
+typedef struct gpu_cmd_encoder gpu_cmd_encoder; // Recording
+typedef struct gpu_cmd_buffer gpu_cmd_buffer; // Ready for submission
+
+enum pipeline_kind {
+ GRAPHICS,
+ COMPUTE,
+} pipeline_kind;
+
+typedef struct shader_desc {
+ const char* debug_name;
+ str8 filepath; // where it came from
+ str8 glsl; // contents
+} shader_desc;
+
+struct pipeline_desc {
+ shader_desc vs; /** @brief Vertex shader stage */
+ shader_desc fs; /** @brief Fragment shader stage */
+};
+
+// lifecycle functions
+gpu_device* gpu_device_create();
+void gpu_device_destroy();
+
+gpu_renderpass* gpu_renderpass_create();
+void gpu_renderpass_destroy(gpu_renderpass* pass);
+
+gpu_pipeline* gpu_pipeline_create(enum pipeline_kind kind, struct pipeline_desc description);
+void gpu_pipeline_destroy(gpu_pipeline* pipeline);
+
+void gpu_cmd_encoder_begin();
+void gpu_cmd_encoder_begin_render();
+void gpu_cmd_encoder_begin_compute();
+
+/* Actual commands that we can encode */
+void encode_buffer_copy(gpu_cmd_encoder* encoder, buffer_handle src, u64 src_offset,
+ buffer_handle dst, u64 dst_offset, u64 copy_size);
+void encode_clear_buffer(gpu_cmd_encoder* encoder, buffer_handle buf);
+void encode_set_pipeline(gpu_cmd_encoder* encoder, gpu_pipeline* pipeline);
+// render pass
+void encode_set_vertex_buffer(gpu_cmd_encoder* encoder, buffer_handle buf);
+void encode_set_index_buffer(gpu_cmd_encoder* encoder, buffer_handle buf);
+void encode_set_bind_group();
+void encode_draw(gpu_cmd_encoder* encoder);
+void encode_draw_indexed(gpu_cmd_encoder* encoder, u64 index_count);
+
+// FUTURE: compute passes
+
+/** @brief Finish recording and return a command buffer that can be submitted to a queue */
+gpu_cmd_buffer gpu_cmd_encoder_finish(gpu_cmd_encoder* encoder);
+
+void gpu_queue_submit(gpu_cmd_buffer* buffer);
+
+// Buffers
+void gpu_buffer_create(u64 size);
+void gpu_buffer_destroy(buffer_handle buffer);
+void gpu_buffer_upload();
+void gpu_buffer_bind(buffer_handle buffer);
+
+// Textures
+void gpu_texture_create();
+void gpu_texture_destroy();
+void gpu_texture_upload();
+
+// Samplers
+void gpu_sampler_create(); \ No newline at end of file
diff --git a/src/renderer/cleanroom/renderer.c b/src/renderer/cleanroom/renderer.c
new file mode 100644
index 0000000..a874664
--- /dev/null
+++ b/src/renderer/cleanroom/renderer.c
@@ -0,0 +1,4 @@
+#include "defines.h"
+#include "render_types.h"
+
+bool renderer_init() {} \ No newline at end of file
diff --git a/src/renderer/cleanroom/renderer.h b/src/renderer/cleanroom/renderer.h
new file mode 100644
index 0000000..8012b49
--- /dev/null
+++ b/src/renderer/cleanroom/renderer.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "cleanroom/ral.h"
+#include "cleanroom/backend_vulkan.h"
+
+typedef struct renderer2 {
+ void* backend_state;
+ gpu_device* device;
+ gpu_pipeline* static_opaque_pipeline;
+} renderer2;
+
+// mesh
+// model
+// material \ No newline at end of file
diff --git a/src/renderer/cleanroom/simda.h b/src/renderer/cleanroom/simda.h
new file mode 100644
index 0000000..d0b4794
--- /dev/null
+++ b/src/renderer/cleanroom/simda.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "maths_types.h"
+
+// 3. SIMA (simplified immediate mode api) / render.h
+// - dont need to worry about uploading mesh data
+// - very useful for debugging
+void imm_draw_cuboid();
+void imm_draw_sphere(vec3 pos, f32 radius, vec4 colour);
+void imm_draw_camera_frustum();
+static void imm_draw_model(
+ const char* model_filepath); // tracks internally whether the model is loaded
+
+static void imm_draw_model(const char* model_filepath) {
+ // check that model is loaded
+ // if not loaded, load model and upload to gpu - LRU cache for models
+ // else submit draw call
+} \ No newline at end of file
diff --git a/src/renderer/cleanroom/types.h b/src/renderer/cleanroom/types.h
index 3f62cab..98c2e21 100644
--- a/src/renderer/cleanroom/types.h
+++ b/src/renderer/cleanroom/types.h
@@ -4,9 +4,13 @@
#include "maths_types.h"
#include "str.h"
-typedef int texture_handle;
-typedef int buffer_handle;
-typedef int model_handle;
+CORE_DEFINE_HANDLE(buffer_handle);
+CORE_DEFINE_HANDLE(texture_handle);
+CORE_DEFINE_HANDLE(sampler_handle);
+CORE_DEFINE_HANDLE(shader_handle);
+CORE_DEFINE_HANDLE(model_handle);
+
+typedef struct transform_hierarchy {} transform_hierarchy;
/** @brief Texture Description - used by texture creation functions */
typedef struct texture_desc {
@@ -47,14 +51,12 @@ typedef enum gpu_texture_format {
} gpu_texture_format;
/* render_types */
-typedef struct mesh mesh;
-typedef struct model model;
typedef struct model pbr_material;
typedef struct model bp_material; // blinn-phong
#include "maths_types.h"
-typedef enum vertex_format { VERTEX_STATIC_3D, VERTEX_SPRITE, VERTEX_COUNT } vertex_format;
+typedef enum vertex_format { VERTEX_STATIC_3D, VERTEX_SPRITE, VERTEX_SKINNED, VERTEX_COUNT } vertex_format;
typedef union vertex {
struct {
@@ -68,7 +70,7 @@ typedef union vertex {
vec2 position;
vec4 colour;
vec2 tex_coords;
- } sprite;
+ } sprite; /** @brief vertex format for 2D sprites or quads */
struct {
vec3 position;
@@ -77,7 +79,7 @@ typedef union vertex {
vec3 normal;
vec4i bone_ids; // Integer vector for bone IDs
vec4 bone_weights; // Weight of each bone's influence
- } animated_3d; /** @brief vertex format for skeletal (animated) geometry in 3D */
+ } skinned_3d; /** @brief vertex format for skeletal (animated) geometry in 3D */
} vertex;
KITC_DECL_TYPED_ARRAY(vertex)
@@ -86,6 +88,7 @@ KITC_DECL_TYPED_ARRAY(u32)
typedef struct geometry_data {
vertex_format format;
vertex_darray vertices;
+ bool has_indices;
u32_darray indices;
} geometry_data;
@@ -105,6 +108,7 @@ C side - reload_model():
*/
+// TODO: move to some sort of render layer (not inside the abstraction layer)
typedef struct model {
str8 debug_name;
mesh* meshes;
@@ -122,79 +126,57 @@ typedef struct model {
// 2 - you need to know how the overall renderer is designed
// 1 - you need to understand graphics API specifics
-/* render.h */
-// frontend -- these can be called from say a loop in an example, or via FFI
-texture_handle texture_create(const char* debug_name, texture_desc description, const u8* data);
+/* ral.h */
-void texture_data_upload(texture_handle texture);
-buffer_handle buffer_create(const char* debug_name, u64 size);
-bool buffer_destroy(buffer_handle buffer);
-// models and meshes are implemented **in terms of the above**
-mesh mesh_create(geometry_data* geometry);
-model_handle model_load(const char* debug_name, const char* filepath);
+// command buffer gubbins
-/* ral.h */
+/* --- Backends */
-enum pipeline_type {
- GRAPHICS,
- COMPUTE,
-} pipeline_type;
+// struct vulkan_backend {
+// gpu_pipeline static_opaque_pipeline;
+// gpu_pipeline skinned_opaque_pipeline;
+// };
-// backend -- these are not seen by the higher-level code
-typedef struct gpu_swapchain gpu_swapchain;
-typedef struct gpu_device gpu_device;
-typedef struct gpu_pipeline gpu_pipeline;
-typedef struct gpu_cmd_encoder gpu_cmd_encoder;
-typedef struct gpu_cmd_buffer gpu_cmd_buffer; // Ready for submission
+/* --- Renderer layer */
+/* render.h */
-void gpu_cmd_encoder_begin();
-void gpu_cmd_encoder_begin_render();
-void gpu_cmd_encoder_begin_compute();
+typedef struct renderer {
+ void* backend_context;
+} renderer;
-/* Actual commands that we can encode */
-void encode_buffer_copy(gpu_cmd_encoder* encoder, buffer_handle src, u64 src_offset,
- buffer_handle dst, u64 dst_offset, u64 copy_size);
-void encode_clear_buffer(gpu_cmd_encoder* encoder, buffer_handle buf);
-// render pass
-void encode_set_vertex_buffer(gpu_cmd_encoder* encoder, buffer_handle buf);
-void encode_set_index_buffer(gpu_cmd_encoder* encoder, buffer_handle buf);
-void encode_draw_indexed(gpu_cmd_encoder* encoder, u64 index_count, u64* indices);
+bool renderer_init(renderer* ren);
+void renderer_shutdown(renderer* ren);
-// FUTURE: compute passes
+// frontend -- these can be called from say a loop in an example, or via FFI
+texture_handle texture_create(const char* debug_name, texture_desc description, const u8* data);
-/** @brief Finish recording and return a command buffer that can be submitted to a queue */
-gpu_cmd_buffer gpu_cmd_encoder_finish(gpu_cmd_encoder* encoder);
+// Frontend Resources
+void texture_data_upload(texture_handle texture);
+buffer_handle buffer_create(const char* debug_name, u64 size);
+bool buffer_destroy(buffer_handle buffer);
+sampler_handle sampler_create();
-void gpu_queue_submit(gpu_cmd_buffer* buffer);
+void shader_hot_reload(const char* filepath);
-// Buffers
-void gpu_buffer_create(u64 size);
-void gpu_buffer_destroy(buffer_handle buffer);
-void gpu_buffer_upload();
-void gpu_buffer_bind(buffer_handle buffer);
+// models and meshes are implemented **in terms of the above**
+mesh mesh_create(geometry_data* geometry);
+model_handle model_load(const char* debug_name, const char* filepath);
-// Textures
-void gpu_texture_create();
-void gpu_texture_destroy();
-void gpu_texture_upload();
+// Drawing
-// Samplers
-void gpu_sampler_create();
+// void draw_mesh(gpu_cmd_encoder* encoder, mesh* mesh) {
+// encode_set_vertex_buffer(encoder, mesh->vertex_buffer);
+// encode_set_index_buffer(encoder, mesh->index_buffer);
+// encode_draw_indexed(encoder, mesh->index_count)
+// // vkCmdDrawIndexed
+// }
-// command buffer gubbins
+// void draw_scene(arena* frame, model_darray* models, renderer* ren, camera* camera,
+// transform_hierarchy* tfh, scene* scene) {
+// // set the pipeline first
+// encode_set_pipeline()
+// // in open this sets the shader
+// // in vulkan it sets the whole pipeline
-// 3. SIMA (simplified immediate mode api) / render.h
-// - dont need to worry about uploading mesh data
-// - very useful for debugging
-void imm_draw_cuboid();
-void imm_draw_sphere(vec3 pos, f32 radius, vec4 colour);
-void imm_draw_camera_frustum();
-static void imm_draw_model(
- const char* model_filepath); // tracks internally whether the model is loaded
-
-static void imm_draw_model(const char* model_filepath) {
- // check that model is loaded
- // if not loaded, load model and upload to gpu - LRU cache for models
- // else submit draw call
-} \ No newline at end of file
+// } \ No newline at end of file
diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h
index 423b58f..387ac81 100644
--- a/src/renderer/render_types.h
+++ b/src/renderer/render_types.h
@@ -1,11 +1,11 @@
-/**
- * @file render_types.h
- * @author Omniscient
- * @brief Type definitions for the majority of data required by the renderer system
- * @date 2024-02-24
- *
- */
-#pragma once
+// /**
+// * @file render_types.h
+// * @author Omniscient
+// * @brief Type definitions for the majority of data required by the renderer system
+// * @date 2024-02-24
+// *
+// */
+// #pragma once
#include "animation.h"
#include "darray.h"
@@ -13,33 +13,33 @@
#include "maths_types.h"
#include "str.h"
-struct GLFWwindow;
+// struct GLFWwindow;
-#define MAX_MATERIAL_NAME_LEN 256
-#define MAX_TEXTURE_NAME_LEN 256
+// #define MAX_MATERIAL_NAME_LEN 256
+// #define MAX_TEXTURE_NAME_LEN 256
-#ifndef RESOURCE_HANDLE_DEFS
-CORE_DEFINE_HANDLE(model_handle);
-#define ABSENT_MODEL_HANDLE 999999999
-CORE_DEFINE_HANDLE(texture_handle);
-#define RESOURCE_HANDLE_DEFS
-#endif
+// #ifndef RESOURCE_HANDLE_DEFS
+// // CORE_DEFINE_HANDLE(model_handle);
+// #define ABSENT_MODEL_HANDLE 999999999
+// // CORE_DEFINE_HANDLE(texture_handle);
+// #define RESOURCE_HANDLE_DEFS
+// #endif
-/* @brief Opaque wrapper around a shader program */
-typedef struct shader {
- u32 program_id;
-} shader;
+// /* @brief Opaque wrapper around a shader program */
+// typedef struct shader {
+// u32 program_id;
+// } shader;
-/** @brief configuration passed to the renderer at init time */
-typedef struct renderer_config {
- char window_name[256];
- u32 scr_width, scr_height;
- vec3 clear_colour; /** colour that the screen gets cleared to every frame */
-} renderer_config;
+// /** @brief configuration passed to the renderer at init time */
+// typedef struct renderer_config {
+// char window_name[256];
+// u32 scr_width, scr_height;
+// vec3 clear_colour; /** colour that the screen gets cleared to every frame */
+// } renderer_config;
-typedef struct frame_stats {
- u64 last_time;
-} frame_stats;
+// typedef struct frame_stats {
+// u64 last_time;
+// } frame_stats;
typedef struct renderer {
struct GLFWwindow *window; /** Currently all platforms use GLFW*/
@@ -50,7 +50,7 @@ typedef struct renderer {
shader skinned;
} renderer;
-// --- Lighting & Materials
+// // --- Lighting & Materials
typedef struct texture {
u32 texture_id;
@@ -63,24 +63,24 @@ typedef struct texture {
u32 channel_type;
} texture;
-typedef struct blinn_phong_material {
- char name[MAX_MATERIAL_NAME_LEN];
- texture diffuse_texture;
- char diffuse_tex_path[256];
- texture specular_texture;
- char specular_tex_path[256];
- vec3 ambient_colour;
- vec3 diffuse;
- vec3 specular;
- f32 spec_exponent;
- bool is_loaded;
- bool is_uploaded;
-} blinn_phong_material;
-typedef blinn_phong_material material; // when we start using PBR, this will no longer be the case
-
-// the default blinn-phong material. MUST be initialised with the function below
-extern material DEFAULT_MATERIAL;
-void default_material_init();
+// typedef struct blinn_phong_material {
+// char name[MAX_MATERIAL_NAME_LEN];
+// texture diffuse_texture;
+// char diffuse_tex_path[256];
+// texture specular_texture;
+// char specular_tex_path[256];
+// vec3 ambient_colour;
+// vec3 diffuse;
+// vec3 specular;
+// f32 spec_exponent;
+// bool is_loaded;
+// bool is_uploaded;
+// } blinn_phong_material;
+// typedef blinn_phong_material material; // when we start using PBR, this will no longer be the case
+
+// // the default blinn-phong material. MUST be initialised with the function below
+// extern material DEFAULT_MATERIAL;
+// void default_material_init();
#ifndef TYPED_MATERIAL_ARRAY
KITC_DECL_TYPED_ARRAY(material) // creates "material_darray"
@@ -92,33 +92,33 @@ KITC_DECL_TYPED_ARRAY(animation_clip) // creates "material_darray"
#define TYPED_ANIMATION_CLIP_ARRAY
#endif
-// lights
-typedef struct point_light {
- vec3 position;
- f32 constant, linear, quadratic;
- vec3 ambient;
- vec3 diffuse;
- vec3 specular;
-} point_light;
-
-typedef struct directional_light {
- vec3 direction;
- vec3 ambient;
- vec3 diffuse;
- vec3 specular;
-} directional_light;
-
-void point_light_upload_uniforms(shader shader, point_light *light, char index);
-void dir_light_upload_uniforms(shader shader, directional_light *light);
-
-// --- Models & Meshes
-
-/** @brief Vertex format for a static mesh */
-typedef struct vertex {
- vec3 position;
- vec3 normal;
- vec2 uv;
-} vertex;
+// // lights
+// typedef struct point_light {
+// vec3 position;
+// f32 constant, linear, quadratic;
+// vec3 ambient;
+// vec3 diffuse;
+// vec3 specular;
+// } point_light;
+
+// typedef struct directional_light {
+// vec3 direction;
+// vec3 ambient;
+// vec3 diffuse;
+// vec3 specular;
+// } directional_light;
+
+// void point_light_upload_uniforms(shader shader, point_light *light, char index);
+// void dir_light_upload_uniforms(shader shader, directional_light *light);
+
+// // --- Models & Meshes
+
+// /** @brief Vertex format for a static mesh */
+// typedef struct vertex {
+// vec3 position;
+// vec3 normal;
+// vec2 uv;
+// } vertex;
typedef struct vertex_bone_data {
vec4u joints; /** @brief 4 indices of joints that influence vectors position */
@@ -146,10 +146,10 @@ typedef struct mesh {
u32 vbo, vao; /** OpenGL data. TODO: dont leak OpenGL details */
} mesh;
-#ifndef TYPED_MESH_ARRAY
-KITC_DECL_TYPED_ARRAY(mesh) // creates "mesh_darray"
-#define TYPED_MESH_ARRAY
-#endif
+// #ifndef TYPED_MESH_ARRAY
+// KITC_DECL_TYPED_ARRAY(mesh) // creates "mesh_darray"
+// #define TYPED_MESH_ARRAY
+// #endif
typedef struct model {
str8 name;
@@ -162,43 +162,48 @@ typedef struct model {
bool is_uploaded;
} model;
-#ifndef TYPED_MODEL_ARRAY
-KITC_DECL_TYPED_ARRAY(model) // creates "model_darray"
-#define TYPED_MODEL_ARRAY
-#endif
-
-// --- Scene
-
-// NOTE: This struct won't stay like this for a long time. It's somewhat temporary
-// in order to get a basic scene working without putting burden on the caller of
-// draw_model()
-typedef struct scene {
- directional_light dir_light;
- point_light point_lights[4];
- size_t n_point_lights;
-} scene;
-
-// --- Graphics API related
-
-typedef enum cel_primitive_topology {
- CEL_PRIMITIVE_TOPOLOGY_POINT,
- CEL_PRIMITIVE_TOPOLOGY_LINE,
- CEL_PRIMITIVE_TOPOLOGY_LINE_STRIP,
- CEL_PRIMITIVE_TOPOLOGY_TRIANGLE,
- CEL_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
- CEL_PRIMITIVE_TOPOLOGY_COUNT
-} cel_primitive_topology;
-
-typedef enum gpu_texture_type {
- TEXTURE_TYPE_2D,
- TEXTURE_TYPE_3D,
- TEXTURE_TYPE_2D_ARRAY,
- TEXTURE_TYPE_CUBE_MAP,
- TEXTURE_TYPE_COUNT
-} gpu_texture_type;
-
-typedef enum gpu_texture_format {
- TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM,
- TEXTURE_FORMAT_DEPTH_DEFAULT,
- TEXTURE_FORMAT_COUNT
-} gpu_texture_format; \ No newline at end of file
+// #ifndef TYPED_MODEL_ARRAY
+// KITC_DECL_TYPED_ARRAY(model) // creates "model_darray"
+// #define TYPED_MODEL_ARRAY
+// #endif
+
+// // --- Scene
+
+// // NOTE: This struct won't stay like this for a long time. It's somewhat temporary
+// // in order to get a basic scene working without putting burden on the caller of
+// // draw_model()
+// typedef struct scene {
+// directional_light dir_light;
+// point_light point_lights[4];
+// size_t n_point_lights;
+// } scene;
+
+// // --- Graphics API related
+
+// // typedef enum cel_primitive_topology {
+// // CEL_PRIMITIVE_TOPOLOGY_POINT,
+// // CEL_PRIMITIVE_TOPOLOGY_LINE,
+// // CEL_PRIMITIVE_TOPOLOGY_LINE_STRIP,
+// // CEL_PRIMITIVE_TOPOLOGY_TRIANGLE,
+// // CEL_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
+// // CEL_PRIMITIVE_TOPOLOGY_COUNT
+// // } cel_primitive_topology;
+
+// // typedef enum gpu_texture_type {
+// // TEXTURE_TYPE_2D,
+// // TEXTURE_TYPE_3D,
+// // TEXTURE_TYPE_2D_ARRAY,
+// // TEXTURE_TYPE_CUBE_MAP,
+// // TEXTURE_TYPE_COUNT
+// // } gpu_texture_type;
+
+// // typedef enum gpu_texture_format {
+// // TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM,
+// // TEXTURE_FORMAT_DEPTH_DEFAULT,
+// // TEXTURE_FORMAT_COUNT
+// // } gpu_texture_format;
+
+// // typedef enum pipeline_kind {
+// // GRAPHICS,
+// // COMPUTE,
+// // } pipeline_kind; \ No newline at end of file
diff --git a/src/resources/gltf.c b/src/resources/gltf.c
index 7668a49..81992d1 100644
--- a/src/resources/gltf.c
+++ b/src/resources/gltf.c
@@ -18,7 +18,6 @@
#define CGLTF_IMPLEMENTATION
#include <cgltf.h>
-// TODO: Port code from old repo
struct face {
cgltf_uint indices[3];
diff --git a/src/systems/physics.c b/src/systems/physics.c
new file mode 100644
index 0000000..299c0c1
--- /dev/null
+++ b/src/systems/physics.c
@@ -0,0 +1 @@
+#include "physics.h" \ No newline at end of file
diff --git a/src/systems/physics.h b/src/systems/physics.h
new file mode 100644
index 0000000..5c96c6e
--- /dev/null
+++ b/src/systems/physics.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "maths_types.h"
+
+// 'system' means that it gets called per frame
+
+typedef struct physics_settings {
+ f32 gravity_strength;
+} physics_settings;
+
+enum collider_type {
+ cuboid_collider,
+ sphere_collider,
+};
+
+/** @brief generic collider structure */
+typedef struct physics_collider {
+ u64 id; // ? Replace with handle?
+ enum collider_type shape;
+ transform transform;
+ u8 layer;
+ bool on_ground;
+} physics_collider;
+
+typedef struct physics_world {
+ physics_settings settings;
+} physics_world;
+
+physics_world physics_init(physics_settings settings);
+void physics_shutdown(physics_world* phys_world);
+
+/** @brief perform one or more simulation steps */
+void physics_system_update(physics_world* phys_world, f64 deltatime); \ No newline at end of file
diff --git a/src/systems/screenspace.h b/src/systems/screenspace.h
index 2250847..f513148 100644
--- a/src/systems/screenspace.h
+++ b/src/systems/screenspace.h
@@ -37,7 +37,7 @@ KITC_DECL_TYPED_ARRAY(draw_cmd)
typedef struct screenspace_state {
u32 rect_vbo;
u32 rect_vao;
- shader rect_shader;
+ // shader rect_shader;
draw_cmd_darray* draw_cmd_buf;
} screenspace_state;
diff --git a/src/systems/text.h b/src/systems/text.h
index 19248a6..4fac0b8 100644
--- a/src/systems/text.h
+++ b/src/systems/text.h
@@ -5,9 +5,11 @@
#include <stb_truetype.h>
+#include "cleanroom/types.h"
#include "darray.h"
#include "defines.h"
#include "render_types.h"
+#include "ral.h"
struct core;
@@ -29,7 +31,7 @@ KITC_DECL_TYPED_ARRAY(draw_text_packet)
typedef struct text_system_state {
font default_font;
- shader glyph_shader;
+ shader_handle glyph_shader;
u32 glyph_vbo;
u32 glyph_vao;
draw_text_packet_darray *draw_cmd_buf;
diff --git a/src/transform_hierarchy.c b/src/transform_hierarchy.c
index f1c859a..2f2ff01 100644
--- a/src/transform_hierarchy.c
+++ b/src/transform_hierarchy.c
@@ -11,7 +11,7 @@
#include "log.h"
#include "maths.h"
#include "maths_types.h"
-#include "render_types.h"
+// #include "render_types.h"
struct transform_hierarchy {
transform_node root;
diff --git a/src/transform_hierarchy.h b/src/transform_hierarchy.h
index af77ee1..d77b846 100644
--- a/src/transform_hierarchy.h
+++ b/src/transform_hierarchy.h
@@ -5,6 +5,7 @@
#include "maths_types.h"
#include "render_types.h"
+#include "ral.h"
#define MAX_TF_NODE_CHILDREN \
32 /** TEMP: Make it simpler to manage children in `transform_node`s */