diff options
Diffstat (limited to 'src/scene/light.c')
-rw-r--r-- | src/scene/light.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/scene/light.c b/src/scene/light.c new file mode 100644 index 0000000..adbec8d --- /dev/null +++ b/src/scene/light.c | |||
@@ -0,0 +1,42 @@ | |||
1 | #include "light_impl.h" | ||
2 | |||
3 | #include "node_impl.h" | ||
4 | #include "scene_memory.h" | ||
5 | |||
6 | #include <error.h> | ||
7 | |||
8 | static void make_environment_light( | ||
9 | Light* light, const EnvironmentLightDesc* desc) { | ||
10 | assert(light); | ||
11 | assert(desc); | ||
12 | light->type = EnvironmentLightType; | ||
13 | light->environment.environment_map = desc->environment_map; | ||
14 | } | ||
15 | |||
16 | Light* gfx_make_light(const LightDesc* desc) { | ||
17 | assert(desc); | ||
18 | |||
19 | Light* light = mem_alloc_light(); | ||
20 | |||
21 | switch (desc->type) { | ||
22 | case EnvironmentLightType: | ||
23 | make_environment_light(light, &desc->light.environment); | ||
24 | break; | ||
25 | default: | ||
26 | log_error("Unhandled light type"); | ||
27 | gfx_destroy_light(&light); | ||
28 | return 0; | ||
29 | } | ||
30 | |||
31 | return light; | ||
32 | } | ||
33 | |||
34 | void gfx_destroy_light(Light** light) { | ||
35 | assert(light); | ||
36 | if (*light) { | ||
37 | if ((*light)->parent.val) { | ||
38 | gfx_del_node((*light)->parent); | ||
39 | } | ||
40 | mem_free_light(light); | ||
41 | } | ||
42 | } | ||