summaryrefslogtreecommitdiff
path: root/gfx/src/scene
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/src/scene')
-rw-r--r--gfx/src/scene/material.c6
-rw-r--r--gfx/src/scene/material_impl.h5
-rw-r--r--gfx/src/scene/mesh.c2
-rw-r--r--gfx/src/scene/mesh_impl.h1
4 files changed, 7 insertions, 7 deletions
diff --git a/gfx/src/scene/material.c b/gfx/src/scene/material.c
index d44746a..e5856d0 100644
--- a/gfx/src/scene/material.c
+++ b/gfx/src/scene/material.c
@@ -8,7 +8,6 @@ static void material_make(Material* material, const MaterialDesc* desc) {
8 assert(material); 8 assert(material);
9 assert(desc); 9 assert(desc);
10 assert(desc->num_uniforms < GFX_MAX_UNIFORMS_PER_MATERIAL); 10 assert(desc->num_uniforms < GFX_MAX_UNIFORMS_PER_MATERIAL);
11 material->shader = desc->shader;
12 material->num_uniforms = desc->num_uniforms; 11 material->num_uniforms = desc->num_uniforms;
13 for (int i = 0; i < desc->num_uniforms; ++i) { 12 for (int i = 0; i < desc->num_uniforms; ++i) {
14 material->uniforms[i] = desc->uniforms[i]; 13 material->uniforms[i] = desc->uniforms[i];
@@ -47,11 +46,10 @@ static void set_uniform(ShaderProgram* prog, const ShaderUniform* uniform) {
47 } 46 }
48} 47}
49 48
50void material_activate(const Material* material) { 49void material_activate(ShaderProgram* shader, const Material* material) {
51 assert(material); 50 assert(material);
52 gfx_activate_shader_program(material->shader);
53 for (int i = 0; i < material->num_uniforms; ++i) { 51 for (int i = 0; i < material->num_uniforms; ++i) {
54 const ShaderUniform* uniform = &material->uniforms[i]; 52 const ShaderUniform* uniform = &material->uniforms[i];
55 set_uniform(material->shader, uniform); 53 set_uniform(shader, uniform);
56 } 54 }
57} 55}
diff --git a/gfx/src/scene/material_impl.h b/gfx/src/scene/material_impl.h
index c680ccf..a6aa95b 100644
--- a/gfx/src/scene/material_impl.h
+++ b/gfx/src/scene/material_impl.h
@@ -5,13 +5,12 @@
5typedef struct ShaderProgram ShaderProgram; 5typedef struct ShaderProgram ShaderProgram;
6 6
7typedef struct Material { 7typedef struct Material {
8 ShaderProgram* shader;
9 ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL]; 8 ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL];
10 int num_uniforms; 9 int num_uniforms;
11} Material; 10} Material;
12 11
13/// Activate the material. 12/// Activate the material.
14/// 13///
15/// This activates the material's shader and configures the shader uniforms that 14/// This activates the material's shader and configures the shader uniforms that
16/// are specific to the material. 15/// are specific to the material.
17void material_activate(const Material* material); 16void material_activate(ShaderProgram* shader, const Material* material);
diff --git a/gfx/src/scene/mesh.c b/gfx/src/scene/mesh.c
index 722eae7..689105c 100644
--- a/gfx/src/scene/mesh.c
+++ b/gfx/src/scene/mesh.c
@@ -9,8 +9,10 @@ static void mesh_make(Mesh* mesh, const MeshDesc* desc) {
9 assert(desc); 9 assert(desc);
10 assert(desc->geometry); 10 assert(desc->geometry);
11 assert(desc->material); 11 assert(desc->material);
12 assert(desc->shader);
12 mesh->geometry = desc->geometry; 13 mesh->geometry = desc->geometry;
13 mesh->material = desc->material; 14 mesh->material = desc->material;
15 mesh->shader = desc->shader;
14} 16}
15 17
16Mesh* gfx_make_mesh(const MeshDesc* desc) { 18Mesh* gfx_make_mesh(const MeshDesc* desc) {
diff --git a/gfx/src/scene/mesh_impl.h b/gfx/src/scene/mesh_impl.h
index 858b147..560b77e 100644
--- a/gfx/src/scene/mesh_impl.h
+++ b/gfx/src/scene/mesh_impl.h
@@ -5,6 +5,7 @@
5typedef struct Mesh { 5typedef struct Mesh {
6 const Geometry* geometry; 6 const Geometry* geometry;
7 const Material* material; 7 const Material* material;
8 ShaderProgram* shader;
8} Mesh; 9} Mesh;
9 10
10// TODO: a mesh_render() that takes a transform, applies the material and the 11// TODO: a mesh_render() that takes a transform, applies the material and the