aboutsummaryrefslogtreecommitdiff
path: root/src/llr/llr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/llr/llr.c')
-rw-r--r--src/llr/llr.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/llr/llr.c b/src/llr/llr.c
index 74cfaed..664c9a4 100644
--- a/src/llr/llr.c
+++ b/src/llr/llr.c
@@ -36,11 +36,14 @@ static bool init_ibl(LLR* renderer) {
36 return true; 36 return true;
37} 37}
38 38
39// TODO: Why is this done lazily here? Do it when the environment light is
40// created.
41//
42/// Compute irradiance and prefiltered environment maps for the light if they 39/// Compute irradiance and prefiltered environment maps for the light if they
43/// have not been already computed. 40/// have not been already computed.
41///
42/// This is done lazily here, and not when the light is created, because we
43/// need an IBL instance to do this and it is more convenient for the public
44/// API to create lights without worrying about those details. It also makes the
45/// public API cheaper, since the maps are only computed when they are actually
46/// needed.
44static bool set_up_environment_light(LLR* renderer, EnvironmentLight* light) { 47static bool set_up_environment_light(LLR* renderer, EnvironmentLight* light) {
45 assert(renderer); 48 assert(renderer);
46 assert(light); 49 assert(light);
@@ -198,11 +201,20 @@ static void configure_state(LLR* renderer) {
198 } 201 }
199 } 202 }
200 203
204 if (renderer->material_changed || renderer->shader_changed) {
205 renderer->material_changed = false;
206
207 gfx_material_activate(renderer->shader, renderer->material);
208 }
209
201 if (renderer->shader_changed) { 210 if (renderer->shader_changed) {
202 renderer->shader_changed = false; 211 renderer->shader_changed = false;
203 gfx_activate_shader_program(renderer->shader); 212 gfx_activate_shader_program(renderer->shader);
204 } 213 }
205 214
215 // TODO: At present, this results in many redundant calls to
216 // glGetUniformLocation() and glUniformXyz(). Look at the trace.
217 //
206 // Must be called after activating the program. 218 // Must be called after activating the program.
207 gfx_apply_uniforms(renderer->shader); 219 gfx_apply_uniforms(renderer->shader);
208} 220}
@@ -293,6 +305,14 @@ void gfx_llr_clear_skeleton(LLR* renderer) {
293 renderer->skeleton_changed = true; 305 renderer->skeleton_changed = true;
294} 306}
295 307
308void gfx_llr_set_material(LLR* renderer, const Material* material) {
309 assert(renderer);
310 assert(material);
311
312 renderer->material = material;
313 renderer->material_changed = true;
314}
315
296void gfx_llr_set_camera(LLR* renderer, const Camera* camera) { 316void gfx_llr_set_camera(LLR* renderer, const Camera* camera) {
297 assert(renderer); 317 assert(renderer);
298 318
@@ -328,7 +348,7 @@ void gfx_llr_render_mesh(LLR* renderer, const Mesh* mesh) {
328 assert(mesh->geometry); 348 assert(mesh->geometry);
329 assert(mesh->material); 349 assert(mesh->material);
330 350
331 gfx_material_activate(renderer->shader, mesh->material); 351 gfx_llr_set_material(renderer, mesh->material);
332 gfx_llr_render_geometry(renderer, mesh->geometry); 352 gfx_llr_render_geometry(renderer, mesh->geometry);
333} 353}
334 354