aboutsummaryrefslogtreecommitdiff
path: root/src/render/llr_impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/llr_impl.h')
-rw-r--r--src/render/llr_impl.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/render/llr_impl.h b/src/render/llr_impl.h
new file mode 100644
index 0000000..9d70843
--- /dev/null
+++ b/src/render/llr_impl.h
@@ -0,0 +1,85 @@
1#pragma once
2
3#include <gfx/render/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
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.
36typedef struct LLR {
37 GfxCore* gfxcore;
38
39 union {
40 struct {
41 bool shader_changed : 1; // Whether the shader has changed.
42 bool camera_changed : 1; // Whether the camera parameters have changed.
43 bool lights_changed : 1; // Whether the lights have changed.
44 bool skeleton_changed : 1; // Whether the skeleton has changed.
45 bool material_changed : 1; // Whether the material 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 const Material* material; // Active material. Not owned.
57
58 vec3 camera_position;
59 mat4 camera_rotation;
60 mat4 view; // Camera view matrix.
61 mat4 projection; // Camera projection matrix.
62 R fovy; // Camera vertical field of view.
63 R aspect; // Aspect ratio.
64
65 // Lights are not const because environment lights store lazily-computed
66 // irradiance maps.
67 Light* lights[GFX_LLR_MAX_NUM_LIGHTS]; // Lights stack.
68 int num_lights; // Number of lights enabled at a given point in time. It
69 // points to one past the top of the stack.
70
71 size_t num_joints;
72 mat4 joint_matrices[GFX_MAX_NUM_JOINTS];
73
74 // The matrix stack contains pre-multiplied matrices.
75 // It is also never empty. The top of the stack is an identity matrix when the
76 // stack is "empty" from the user's perspective.
77 mat4 matrix_stack[GFX_LLR_MAX_NUM_MATRICES];
78 int stack_pointer; // Points to the top of the stack.
79} LLR;
80
81/// Create a new immediate mode renderer.
82bool gfx_llr_make(LLR*, GfxCore*);
83
84/// Destroy the immediate mode renderer.
85void gfx_llr_destroy(LLR*);