diff options
Diffstat (limited to 'src/scene')
| -rw-r--r-- | src/scene/light.c | 39 | ||||
| -rw-r--r-- | src/scene/light_impl.h | 20 | ||||
| -rw-r--r-- | src/scene/material.c | 24 | ||||
| -rw-r--r-- | src/scene/material_impl.h | 13 | ||||
| -rw-r--r-- | src/scene/mesh.c | 26 | ||||
| -rw-r--r-- | src/scene/mesh_impl.h | 11 | ||||
| -rw-r--r-- | src/scene/object.c | 3 |
7 files changed, 135 insertions, 1 deletions
diff --git a/src/scene/light.c b/src/scene/light.c new file mode 100644 index 0000000..4233330 --- /dev/null +++ b/src/scene/light.c | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #include "light_impl.h" | ||
| 2 | |||
| 3 | #include "memory.h" | ||
| 4 | |||
| 5 | #include <cassert.h> | ||
| 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 | mem_free_light(light); | ||
| 38 | } | ||
| 39 | } | ||
diff --git a/src/scene/light_impl.h b/src/scene/light_impl.h new file mode 100644 index 0000000..3191a50 --- /dev/null +++ b/src/scene/light_impl.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <gfx/scene.h> | ||
| 4 | |||
| 5 | /// An environment light. | ||
| 6 | typedef struct EnvironmentLight { | ||
| 7 | const Texture* environment_map; | ||
| 8 | const Texture* irradiance_map; // Renderer implementation. | ||
| 9 | const Texture* prefiltered_environment_map; // Renderer implementation. | ||
| 10 | int max_reflection_lod; // Mandatory when prefiltered_environment_map is | ||
| 11 | // given. | ||
| 12 | } EnvironmentLight; | ||
| 13 | |||
| 14 | /// A scene light. | ||
| 15 | typedef struct Light { | ||
| 16 | LightType type; | ||
| 17 | union { | ||
| 18 | EnvironmentLight environment; | ||
| 19 | }; | ||
| 20 | } Light; | ||
diff --git a/src/scene/material.c b/src/scene/material.c new file mode 100644 index 0000000..9fe6c1b --- /dev/null +++ b/src/scene/material.c | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #include "material_impl.h" | ||
| 2 | |||
| 3 | #include "memory.h" | ||
| 4 | |||
| 5 | static void material_make(Material* material, const MaterialDesc* desc) { | ||
| 6 | assert(material); | ||
| 7 | assert(desc); | ||
| 8 | assert(desc->num_uniforms < GFX_MAX_UNIFORMS_PER_MATERIAL); | ||
| 9 | material->alpha_mode = desc->alpha_mode; | ||
| 10 | material->alpha_cutoff = desc->alpha_cutoff; | ||
| 11 | material->num_uniforms = (int8_t)desc->num_uniforms; | ||
| 12 | for (int i = 0; i < desc->num_uniforms; ++i) { | ||
| 13 | material->uniforms[i] = desc->uniforms[i]; | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 17 | Material* gfx_make_material(const MaterialDesc* desc) { | ||
| 18 | assert(desc); | ||
| 19 | Material* material = mem_alloc_material(); | ||
| 20 | material_make(material, desc); | ||
| 21 | return material; | ||
| 22 | } | ||
| 23 | |||
| 24 | void gfx_destroy_material(Material** material) { mem_free_material(material); } | ||
diff --git a/src/scene/material_impl.h b/src/scene/material_impl.h new file mode 100644 index 0000000..488ffc7 --- /dev/null +++ b/src/scene/material_impl.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <gfx/scene.h> | ||
| 4 | #include <gfx/sizes.h> | ||
| 5 | |||
| 6 | typedef struct ShaderProgram ShaderProgram; | ||
| 7 | |||
| 8 | typedef struct Material { | ||
| 9 | AlphaMode alpha_mode; | ||
| 10 | float alpha_cutoff; | ||
| 11 | int8_t num_uniforms; | ||
| 12 | ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL]; | ||
| 13 | } Material; | ||
diff --git a/src/scene/mesh.c b/src/scene/mesh.c new file mode 100644 index 0000000..770c3fb --- /dev/null +++ b/src/scene/mesh.c | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #include "mesh_impl.h" | ||
| 2 | |||
| 3 | #include <gfx/scene.h> | ||
| 4 | |||
| 5 | #include "memory.h" | ||
| 6 | |||
| 7 | #include <cassert.h> | ||
| 8 | |||
| 9 | static void mesh_make(Mesh* mesh, const MeshDesc* desc) { | ||
| 10 | assert(mesh); | ||
| 11 | assert(desc); | ||
| 12 | assert(desc->geometry); | ||
| 13 | assert(desc->material); | ||
| 14 | assert(desc->shader); | ||
| 15 | mesh->geometry = desc->geometry; | ||
| 16 | mesh->material = desc->material; | ||
| 17 | mesh->shader = desc->shader; | ||
| 18 | } | ||
| 19 | |||
| 20 | Mesh* gfx_make_mesh(const MeshDesc* desc) { | ||
| 21 | Mesh* mesh = mem_alloc_mesh(); | ||
| 22 | mesh_make(mesh, desc); | ||
| 23 | return mesh; | ||
| 24 | } | ||
| 25 | |||
| 26 | void gfx_destroy_mesh(Mesh** mesh) { mem_free_mesh(mesh); } | ||
diff --git a/src/scene/mesh_impl.h b/src/scene/mesh_impl.h new file mode 100644 index 0000000..c7e2211 --- /dev/null +++ b/src/scene/mesh_impl.h | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | typedef struct Geometry Geometry; | ||
| 4 | typedef struct Material Material; | ||
| 5 | typedef struct ShaderProgram ShaderProgram; | ||
| 6 | |||
| 7 | typedef struct Mesh { | ||
| 8 | const Geometry* geometry; | ||
| 9 | const Material* material; | ||
| 10 | ShaderProgram* shader; // TODO: Move this back to Material? | ||
| 11 | } Mesh; | ||
diff --git a/src/scene/object.c b/src/scene/object.c index 7004ce1..ac86b39 100644 --- a/src/scene/object.c +++ b/src/scene/object.c | |||
| @@ -3,8 +3,9 @@ | |||
| 3 | #include <gfx/core.h> | 3 | #include <gfx/core.h> |
| 4 | 4 | ||
| 5 | #include "memory.h" | 5 | #include "memory.h" |
| 6 | #include "node_impl.h" | ||
| 7 | #include "render/llr_impl.h" | 6 | #include "render/llr_impl.h" |
| 7 | #include "scene/mesh_impl.h" | ||
| 8 | #include "scene/node_impl.h" | ||
| 8 | 9 | ||
| 9 | #include <assert.h> | 10 | #include <assert.h> |
| 10 | 11 | ||
