diff options
Diffstat (limited to 'src/llr')
-rw-r--r-- | src/llr/light.c | 4 | ||||
-rw-r--r-- | src/llr/light_impl.h | 4 | ||||
-rw-r--r-- | src/llr/llr.c | 28 | ||||
-rw-r--r-- | src/llr/llr_impl.h | 3 | ||||
-rw-r--r-- | src/llr/material.c | 2 | ||||
-rw-r--r-- | src/llr/material_impl.h | 2 | ||||
-rw-r--r-- | src/llr/mesh.c | 2 | ||||
-rw-r--r-- | src/llr/mesh_impl.h | 5 |
8 files changed, 35 insertions, 15 deletions
diff --git a/src/llr/light.c b/src/llr/light.c index 1d1c40d..0fa1522 100644 --- a/src/llr/light.c +++ b/src/llr/light.c | |||
@@ -1,7 +1,7 @@ | |||
1 | #include "light_impl.h" | 1 | #include "light_impl.h" |
2 | 2 | ||
3 | #include "../scene/node_impl.h" | 3 | #include "memory.h" |
4 | #include "../scene/scene_memory.h" | 4 | #include "scene/node_impl.h" |
5 | 5 | ||
6 | #include <error.h> | 6 | #include <error.h> |
7 | 7 | ||
diff --git a/src/llr/light_impl.h b/src/llr/light_impl.h index 32203c4..5ec8145 100644 --- a/src/llr/light_impl.h +++ b/src/llr/light_impl.h | |||
@@ -1,8 +1,8 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include <../../include/gfx/llr/light.h> | 3 | #include <gfx/llr/light.h> |
4 | 4 | ||
5 | #include "../scene/types.h" | 5 | #include "scene/types.h" |
6 | 6 | ||
7 | typedef struct Texture Texture; | 7 | typedef struct Texture Texture; |
8 | 8 | ||
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. | ||
44 | static bool set_up_environment_light(LLR* renderer, EnvironmentLight* light) { | 47 | static 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 | ||
308 | void 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 | |||
296 | void gfx_llr_set_camera(LLR* renderer, const Camera* camera) { | 316 | void 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 | ||
diff --git a/src/llr/llr_impl.h b/src/llr/llr_impl.h index ada2d79..3f6a68f 100644 --- a/src/llr/llr_impl.h +++ b/src/llr/llr_impl.h | |||
@@ -43,6 +43,7 @@ typedef struct LLR { | |||
43 | bool camera_changed : 1; // Whether the camera parameters have changed. | 43 | bool camera_changed : 1; // Whether the camera parameters have changed. |
44 | bool lights_changed : 1; // Whether the lights have changed. | 44 | bool lights_changed : 1; // Whether the lights have changed. |
45 | bool skeleton_changed : 1; // Whether the skeleton has changed. | 45 | bool skeleton_changed : 1; // Whether the skeleton has changed. |
46 | bool material_changed : 1; // Whether the material has changed. | ||
46 | bool matrix_changed : 1; // Whether the matrix stack has changed. | 47 | bool matrix_changed : 1; // Whether the matrix stack has changed. |
47 | }; | 48 | }; |
48 | uint8_t changed_flags; | 49 | uint8_t changed_flags; |
@@ -53,6 +54,8 @@ typedef struct LLR { | |||
53 | 54 | ||
54 | ShaderProgram* shader; // Active shader. Not owned. | 55 | ShaderProgram* shader; // Active shader. Not owned. |
55 | 56 | ||
57 | const Material* material; // Active material. Not owned. | ||
58 | |||
56 | vec3 camera_position; | 59 | vec3 camera_position; |
57 | mat4 camera_rotation; | 60 | mat4 camera_rotation; |
58 | mat4 view; // Camera view matrix. | 61 | mat4 view; // Camera view matrix. |
diff --git a/src/llr/material.c b/src/llr/material.c index 4014482..f09dd3f 100644 --- a/src/llr/material.c +++ b/src/llr/material.c | |||
@@ -1,6 +1,6 @@ | |||
1 | #include "material_impl.h" | 1 | #include "material_impl.h" |
2 | 2 | ||
3 | #include "../scene/scene_memory.h" | 3 | #include "memory.h" |
4 | 4 | ||
5 | #include <gfx/core.h> | 5 | #include <gfx/core.h> |
6 | 6 | ||
diff --git a/src/llr/material_impl.h b/src/llr/material_impl.h index 138497f..2b7cd89 100644 --- a/src/llr/material_impl.h +++ b/src/llr/material_impl.h | |||
@@ -1,6 +1,6 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include <../../include/gfx/llr/material.h> | 3 | #include <gfx/llr/material.h> |
4 | 4 | ||
5 | typedef struct ShaderProgram ShaderProgram; | 5 | typedef struct ShaderProgram ShaderProgram; |
6 | 6 | ||
diff --git a/src/llr/mesh.c b/src/llr/mesh.c index 3aebb04..5f9e5d0 100644 --- a/src/llr/mesh.c +++ b/src/llr/mesh.c | |||
@@ -1,6 +1,6 @@ | |||
1 | #include "mesh_impl.h" | 1 | #include "mesh_impl.h" |
2 | 2 | ||
3 | #include "../scene/scene_memory.h" | 3 | #include "memory.h" |
4 | 4 | ||
5 | #include <assert.h> | 5 | #include <assert.h> |
6 | 6 | ||
diff --git a/src/llr/mesh_impl.h b/src/llr/mesh_impl.h index 47ff525..96e60df 100644 --- a/src/llr/mesh_impl.h +++ b/src/llr/mesh_impl.h | |||
@@ -1,12 +1,9 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include <../../include/gfx/llr/mesh.h> | 3 | #include <gfx/llr/mesh.h> |
4 | 4 | ||
5 | typedef struct Mesh { | 5 | typedef struct Mesh { |
6 | const Geometry* geometry; | 6 | const Geometry* geometry; |
7 | const Material* material; | 7 | const Material* material; |
8 | ShaderProgram* shader; | 8 | ShaderProgram* shader; |
9 | } Mesh; | 9 | } Mesh; |
10 | |||
11 | // TODO: a mesh_render() that takes a transform, applies the material and the | ||
12 | // transform, and then renders the geometry. | ||