aboutsummaryrefslogtreecommitdiff
path: root/src/llr/llr_impl.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-07-04 10:27:06 -0700
committer3gg <3gg@shellblade.net>2025-07-04 10:27:06 -0700
commit1ec46bead3cf87971a2329f9ef4ddde5a0c48325 (patch)
tree3f4c404467c3ad9c94265295f4aa1b97a10a9eb3 /src/llr/llr_impl.h
parente386405ac636b7e4a41d5c03eb363e9c120ce919 (diff)
Clarify doc
Diffstat (limited to 'src/llr/llr_impl.h')
-rw-r--r--src/llr/llr_impl.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/llr/llr_impl.h b/src/llr/llr_impl.h
new file mode 100644
index 0000000..5ccabd1
--- /dev/null
+++ b/src/llr/llr_impl.h
@@ -0,0 +1,99 @@
1#pragma once
2
3#include <gfx/llr/llr.h>
4#include <gfx/sizes.h>
5
6#include <math/mat4.h>
7#include <math/vec3.h>
8
9#include <stdbool.h>
10#include <stddef.h>
11
12typedef struct Geometry Geometry;
13typedef struct GfxCore GfxCore;
14typedef struct IBL IBL;
15typedef struct Material Material;
16typedef struct ShaderProgram ShaderProgram;
17typedef struct Texture Texture;
18
19/// Immediate mode renderer.
20///
21/// The renderer caches state changes in memory and only programs the underlying
22/// shader program when a draw call is issued and if anything has changed. This
23/// keeps the number of graphics API calls to a minimum, but requires tracking
24/// state changes. The 'changed' booleans below fulfill this purpose, and
25/// indicate whether a given state has changed since the last draw call.
26///
27/// The renderer must combine state changes accordingly. For example, if only
28/// the lights have changed, then it is sufficient to update light uniforms in
29/// the current shader program. On the other hand, if the shader program has
30/// changed, then the renderer must reconfigure it from scratch and set light
31/// uniforms, camera uniforms, etc.
32///
33/// 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/// worst-case set of graphics API calls.
36///
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;
44
45 vec3 camera_position;
46 mat4 view; // Camera view matrix.
47 mat4 projection; // Camera projection matrix.
48 bool camera_changed; // Whether the camera parameters have changed.
49
50 // -------------------------------------------
51 // Immediate-mode rendering of scene elements.
52
53 IBL* ibl;
54 Texture* brdf_integration_map;
55
56 ShaderProgram* shader; // Active shader. Not owned.
57 bool shader_changed; // Whether the shader has changed.
58
59 // Lights are not const because environment lights store lazily-computed
60 // irradiance maps.
61 Light* lights[IMM_MAX_NUM_LIGHTS]; // Lights stack.
62 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 bool lights_changed; // Whether the lights have changed.
65
66 bool skeleton_changed;
67 size_t num_joints;
68 mat4 joint_matrices[GFX_MAX_NUM_JOINTS];
69
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.
86 // 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.
88 mat4 matrix_stack[IMM_MAX_NUM_MATRICES];
89 int stack_pointer; // Points to the top of the stack.
90} ImmRenderer;
91
92/// Create a new immediate mode renderer.
93bool gfx_imm_make(ImmRenderer*, GfxCore*);
94
95/// Destroy the immediate mode renderer.
96void gfx_imm_destroy(ImmRenderer*);
97
98/// Flush draw commands.
99void gfx_imm_flush(ImmRenderer*);