From 634f22e2b6d538fc5a45da2b1b23af631f6f8703 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sun, 12 May 2024 15:07:57 +1000 Subject: more restructuring --- examples/cube/ex_cube.c | 5 + src/maths/primitives.c | 265 +++++++++++++++++---------------- src/physics/broadphase.h | 10 ++ src/physics/collision.h | 30 ++++ src/physics/narrowphase.h | 10 ++ src/physics/physics.c | 1 + src/physics/physics.h | 23 +++ src/renderer/backends/backend_vulkan.c | 7 +- src/renderer/backends/metal/README.md | 1 + src/renderer/backends/opengl/README.md | 1 + src/renderer/backends/vulkan/README.md | 1 + src/renderer/ral.h | 4 + src/renderer/ral_types.h | 32 +++- src/renderer/render.h | 2 + src/renderer/standard_vertex_types.c | 11 ++ src/systems/physics.c | 1 - src/systems/physics.h | 41 ----- xmake.lua | 2 + 18 files changed, 274 insertions(+), 173 deletions(-) create mode 100644 src/physics/broadphase.h create mode 100644 src/physics/collision.h create mode 100644 src/physics/narrowphase.h create mode 100644 src/physics/physics.c create mode 100644 src/physics/physics.h create mode 100644 src/renderer/backends/metal/README.md create mode 100644 src/renderer/backends/opengl/README.md create mode 100644 src/renderer/backends/vulkan/README.md create mode 100644 src/renderer/standard_vertex_types.c delete mode 100644 src/systems/physics.c delete mode 100644 src/systems/physics.h diff --git a/examples/cube/ex_cube.c b/examples/cube/ex_cube.c index 712485c..a115fe3 100644 --- a/examples/cube/ex_cube.c +++ b/examples/cube/ex_cube.c @@ -52,6 +52,10 @@ int main() { DEBUG("render capacity %d", g_core.default_scene.renderables->capacity); + vertex_description vertex_input = {0}; + vertex_desc_add(&vertex_input, "inPosition", ATTR_F32x2); + vertex_desc_add(&vertex_input, "inColor", ATTR_F32x3); + shader_data mvp_uniforms_data = { .data = NULL, .shader_data_get_layout = &mvp_uniforms_layout }; gpu_renderpass_desc pass_description = {}; @@ -67,6 +71,7 @@ int main() { struct graphics_pipeline_desc pipeline_description = { .debug_name = "Basic Pipeline", + .vertex_desc = vertex_input, .data_layouts = { mvp_uniforms_data }, .data_layouts_count = 1, .vs = { .debug_name = "Triangle Vertex Shader", diff --git a/src/maths/primitives.c b/src/maths/primitives.c index 310fc98..459a535 100644 --- a/src/maths/primitives.c +++ b/src/maths/primitives.c @@ -1,5 +1,6 @@ #include "primitives.h" #include "maths.h" +#include "ral_types.h" // vertices f32 plane_vertex_positions[] = { @@ -30,136 +31,148 @@ static const vec3 FRONT_BOT_RIGHT = (vec3){ 1, 0, 1 }; static const vec3 FRONT_TOP_LEFT = (vec3){ 0, 1, 1 }; static const vec3 FRONT_TOP_RIGHT = (vec3){ 1, 1, 1 }; +#define VERT_3D(arr, pos, norm, uv) \ + { \ + vertex v = { + .static_3d = { \ + .position = pos, \ + .normal = norm, \ + .tex_coords = uv \ + }}; \ + vertex_darray_push(arr, v); \ + } + static mesh prim_cube_mesh_create() { mesh cube = { 0 }; cube.vertices = vertex_darray_new(36); - // // back faces - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 1 } }); - - // // front faces - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 0 } }); - - // // top faces - // vertex_darray_push(cube.vertices, - // (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 0 - // } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 1 } }); - // vertex_darray_push(cube.vertices, - // (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 0 - // } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 0 } }); - - // // bottom faces - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); - - // // right faces - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 1 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 1 } }); - - // // left faces - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); - // vertex_darray_push( - // cube.vertices, - // (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); - - // cube.indices_len = cube.vertices->len; - // cube.indices = malloc(sizeof(u32) * cube.indices_len); - - // for (u32 i = 0; i < cube.indices_len; i++) { - // cube.indices[i] = i; - // } + // back faces + VERT_3D(cube.vertices, BACK_BOT_LEFT, VEC3_NEG_Z, (vec2){ 0, 1 })) + // vertex_darray_push( + // cube.vertices, + // (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 1 } }); + // vertex_darray_push( + // cube.vertices, + // (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 0 } }); + // vertex_darray_push( + // cube.vertices, + // (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 0 } }); + // vertex_darray_push( + // cube.vertices, + // (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 0 } }); + // vertex_darray_push( + // cube.vertices, + // (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 1 } }); + // vertex_darray_push( + // cube.vertices, + // (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 1 } }); + + // front faces + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 1 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 1 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 1 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 0 } }); + + // top faces + vertex_darray_push(cube.vertices, + (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 0 + } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 1 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 1 } }); + vertex_darray_push(cube.vertices, + (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 0 + } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 1 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 0 } }); + + // bottom faces + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } }); + + // right faces + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 1 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 1 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 1 } }); + + // left faces + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); + vertex_darray_push( + cube.vertices, + (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } }); + + cube.indices_len = cube.vertices->len; + cube.indices = malloc(sizeof(u32) * cube.indices_len); + + for (u32 i = 0; i < cube.indices_len; i++) { + cube.indices[i] = i; + } cube.has_indices = true; diff --git a/src/physics/broadphase.h b/src/physics/broadphase.h new file mode 100644 index 0000000..43b57f6 --- /dev/null +++ b/src/physics/broadphase.h @@ -0,0 +1,10 @@ +/** + * @file broadphase.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-05-12 + * + * @copyright Copyright (c) 2024 + * + */ \ No newline at end of file diff --git a/src/physics/collision.h b/src/physics/collision.h new file mode 100644 index 0000000..3b65b1b --- /dev/null +++ b/src/physics/collision.h @@ -0,0 +1,30 @@ +/** + * @file collision.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-05-12 + * + * @copyright Copyright (c) 2024 + * + */ +#pragma once +#include "geometry.h" + + enum collider_type { + cuboid_collider, + sphere_collider, +}; + +/** @brief generic collider structure */ +typedef struct physics_collider { + u64 id; // ? Replace with handle? + enum collider_type shape; + union collider_data { + cuboid cuboid; + sphere sphere; + } geometry; + transform transform; + u8 layer; + bool on_ground; +} physics_collider; \ No newline at end of file diff --git a/src/physics/narrowphase.h b/src/physics/narrowphase.h new file mode 100644 index 0000000..501c690 --- /dev/null +++ b/src/physics/narrowphase.h @@ -0,0 +1,10 @@ +/** + * @file narrowphase.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-05-12 + * + * @copyright Copyright (c) 2024 + * + */ \ No newline at end of file diff --git a/src/physics/physics.c b/src/physics/physics.c new file mode 100644 index 0000000..299c0c1 --- /dev/null +++ b/src/physics/physics.c @@ -0,0 +1 @@ +#include "physics.h" \ No newline at end of file diff --git a/src/physics/physics.h b/src/physics/physics.h new file mode 100644 index 0000000..e0e3b89 --- /dev/null +++ b/src/physics/physics.h @@ -0,0 +1,23 @@ +#pragma once + +#include "geometry.h" +#include "maths_types.h" + +// 'system' means that it gets called per frame + +typedef struct physics_settings { + f32 gravity_strength; +} physics_settings; + +// What else do I need? +// intersection methods + +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/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c index a845ebf..f83ef84 100644 --- a/src/renderer/backends/backend_vulkan.c +++ b/src/renderer/backends/backend_vulkan.c @@ -393,6 +393,7 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip attribute_descs[1].offset = offsetof(custom_vertex, color); // Vertex input + // TODO: Generate this from descroiption now VkVertexInputBindingDescription binding_desc; binding_desc.binding = 0; binding_desc.stride = sizeof(custom_vertex); @@ -819,9 +820,9 @@ void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* d alloc_info.pSetLayouts = &encoder->pipeline->desc_set_layouts[group]; VkDescriptorSet sets[1]; - /* VK_CHECK( */ - vkAllocateDescriptorSets(context.device->logical_device, &alloc_info, sets); - /* ); */ + VK_CHECK( + vkAllocateDescriptorSets(context.device->logical_device, &alloc_info, sets) + ); VkDescriptorSet_darray_push(context.free_set_queue, sets[0]); shader_data_layout sdl = data->shader_data_get_layout(NULL); diff --git a/src/renderer/backends/metal/README.md b/src/renderer/backends/metal/README.md new file mode 100644 index 0000000..f87f5c1 --- /dev/null +++ b/src/renderer/backends/metal/README.md @@ -0,0 +1 @@ +# TODO \ No newline at end of file diff --git a/src/renderer/backends/opengl/README.md b/src/renderer/backends/opengl/README.md new file mode 100644 index 0000000..f87f5c1 --- /dev/null +++ b/src/renderer/backends/opengl/README.md @@ -0,0 +1 @@ +# TODO \ No newline at end of file diff --git a/src/renderer/backends/vulkan/README.md b/src/renderer/backends/vulkan/README.md new file mode 100644 index 0000000..220ed64 --- /dev/null +++ b/src/renderer/backends/vulkan/README.md @@ -0,0 +1 @@ +# Vulkan Backend Overview \ No newline at end of file diff --git a/src/renderer/ral.h b/src/renderer/ral.h index 0df23ea..30d5413 100644 --- a/src/renderer/ral.h +++ b/src/renderer/ral.h @@ -54,6 +54,7 @@ typedef struct shader_desc { struct graphics_pipeline_desc { const char* debug_name; + vertex_description vertex_desc; shader_desc vs; /** @brief Vertex shader stage */ shader_desc fs; /** @brief Fragment shader stage */ @@ -150,8 +151,11 @@ void gpu_sampler_create(); // --- Vertex formats bytebuffer vertices_as_bytebuffer(arena* a, vertex_format format, vertex_darray* vertices); +void vertex_desc_add(vertex_description* builder, const char* name, vertex_attrib_type type); + // TODO: Bindgroup texture samplers / shader resources // TEMP void gpu_temp_draw(size_t n_verts); + diff --git a/src/renderer/ral_types.h b/src/renderer/ral_types.h index e7863a9..48695ea 100644 --- a/src/renderer/ral_types.h +++ b/src/renderer/ral_types.h @@ -1,7 +1,7 @@ /** * @file ral_types.h * @author your name (you@domain.com) - * @brief + * @brief Struct and enum definitions for RAL * @version 0.1 * @date 2024-04-27 * @@ -14,6 +14,8 @@ #include "defines.h" #include "maths_types.h" +#define MAX_VERTEX_ATTRIBUTES 16 + #ifndef RENDERER_TYPED_HANDLES CORE_DEFINE_HANDLE(buffer_handle); CORE_DEFINE_HANDLE(texture_handle); @@ -143,19 +145,45 @@ typedef enum vertex_attrib_type { ATTR_I32x4, } vertex_attrib_type; +typedef struct vertex_description { + char* debug_label; + const char* attr_names[MAX_VERTEX_ATTRIBUTES]; + vertex_attrib_type attributes[MAX_VERTEX_ATTRIBUTES]; + size_t stride; +} vertex_description; + +// --- Shaders & Bindings + typedef enum shader_visibility { VISIBILITY_VERTEX = 1 << 0, VISIBILITY_FRAGMENT = 1 << 1 , VISIBILITY_COMPUTE = 1 << 2, } shader_visibility; +/** @brief Describes the kind of binding a `shader_binding` is for. This changes how we create backing data for it. */ typedef enum shader_binding_type { + /** + * @brief Binds a buffer to a shader + * @note Vulkan: Becomes a Storage Buffer + */ SHADER_BINDING_BUFFER, + SHADER_BINDING_BUFFER_ARRAY, SHADER_BINDING_TEXTURE, + SHADER_BINDING_TEXTURE_ARRAY, + SHADER_BINDING_SAMPLER, + /** + * @brief Binds raw data to a shader + * @note Vulkan: Becomes a Uniform Buffer + */ SHADER_BINDING_BYTES, + // TODO: Acceleration Structure SHADER_BINDING_COUNT } shader_binding_type; +// pub trait ShaderBindable: Clone + Copy { +// fn bind_to(&self, context: &mut PipelineContext, index: u32); +// } + typedef struct shader_binding { const char* label; shader_binding_type type; @@ -171,7 +199,7 @@ typedef struct shader_binding { void* data; size_t size; } bytes; - } data; + } data; /** @brief */ } shader_binding; #define MAX_LAYOUT_BINDINGS 8 diff --git a/src/renderer/render.h b/src/renderer/render.h index c690e80..4477121 100644 --- a/src/renderer/render.h +++ b/src/renderer/render.h @@ -44,3 +44,5 @@ mesh mesh_create(geometry_data* geometry); model_handle model_load(const char* debug_name, const char* filepath); void geo_set_vertex_colours(geometry_data* geo, vec4 colour); + +vertex_description static_3d_vertex_description(); \ No newline at end of file diff --git a/src/renderer/standard_vertex_types.c b/src/renderer/standard_vertex_types.c new file mode 100644 index 0000000..4973bf0 --- /dev/null +++ b/src/renderer/standard_vertex_types.c @@ -0,0 +1,11 @@ +#include "ral.h" +#include "ral_types.h" +#include "render.h" + +vertex_description static_3d_vertex_description() { + vertex_description builder = { .debug_label = "vertex" }; + vertex_desc_add(&builder, "position", ATTR_F32x3); + vertex_desc_add(&builder, "normal", ATTR_F32x3); + vertex_desc_add(&builder, "texCoords", ATTR_F32x2); + return builder; +} \ No newline at end of file diff --git a/src/systems/physics.c b/src/systems/physics.c deleted file mode 100644 index 299c0c1..0000000 --- a/src/systems/physics.c +++ /dev/null @@ -1 +0,0 @@ -#include "physics.h" \ No newline at end of file diff --git a/src/systems/physics.h b/src/systems/physics.h deleted file mode 100644 index 7239ab5..0000000 --- a/src/systems/physics.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include "geometry.h" -#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; - union collider_data { - cuboid cuboid; - sphere sphere; - } geometry; - transform transform; - u8 layer; - bool on_ground; -} physics_collider; - -// What else do I need? -// intersection methods - -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/xmake.lua b/xmake.lua index f1b648b..1d576c7 100644 --- a/xmake.lua +++ b/xmake.lua @@ -59,6 +59,7 @@ local core_sources = { -- "src/logos/*.c", "src/maths/*.c", "src/platform/*.c", + "src/physics/*.c", "src/renderer/*.c", "src/renderer/backends/*.c", "src/resources/*.c", @@ -103,6 +104,7 @@ target("core_config") -- add_includedirs("src/logos/", {public = true}) add_includedirs("src/maths/", {public = true}) add_includedirs("src/platform/", {public = true}) + add_includedirs("src/physics/", {public = true}) add_includedirs("src/renderer/", {public = true}) add_includedirs("src/renderer/backends/", {public = true}) add_includedirs("src/resources/", {public = true}) -- cgit v1.2.3-70-g09d2