diff options
Diffstat (limited to 'src/llr/llr_impl.h')
-rw-r--r-- | src/llr/llr_impl.h | 99 |
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 | |||
12 | typedef struct Geometry Geometry; | ||
13 | typedef struct GfxCore GfxCore; | ||
14 | typedef struct IBL IBL; | ||
15 | typedef struct Material Material; | ||
16 | typedef struct ShaderProgram ShaderProgram; | ||
17 | typedef 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. | ||
42 | typedef 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. | ||
93 | bool gfx_imm_make(ImmRenderer*, GfxCore*); | ||
94 | |||
95 | /// Destroy the immediate mode renderer. | ||
96 | void gfx_imm_destroy(ImmRenderer*); | ||
97 | |||
98 | /// Flush draw commands. | ||
99 | void gfx_imm_flush(ImmRenderer*); | ||