diff options
-rw-r--r-- | src/defines.h | 6 | ||||
-rw-r--r-- | src/logos/README.md | 6 | ||||
-rw-r--r-- | src/maths/maths.h | 25 | ||||
-rw-r--r-- | src/maths/maths_types.h | 33 | ||||
-rw-r--r-- | src/maths/primitives.c | 187 | ||||
-rw-r--r-- | src/maths/primitives.h | 162 | ||||
-rw-r--r-- | src/renderer/backends/backend_dx11.c | 3 | ||||
-rw-r--r-- | src/systems/terrain.c | 0 | ||||
-rw-r--r-- | src/systems/terrain.h | 10 |
9 files changed, 250 insertions, 182 deletions
diff --git a/src/defines.h b/src/defines.h index 8cd4f98..54f2dd5 100644 --- a/src/defines.h +++ b/src/defines.h @@ -65,11 +65,15 @@ Renderer backend defines: */ // Platform will inform renderer backend (unless user overrides) -#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_WINDOWS) +#if defined(CEL_PLATFORM_LINUX) #define CEL_REND_BACKEND_OPENGL 1 // #define CEL_REND_BACKEND_VULKAN 1 #endif +#if defined(CEL_PLATFORM_WINDOWS) +#define CEL_REND_BACKEND_DX11 1 +#endif + #if defined(CEL_PLATFORM_MAC) // #define CEL_REND_BACKEND_METAL 1 #define CEL_REND_BACKEND_OPENGL 1 diff --git a/src/logos/README.md b/src/logos/README.md new file mode 100644 index 0000000..25b7bef --- /dev/null +++ b/src/logos/README.md @@ -0,0 +1,6 @@ +# Logos + +Logos is the namespace for threadpool & job system code. This is not a 'system' as it is underlying core unit of the engine. + +Threadpool currently gets initialised at core bringup with a set number of threads and results are processed once per frame +on the main thread. This is subject to change but multithreading is not the highest priority right now.
\ No newline at end of file diff --git a/src/maths/maths.h b/src/maths/maths.h index e0d39d7..ad33981 100644 --- a/src/maths/maths.h +++ b/src/maths/maths.h @@ -319,27 +319,4 @@ static inline mat4 transform_to_mat(transform *tf) { _Static_assert(alignof(vec3) == 4, "vec3 is 4 byte aligned"); _Static_assert(sizeof(vec3) == 12, "vec3 is 12 bytes so has no padding"); -_Static_assert(alignof(vec4) == 4, "vec4 is 4 byte aligned"); - -// --- Some other types -typedef struct u32x3 { - union { - struct { - u32 x; - u32 y; - u32 z; - }; - struct { - u32 r; - u32 g; - u32 b; - }; - }; -} 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 +_Static_assert(alignof(vec4) == 4, "vec4 is 4 byte aligned");
\ No newline at end of file diff --git a/src/maths/maths_types.h b/src/maths/maths_types.h index 53cac55..aa86eb0 100644 --- a/src/maths/maths_types.h +++ b/src/maths/maths_types.h @@ -68,4 +68,35 @@ typedef struct vec4i { typedef struct vec4u { u32 x, y, z, w; -} vec4u;
\ No newline at end of file +} vec4u; + +// --- Some other types +typedef struct u32x3 { + union { + struct { + u32 x; + u32 y; + u32 z; + }; + struct { + u32 r; + u32 g; + u32 b; + }; + }; +} 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 }) + +// Type aliass + +typedef struct vec2 f32x2; +#define f32x2(x, y) ((f32x2){ x, y }) + +typedef struct vec3 f32x3; +#define f32x3(x, y, z) ((f32x3){ x, y, z })
\ No newline at end of file diff --git a/src/maths/primitives.c b/src/maths/primitives.c new file mode 100644 index 0000000..42c51ea --- /dev/null +++ b/src/maths/primitives.c @@ -0,0 +1,187 @@ +#include "primitives.h" + +// vertices +f32 plane_vertex_positions[] = { + // triangle 1 + -0.5, 0, -0.5, -0.5, 0, 0.5, 0.5, 0, -0.5, + // triangle 2 + 0.5, 0, -0.5, -0.5, 0, 0.5, 0.5, 0, 0.5 +}; + +geometry_data geo_create_plane(f32x2 extents) { + f32x2 half_extents = vec2_div(extents, 2.0); + vertex_format format = VERTEX_STATIC_3D; + vertex_darray* vertices = vertex_darray_new(4); + + vertex_darray_push( + vertices, + (vertex) {.static_3d = { + .position = + }} + ); + + return (geometry_data) { + .format = format, + .vertices = + .has_indices = true, + } +} + + +// OLD + +static const vec3 BACK_BOT_LEFT = (vec3){ 0, 0, 0 }; +static const vec3 BACK_BOT_RIGHT = (vec3){ 1, 0, 0 }; +static const vec3 BACK_TOP_LEFT = (vec3){ 0, 1, 0 }; +static const vec3 BACK_TOP_RIGHT = (vec3){ 1, 1, 0 }; +static const vec3 FRONT_BOT_LEFT = (vec3){ 0, 0, 1 }; +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 }; + +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; + } + + cube.has_indices = true; + + return cube; +} + +/** @brief create a new model with the shape of a cube */ +static model_handle prim_cube_new(core* core) { + model model = { 0 }; + mesh cube = prim_cube_mesh_create(); + + mesh_darray_push(model.meshes, cube); + assert(mesh_darray_len(model.meshes) == 1); + + u32 index = (u32)model_darray_len(core->models); + model_darray_push_copy(core->models, &model); + return (model_handle){ .raw = index }; +}
\ No newline at end of file diff --git a/src/maths/primitives.h b/src/maths/primitives.h index ed52c8c..3e0cc5f 100644 --- a/src/maths/primitives.h +++ b/src/maths/primitives.h @@ -3,161 +3,11 @@ #include <assert.h> #include <stdlib.h> #include "core.h" -#include "maths.h" +#include "maths_types.h" #include "render_types.h" -static const vec3 BACK_BOT_LEFT = (vec3){ 0, 0, 0 }; -static const vec3 BACK_BOT_RIGHT = (vec3){ 1, 0, 0 }; -static const vec3 BACK_TOP_LEFT = (vec3){ 0, 1, 0 }; -static const vec3 BACK_TOP_RIGHT = (vec3){ 1, 1, 0 }; -static const vec3 FRONT_BOT_LEFT = (vec3){ 0, 0, 1 }; -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 }; - -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; - } - - cube.has_indices = true; - - return cube; -} - -/** @brief create a new model with the shape of a cube */ -static model_handle prim_cube_new(core* core) { - model model = { 0 }; - mesh cube = prim_cube_mesh_create(); - - mesh_darray_push(model.meshes, cube); - assert(mesh_darray_len(model.meshes) == 1); - - u32 index = (u32)model_darray_len(core->models); - model_darray_push_copy(core->models, &model); - return (model_handle){ .raw = index }; -}
\ No newline at end of file +geometry_data geo_create_plane(f32x2 extents); +geometry_data geo_create_cuboid(f32x3 extents); +geometry_data geo_create_cylinder(f32 radius, f32 height, u32 resolution); +geometry_data geo_create_uvsphere(f32 radius, f32 north_south_lines, f32 east_west_lines); +geometry_data geo_create_icosphere(f32 radius, f32 n_subdivisions);
\ No newline at end of file diff --git a/src/renderer/backends/backend_dx11.c b/src/renderer/backends/backend_dx11.c new file mode 100644 index 0000000..d991f03 --- /dev/null +++ b/src/renderer/backends/backend_dx11.c @@ -0,0 +1,3 @@ +#if CEL_REND_BACKEND_DX11 + +#endif
\ No newline at end of file diff --git a/src/systems/terrain.c b/src/systems/terrain.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/systems/terrain.c diff --git a/src/systems/terrain.h b/src/systems/terrain.h new file mode 100644 index 0000000..fa2d3b3 --- /dev/null +++ b/src/systems/terrain.h @@ -0,0 +1,10 @@ +/** + * @file terrain.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-04-27 + * + * @copyright Copyright (c) 2024 + * + */ |