summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-27 23:07:16 +1100
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-27 23:07:16 +1100
commitfe83372519e3ae8dd88ecfb4c67d484a1a5f13af (patch)
tree7c60d8840d457a95a0f01e9e2f0c55971948ce5f
parentff907c6ffa7ed0a7c6ce938b40a6c223dd0a3b9d (diff)
brainsforming refined layout for renderer
-rw-r--r--assets/shaders/triangle.frag4
-rw-r--r--assets/shaders/triangle.vert4
-rw-r--r--src/maths/maths.h6
-rw-r--r--src/platform/file.c50
-rw-r--r--src/platform/file.h6
-rw-r--r--src/renderer/backends/backend_vulkan.c15
-rw-r--r--src/renderer/cleanroom/README.md1
-rw-r--r--src/renderer/cleanroom/types.h63
-rw-r--r--src/renderer/render_types.h3
-rw-r--r--src/std/containers/darray.h3
10 files changed, 109 insertions, 46 deletions
diff --git a/assets/shaders/triangle.frag b/assets/shaders/triangle.frag
index d26e5c4..44c1eb3 100644
--- a/assets/shaders/triangle.frag
+++ b/assets/shaders/triangle.frag
@@ -3,6 +3,4 @@
layout(location = 0) out vec4 out_colour;
-void main() {
- out_colour = vec4(1.0);
-} \ No newline at end of file
+void main() { out_colour = vec4(1.0); } \ No newline at end of file
diff --git a/assets/shaders/triangle.vert b/assets/shaders/triangle.vert
index 0518c62..f253d9b 100644
--- a/assets/shaders/triangle.vert
+++ b/assets/shaders/triangle.vert
@@ -3,6 +3,4 @@
layout(location = 0) in vec3 in_position;
-void main() {
- gl_Position = vec4(in_position, 1.0);
-} \ No newline at end of file
+void main() { gl_Position = vec4(in_position, 1.0); } \ No newline at end of file
diff --git a/src/maths/maths.h b/src/maths/maths.h
index 6816415..db63072 100644
--- a/src/maths/maths.h
+++ b/src/maths/maths.h
@@ -236,3 +236,9 @@ typedef struct u32x3 {
};
} u32x3;
#define u32x3(x, y, z) ((u32x3){ x, y, z })
+
+typedef struct u32x2 {
+ u32 x;
+ u32 y;
+} u32x2;
+#define u32x2(x, y) ((u32x3){ x, y }) \ No newline at end of file
diff --git a/src/platform/file.c b/src/platform/file.c
index ac5014d..6030620 100644
--- a/src/platform/file.c
+++ b/src/platform/file.c
@@ -63,31 +63,31 @@ str8_opt str8_from_file(arena *a, str8 path) {
}
FileData load_spv_file(const char *path) {
- FILE *f = fopen(path, "rb");
- if (f == NULL) {
- perror("Error opening file");
- return (FileData){NULL, 0};
- }
-
- fseek(f, 0, SEEK_END);
- long fsize = ftell(f);
- rewind(f);
-
- char *data = (char *)malloc(fsize);
- if (data == NULL) {
- perror("Memory allocation failed");
- fclose(f);
- return (FileData){NULL, 0};
- }
-
- size_t bytesRead = fread(data, 1, fsize, f);
- if (bytesRead < fsize) {
- perror("Failed to read the entire file");
- free(data);
- fclose(f);
- return (FileData){NULL, 0};
- }
+ FILE *f = fopen(path, "rb");
+ if (f == NULL) {
+ perror("Error opening file");
+ return (FileData){ NULL, 0 };
+ }
+
+ fseek(f, 0, SEEK_END);
+ long fsize = ftell(f);
+ rewind(f);
+ char *data = (char *)malloc(fsize);
+ if (data == NULL) {
+ perror("Memory allocation failed");
fclose(f);
- return (FileData){data, bytesRead};
+ return (FileData){ NULL, 0 };
+ }
+
+ size_t bytesRead = fread(data, 1, fsize, f);
+ if (bytesRead < fsize) {
+ perror("Failed to read the entire file");
+ free(data);
+ fclose(f);
+ return (FileData){ NULL, 0 };
+ }
+
+ fclose(f);
+ return (FileData){ data, bytesRead };
} \ No newline at end of file
diff --git a/src/platform/file.h b/src/platform/file.h
index 83d1317..a8aa8ea 100644
--- a/src/platform/file.h
+++ b/src/platform/file.h
@@ -19,8 +19,8 @@ const char* string_from_file(const char* path);
str8_opt str8_from_file(arena* a, str8 path);
typedef struct {
- char *data;
- size_t size;
+ char* data;
+ size_t size;
} FileData;
-FileData load_spv_file(const char *path); \ No newline at end of file
+FileData load_spv_file(const char* path); \ No newline at end of file
diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c
index c57da9d..d78d4d2 100644
--- a/src/renderer/backends/backend_vulkan.c
+++ b/src/renderer/backends/backend_vulkan.c
@@ -173,20 +173,15 @@ typedef struct vulkan_state {
} vulkan_state;
// pipeline stuff
-bool vulkan_graphics_pipeline_create(
- vulkan_context* context,
- vulkan_renderpass* renderpass,
- u32 attribute_count,
- VkVertexInputAttributeDescription* attributes,
- // ... https://youtu.be/OmPmftW7Kjg?si=qn_777v_ppHKzswK&t=568
-) {
-
-}
+bool vulkan_graphics_pipeline_create(vulkan_context* context, vulkan_renderpass* renderpass,
+ u32 attribute_count,
+ VkVertexInputAttributeDescription* attributes,
+ // ... https://youtu.be/OmPmftW7Kjg?si=qn_777v_ppHKzswK&t=568
+) {}
bool create_shader_module(vulkan_context* context, const char* filename, const char* type_str,
VkShaderStageFlagBits flag, u32 stage_index,
vulkan_shader_stage* shader_stages) {
-
memset(&shader_stages[stage_index].create_info, 0, sizeof(VkShaderModuleCreateInfo));
memset(&shader_stages[stage_index].stage_create_info, 0, sizeof(VkPipelineShaderStageCreateInfo));
diff --git a/src/renderer/cleanroom/README.md b/src/renderer/cleanroom/README.md
new file mode 100644
index 0000000..d510f16
--- /dev/null
+++ b/src/renderer/cleanroom/README.md
@@ -0,0 +1 @@
+# Cleanroom / Re-jig of the renderer structure \ No newline at end of file
diff --git a/src/renderer/cleanroom/types.h b/src/renderer/cleanroom/types.h
new file mode 100644
index 0000000..cd51fca
--- /dev/null
+++ b/src/renderer/cleanroom/types.h
@@ -0,0 +1,63 @@
+#pragma once
+#include "defines.h"
+
+typedef int texture_handle;
+typedef int buffer_handle;
+typedef int model_handle;
+
+/** @brief Texture Description - used by texture creation functions */
+typedef struct texture_desc {
+ // gpu_texture_type tex_type;
+ // gpu_texture_format format;
+ // u32x2 extents;
+} texture_desc;
+
+/*
+ - render_types.h
+ - ral_types.h
+ - ral.h
+ - render.h ?
+*/
+
+/* render_types */
+typedef struct mesh mesh;
+typedef struct model model;
+typedef struct model pbr_material;
+typedef struct model bp_material; // blinn-phong
+
+// Three registers
+// 1. low level graphics api calls "ral"
+// 2. higher level render calls
+// 3. simplified immediate mode API
+
+/* 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);
+void texture_data_upload(texture_handle texture);
+buffer_handle buffer_create(const char* debug_name, u64 size);
+
+// models and meshes are implemented **in terms of the above**
+mesh mesh_create();
+model_handle model_load(const char* filepath);
+
+/* ral.h */
+// backend -- these are not seen by the higher-level code
+void gpu_texture_init();
+void gpu_texture_upload();
+void gpu_buffer_init();
+void gpu_buffer_upload();
+
+// command buffer gubbins
+
+// 3. SIMA (simplified immediate mode api)
+// - dont need to worry about uploading mesh data
+void debug_draw_cuboid();
+void debug_draw_sphere();
+void debug_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/render_types.h b/src/renderer/render_types.h
index 7bb6e60..2cc321c 100644
--- a/src/renderer/render_types.h
+++ b/src/renderer/render_types.h
@@ -8,6 +8,7 @@
#pragma once
#include "darray.h"
+#include "maths.h"
#include "maths_types.h"
#include "str.h"
@@ -178,4 +179,4 @@ typedef enum gpu_texture_format {
TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM,
TEXTURE_FORMAT_DEPTH_DEFAULT,
TEXTURE_FORMAT_COUNT
-} gpu_texture_format;
+} gpu_texture_format; \ No newline at end of file
diff --git a/src/std/containers/darray.h b/src/std/containers/darray.h
index 45d92e2..b15d269 100644
--- a/src/std/containers/darray.h
+++ b/src/std/containers/darray.h
@@ -6,7 +6,8 @@
// COPIED FROM KITC WITH SOME MINOR ADJUSTMENTS
/* TODO:
- - a 'find' function that takes a predicate (maybe wrap with a macro so we dont have to define a new function?)
+ - a 'find' function that takes a predicate (maybe wrap with a macro so we dont have to define a
+ new function?)
*/
#ifndef KITC_TYPED_ARRAY_H