aboutsummaryrefslogtreecommitdiff
path: root/src/scene
diff options
context:
space:
mode:
Diffstat (limited to 'src/scene')
-rw-r--r--src/scene/light.c42
-rw-r--r--src/scene/light_impl.h25
-rw-r--r--src/scene/material.c57
-rw-r--r--src/scene/material_impl.h16
-rw-r--r--src/scene/mesh.c24
-rw-r--r--src/scene/mesh_impl.h12
6 files changed, 0 insertions, 176 deletions
diff --git a/src/scene/light.c b/src/scene/light.c
deleted file mode 100644
index adbec8d..0000000
--- a/src/scene/light.c
+++ /dev/null
@@ -1,42 +0,0 @@
1#include "light_impl.h"
2
3#include "node_impl.h"
4#include "scene_memory.h"
5
6#include <error.h>
7
8static 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
16Light* 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
34void 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}
diff --git a/src/scene/light_impl.h b/src/scene/light_impl.h
deleted file mode 100644
index 1aa0bb4..0000000
--- a/src/scene/light_impl.h
+++ /dev/null
@@ -1,25 +0,0 @@
1#pragma once
2
3#include <gfx/scene/light.h>
4
5#include "types.h"
6
7typedef struct Texture Texture;
8
9/// An environment light.
10typedef struct EnvironmentLight {
11 const Texture* environment_map;
12 const Texture* irradiance_map; // Renderer implementation.
13 const Texture* prefiltered_environment_map; // Renderer implementation.
14 int max_reflection_lod; // Mandatory when prefiltered_environment_map is
15 // given.
16} EnvironmentLight;
17
18/// A scene light.
19typedef struct Light {
20 LightType type;
21 union {
22 EnvironmentLight environment;
23 };
24 node_idx parent; // Parent SceneNode.
25} Light;
diff --git a/src/scene/material.c b/src/scene/material.c
deleted file mode 100644
index 3248243..0000000
--- a/src/scene/material.c
+++ /dev/null
@@ -1,57 +0,0 @@
1#include "material_impl.h"
2
3#include "scene_memory.h"
4
5#include <gfx/core.h>
6
7static void material_make(Material* material, const MaterialDesc* desc) {
8 assert(material);
9 assert(desc);
10 assert(desc->num_uniforms < GFX_MAX_UNIFORMS_PER_MATERIAL);
11 material->num_uniforms = desc->num_uniforms;
12 for (int i = 0; i < desc->num_uniforms; ++i) {
13 material->uniforms[i] = desc->uniforms[i];
14 }
15}
16
17Material* 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
24void gfx_destroy_material(Material** material) { mem_free_material(material); }
25
26static void set_uniform(ShaderProgram* prog, const ShaderUniform* uniform) {
27 switch (uniform->type) {
28 case UniformTexture:
29 gfx_set_texture_uniform(prog, uniform->name.str, uniform->value.texture);
30 break;
31 case UniformMat4:
32 gfx_set_mat4_uniform(prog, uniform->name.str, &uniform->value.mat4);
33 break;
34 case UniformVec3:
35 gfx_set_vec3_uniform(prog, uniform->name.str, uniform->value.vec3);
36 break;
37 case UniformVec4:
38 gfx_set_vec4_uniform(prog, uniform->name.str, uniform->value.vec4);
39 break;
40 case UniformFloat:
41 gfx_set_float_uniform(prog, uniform->name.str, uniform->value.scalar);
42 break;
43 case UniformMat4Array:
44 gfx_set_mat4_array_uniform(
45 prog, uniform->name.str, uniform->value.array.values,
46 uniform->value.array.count);
47 break;
48 }
49}
50
51void material_activate(ShaderProgram* shader, const Material* material) {
52 assert(material);
53 for (int i = 0; i < material->num_uniforms; ++i) {
54 const ShaderUniform* uniform = &material->uniforms[i];
55 set_uniform(shader, uniform);
56 }
57}
diff --git a/src/scene/material_impl.h b/src/scene/material_impl.h
deleted file mode 100644
index a6aa95b..0000000
--- a/src/scene/material_impl.h
+++ /dev/null
@@ -1,16 +0,0 @@
1#pragma once
2
3#include <gfx/scene/material.h>
4
5typedef struct ShaderProgram ShaderProgram;
6
7typedef struct Material {
8 ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL];
9 int num_uniforms;
10} Material;
11
12/// Activate the material.
13///
14/// This activates the material's shader and configures the shader uniforms that
15/// are specific to the material.
16void material_activate(ShaderProgram* shader, const Material* material);
diff --git a/src/scene/mesh.c b/src/scene/mesh.c
deleted file mode 100644
index 1a93bed..0000000
--- a/src/scene/mesh.c
+++ /dev/null
@@ -1,24 +0,0 @@
1#include "mesh_impl.h"
2
3#include "scene_memory.h"
4
5#include <assert.h>
6
7static void mesh_make(Mesh* mesh, const MeshDesc* desc) {
8 assert(mesh);
9 assert(desc);
10 assert(desc->geometry);
11 assert(desc->material);
12 assert(desc->shader);
13 mesh->geometry = desc->geometry;
14 mesh->material = desc->material;
15 mesh->shader = desc->shader;
16}
17
18Mesh* gfx_make_mesh(const MeshDesc* desc) {
19 Mesh* mesh = mem_alloc_mesh();
20 mesh_make(mesh, desc);
21 return mesh;
22}
23
24void gfx_destroy_mesh(Mesh** mesh) { mem_free_mesh(mesh); }
diff --git a/src/scene/mesh_impl.h b/src/scene/mesh_impl.h
deleted file mode 100644
index 560b77e..0000000
--- a/src/scene/mesh_impl.h
+++ /dev/null
@@ -1,12 +0,0 @@
1#pragma once
2
3#include <gfx/scene/mesh.h>
4
5typedef struct Mesh {
6 const Geometry* geometry;
7 const Material* material;
8 ShaderProgram* shader;
9} Mesh;
10
11// TODO: a mesh_render() that takes a transform, applies the material and the
12// transform, and then renders the geometry.