diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-04-27 12:00:37 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-04-27 12:00:37 +1000 |
commit | d6837defc03e431517f6616ec8e49a8eb3643011 (patch) | |
tree | 14e6685c86d268dfc08f3f831e7ee9b19efc60e0 | |
parent | 8dae0a94059bd21a5a10e4434cadc843126d8b05 (diff) |
Start moving more files to using ral.h
-rw-r--r-- | examples/transforms/ex_transforms.c | 2 | ||||
-rw-r--r-- | src/core.h | 3 | ||||
-rw-r--r-- | src/renderer/backends/backend_opengl.c | 6 | ||||
-rw-r--r-- | src/renderer/backends/backend_vulkan.c | 62 | ||||
-rw-r--r-- | src/renderer/cleanroom/backend_vulkan.c | 16 | ||||
-rw-r--r-- | src/renderer/cleanroom/ral.h | 23 | ||||
-rw-r--r-- | src/renderer/cleanroom/renderer.c | 6 | ||||
-rw-r--r-- | src/renderer/cleanroom/renderer.h | 6 | ||||
-rw-r--r-- | src/renderer/cleanroom/types.h | 24 | ||||
-rw-r--r-- | src/renderer/render_types.h | 378 | ||||
-rw-r--r-- | src/resources/gltf.c | 3 | ||||
-rw-r--r-- | src/systems/screenspace.h | 2 | ||||
-rw-r--r-- | src/systems/text.h | 4 | ||||
-rw-r--r-- | src/transform_hierarchy.c | 2 | ||||
-rw-r--r-- | src/transform_hierarchy.h | 1 |
15 files changed, 277 insertions, 261 deletions
diff --git a/examples/transforms/ex_transforms.c b/examples/transforms/ex_transforms.c index 689c49d..fc225b4 100644 --- a/examples/transforms/ex_transforms.c +++ b/examples/transforms/ex_transforms.c @@ -5,7 +5,7 @@ #include "maths_types.h" #include "mem.h" #include "render.h" -#include "render_types.h" +// #include "render_types.h" #include "transform_hierarchy.h" const vec3 pointlight_positions[4] = { @@ -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/renderer/backends/backend_opengl.c b/src/renderer/backends/backend_opengl.c index a9f7482..ffeb051 100644 --- a/src/renderer/backends/backend_opengl.c +++ b/src/renderer/backends/backend_opengl.c @@ -5,7 +5,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 @@ -60,7 +62,7 @@ void clear_screen(vec3 colour) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } -void texture_data_upload(texture* tex) { +void texture_data_upload(texture *tex) { printf("Texture name %s\n", tex->name); TRACE("Upload texture data"); u32 texture_id; diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c index 9d0ef51..4a4b09e 100644 --- a/src/renderer/backends/backend_vulkan.c +++ b/src/renderer/backends/backend_vulkan.c @@ -867,15 +867,10 @@ void vulkan_image_view_create(vulkan_context* context, VkFormat format, vulkan_i &image->view); } -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}; +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; @@ -892,12 +887,14 @@ void vulkan_image_transition_layout( VkPipelineStageFlags source_stage; VkPipelineStageFlags dest_stage; - if (old_layout == VK_IMAGE_LAYOUT_UNDEFINED && new_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { + if (old_layout == VK_IMAGE_LAYOUT_UNDEFINED && + new_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { barrier.srcAccessMask = 0; barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; source_stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; dest_stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; - } else if (old_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && new_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { + } else if (old_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && + new_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; source_stage = VK_PIPELINE_STAGE_TRANSFER_BIT; @@ -907,14 +904,12 @@ void vulkan_image_transition_layout( return; } - vkCmdPipelineBarrier(command_buffer->handle, source_stage, dest_stage, 0, 0, 0, 0, 0, 1, &barrier); + vkCmdPipelineBarrier(command_buffer->handle, source_stage, dest_stage, 0, 0, 0, 0, 0, 1, + &barrier); } -void vulkan_image_copy_from_buffer( - vulkan_image* image, - VkBuffer buffer, - vulkan_command_buffer* command_buffer -) { +void vulkan_image_copy_from_buffer(vulkan_image* image, VkBuffer buffer, + vulkan_command_buffer* command_buffer) { VkBufferImageCopy region; region.bufferOffset = 0; region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -925,7 +920,8 @@ void vulkan_image_copy_from_buffer( region.imageExtent.height = image->height; region.imageExtent.depth = 1; - vkCmdCopyBufferToImage(command_buffer->handle, buffer, image->handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + vkCmdCopyBufferToImage(command_buffer->handle, buffer, image->handle, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); } void vulkan_image_create(vulkan_context* context, VkImageType image_type, u32 width, u32 height, @@ -1755,27 +1751,35 @@ void texture_data_upload(texture* tex) { VkFormat image_format = VK_FORMAT_R8G8B8A8_SNORM; VkBufferUsageFlags usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; - VkMemoryPropertyFlags memory_prop_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + VkMemoryPropertyFlags memory_prop_flags = + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; vulkan_buffer staging; vulkan_buffer_create(&context, image_size, usage, memory_prop_flags, true, &staging); vulkan_buffer_load_data(&context, &staging, 0, image_size, 0, tex->image_data); - vulkan_image_create(&context, VK_IMAGE_TYPE_2D, tex->width, tex->height, image_format, VK_IMAGE_TILING_OPTIMAL, - VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT - , VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, true, VK_IMAGE_ASPECT_COLOR_BIT, &data->image); + vulkan_image_create( + &context, VK_IMAGE_TYPE_2D, tex->width, tex->height, image_format, VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | + VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, true, VK_IMAGE_ASPECT_COLOR_BIT, &data->image); vulkan_command_buffer temp_buffer; - vulkan_command_buffer_allocate_and_begin_oneshot(&context, context.device.gfx_command_pool, &temp_buffer); + vulkan_command_buffer_allocate_and_begin_oneshot(&context, context.device.gfx_command_pool, + &temp_buffer); - vulkan_image_transition_layout(&context, &temp_buffer, &data->image, image_format, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + vulkan_image_transition_layout(&context, &temp_buffer, &data->image, image_format, + VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); vulkan_image_copy_from_buffer(&data->image, staging.handle, &temp_buffer); - vulkan_image_transition_layout(&context, &temp_buffer, &data->image, image_format, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + vulkan_image_transition_layout(&context, &temp_buffer, &data->image, image_format, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - vulkan_command_buffer_end_oneshot(&context, context.device.gfx_command_pool, &temp_buffer, context.device.graphics_queue); + vulkan_command_buffer_end_oneshot(&context, context.device.gfx_command_pool, &temp_buffer, + context.device.graphics_queue); - VkSamplerCreateInfo sampler_info = {VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; + VkSamplerCreateInfo sampler_info = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO }; sampler_info.magFilter = VK_FILTER_LINEAR; sampler_info.minFilter = VK_FILTER_LINEAR; sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; @@ -1792,12 +1796,12 @@ void texture_data_upload(texture* tex) { sampler_info.minLod = 0.0; sampler_info.maxLod = 0.0; - VkResult res = vkCreateSampler(context.device.logical_device, &sampler_info, context.allocator, &data->sampler); + VkResult res = vkCreateSampler(context.device.logical_device, &sampler_info, context.allocator, + &data->sampler); if (res != VK_SUCCESS) { ERROR("Error creating texture sampler for image %s", tex->name); return; } - } // TODO: destroy texture diff --git a/src/renderer/cleanroom/backend_vulkan.c b/src/renderer/cleanroom/backend_vulkan.c index 2838f20..71a09f3 100644 --- a/src/renderer/cleanroom/backend_vulkan.c +++ b/src/renderer/cleanroom/backend_vulkan.c @@ -1,16 +1,17 @@ #include <stdlib.h> #include "ral.h" #include "types.h" -#include "render_types.h" +// #include "render_types.h" #define VULKAN_QUEUES_COUNT 2 -const char* queue_names[VULKAN_QUEUES_COUNT] = { - "GRAPHICS", "TRANSFER" -}; +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; @@ -41,7 +42,6 @@ bool gpu_device_create(gpu_device* out_device) { // Queues // Create the command pool - } gpu_renderpass* gpu_renderpass_create() { @@ -51,8 +51,8 @@ gpu_renderpass* gpu_renderpass_create() { } 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) { + // VK_PIPELINE_BIND_POINT_GRAPHICS, &shader->pipeline); + if (kind == PIPELINE_GRAPHICS) { // ... } else { // ... diff --git a/src/renderer/cleanroom/ral.h b/src/renderer/cleanroom/ral.h index 8f7c8a4..a1e9929 100644 --- a/src/renderer/cleanroom/ral.h +++ b/src/renderer/cleanroom/ral.h @@ -14,12 +14,6 @@ #include "cleanroom/types.h" #include "defines.h" -// TODO: Replace with handle defines -typedef int buffer_handle; -typedef int texture_handle; -typedef int sampler_handle; -typedef int model_handle; - // Forward declare structs typedef struct gpu_swapchain gpu_swapchain; typedef struct gpu_device gpu_device; @@ -28,6 +22,21 @@ 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(); @@ -36,7 +45,7 @@ void gpu_device_destroy(); gpu_renderpass* gpu_renderpass_create(); void gpu_renderpass_destroy(gpu_renderpass* pass); -gpu_pipeline* gpu_pipeline_create(pipeline_kind kind); +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(); diff --git a/src/renderer/cleanroom/renderer.c b/src/renderer/cleanroom/renderer.c index 65c09de..a874664 100644 --- a/src/renderer/cleanroom/renderer.c +++ b/src/renderer/cleanroom/renderer.c @@ -1,6 +1,4 @@ -#include "render_types.h" #include "defines.h" +#include "render_types.h" -bool renderer_init() { - -}
\ No newline at end of file +bool renderer_init() {}
\ No newline at end of file diff --git a/src/renderer/cleanroom/renderer.h b/src/renderer/cleanroom/renderer.h index 7d56fe2..8012b49 100644 --- a/src/renderer/cleanroom/renderer.h +++ b/src/renderer/cleanroom/renderer.h @@ -7,4 +7,8 @@ typedef struct renderer2 { void* backend_state; gpu_device* device; gpu_pipeline* static_opaque_pipeline; -} renderer2;
\ No newline at end of file +} renderer2; + +// mesh +// model +// material
\ No newline at end of file diff --git a/src/renderer/cleanroom/types.h b/src/renderer/cleanroom/types.h index a37e0e6..98c2e21 100644 --- a/src/renderer/cleanroom/types.h +++ b/src/renderer/cleanroom/types.h @@ -4,11 +4,11 @@ #include "maths_types.h" #include "str.h" -// TODO: Replace with handle defines -typedef int buffer_handle; -typedef int texture_handle; -typedef int sampler_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; @@ -56,7 +56,7 @@ 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 { @@ -70,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; @@ -79,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 - } skinned_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) @@ -88,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; @@ -107,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; @@ -126,12 +128,6 @@ typedef struct model { /* ral.h */ -// enum pipeline_type { -// GRAPHICS, -// COMPUTE, -// } pipeline_type; - - // command buffer gubbins diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h index 6252dee..af20999 100644 --- a/src/renderer/render_types.h +++ b/src/renderer/render_types.h @@ -1,189 +1,189 @@ -/** - * @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 "darray.h" -#include "maths.h" -#include "maths_types.h" -#include "str.h" - -struct GLFWwindow; - -#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 - -/* @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; - -typedef struct frame_stats { - u64 last_time; -} frame_stats; - -typedef struct renderer { - struct GLFWwindow *window; /** Currently all platforms use GLFW*/ - void *backend_state; /** Graphics API-specific state */ - renderer_config config; - // shaders - shader blinn_phong; -} renderer; - -// --- Lighting & Materials - -typedef struct texture { - u32 texture_id; - char name[MAX_TEXTURE_NAME_LEN]; - void* image_data; - void* backend_data; - u32 width; - u32 height; - u8 channel_count; - 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(); - -#ifndef TYPED_MATERIAL_ARRAY -KITC_DECL_TYPED_ARRAY(material) // creates "material_darray" -#define TYPED_MATERIAL_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; - -#ifndef TYPED_VERTEX_ARRAY -KITC_DECL_TYPED_ARRAY(vertex) // creates "vertex_darray" -#define TYPED_VERTEX_ARRAY -#endif - -typedef struct mesh { - vertex_darray *vertices; - u32 vertex_size; /** size in bytes of each vertex including necessary padding */ - bool has_indices; - u32 *indices; - u32 indices_len; - size_t material_index; - 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 - -typedef struct model { - str8 name; - mesh_darray *meshes; - aabb_3d bbox; - material_darray *materials; - bool is_loaded; - 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; - -typedef enum pipeline_kind { - GRAPHICS, - COMPUTE, -} pipeline_kind;
\ No newline at end of file +// /** +// * @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 "darray.h" +// #include "maths.h" +// #include "maths_types.h" +// #include "str.h" + +// struct GLFWwindow; + +// #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 + +// /* @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; + +// typedef struct frame_stats { +// u64 last_time; +// } frame_stats; + +// typedef struct renderer { +// struct GLFWwindow *window; /** Currently all platforms use GLFW*/ +// void *backend_state; /** Graphics API-specific state */ +// renderer_config config; +// // shaders +// shader blinn_phong; +// } renderer; + +// // --- Lighting & Materials + +// typedef struct texture { +// u32 texture_id; +// char name[MAX_TEXTURE_NAME_LEN]; +// void* image_data; +// void* backend_data; +// u32 width; +// u32 height; +// u8 channel_count; +// 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(); + +// #ifndef TYPED_MATERIAL_ARRAY +// KITC_DECL_TYPED_ARRAY(material) // creates "material_darray" +// #define TYPED_MATERIAL_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; + +// #ifndef TYPED_VERTEX_ARRAY +// KITC_DECL_TYPED_ARRAY(vertex) // creates "vertex_darray" +// #define TYPED_VERTEX_ARRAY +// #endif + +// typedef struct mesh { +// vertex_darray *vertices; +// u32 vertex_size; /** size in bytes of each vertex including necessary padding */ +// bool has_indices; +// u32 *indices; +// u32 indices_len; +// size_t material_index; +// 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 + +// typedef struct model { +// str8 name; +// mesh_darray *meshes; +// aabb_3d bbox; +// material_darray *materials; +// bool is_loaded; +// 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; + +// // 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 b269fcd..f4e11f2 100644 --- a/src/resources/gltf.c +++ b/src/resources/gltf.c @@ -8,12 +8,11 @@ #include "log.h" #include "path.h" #include "render.h" -#include "render_types.h" +// #include "render_types.h" #include "str.h" #define CGLTF_IMPLEMENTATION #include <cgltf.h> -// TODO: Port code from old repo struct face { cgltf_uint indices[3]; 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 */ |