diff options
Diffstat (limited to 'src/llr/llr_impl.h')
-rw-r--r-- | src/llr/llr_impl.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/llr/llr_impl.h b/src/llr/llr_impl.h new file mode 100644 index 0000000..ada2d79 --- /dev/null +++ b/src/llr/llr_impl.h | |||
@@ -0,0 +1,83 @@ | |||
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 | #include <stdint.h> | ||
12 | |||
13 | typedef struct Geometry Geometry; | ||
14 | typedef struct GfxCore GfxCore; | ||
15 | typedef struct IBL IBL; | ||
16 | typedef struct Material Material; | ||
17 | typedef struct ShaderProgram ShaderProgram; | ||
18 | typedef struct Texture Texture; | ||
19 | |||
20 | /// Immediate mode renderer. | ||
21 | /// | ||
22 | /// The renderer caches state changes in memory and only programs the underlying | ||
23 | /// shader program when a draw call is issued and if anything has changed. This | ||
24 | /// keeps the number of graphics API calls to a minimum, but requires tracking | ||
25 | /// state changes. The 'changed' booleans below fulfill this purpose, and | ||
26 | /// indicate whether a given state has changed since the last draw call. | ||
27 | /// | ||
28 | /// The renderer must combine state changes accordingly. For example, if only | ||
29 | /// the lights have changed, then it is sufficient to update light uniforms in | ||
30 | /// the current shader program. On the other hand, if the shader program has | ||
31 | /// changed, then the renderer must reconfigure it from scratch and set light | ||
32 | /// uniforms, camera uniforms, etc. | ||
33 | /// | ||
34 | /// Note that the shader program API has its own level of caching as well, so | ||
35 | /// reconfiguration at the level of the renderer does not result in the | ||
36 | /// worst-case set of graphics API calls. | ||
37 | typedef struct LLR { | ||
38 | GfxCore* gfxcore; | ||
39 | |||
40 | union { | ||
41 | struct { | ||
42 | bool shader_changed : 1; // Whether the shader has changed. | ||
43 | bool camera_changed : 1; // Whether the camera parameters have changed. | ||
44 | bool lights_changed : 1; // Whether the lights have changed. | ||
45 | bool skeleton_changed : 1; // Whether the skeleton has changed. | ||
46 | bool matrix_changed : 1; // Whether the matrix stack has changed. | ||
47 | }; | ||
48 | uint8_t changed_flags; | ||
49 | }; | ||
50 | |||
51 | IBL* ibl; | ||
52 | Texture* brdf_integration_map; | ||
53 | |||
54 | ShaderProgram* shader; // Active shader. Not owned. | ||
55 | |||
56 | vec3 camera_position; | ||
57 | mat4 camera_rotation; | ||
58 | mat4 view; // Camera view matrix. | ||
59 | mat4 projection; // Camera projection matrix. | ||
60 | R fovy; // Camera vertical field of view. | ||
61 | R aspect; // Aspect ratio. | ||
62 | |||
63 | // Lights are not const because environment lights store lazily-computed | ||
64 | // irradiance maps. | ||
65 | Light* lights[GFX_LLR_MAX_NUM_LIGHTS]; // Lights stack. | ||
66 | int num_lights; // Number of lights enabled at a given point in time. It | ||
67 | // points to one past the top of the stack. | ||
68 | |||
69 | size_t num_joints; | ||
70 | mat4 joint_matrices[GFX_MAX_NUM_JOINTS]; | ||
71 | |||
72 | // The matrix stack contains pre-multiplied matrices. | ||
73 | // It is also never empty. The top of the stack is an identity matrix when the | ||
74 | // stack is "empty" from the user's perspective. | ||
75 | mat4 matrix_stack[GFX_LLR_MAX_NUM_MATRICES]; | ||
76 | int stack_pointer; // Points to the top of the stack. | ||
77 | } LLR; | ||
78 | |||
79 | /// Create a new immediate mode renderer. | ||
80 | bool gfx_llr_make(LLR*, GfxCore*); | ||
81 | |||
82 | /// Destroy the immediate mode renderer. | ||
83 | void gfx_llr_destroy(LLR*); | ||