summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-07-11 18:03:29 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-07-11 18:03:29 +1000
commit65d74bdb26af833b5380046dec204f685f745cc1 (patch)
tree6a913e8b47787fff9f4650963074ea3f8ab5de27 /src
parent3103f383751a12f8a0bdb22309704f1f826d204c (diff)
changing styles plus simplifying a bit
Diffstat (limited to 'src')
-rw-r--r--src/camera.c17
-rw-r--r--src/camera.h34
-rw-r--r--src/core/README.md3
-rw-r--r--src/core/camera.c22
-rw-r--r--src/core/camera.h37
-rw-r--r--src/core/core.c (renamed from src/core.c)0
-rw-r--r--src/core/core.h (renamed from src/core.h)0
-rw-r--r--src/defines.h8
-rw-r--r--src/maths/maths_types.h50
-rw-r--r--src/new_render/pbr.h60
-rw-r--r--src/new_render/shadows.h30
-rw-r--r--src/ral/README.md5
-rw-r--r--src/ral/ral_common.h13
-rw-r--r--src/ral/ral_types.h5
14 files changed, 199 insertions, 85 deletions
diff --git a/src/camera.c b/src/camera.c
deleted file mode 100644
index 8ec1251..0000000
--- a/src/camera.c
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "camera.h"
-
-#include "maths.h"
-
-camera camera_create(vec3 pos, vec3 front, vec3 up, f32 fov) {
- camera c = { .position = pos, .front = front, .up = up, .fov = fov };
- return c;
-}
-
-void camera_view_projection(camera *c, f32 screen_height, f32 screen_width, mat4 *out_view,
- mat4 *out_proj) {
- mat4 proj = mat4_perspective(c->fov, screen_width / screen_height, 0.1, 100.0);
- vec3 camera_direction = vec3_add(c->position, c->front);
- mat4 view = mat4_look_at(c->position, camera_direction, c->up);
- *out_view = view;
- *out_proj = proj;
-} \ No newline at end of file
diff --git a/src/camera.h b/src/camera.h
deleted file mode 100644
index ec867c5..0000000
--- a/src/camera.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * @file camera.h
- * @author your name (you@domain.com)
- * @brief
- * @version 0.1
- * @date 2024-02-24
- *
- * @copyright Copyright (c) 2024
- *
- */
-#pragma once
-
-#include "maths_types.h"
-
-typedef struct camera {
- vec3 position;
- vec3 front;
- vec3 up;
- f32 fov;
-} camera;
-
-/** @brief create a camera */
-camera camera_create(vec3 pos, vec3 front, vec3 up, f32 fov);
-
-/** @brief get a 4x4 transform matrix for the view and perspective projection */
-void camera_view_projection(camera *c, f32 screen_height, f32 screen_width, mat4 *out_view,
- mat4 *out_proj);
-
-// TODO: Basic reusable camera controls
-/*
-Right click + move = pan
-Left click = orbit camera
-WASD = forward/backward/left/right
-*/ \ No newline at end of file
diff --git a/src/core/README.md b/src/core/README.md
new file mode 100644
index 0000000..19cc1d0
--- /dev/null
+++ b/src/core/README.md
@@ -0,0 +1,3 @@
+# Core
+
+Core engine facilities
diff --git a/src/core/camera.c b/src/core/camera.c
new file mode 100644
index 0000000..50c4054
--- /dev/null
+++ b/src/core/camera.c
@@ -0,0 +1,22 @@
+#include "camera.h"
+
+#include "maths.h"
+
+Camera Camera_Create(vec3 pos, vec3 front, vec3 up, f32 fov) {
+ Camera c = { .position = pos, .front = front, .up = up, .fov = fov };
+ return c;
+}
+
+mat4 Camera_ViewProj(Camera *c, f32 lens_height, f32 lens_width, mat4 *out_view,
+ mat4 *out_proj) {
+ mat4 proj = mat4_perspective(c->fov, lens_width / lens_height, 0.1, 100.0);
+ vec3 camera_direction = vec3_add(c->position, c->front);
+ mat4 view = mat4_look_at(c->position, camera_direction, c->up);
+ if (out_view) {
+ *out_view = view;
+ }
+ if (out_proj) {
+ *out_proj = proj;
+ }
+ return mat4_mult(view, proj);
+}
diff --git a/src/core/camera.h b/src/core/camera.h
new file mode 100644
index 0000000..233f5f3
--- /dev/null
+++ b/src/core/camera.h
@@ -0,0 +1,37 @@
+/**
+ * @file camera.h
+ * @brief
+ */
+#pragma once
+
+#include "defines.h"
+#include "maths_types.h"
+
+typedef struct Camera {
+ vec3 position;
+ vec3 front;
+ vec3 up;
+ f32 fov;
+} Camera;
+
+/** @brief create a camera */
+Camera Camera_Create(vec3 pos, vec3 front, vec3 up, f32 fov);
+
+/**
+ * @brief Get 3D camera transform matrix
+ * @param out_view optionally stores just the view matrix
+ * @param out_proj optionally stores just the projection matrix
+ * @returns the camera's view projection matrix pre-multiplied
+*/
+PUB mat4 Camera_ViewProj(Camera* c, f32 lens_height, f32 lens_width, mat4* out_view, mat4* out_proj);
+
+/** @brief Get 2D camera transform matrix */
+PUB mat4 Camera_View2D(Camera* c); // TODO: 2D cameras
+
+
+// TODO: Basic reusable camera controls
+/*
+Right click + move = pan
+Left click = orbit camera
+WASD = forward/backward/left/right
+*/
diff --git a/src/core.c b/src/core/core.c
index 1d8fe91..1d8fe91 100644
--- a/src/core.c
+++ b/src/core/core.c
diff --git a/src/core.h b/src/core/core.h
index 89702fd..89702fd 100644
--- a/src/core.h
+++ b/src/core/core.h
diff --git a/src/defines.h b/src/defines.h
index a35dbf4..e0a7782 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -38,7 +38,7 @@ _Static_assert(sizeof(i64) == 8, "type i64 should be 8 byte");
_Static_assert(sizeof(f32) == 4, "type f32 should be 4 bytes");
_Static_assert(sizeof(f64) == 8, "type f64 should be 8 bytes");
-_Static_assert(sizeof(ptrdiff_t) == 8, "");
+_Static_assert(sizeof(ptrdiff_t) == 8, "type ptrdiff_t should be 8 bytes");
#define alignof(x) _Alignof(x)
@@ -49,6 +49,10 @@ _Static_assert(sizeof(ptrdiff_t) == 8, "");
u32 raw; \
}
+CORE_DEFINE_HANDLE(Handle); // Untyped handle that can be casted to a strongly typed resource handle
+
+#define PUB // For collecting public APIs to expose in an amalgamation header file
+
/*
Possible platform defines:
#define CEL_PLATFORM_LINUX 1
@@ -79,4 +83,4 @@ Renderer backend defines:
#if defined(CEL_PLATFORM_MAC)
// #define CEL_REND_BACKEND_METAL 1
#define CEL_REND_BACKEND_OPENGL 1
-#endif \ No newline at end of file
+#endif
diff --git a/src/maths/maths_types.h b/src/maths/maths_types.h
index 609672c..5bfc43c 100644
--- a/src/maths/maths_types.h
+++ b/src/maths/maths_types.h
@@ -22,54 +22,54 @@
// --- Types
/** @brief 2D Vector */
-typedef struct vec2 {
+typedef struct Vec2 {
f32 x, y;
-} vec2;
+} Vec2;
/** @brief 3D Vector */
-typedef struct vec3 {
+typedef struct Vec3 {
f32 x, y, z;
-} vec3;
+} Vec3;
/** @brief 4D Vector */
-typedef struct vec4 {
+typedef struct Vec4 {
f32 x, y, z, w;
-} vec4;
+} Vec4;
/** @brief Quaternion */
-typedef vec4 quat;
+typedef Vec4 Quat;
/** @brief 4x4 Matrix */
-typedef struct mat4 {
+typedef union Mat4 {
// TODO: use this format for more readable code: vec4 x_axis, y_axis, z_axis, w_axis;
f32 data[16];
-} mat4;
+ Vec4 cols[4];
+} Mat4;
/** @brief Three dimensional bounding box */
-typedef struct bbox_3d {
- vec3 min; // minimum point of the box
- vec3 max; // maximum point of the box
-} bbox_3d;
+typedef struct Bbox_3D {
+ Vec3 min; // minimum point of the box
+ Vec3 max; // maximum point of the box
+} Bbox_3d;
/** @brief 3D Axis-aligned bounding box */
-typedef bbox_3d aabb_3d;
+typedef Bbox_3d Aabb_3D;
/** @brief 3D affine transformation */
-typedef struct transform {
- vec3 position;
- quat rotation;
+typedef struct Transform {
+ Vec3 position;
+ Quat rotation;
f32 scale;
bool is_dirty;
-} transform;
-typedef transform transform3d;
+} Transform;
-typedef struct vec4i {
+typedef struct Vec4i {
i32 x, y, z, w;
-} vec4i;
+} Vec4i;
-typedef struct vec4u {
+typedef struct Vec4u {
u32 x, y, z, w;
-} vec4u;
+} Vec4u;
// --- Some other types
typedef struct u32x3 {
@@ -96,8 +96,8 @@ typedef struct u32x2 {
// Type aliass
-typedef struct vec2 f32x2;
+typedef struct Vec2 f32x2;
#define f32x2(x, y) ((f32x2){ x, y })
-typedef struct vec3 f32x3;
+typedef struct Vec3 f32x3;
#define f32x3(x, y, z) ((f32x3){ x, y, z })
diff --git a/src/new_render/pbr.h b/src/new_render/pbr.h
new file mode 100644
index 0000000..dd29301
--- /dev/null
+++ b/src/new_render/pbr.h
@@ -0,0 +1,60 @@
+/**
+ * @file pbr.h
+ * @brief PBR render pass
+ */
+
+#pragma once
+#include "defines.h"
+#include "camera.h"
+#include "maths_types.h"
+#include "ral/ral.h"
+#include "ral/ral_common.h"
+
+// PBR;
+
+// --- Public API
+typedef struct PBR_Storage PBR_Storage; // Stores all necessary data and handles
+
+PUB void PBR_Init(PBR_Storage* storage);
+
+// NOTE: For simplicity's sake we will render this pass directly to the default framebuffer
+PUB void PBR_Run(
+ PBR_Storage* storage
+ // light data
+ // camera
+ // geometry
+ // materials
+);
+
+typedef struct PBR_Params {
+ Vec3 albedo;
+ f32 metallic;
+ f32 roughness;
+ f32 ao;
+} PBR_Params;
+
+typedef struct PBR_Textures {
+ TextureHandle albedo_map;
+ TextureHandle normal_map;
+ bool metal_roughness_combined;
+ TextureHandle metallic_map;
+ TextureHandle roughness_map;
+ TextureHandle ao_map;
+} PBR_Textures;
+
+// --- Internal
+
+
+GPU_Renderpass* PBR_RPassCreate();
+GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass);
+void PBR_Execute(
+ PBR_Storage* storage,
+ Camera camera,
+ TextureHandle shadowmap_tex,
+ MaterialMap* materials, // map of String -> Material
+ RenderEnt* entities,
+ size_t entity_count
+
+);
+
+// Internally this will need to update material parameters
diff --git a/src/new_render/shadows.h b/src/new_render/shadows.h
new file mode 100644
index 0000000..4f10f35
--- /dev/null
+++ b/src/new_render/shadows.h
@@ -0,0 +1,30 @@
+/**
+ * @file shadows.h
+ * @brief Functions for adding shadows to scene rendering.
+*/
+
+
+#pragma once
+#include "defines.h"
+#include "ral/ral_types.h"
+
+typedef struct Shadow_Storage Shadow_Storage;
+
+typedef struct RenderEnt RenderEnt;
+typedef struct Camera Camera;
+typedef struct Mat4 Mat4;
+
+// --- Public API
+PUB void Shadow_Init(Shadow_Storage* storage);
+
+/** @brief Run shadow map generation for given entities, and store in a texture.
+ * @note Uses active directional light for now */
+PUB void Shadow_Run(Shadow_Storage* storage, RenderEnt* entities, size_t entity_count);
+
+/** @brief Get the shadow texture generated from shadowmap pass */
+PUB Handle Shadow_GetShadowMapTexture(Shadow_Storage* storage);
+
+// --- Internal
+GPU_Renderpass* Shadow_RPassCreate(); // Creates the render pass
+GPU_Pipeline* Shadow_PipelineCreate(GPU_Renderpass* rpass); // Creates the pipeline
+void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform, RenderEnt* entites, size_t entity_count);
diff --git a/src/ral/README.md b/src/ral/README.md
new file mode 100644
index 0000000..f66b95a
--- /dev/null
+++ b/src/ral/README.md
@@ -0,0 +1,5 @@
+# RAL
+
+**Render Abstraction Layer** is a thin abstraction over graphics APIs. Everything in `render` builds on top of the code in
+this folder in order to be API-agnostic. It also makes writing graphics code easier as it smooths over some of the discrepancies
+between APIs like texture/buffer creation and updating shader values. \ No newline at end of file
diff --git a/src/ral/ral_common.h b/src/ral/ral_common.h
index bc86945..fabf264 100644
--- a/src/ral/ral_common.h
+++ b/src/ral/ral_common.h
@@ -4,10 +4,11 @@
#include "ral_types.h"
#include "ral_impl.h"
-CORE_DEFINE_HANDLE(buffer_handle);
-CORE_DEFINE_HANDLE(texture_handle);
-CORE_DEFINE_HANDLE(sampler_handle);
-CORE_DEFINE_HANDLE(shader_handle);
+CORE_DEFINE_HANDLE(BufferHandle);
+CORE_DEFINE_HANDLE(TextureHandle);
+CORE_DEFINE_HANDLE(SamplerHandle);
+CORE_DEFINE_HANDLE(ShaderHandle);
+
CORE_DEFINE_HANDLE(pipeline_layout_handle);
CORE_DEFINE_HANDLE(pipeline_handle);
CORE_DEFINE_HANDLE(renderpass_handle);
@@ -18,7 +19,7 @@ CORE_DEFINE_HANDLE(renderpass_handle);
#define MAX_PIPELINES 128
#define MAX_RENDERPASSES 128
-TYPED_POOL(gpu_buffer, buffer);
+TYPED_POOL(GPU_Buffer, Buffer);
TYPED_POOL(gpu_texture, texture);
TYPED_POOL(gpu_pipeline_layout, pipeline_layout);
TYPED_POOL(gpu_pipeline, pipeline);
@@ -42,4 +43,4 @@ struct resource_pools {
};
void resource_pools_init(arena* a, struct resource_pools* res_pools);
-// vertex_description static_3d_vertex_description(); \ No newline at end of file
+// vertex_description static_3d_vertex_description();
diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h
index bc24d7f..a27bbd2 100644
--- a/src/ral/ral_types.h
+++ b/src/ral/ral_types.h
@@ -11,6 +11,9 @@ typedef struct gpu_cmd_buffer gpu_cmd_buffer; // Ready for submission
typedef struct gpu_buffer gpu_buffer;
typedef struct gpu_texture gpu_texture;
+typedef struct GPU_Renderpass GPU_Renderpass;
+typedef struct GPU_Pipeline GPU_Pipeline;
+
typedef enum gpu_primitive_topology {
CEL_PRIMITIVE_TOPOLOGY_POINT,
CEL_PRIMITIVE_TOPOLOGY_LINE,
@@ -77,4 +80,4 @@ typedef struct gpu_renderpass_desc {
texture_handle color_target; // for now only support one
bool has_depth_stencil;
texture_handle depth_stencil;
-} gpu_renderpass_desc; \ No newline at end of file
+} gpu_renderpass_desc;