summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx/src/renderer/renderer.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/gfx/src/renderer/renderer.c b/gfx/src/renderer/renderer.c
index 5d88ae6..1e96873 100644
--- a/gfx/src/renderer/renderer.c
+++ b/gfx/src/renderer/renderer.c
@@ -32,19 +32,6 @@ bool renderer_make(Renderer* renderer, RenderBackend* render_backend) {
32 32
33 renderer->render_backend = render_backend; 33 renderer->render_backend = render_backend;
34 34
35 // TODO: Load the IBL stuff lazily.
36 if (!(renderer->ibl = gfx_make_ibl(render_backend))) {
37 renderer_destroy(renderer);
38 return false;
39 }
40
41 if (!(renderer->brdf_integration_map = gfx_make_brdf_integration_map(
42 renderer->ibl, render_backend, BRDF_INTEGRATION_MAP_WIDTH,
43 BRDF_INTEGRATION_MAP_HEIGHT))) {
44 renderer_destroy(renderer);
45 return false;
46 }
47
48 return true; 35 return true;
49} 36}
50 37
@@ -58,6 +45,25 @@ void renderer_destroy(Renderer* renderer) {
58 } 45 }
59} 46}
60 47
48/// Initialize renderer state for IBL if not already initialized.
49static bool init_ibl(Renderer* renderer) {
50 assert(renderer);
51
52 if (!renderer->ibl &&
53 !(renderer->ibl = gfx_make_ibl(renderer->render_backend))) {
54 return false;
55 }
56
57 if (!renderer->brdf_integration_map &&
58 !(renderer->brdf_integration_map = gfx_make_brdf_integration_map(
59 renderer->ibl, renderer->render_backend, BRDF_INTEGRATION_MAP_WIDTH,
60 BRDF_INTEGRATION_MAP_HEIGHT))) {
61 return false;
62 }
63
64 return true;
65}
66
61// static void log_matrix(const mat4* m) { 67// static void log_matrix(const mat4* m) {
62// for (int row = 0; row < 4; ++row) { 68// for (int row = 0; row < 4; ++row) {
63// LOGI("[ %5.2f, %5.2f, %5.2f, %5.2f ]", m->val[0][row], m->val[1][row], 69// LOGI("[ %5.2f, %5.2f, %5.2f, %5.2f ]", m->val[0][row], m->val[1][row],
@@ -72,7 +78,10 @@ static bool setup_environment_light(
72 EnvironmentLight* light) { 78 EnvironmentLight* light) {
73 assert(renderer); 79 assert(renderer);
74 assert(light); 80 assert(light);
75 assert(renderer->ibl); 81
82 if (!init_ibl(renderer)) {
83 return false;
84 }
76 85
77 if (light->irradiance_map) { 86 if (light->irradiance_map) {
78 assert(light->prefiltered_environment_map); 87 assert(light->prefiltered_environment_map);
@@ -217,6 +226,7 @@ static void draw_recursively(
217 // Apply lights. 226 // Apply lights.
218 if (state->environment_light) { 227 if (state->environment_light) {
219 const EnvironmentLight* light = &state->environment_light->environment; 228 const EnvironmentLight* light = &state->environment_light->environment;
229 assert(light->environment_map);
220 assert(light->irradiance_map); 230 assert(light->irradiance_map);
221 assert(light->prefiltered_environment_map); 231 assert(light->prefiltered_environment_map);
222 assert(state->renderer->brdf_integration_map); 232 assert(state->renderer->brdf_integration_map);