diff options
| author | 3gg <3gg@shellblade.net> | 2025-07-04 10:37:01 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-07-04 10:37:01 -0700 |
| commit | b37b5398a6afa940acd1138bde922a70838f33af (patch) | |
| tree | 9ff988e0412d4210362b52f82fbe723e734b6228 /include | |
| parent | 1ec46bead3cf87971a2329f9ef4ddde5a0c48325 (diff) | |
Add the new low-level renderer, shared between the imm and scene graph renderer. LLR integration with the scene graph renderer not yet done.
Diffstat (limited to 'include')
| -rw-r--r-- | include/gfx/gfx.h | 6 | ||||
| -rw-r--r-- | include/gfx/llr/llr.h | 107 | ||||
| -rw-r--r-- | include/gfx/renderer.h | 77 | ||||
| -rw-r--r-- | include/gfx/renderer/imm_renderer.h | 55 | ||||
| -rw-r--r-- | include/gfx/scene.h | 7 | ||||
| -rw-r--r-- | include/gfx/sizes.h | 16 |
6 files changed, 103 insertions, 165 deletions
diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index 7c670a5..d5c25b6 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | typedef struct AssetCache AssetCache; | 3 | typedef struct AssetCache AssetCache; |
| 4 | typedef struct GfxCore GfxCore; | 4 | typedef struct GfxCore GfxCore; |
| 5 | typedef struct ImmRenderer ImmRenderer; | 5 | typedef struct ImmRenderer ImmRenderer; |
| 6 | typedef struct LLR LLR; | ||
| 6 | typedef struct Renderer Renderer; | 7 | typedef struct Renderer Renderer; |
| 7 | 8 | ||
| 8 | typedef struct Gfx Gfx; | 9 | typedef struct Gfx Gfx; |
| @@ -16,12 +17,15 @@ void gfx_destroy(Gfx**); | |||
| 16 | /// Get the render backend. | 17 | /// Get the render backend. |
| 17 | GfxCore* gfx_get_core(Gfx*); | 18 | GfxCore* gfx_get_core(Gfx*); |
| 18 | 19 | ||
| 19 | /// Get the renderer. | 20 | /// Get the scene renderer. |
| 20 | Renderer* gfx_get_renderer(Gfx*); | 21 | Renderer* gfx_get_renderer(Gfx*); |
| 21 | 22 | ||
| 22 | /// Get the immediate mode renderer. | 23 | /// Get the immediate mode renderer. |
| 23 | ImmRenderer* gfx_get_imm_renderer(Gfx*); | 24 | ImmRenderer* gfx_get_imm_renderer(Gfx*); |
| 24 | 25 | ||
| 26 | /// Get the low-level renderer. | ||
| 27 | LLR* gfx_get_llr(Gfx*); | ||
| 28 | |||
| 25 | /// Get the asset cache. | 29 | /// Get the asset cache. |
| 26 | AssetCache* gfx_get_asset_cache(Gfx*); | 30 | AssetCache* gfx_get_asset_cache(Gfx*); |
| 27 | 31 | ||
diff --git a/include/gfx/llr/llr.h b/include/gfx/llr/llr.h index 49b7706..57abffc 100644 --- a/include/gfx/llr/llr.h +++ b/include/gfx/llr/llr.h | |||
| @@ -1,117 +1,64 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <math/aabb2.h> | ||
| 4 | #include <math/aabb3.h> | ||
| 5 | #include <math/camera.h> | 3 | #include <math/camera.h> |
| 6 | #include <math/mat4.h> | 4 | #include <math/mat4.h> |
| 7 | #include <math/vec3.h> | 5 | #include <math/vec3.h> |
| 8 | #include <math/vec4.h> | ||
| 9 | 6 | ||
| 10 | typedef struct Anima Anima; | 7 | typedef struct Anima Anima; |
| 11 | typedef struct Light Light; | 8 | typedef struct Geometry Geometry; |
| 12 | typedef struct Mesh Mesh; | 9 | typedef struct Light Light; |
| 13 | typedef struct Skeleton Skeleton; | 10 | typedef struct Mesh Mesh; |
| 11 | typedef struct ShaderProgram ShaderProgram; | ||
| 12 | typedef struct Skeleton Skeleton; | ||
| 14 | 13 | ||
| 15 | typedef struct ImmRenderer ImmRenderer; | 14 | typedef struct LLR LLR; |
| 16 | 15 | ||
| 17 | /// Prepare the graphics systems for immediate-mode rendering. | 16 | /// Set the shader to be used for subsequent draw calls. |
| 18 | /// | 17 | /// The shader is not yet activated at this point. |
| 19 | /// Call this before issuing any immediate-mode rendering draws. | 18 | void gfx_llr_set_shader(LLR*, ShaderProgram*); |
| 20 | void gfx_imm_start(ImmRenderer*); | ||
| 21 | |||
| 22 | /// End immediate mode rendering. | ||
| 23 | /// | ||
| 24 | /// Call this after issuing immediate-mode rendering draws and before swapping | ||
| 25 | /// buffers. | ||
| 26 | void gfx_imm_end(ImmRenderer*); | ||
| 27 | |||
| 28 | // ----------------------------------------------------------------------------- | ||
| 29 | // Immediate-mode rendering of scene elements. | ||
| 30 | // | ||
| 31 | // This renders models and meshes under lighting. It is up to the client to | ||
| 32 | // determine visibility, sort the calls optimally, etc. | ||
| 33 | 19 | ||
| 34 | /// Push a light into the lights stack. | 20 | /// Push a light into the lights stack. |
| 35 | void gfx_imm_push_light(ImmRenderer*, Light*); | 21 | void gfx_llr_push_light(LLR*, Light*); |
| 36 | 22 | ||
| 37 | /// Pop the last light from the lights stack. | 23 | /// Pop the last light from the lights stack. |
| 38 | void gfx_imm_pop_light(ImmRenderer*); | 24 | void gfx_llr_pop_light(LLR*); |
| 39 | 25 | ||
| 40 | /// Load a skeleton. | 26 | /// Load a skeleton. |
| 41 | /// | 27 | /// |
| 42 | /// If a skeleton is loaded, subsequent meshes are rendered with joint data | 28 | /// If a skeleton is loaded, subsequent meshes are rendered with joint data |
| 43 | /// passed to the shader. This has a cost, so if subsequent meshes are not | 29 | /// passed to the shader. This has a cost, so if subsequent meshes are not |
| 44 | /// animated, unload the skeleton prior to rendering them. | 30 | /// animated, unload the skeleton prior to rendering them. |
| 45 | void gfx_imm_set_skeleton(ImmRenderer*, const Anima*, const Skeleton*); | 31 | void gfx_llr_set_skeleton(LLR*, const Anima*, const Skeleton*); |
| 46 | 32 | ||
| 47 | /// Unload the loaded skeleton. | 33 | /// Unload the loaded skeleton. |
| 48 | void gfx_imm_unset_skeleton(ImmRenderer*); | 34 | void gfx_llr_unset_skeleton(LLR*); |
| 49 | 35 | ||
| 50 | /// Render the mesh. | 36 | /// Set the camera. |
| 51 | void gfx_imm_render_mesh(ImmRenderer*, const Mesh*); | 37 | void gfx_llr_set_camera(LLR*, const Camera*); |
| 52 | |||
| 53 | // ----------------------------------------------------------------------------- | ||
| 54 | // Immediate-mode rendering of primitives. | ||
| 55 | // | ||
| 56 | // This is rather inefficient and should be reserved for debug rendering. It | ||
| 57 | // also does not support lighting; the primitives are rendered with a constant | ||
| 58 | // colour. | ||
| 59 | |||
| 60 | /// Draw a set of triangles. | ||
| 61 | void gfx_imm_draw_triangles(ImmRenderer*, const vec3[], size_t num_triangles); | ||
| 62 | |||
| 63 | /// Draw a triangle. | ||
| 64 | void gfx_imm_draw_triangle(ImmRenderer*, const vec3[3]); | ||
| 65 | 38 | ||
| 66 | /// Draw a bounding box. | 39 | /// Set the view-projection matrix. |
| 67 | void gfx_imm_draw_aabb2(ImmRenderer*, aabb2); | 40 | // void gfx_llr_set_view_projection_matrix(LLR*, const mat4*); |
| 68 | 41 | ||
| 69 | /// Draw a bounding box. | 42 | /// Render the geometry. |
| 70 | void gfx_imm_draw_aabb3(ImmRenderer*, aabb3); | 43 | void gfx_llr_render_geometry(LLR*, const Geometry*); |
| 71 | 44 | ||
| 72 | /// Draw a box. | 45 | /// Render the mesh. |
| 73 | /// | 46 | void gfx_llr_render_mesh(LLR*, const Mesh*); |
| 74 | /// The vertices must be given in the following order: | ||
| 75 | /// | ||
| 76 | /// 7 ----- 6 | ||
| 77 | /// / /| | ||
| 78 | /// 3 ----- 2 | | ||
| 79 | /// | | | | ||
| 80 | /// | 4 ----- 5 | ||
| 81 | /// |/ |/ | ||
| 82 | /// 0 ----- 1 | ||
| 83 | void gfx_imm_draw_box3(ImmRenderer* renderer, const vec3 vertices[8]); | ||
| 84 | |||
| 85 | /// Set the render colour. | ||
| 86 | void gfx_imm_set_colour(ImmRenderer*, vec4 colour); | ||
| 87 | 47 | ||
| 88 | // ----------------------------------------------------------------------------- | 48 | // ----------------------------------------------------------------------------- |
| 89 | // Matrix stack manipulation. | 49 | // Matrix stack manipulation. |
| 90 | // | ||
| 91 | // Common to both scene and and primitive rendering. | ||
| 92 | 50 | ||
| 93 | /// Load an identity model matrix. Clears the matrix stack. | 51 | /// Load an identity model matrix. Clears the matrix stack. |
| 94 | void gfx_imm_load_identity(ImmRenderer* renderer); | 52 | void gfx_llr_load_identity(LLR* renderer); |
| 95 | 53 | ||
| 96 | /// Push the given matrix to the matrix stack. | 54 | /// Push the given matrix to the matrix stack. |
| 97 | void gfx_imm_push_matrix(ImmRenderer* renderer, const mat4* matrix); | 55 | void gfx_llr_push_matrix(LLR* renderer, const mat4* matrix); |
| 98 | 56 | ||
| 99 | /// Pop the top of the matrix stack. | 57 | /// Pop the top of the matrix stack. |
| 100 | void gfx_imm_pop_matrix(ImmRenderer* renderer); | 58 | void gfx_llr_pop_matrix(LLR* renderer); |
| 101 | 59 | ||
| 102 | /// Push a translation matrix to the matrix stack. | 60 | /// Push a translation matrix to the matrix stack. |
| 103 | void gfx_imm_translate(ImmRenderer* renderer, vec3 offset); | 61 | void gfx_llr_translate(LLR* renderer, vec3 offset); |
| 104 | 62 | ||
| 105 | /// Set the model matrix. Clears the matrix stack. | 63 | /// Set the model matrix. Clears the matrix stack. |
| 106 | void gfx_imm_set_model_matrix(ImmRenderer*, const mat4*); | 64 | void gfx_llr_set_model_matrix(LLR*, const mat4*); |
| 107 | |||
| 108 | // ----------------------------------------------------------------------------- | ||
| 109 | // Camera | ||
| 110 | // | ||
| 111 | // Common to both scene and and primitive rendering. | ||
| 112 | |||
| 113 | /// Set the camera. | ||
| 114 | void gfx_imm_set_camera(ImmRenderer*, const Camera*); | ||
| 115 | |||
| 116 | /// Set the view-projection matrix. | ||
| 117 | // void gfx_imm_set_view_projection_matrix(ImmRenderer*, const mat4*); | ||
diff --git a/include/gfx/renderer.h b/include/gfx/renderer.h index 2a4ada1..1da74eb 100644 --- a/include/gfx/renderer.h +++ b/include/gfx/renderer.h | |||
| @@ -1,23 +1,12 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <math/aabb2.h> | ||
| 4 | #include <math/aabb3.h> | ||
| 5 | #include <math/camera.h> | ||
| 6 | #include <math/defs.h> | 3 | #include <math/defs.h> |
| 7 | #include <math/mat4.h> | ||
| 8 | #include <math/vec3.h> | ||
| 9 | #include <math/vec4.h> | ||
| 10 | 4 | ||
| 11 | typedef struct GfxCore GfxCore; | 5 | typedef struct GfxCore GfxCore; |
| 12 | typedef struct Scene Scene; | 6 | typedef struct Scene Scene; |
| 13 | typedef struct SceneCamera SceneCamera; | 7 | typedef struct SceneCamera SceneCamera; |
| 14 | 8 | ||
| 15 | typedef struct ImmRenderer ImmRenderer; | 9 | typedef struct Renderer Renderer; |
| 16 | typedef struct Renderer Renderer; | ||
| 17 | |||
| 18 | // ----------------------------------------------------------------------------- | ||
| 19 | // Main Renderer. | ||
| 20 | // ----------------------------------------------------------------------------- | ||
| 21 | 10 | ||
| 22 | typedef enum RenderSceneMode { | 11 | typedef enum RenderSceneMode { |
| 23 | RenderDefault, | 12 | RenderDefault, |
| @@ -38,67 +27,3 @@ void gfx_render_scene(Renderer*, const RenderSceneParams*); | |||
| 38 | 27 | ||
| 39 | /// Update the scene. | 28 | /// Update the scene. |
| 40 | void gfx_update(Scene*, const SceneCamera*, R t); | 29 | void gfx_update(Scene*, const SceneCamera*, R t); |
| 41 | |||
| 42 | // ----------------------------------------------------------------------------- | ||
| 43 | // Immediate Mode Renderer. | ||
| 44 | // ----------------------------------------------------------------------------- | ||
| 45 | |||
| 46 | /// Prepare the graphics systems for immediate-mode rendering. | ||
| 47 | /// | ||
| 48 | /// Call this before issuing any immediate-mode rendering draws. | ||
| 49 | void gfx_imm_start(ImmRenderer*); | ||
| 50 | |||
| 51 | /// End immediate mode rendering. | ||
| 52 | /// | ||
| 53 | /// Call this after issuing immediate-mode rendering draws and before swapping | ||
| 54 | /// buffers. | ||
| 55 | void gfx_imm_end(ImmRenderer*); | ||
| 56 | |||
| 57 | /// Draw a set of triangles. | ||
| 58 | void gfx_imm_draw_triangles(ImmRenderer*, const vec3[], size_t num_triangles); | ||
| 59 | |||
| 60 | /// Draw a triangle. | ||
| 61 | void gfx_imm_draw_triangle(ImmRenderer*, const vec3[3]); | ||
| 62 | |||
| 63 | /// Draw a bounding box. | ||
| 64 | void gfx_imm_draw_aabb2(ImmRenderer*, aabb2); | ||
| 65 | |||
| 66 | /// Draw a bounding box. | ||
| 67 | void gfx_imm_draw_aabb3(ImmRenderer*, aabb3); | ||
| 68 | |||
| 69 | /// Draw a box. | ||
| 70 | /// | ||
| 71 | /// The vertices must be given in the following order: | ||
| 72 | /// | ||
| 73 | /// 7 ----- 6 | ||
| 74 | /// / /| | ||
| 75 | /// 3 ----- 2 | | ||
| 76 | /// | | | | ||
| 77 | /// | 4 ----- 5 | ||
| 78 | /// |/ |/ | ||
| 79 | /// 0 ----- 1 | ||
| 80 | void gfx_imm_draw_box3(ImmRenderer* renderer, const vec3 vertices[8]); | ||
| 81 | |||
| 82 | /// Set the camera. | ||
| 83 | void gfx_imm_set_camera(ImmRenderer*, const Camera*); | ||
| 84 | |||
| 85 | /// Load an identity model matrix. Clears the matrix stack. | ||
| 86 | void gfx_imm_load_identity(ImmRenderer* renderer); | ||
| 87 | |||
| 88 | /// Push the given matrix to the matrix stack. | ||
| 89 | void gfx_imm_push_matrix(ImmRenderer* renderer, const mat4* matrix); | ||
| 90 | |||
| 91 | /// Pop the top of the matrix stack. | ||
| 92 | void gfx_imm_pop_matrix(ImmRenderer* renderer); | ||
| 93 | |||
| 94 | /// Push a translation matrix to the matrix stack. | ||
| 95 | void gfx_imm_translate(ImmRenderer* renderer, vec3 offset); | ||
| 96 | |||
| 97 | /// Set the model matrix. Clears the matrix stack. | ||
| 98 | void gfx_imm_set_model_matrix(ImmRenderer*, const mat4*); | ||
| 99 | |||
| 100 | /// Set the view-projection matrix. | ||
| 101 | void gfx_imm_set_view_projection_matrix(ImmRenderer*, const mat4*); | ||
| 102 | |||
| 103 | /// Set the render colour. | ||
| 104 | void gfx_imm_set_colour(ImmRenderer*, vec4 colour); | ||
diff --git a/include/gfx/renderer/imm_renderer.h b/include/gfx/renderer/imm_renderer.h new file mode 100644 index 0000000..db4d290 --- /dev/null +++ b/include/gfx/renderer/imm_renderer.h | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <math/aabb2.h> | ||
| 4 | #include <math/aabb3.h> | ||
| 5 | #include <math/camera.h> | ||
| 6 | #include <math/mat4.h> | ||
| 7 | #include <math/vec3.h> | ||
| 8 | #include <math/vec4.h> | ||
| 9 | |||
| 10 | typedef struct ImmRenderer ImmRenderer; | ||
| 11 | |||
| 12 | /// Prepare the graphics systems for immediate-mode rendering. | ||
| 13 | /// | ||
| 14 | /// Call this before issuing any immediate-mode rendering draws. | ||
| 15 | void gfx_imm_start(ImmRenderer*); | ||
| 16 | |||
| 17 | /// End immediate mode rendering. | ||
| 18 | /// | ||
| 19 | /// Call this after issuing immediate-mode rendering draws and before swapping | ||
| 20 | /// buffers. | ||
| 21 | void gfx_imm_end(ImmRenderer*); | ||
| 22 | |||
| 23 | /// Flush draw commands. | ||
| 24 | /// | ||
| 25 | /// This should be done when changing any state that may affect the rendering of | ||
| 26 | /// primitives; for example, LLR matrix stack changes. | ||
| 27 | void gfx_imm_flush(ImmRenderer*); | ||
| 28 | |||
| 29 | /// Draw a set of triangles. | ||
| 30 | void gfx_imm_draw_triangles(ImmRenderer*, const vec3[], size_t num_triangles); | ||
| 31 | |||
| 32 | /// Draw a triangle. | ||
| 33 | void gfx_imm_draw_triangle(ImmRenderer*, const vec3[3]); | ||
| 34 | |||
| 35 | /// Draw a bounding box. | ||
| 36 | void gfx_imm_draw_aabb2(ImmRenderer*, aabb2); | ||
| 37 | |||
| 38 | /// Draw a bounding box. | ||
| 39 | void gfx_imm_draw_aabb3(ImmRenderer*, aabb3); | ||
| 40 | |||
| 41 | /// Draw a box. | ||
| 42 | /// | ||
| 43 | /// The vertices must be given in the following order: | ||
| 44 | /// | ||
| 45 | /// 7 ----- 6 | ||
| 46 | /// / /| | ||
| 47 | /// 3 ----- 2 | | ||
| 48 | /// | | | | ||
| 49 | /// | 4 ----- 5 | ||
| 50 | /// |/ |/ | ||
| 51 | /// 0 ----- 1 | ||
| 52 | void gfx_imm_draw_box3(ImmRenderer* renderer, const vec3 vertices[8]); | ||
| 53 | |||
| 54 | /// Set the render colour. | ||
| 55 | void gfx_imm_set_colour(ImmRenderer*, vec4 colour); | ||
diff --git a/include/gfx/scene.h b/include/gfx/scene.h index abcaa70..37a7e0b 100644 --- a/include/gfx/scene.h +++ b/include/gfx/scene.h | |||
| @@ -1,10 +1,11 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | // TODO: Remove references to gfx/llr once the transition is complete. | ||
| 4 | #include <gfx/llr/light.h> | ||
| 5 | #include <gfx/llr/material.h> | ||
| 6 | #include <gfx/llr/mesh.h> | ||
| 3 | #include <gfx/scene/animation.h> | 7 | #include <gfx/scene/animation.h> |
| 4 | #include <gfx/scene/camera.h> | 8 | #include <gfx/scene/camera.h> |
| 5 | #include <gfx/scene/light.h> | ||
| 6 | #include <gfx/scene/material.h> | ||
| 7 | #include <gfx/scene/mesh.h> | ||
| 8 | #include <gfx/scene/model.h> | 9 | #include <gfx/scene/model.h> |
| 9 | #include <gfx/scene/node.h> | 10 | #include <gfx/scene/node.h> |
| 10 | #include <gfx/scene/object.h> | 11 | #include <gfx/scene/object.h> |
diff --git a/include/gfx/sizes.h b/include/gfx/sizes.h index 14f72bc..3eb7481 100644 --- a/include/gfx/sizes.h +++ b/include/gfx/sizes.h | |||
| @@ -77,14 +77,20 @@ | |||
| 77 | /// Maximum number of compiler defines in a Shader. | 77 | /// Maximum number of compiler defines in a Shader. |
| 78 | #define GFX_MAX_SHADER_COMPILER_DEFINES 16 | 78 | #define GFX_MAX_SHADER_COMPILER_DEFINES 16 |
| 79 | 79 | ||
| 80 | // Renderer. | 80 | // Low-level renderer. |
| 81 | |||
| 82 | /// Maximum number of lights that the low-level renderer can enable per rendered | ||
| 83 | /// mesh. | ||
| 84 | #define GFX_LLR_MAX_NUM_LIGHTS 8 | ||
| 85 | |||
| 86 | /// Maximum number of matrices in the low-level renderer's matrix stack. | ||
| 87 | #define GFX_LLR_MAX_NUM_MATRICES 32 | ||
| 88 | |||
| 89 | // Immediate-mode Renderer. | ||
| 81 | 90 | ||
| 82 | /// Maximum number of triangles that the immediate-mode renderer can draw in a | 91 | /// Maximum number of triangles that the immediate-mode renderer can draw in a |
| 83 | /// frame. | 92 | /// frame. |
| 84 | #define IMM_MAX_NUM_TRIANGLES 1024 | 93 | #define GFX_IMM_MAX_NUM_TRIANGLES 1024 |
| 85 | |||
| 86 | /// Maximum number of matrices in the immediate-mode renderer's matrix stack. | ||
| 87 | #define IMM_MAX_NUM_MATRICES 32 | ||
| 88 | 94 | ||
| 89 | // Asset Cache. | 95 | // Asset Cache. |
| 90 | 96 | ||
