$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
scene.h
Go to the documentation of this file.
1 #ifndef SCENE_H
2 #define SCENE_H
3 
4 #include "app_settings.h"
5 #include "billboard_rendering.h"
6 #include "gl_common.h"
7 #include "gpu_profiler.h"
8 #include "ibl_coordinator.h"
9 #include "icosphere.h"
10 #include "instanced_rendering.h"
11 #include "light_probes.h"
12 #include "material.h"
13 #include "shader.h"
14 #include "skybox.h"
15 #include "sphere_sorting.h"
16 #include <cglm/cglm.h>
17 
18 #ifdef USE_SSBO_RENDERING
19 #include "ssbo_rendering.h"
20 #endif
21 
22 typedef struct PostProcess PostProcess;
23 
28 typedef enum {
34 
39 typedef enum {
45 
50 typedef enum {
55 
61 enum { IBL_TEXTURE_COUNT = 3 };
62 enum { TEXTURE_UNIT_IBL_START = 15 };
63 
64 typedef struct {
66  GLint prefilter_map;
67  GLint brdf_lut;
68  GLint debug_mode;
69  GLint cam_pos;
70  GLint projection;
71  GLint view;
76  GLint gi_mode;
78  GLint u_aa_mode;
79  GLint
80  sh_textures[SH_TEXTURE_COUNT];
82 
87 typedef struct {
88  GLint projection;
89  GLint view;
90  GLint u_stippled;
93  GLint u_color;
95 
101 enum { MAT4_FLOAT_COUNT = 16 };
102 typedef struct {
103  float projection[MAT4_FLOAT_COUNT];
104  float view[MAT4_FLOAT_COUNT];
105  float previous_view_proj[MAT4_FLOAT_COUNT];
107  float cam_pos[3];
108  int32_t debug_mode;
109  float screen_size[2];
110  float _pad0[2];
111  float probe_grid_min[3];
112  int32_t gi_mode;
113  float probe_grid_max[3];
115  int32_t probe_grid_dim[3];
116  int32_t aa_mode;
117  float grid_to_idx_scale[3];
118  float _pad1;
120 
122 
129 typedef struct {
130  GLint
131  sh_textures[SH_TEXTURE_COUNT];
133 
138 typedef struct Scene {
139  /* --- Geometry & Meshes --- */
144 #ifdef USE_SSBO_RENDERING
145  SSBOGroup ssbo_group;
146 #endif
147 
148 #ifdef USE_TRANSPARENT_BILLBOARDS
152 #endif
153 
156  char** hdr_files;
157  int hdr_count;
163  /* --- Shaders --- */
165  Shader*
167 #ifdef USE_SSBO_RENDERING
168  Shader* pbr_ssbo_shader;
169 #endif
174  /* --- GPU Resources --- */
175  GLuint sphere_vao;
176  GLuint sphere_vbo;
177  GLuint sphere_nbo;
178  GLuint sphere_ebo;
179  GLuint quad_vbo;
180  GLuint wire_cube_vbo;
181  GLuint wire_quad_vbo;
182  GLuint hdr_texture;
185  GLuint irradiance_tex;
186  GLuint brdf_lut_tex;
187  GLuint empty_vao;
188  GLuint shader_spmap;
189  GLuint shader_irmap;
194  GLuint lum_ssbo[2];
196  GLuint billboard_ubo;
199  /* --- IBL Binding Cache (Tier 5 — units 15-17) --- */
202  /* --- SH/Probe Binding Cache (Tier 3 — units 8-14 + SSBO 3) --- */
206  /* --- Render Configuration --- */
207  int wireframe;
212  float env_lod;
219  /* --- Uniform Caches --- */
224 } Scene;
225 
231 int scene_init(Scene* scene);
232 
237 void scene_cleanup(Scene* scene);
238 
244 const char* aa_mode_to_string(AAMode mode);
245 
256 void scene_render(Scene* scene, GPUProfiler* profiler, mat4 view, mat4 proj,
257  vec3 camera_pos, mat4 previous_view_proj, int width,
258  int height);
259 
264 void scene_update_gpu_buffers(Scene* scene);
265 
266 #endif /* SCENE_H */
Global application constants, configuration macros, and default values.
View-aligned quad rendering (billboarding) for optimized sphere drawing.
Common OpenGL definitions, RAII helpers, and utilities.
#define GL_ASSERT_UBO_ALIGNMENT(type)
Compile-time assertion that a UBO struct meets AVX alignment. Place after the typedef to catch miscon...
Definition: gl_common.h:153
#define GL_UBO_ALIGNED
Attribute to apply on UBO typedef to enforce AVX alignment. Usage: } GL_UBO_ALIGNED MyUBOType;.
Definition: gl_common.h:146
Coordinator for progressive Image-Based Lighting (IBL) generation.
Procedural icosphere geometry generation.
Mesh-based instanced rendering for spheres.
@ SH_TEXTURE_COUNT
Definition: light_probes.h:21
PBR material definitions and management.
AAMode
Specular Anti-Aliasing modes.
Definition: scene.h:50
@ AA_MODE_CURVATURE
Definition: scene.h:52
@ AA_MODE_COUNT
Definition: scene.h:53
@ AA_MODE_SCREEN_SPACE
Definition: scene.h:51
void scene_render(Scene *scene, GPUProfiler *profiler, mat4 view, mat4 proj, vec3 camera_pos, mat4 previous_view_proj, int width, int height)
Renders the scene.
Definition: scene.c:825
@ TEXTURE_UNIT_IBL_START
Definition: scene.h:62
void scene_cleanup(Scene *scene)
Cleans up scene resources.
Definition: scene.c:533
GIMode
Global Illumination sampling methods.
Definition: scene.h:39
@ GI_MODE_COUNT
Definition: scene.h:43
@ GI_MODE_3D_TEX
Definition: scene.h:41
@ GI_MODE_OFF
Definition: scene.h:40
@ GI_MODE_SSBO
Definition: scene.h:42
void scene_update_gpu_buffers(Scene *scene)
Updates GPU buffers for dynamic geometry (e.g. LOD changes).
Definition: scene.c:588
SortingMode
Sorting algorithms for transparent billboards.
Definition: scene.h:28
@ SORTING_MODE_CPU_QSORT
Definition: scene.h:29
@ SORTING_MODE_CPU_RADIX
Definition: scene.h:30
@ SORTING_MODE_GPU_BITONIC
Definition: scene.h:31
@ SORTING_MODE_COUNT
Definition: scene.h:32
@ IBL_TEXTURE_COUNT
Definition: scene.h:61
@ MAT4_FLOAT_COUNT
Definition: scene.h:101
int scene_init(Scene *scene)
Initializes the scene resources.
Definition: scene.c:408
const char * aa_mode_to_string(AAMode mode)
Returns a string representation of the AA mode.
Definition: scene.c:576
High-level OpenGL shader management with metadata and uniform caching.
Infinite-distance background rendering (fullscreen quad approach).
Back-to-front sorting for transparent geometry.
Buffer-backed instancing for ultra-large-scale rendering.
Manages a set of billboarded instances on the GPU.
Definition: billboard_rendering.h:22
GPU-side uniform buffer for billboard rendering (std140 layout).
Definition: scene.h:102
int32_t gi_mode
Definition: scene.h:112
int32_t aa_mode
Definition: scene.h:116
float _pad1
Definition: scene.h:118
int32_t debug_mode
Definition: scene.h:108
int32_t specular_aa_enabled
Definition: scene.h:114
Cached uniform locations for billboard rendering.
Definition: scene.h:129
Cached uniform locations for debug line rendering.
Definition: scene.h:87
GLint view
Definition: scene.h:89
GLint u_billboard_mode
Definition: scene.h:91
GLint u_stippled
Definition: scene.h:90
GLint u_color
Definition: scene.h:93
GLint u_use_instance_col
Definition: scene.h:92
GLint projection
Definition: scene.h:88
Manages GPU timing using double-buffered queries to avoid stalls.
Definition: gpu_profiler.h:86
Manages the progressive IBL generation process.
Definition: ibl_coordinator.h:36
Container for procedural mesh data.
Definition: icosphere.h:40
Manages mesh-based instanced spheres on the GPU.
Definition: instanced_rendering.h:36
Cached uniform locations for PBR instanced rendering.
Definition: scene.h:64
GLint gi_mode
Definition: scene.h:76
GLint debug_mode
Definition: scene.h:68
GLint probe_grid_dim
Definition: scene.h:75
GLint probe_grid_max
Definition: scene.h:74
GLint u_specular_aa_enabled
Definition: scene.h:77
GLint u_aa_mode
Definition: scene.h:78
GLint prefilter_map
Definition: scene.h:66
GLint previous_view_proj
Definition: scene.h:72
GLint view
Definition: scene.h:71
GLint irradiance_map
Definition: scene.h:65
GLint probe_grid_min
Definition: scene.h:73
GLint cam_pos
Definition: scene.h:69
GLint brdf_lut
Definition: scene.h:67
GLint projection
Definition: scene.h:70
Definition: light_probes.h:30
A collection of material presets loaded from disk or defined at runtime.
Definition: material.h:34
Main pipeline state for post-processing.
Definition: postprocess.h:353
GPU resources for an SSBO-based render group.
Definition: ssbo_rendering.h:35
Encapsulates all 3D scene data, geometry, and rendering state.
Definition: scene.h:138
GLuint bound_sh_textures[SH_TEXTURE_COUNT]
Definition: scene.h:203
SortingMode sorting_mode
Definition: scene.h:209
GLuint empty_vao
Definition: scene.h:187
Skybox skybox
Definition: scene.h:154
BillboardGroup billboard_group
Definition: scene.h:143
GLuint wire_quad_vbo
Definition: scene.h:181
GLuint shader_lum_pass1
Definition: scene.h:190
Shader * debug_line_shader
Definition: scene.h:171
InstancedUniforms instanced_uniforms
Definition: scene.h:221
Shader * pbr_instanced_shader
Definition: scene.h:164
int show_probe_grid
Definition: scene.h:215
void * billboard_ubo_ptr
Definition: scene.h:197
AAMode aa_mode
Definition: scene.h:217
int subdivisions
Definition: scene.h:213
int show_envmap
Definition: scene.h:211
GLuint bound_ibl_textures[IBL_TEXTURE_COUNT]
Definition: scene.h:200
GLuint lum_ssbo[2]
Definition: scene.h:194
GLuint spec_prefiltered_tex
Definition: scene.h:184
int current_hdr_index
Definition: scene.h:158
DebugUniforms debug_uniforms
Definition: scene.h:222
GLuint hdr_texture
Definition: scene.h:182
float env_lod
Definition: scene.h:212
GLuint billboard_ubo
Definition: scene.h:196
GLuint recycled_hdr_tex
Definition: scene.h:183
SphereSorter sphere_sorter
Definition: scene.h:149
GLuint bound_probe_ssbo
Definition: scene.h:204
int sphere_instance_count
Definition: scene.h:151
int hdr_count
Definition: scene.h:157
int specular_aa_enabled
Definition: scene.h:216
GLuint irradiance_tex
Definition: scene.h:185
Shader * debug_shader
Definition: scene.h:170
GLuint shader_lum_pass2
Definition: scene.h:191
MaterialLib * material_lib
Definition: scene.h:155
SphereInstance * sphere_instances
Definition: scene.h:150
GLuint dummy_black_tex
Definition: scene.h:192
Shader * pbr_billboard_shader
Definition: scene.h:166
GLuint brdf_lut_tex
Definition: scene.h:186
int billboard_mode
Definition: scene.h:208
BillboardUniforms billboard_uniforms
Definition: scene.h:220
GLuint transition_snapshot_tex
Definition: scene.h:195
Shader * skybox_shader
Definition: scene.h:172
int pbr_debug_mode
Definition: scene.h:210
IcosphereGeometry geometry
Definition: scene.h:140
GLuint shader_irmap
Definition: scene.h:189
char ** hdr_files
Definition: scene.h:156
GLuint sphere_ebo
Definition: scene.h:178
GLuint wire_cube_vbo
Definition: scene.h:180
int wireframe
Definition: scene.h:207
GLuint sphere_nbo
Definition: scene.h:177
InstancedGroup instanced_group
Definition: scene.h:142
LightProbeGrid probe_grid
Definition: scene.h:161
GLuint sphere_vao
Definition: scene.h:175
GLuint quad_vbo
Definition: scene.h:179
GIMode gi_mode
Definition: scene.h:214
IBLCoordinator ibl_coord
Definition: scene.h:159
GLuint shader_spmap
Definition: scene.h:188
GLuint dummy_white_tex
Definition: scene.h:193
GLuint sphere_vbo
Definition: scene.h:176
Wrapper for an OpenGL program with uniform caching and automatic cleanup.
Definition: shader.h:71
Persistent state and resource handles for the environment renderer.
Definition: skybox.h:23
Per-instance data sent to the shader via an instanced VBO.
Definition: instanced_rendering.h:23
Reusable memory context for sorting operations.
Definition: sphere_sorting.h:28