From b37b5398a6afa940acd1138bde922a70838f33af Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 4 Jul 2025 10:37:01 -0700 Subject: Add the new low-level renderer, shared between the imm and scene graph renderer. LLR integration with the scene graph renderer not yet done. --- src/llr/llr_impl.h | 67 +++++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 43 deletions(-) (limited to 'src/llr/llr_impl.h') 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 @@ #include #include +#include typedef struct Geometry Geometry; typedef struct GfxCore GfxCore; @@ -33,67 +34,47 @@ typedef struct Texture Texture; /// Note that the shader program API has its own level of caching as well, so /// reconfiguration at the level of the renderer does not result in the /// worst-case set of graphics API calls. -/// -/// Currently, the immediate mode renderer can only draw up to a maximum number -/// of primitives per frame. It does not adjust this number dynamically. Keeps -/// things simple while the extra complexity is not needed. -/// TODO: Flush the buffer when it reaches its maximum size to remove this -/// constraint. -typedef struct ImmRenderer { +typedef struct LLR { GfxCore* gfxcore; - vec3 camera_position; - mat4 view; // Camera view matrix. - mat4 projection; // Camera projection matrix. - bool camera_changed; // Whether the camera parameters have changed. - - // ------------------------------------------- - // Immediate-mode rendering of scene elements. + union { + struct { + bool shader_changed : 1; // Whether the shader has changed. + bool camera_changed : 1; // Whether the camera parameters have changed. + bool lights_changed : 1; // Whether the lights have changed. + bool skeleton_changed : 1; // Whether the skeleton has changed. + bool matrix_changed : 1; // Whether the matrix stack has changed. + }; + uint8_t changed_flags; + }; IBL* ibl; Texture* brdf_integration_map; - ShaderProgram* shader; // Active shader. Not owned. - bool shader_changed; // Whether the shader has changed. + ShaderProgram* shader; // Active shader. Not owned. + + vec3 camera_position; + mat4 view; // Camera view matrix. + mat4 projection; // Camera projection matrix. // Lights are not const because environment lights store lazily-computed // irradiance maps. - Light* lights[IMM_MAX_NUM_LIGHTS]; // Lights stack. - int num_lights; // Number of lights enabled at a given point in time. It - // points to one past the top of the stack. - bool lights_changed; // Whether the lights have changed. + Light* lights[GFX_LLR_MAX_NUM_LIGHTS]; // Lights stack. + int num_lights; // Number of lights enabled at a given point in time. It + // points to one past the top of the stack. - bool skeleton_changed; size_t num_joints; mat4 joint_matrices[GFX_MAX_NUM_JOINTS]; - // --------------------------------------- - // Immediate-mode rendering of primitives. - - ShaderProgram* imm_shader; // Immediate-mode shader program for primitives. - Geometry* triangles; - size_t num_triangle_verts; // Number of triangle verts this frame. - // TODO: wireframe rendering. - struct { - bool wireframe : 1; - } flags; - vec3 triangle_verts[IMM_MAX_NUM_TRIANGLES * 3]; - - // ------------- - // Matrix stack. - // The matrix stack contains pre-multiplied matrices. // It is also never empty. The top of the stack is an identity matrix when the // stack is "empty" from the user's perspective. - mat4 matrix_stack[IMM_MAX_NUM_MATRICES]; + mat4 matrix_stack[GFX_LLR_MAX_NUM_MATRICES]; int stack_pointer; // Points to the top of the stack. -} ImmRenderer; +} LLR; /// Create a new immediate mode renderer. -bool gfx_imm_make(ImmRenderer*, GfxCore*); +bool gfx_llr_make(LLR*, GfxCore*); /// Destroy the immediate mode renderer. -void gfx_imm_destroy(ImmRenderer*); - -/// Flush draw commands. -void gfx_imm_flush(ImmRenderer*); +void gfx_llr_destroy(LLR*); -- cgit v1.2.3