You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
|
|
#include <sstream> // stringstream |
|
|
|
#include "lights.h" |
|
|
|
|
|
light_group* |
|
lightsInit(uint max_lights) |
|
{ |
|
light_group* lg = UTIL_ALLOC(1, light_group); |
|
lg->lights = UTIL_ALLOC(max_lights, point_light); |
|
lg->max_lights = max_lights; |
|
return lg; |
|
} |
|
|
|
void |
|
lightsOut(light_group* lights) |
|
{ |
|
utilSafeFree(lights->lights); |
|
utilSafeFree(lights); |
|
} |
|
|
|
bool |
|
lightsAdd(light_group* lights, glm::vec3 pos, glm::vec3 color, float intensity) |
|
{ |
|
if (lights->num_lights == lights->max_lights) |
|
return false; |
|
|
|
point_light& pl = lights->lights[lights->num_lights]; |
|
pl.position = pos; |
|
pl.color = color; |
|
pl.intensity = intensity; |
|
lights->needs_update = true; |
|
lights->num_lights++; |
|
|
|
return true; |
|
} |
|
|
|
void |
|
lightsUpdate(light_group* lights, default_shader_program* shader) |
|
{ |
|
glUniform1ui(shader->num_lights_id, lights->num_lights); |
|
|
|
for (uint i = 0; i < lights->num_lights; i++) { |
|
std::stringstream ss; |
|
ss << "lights[" << i << "].position"; |
|
int light_pos_loc = |
|
glGetUniformLocation(shader->program_id, ss.str().c_str()); |
|
|
|
glUniform3fv(light_pos_loc, 1, &lights->lights[i].position[0]); |
|
} |
|
|
|
lights->needs_update = false; |
|
} |
|
|
|
|