diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2017-12-10 12:32:19 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2017-12-10 12:38:29 -0800 |
commit | 5c287c99a3fa8f137dc279b2253c628e83786afe (patch) | |
tree | 6c9922849280552c97fa3961425dd63c4153db64 /src/modules/ray/ray.c | |
parent | 1d73823602297ab490dc4222f63c1845f84a9e98 (diff) |
ray: split scene data from render state
This introduces ray_render_t, and ray_render.[ch].
The _prepared member of ray_scene_t has been moved to ray_render_t,
and the other _prepared members (e.g. objects) will follow.
Up until now I've just been sticking the precomputed state under
_prepared members of their associated structures, and simply using
convention to enforce anything resembling an api boundary. It's
been convenient without being inefficient, but I'd like to move
the ray code into more of a reusable library and this wart needs
to be addressed.
The render state is also where any spatial indexes will be built
and maintained, another thing I've been experimenting with.
Note most of the churn here is just renaming ray_scene.c to
ray_render.c. A nearly global s/ray_scene/ray_render/ has occurred,
now that ray_scene_t really only serves as glue to bind objects,
lights, and scene-global properties into a cohesive unit.
Diffstat (limited to 'src/modules/ray/ray.c')
-rw-r--r-- | src/modules/ray/ray.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/modules/ray/ray.c b/src/modules/ray/ray.c index 5f6326d..bb9c042 100644 --- a/src/modules/ray/ray.c +++ b/src/modules/ray/ray.c @@ -8,6 +8,7 @@ #include "ray_camera.h" #include "ray_object.h" +#include "ray_render.h" #include "ray_scene.h" /* Copyright (C) 2016-2017 Vito Caputo <vcaputo@pengaru.com> */ @@ -118,6 +119,7 @@ static float r; typedef struct ray_context_t { + ray_render_t *render; } ray_context_t; @@ -142,6 +144,8 @@ static int ray_fragmenter(void *context, const fb_fragment_t *fragment, unsigned /* prepare a frame for concurrent rendering */ static void ray_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter) { + ray_context_t *ctxt = context; + *res_fragmenter = ray_fragmenter; /* TODO: the camera doesn't need the width and height anymore, the fragment has the frame_width/frame_height */ @@ -169,14 +173,24 @@ static void ray_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fra /* tilt camera pitch in time with up and down movements, phase shifted appreciably */ camera.orientation.pitch = -(sinf((M_PI * 1.5f) + r * 1.3f) * .6f + -.35f); #endif - ray_scene_prepare(&scene, &camera); + ctxt->render = ray_render_new(&scene, &camera); } /* ray trace a simple scene into the fragment */ static void ray_render_fragment(void *context, fb_fragment_t *fragment) { - ray_scene_render_fragment(&scene, fragment); + ray_context_t *ctxt = context; + + ray_render_trace_fragment(ctxt->render, fragment); +} + + +static void ray_finish_frame(void *context, fb_fragment_t *fragment) +{ + ray_context_t *ctxt = context; + + ray_render_free(ctxt->render); } @@ -185,6 +199,7 @@ rototiller_module_t ray_module = { .destroy_context = ray_destroy_context, .prepare_frame = ray_prepare_frame, .render_fragment = ray_render_fragment, + .finish_frame = ray_finish_frame, .name = "ray", .description = "Ray tracer (threaded)", .author = "Vito Caputo <vcaputo@pengaru.com>", |