aboutsummaryrefslogtreecommitdiff
path: root/src/render/llr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/llr.c')
-rw-r--r--src/render/llr.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/render/llr.c b/src/render/llr.c
index 76935f9..c9c6d34 100644
--- a/src/render/llr.c
+++ b/src/render/llr.c
@@ -54,7 +54,9 @@ static void material_make(Material* material, const MaterialDesc* desc) {
54 assert(material); 54 assert(material);
55 assert(desc); 55 assert(desc);
56 assert(desc->num_uniforms < GFX_MAX_UNIFORMS_PER_MATERIAL); 56 assert(desc->num_uniforms < GFX_MAX_UNIFORMS_PER_MATERIAL);
57 material->num_uniforms = desc->num_uniforms; 57 material->alpha_mode = desc->alpha_mode;
58 material->alpha_cutoff = desc->alpha_cutoff;
59 material->num_uniforms = (int8_t)desc->num_uniforms;
58 for (int i = 0; i < desc->num_uniforms; ++i) { 60 for (int i = 0; i < desc->num_uniforms; ++i) {
59 material->uniforms[i] = desc->uniforms[i]; 61 material->uniforms[i] = desc->uniforms[i];
60 } 62 }
@@ -69,22 +71,27 @@ Material* gfx_make_material(const MaterialDesc* desc) {
69 71
70void gfx_destroy_material(Material** material) { mem_free_material(material); } 72void gfx_destroy_material(Material** material) { mem_free_material(material); }
71 73
74// TODO: Move this to core/shader_program.
72static void set_uniform(ShaderProgram* prog, const ShaderUniform* uniform) { 75static void set_uniform(ShaderProgram* prog, const ShaderUniform* uniform) {
73 switch (uniform->type) { 76 switch (uniform->type) {
74 case UniformTexture: 77 case UniformInt:
75 gfx_set_texture_uniform(prog, uniform->name.str, uniform->value.texture); 78 gfx_set_int_uniform(prog, uniform->name.str, uniform->value.uniform_int);
79 break;
80 case UniformFloat:
81 gfx_set_float_uniform(
82 prog, uniform->name.str, uniform->value.uniform_float);
76 break; 83 break;
77 case UniformMat4: 84 case UniformMat4:
78 gfx_set_mat4_uniform(prog, uniform->name.str, &uniform->value.mat4); 85 gfx_set_mat4_uniform(prog, uniform->name.str, &uniform->value.uniform_mat4);
79 break; 86 break;
80 case UniformVec3: 87 case UniformVec3:
81 gfx_set_vec3_uniform(prog, uniform->name.str, uniform->value.vec3); 88 gfx_set_vec3_uniform(prog, uniform->name.str, uniform->value.uniform_vec3);
82 break; 89 break;
83 case UniformVec4: 90 case UniformVec4:
84 gfx_set_vec4_uniform(prog, uniform->name.str, uniform->value.vec4); 91 gfx_set_vec4_uniform(prog, uniform->name.str, uniform->value.uniform_vec4);
85 break; 92 break;
86 case UniformFloat: 93 case UniformTexture:
87 gfx_set_float_uniform(prog, uniform->name.str, uniform->value.scalar); 94 gfx_set_texture_uniform(prog, uniform->name.str, uniform->value.texture);
88 break; 95 break;
89 case UniformMat4Array: 96 case UniformMat4Array:
90 gfx_set_mat4_array_uniform( 97 gfx_set_mat4_array_uniform(
@@ -104,6 +111,19 @@ static void gfx_material_activate(
104 const ShaderUniform* uniform = &material->uniforms[i]; 111 const ShaderUniform* uniform = &material->uniforms[i];
105 set_uniform(shader, uniform); 112 set_uniform(shader, uniform);
106 } 113 }
114 if (material->alpha_mode != Opaque) {
115 set_uniform(
116 shader, &(ShaderUniform){.name = sstring_make("AlphaMode"),
117 .type = UniformInt,
118 .value.uniform_int = material->alpha_mode});
119 }
120 if (material->alpha_mode == Mask) {
121 set_uniform(
122 shader,
123 &(ShaderUniform){.name = sstring_make("AlphaCutoff"),
124 .type = UniformFloat,
125 .value.uniform_float = material->alpha_cutoff});
126 }
107} 127}
108 128
109static void mesh_make(Mesh* mesh, const MeshDesc* desc) { 129static void mesh_make(Mesh* mesh, const MeshDesc* desc) {