fix: OnShaderLoaded now checks if locations exist before setting uniforms

This commit is contained in:
Sara 2024-09-19 15:45:01 +02:00
parent 8422c9166f
commit 90f01de0cb

View file

@ -11,7 +11,7 @@ static Matrix g_light_direction = {};
void InitializeRenderingSubsystem() {
g_render_objects = list_from_type(Renderable); // Allocate list of renderable typeclass wrappers
g_light_direction = QuaternionToMatrix(QuaternionFromEuler(-65.f, 45.f, 0.f));
g_light_direction = QuaternionToMatrix(QuaternionFromEuler(50.f * DEG2RAD, 0.f, 0.f));
g_shaders = list_from_type(ShaderResource);
}
@ -64,9 +64,13 @@ void RenderNextFrame() {
void Internal_OnShaderLoaded(ShaderResource resource) {
list_add(&g_shaders, &resource);
int light_direction_loc = GetShaderLocation(*resource.resource, "lightDirection");
int ambient_level_loc = GetShaderLocation(*resource.resource, "ambient");
SetShaderValue(*resource.resource, light_direction_loc, &MATRIX_FORWARD(g_light_direction), SHADER_UNIFORM_VEC3);
SetShaderValue(*resource.resource, ambient_level_loc, &WHITE, SHADER_UNIFORM_VEC4);
int ambient_level_loc = GetShaderLocation(*resource.resource, "ambientLight");
Vector3 lightdir = MATRIX_FORWARD(g_light_direction);
Vector4 ambient_color = {0.2, 0.2, 0.2, 1.0};
if(light_direction_loc != -1)
SetShaderValue(*resource.resource, light_direction_loc, &MATRIX_FORWARD(g_light_direction), SHADER_UNIFORM_VEC3);
if(ambient_level_loc != -1)
SetShaderValue(*resource.resource, ambient_level_loc, &ambient_color, SHADER_UNIFORM_VEC4);
}
void Internal_OnShaderUnloaded(ShaderResource resource) {