aboutsummaryrefslogtreecommitdiff
path: root/src/llr/llr_impl.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-07-04 10:37:01 -0700
committer3gg <3gg@shellblade.net>2025-07-04 10:37:01 -0700
commitb37b5398a6afa940acd1138bde922a70838f33af (patch)
tree9ff988e0412d4210362b52f82fbe723e734b6228 /src/llr/llr_impl.h
parent1ec46bead3cf87971a2329f9ef4ddde5a0c48325 (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 'src/llr/llr_impl.h')
-rw-r--r--src/llr/llr_impl.h67
1 files changed, 24 insertions, 43 deletions
diff --git a/src/llr/llr_impl.h b/src/llr/llr_impl.h
index 5ccabd1..e9dc0ac 100644
--- a/src/llr/llr_impl.h
+++ b/src/llr/llr_impl.h
@@ -8,6 +8,7 @@
8 8
9#include <stdbool.h> 9#include <stdbool.h>
10#include <stddef.h> 10#include <stddef.h>
11#include <stdint.h>
11 12
12typedef struct Geometry Geometry; 13typedef struct Geometry Geometry;
13typedef struct GfxCore GfxCore; 14typedef struct GfxCore GfxCore;
@@ -33,67 +34,47 @@ typedef struct Texture Texture;
33/// Note that the shader program API has its own level of caching as well, so 34/// Note that the shader program API has its own level of caching as well, so
34/// reconfiguration at the level of the renderer does not result in the 35/// reconfiguration at the level of the renderer does not result in the
35/// worst-case set of graphics API calls. 36/// worst-case set of graphics API calls.
36/// 37typedef struct LLR {
37/// Currently, the immediate mode renderer can only draw up to a maximum number
38/// of primitives per frame. It does not adjust this number dynamically. Keeps
39/// things simple while the extra complexity is not needed.
40/// TODO: Flush the buffer when it reaches its maximum size to remove this
41/// constraint.
42typedef struct ImmRenderer {
43 GfxCore* gfxcore; 38 GfxCore* gfxcore;
44 39
45 vec3 camera_position; 40 union {
46 mat4 view; // Camera view matrix. 41 struct {
47 mat4 projection; // Camera projection matrix. 42 bool shader_changed : 1; // Whether the shader has changed.
48 bool camera_changed; // Whether the camera parameters have changed. 43 bool camera_changed : 1; // Whether the camera parameters have changed.
49 44 bool lights_changed : 1; // Whether the lights have changed.
50 // ------------------------------------------- 45 bool skeleton_changed : 1; // Whether the skeleton has changed.
51 // Immediate-mode rendering of scene elements. 46 bool matrix_changed : 1; // Whether the matrix stack has changed.
47 };
48 uint8_t changed_flags;
49 };
52 50
53 IBL* ibl; 51 IBL* ibl;
54 Texture* brdf_integration_map; 52 Texture* brdf_integration_map;
55 53
56 ShaderProgram* shader; // Active shader. Not owned. 54 ShaderProgram* shader; // Active shader. Not owned.
57 bool shader_changed; // Whether the shader has changed. 55
56 vec3 camera_position;
57 mat4 view; // Camera view matrix.
58 mat4 projection; // Camera projection matrix.
58 59
59 // Lights are not const because environment lights store lazily-computed 60 // Lights are not const because environment lights store lazily-computed
60 // irradiance maps. 61 // irradiance maps.
61 Light* lights[IMM_MAX_NUM_LIGHTS]; // Lights stack. 62 Light* lights[GFX_LLR_MAX_NUM_LIGHTS]; // Lights stack.
62 int num_lights; // Number of lights enabled at a given point in time. It 63 int num_lights; // Number of lights enabled at a given point in time. It
63 // points to one past the top of the stack. 64 // points to one past the top of the stack.
64 bool lights_changed; // Whether the lights have changed.
65 65
66 bool skeleton_changed;
67 size_t num_joints; 66 size_t num_joints;
68 mat4 joint_matrices[GFX_MAX_NUM_JOINTS]; 67 mat4 joint_matrices[GFX_MAX_NUM_JOINTS];
69 68
70 // ---------------------------------------
71 // Immediate-mode rendering of primitives.
72
73 ShaderProgram* imm_shader; // Immediate-mode shader program for primitives.
74 Geometry* triangles;
75 size_t num_triangle_verts; // Number of triangle verts this frame.
76 // TODO: wireframe rendering.
77 struct {
78 bool wireframe : 1;
79 } flags;
80 vec3 triangle_verts[IMM_MAX_NUM_TRIANGLES * 3];
81
82 // -------------
83 // Matrix stack.
84
85 // The matrix stack contains pre-multiplied matrices. 69 // The matrix stack contains pre-multiplied matrices.
86 // It is also never empty. The top of the stack is an identity matrix when the 70 // It is also never empty. The top of the stack is an identity matrix when the
87 // stack is "empty" from the user's perspective. 71 // stack is "empty" from the user's perspective.
88 mat4 matrix_stack[IMM_MAX_NUM_MATRICES]; 72 mat4 matrix_stack[GFX_LLR_MAX_NUM_MATRICES];
89 int stack_pointer; // Points to the top of the stack. 73 int stack_pointer; // Points to the top of the stack.
90} ImmRenderer; 74} LLR;
91 75
92/// Create a new immediate mode renderer. 76/// Create a new immediate mode renderer.
93bool gfx_imm_make(ImmRenderer*, GfxCore*); 77bool gfx_llr_make(LLR*, GfxCore*);
94 78
95/// Destroy the immediate mode renderer. 79/// Destroy the immediate mode renderer.
96void gfx_imm_destroy(ImmRenderer*); 80void gfx_llr_destroy(LLR*);
97
98/// Flush draw commands.
99void gfx_imm_flush(ImmRenderer*);