|
|
|
|
@ -10,6 +10,11 @@
|
|
|
|
|
bool initGLFloatBuffer(glm::vec3* buffer, uint count, GLuint& buffer_id); |
|
|
|
|
bool initGLIndexBuffer(uint* buffer, uint num_indices, GLuint& buffer_id); |
|
|
|
|
bool initGLTexture(const util_image image, GLuint& tex_id); |
|
|
|
|
inline void |
|
|
|
|
updateMatrices(shader_program& shader, camera& cam, glm::mat4 node_xform); |
|
|
|
|
inline void enableGLFloatBuffer(uint buffer_id, uint location); |
|
|
|
|
inline void |
|
|
|
|
updateLights(shader_program& shader, point_light* lights, uint num_lights); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface
|
|
|
|
|
@ -47,52 +52,6 @@ roFree(render_object& ro)
|
|
|
|
|
LOG(Debug) << "TODO: release GL buffers from render_object\n"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//----------- WIP --------------
|
|
|
|
|
|
|
|
|
|
// TODO: really only need to update the view and projection matrices once per
|
|
|
|
|
// frame, maybe add another interface function in render_object to call from
|
|
|
|
|
// renRenderFrame
|
|
|
|
|
inline void |
|
|
|
|
updateMatrices(shader_program& shader, camera& cam, glm::mat4 node_xform) |
|
|
|
|
{ |
|
|
|
|
glUniformMatrix4fv(shader.model_matrix_id, 1, GL_FALSE, &node_xform[0][0]); |
|
|
|
|
glUniformMatrix4fv(shader.view_matrix_id, 1, GL_FALSE, &cam.view[0][0]); |
|
|
|
|
glUniformMatrix4fv(shader.projection_matrix_id, 1, GL_FALSE, &cam.projection[0][0]); |
|
|
|
|
|
|
|
|
|
glm::mat3 normal_matrix = glm::transpose(glm::inverse(glm::mat3(cam.model))); |
|
|
|
|
glUniformMatrix3fv(shader.normal_matrix_id, 1, GL_FALSE, &normal_matrix[0][0]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void |
|
|
|
|
enableGLFloatBuffer(uint buffer_id, uint location) |
|
|
|
|
{ |
|
|
|
|
glEnableVertexAttribArray(location); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer_id); |
|
|
|
|
glVertexAttribPointer(location, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#include <sstream> // TODO: remove this and make something in util.h |
|
|
|
|
|
|
|
|
|
inline void |
|
|
|
|
updateLights(shader_program& shader, point_light* lights, uint num_lights) |
|
|
|
|
{ |
|
|
|
|
// TODO: use Uniform Buffer Objects to update light data
|
|
|
|
|
// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_uniform_buffer_object.txt
|
|
|
|
|
// https://www.khronos.org/opengl/wiki/Uniform_Buffer_Objects
|
|
|
|
|
|
|
|
|
|
glUniform1ui(shader.num_lights_id, num_lights); |
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < num_lights; i++) { |
|
|
|
|
// TODO: don't do this every frame * every render_group
|
|
|
|
|
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[i].position[0]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//----------- WIP --------------
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
roDraw(render_object& ro, |
|
|
|
|
camera& cam, |
|
|
|
|
@ -162,3 +121,46 @@ initGLTexture(const util_image image, GLuint& tex_id)
|
|
|
|
|
|
|
|
|
|
return (glGetError() == GL_NO_ERROR); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: really only need to update the view and projection matrices once per
|
|
|
|
|
// frame, maybe add another interface function in render_object to call from
|
|
|
|
|
// renRenderFrame
|
|
|
|
|
inline void |
|
|
|
|
updateMatrices(shader_program& shader, camera& cam, glm::mat4 node_xform) |
|
|
|
|
{ |
|
|
|
|
glUniformMatrix4fv(shader.model_matrix_id, 1, GL_FALSE, &node_xform[0][0]); |
|
|
|
|
glUniformMatrix4fv(shader.view_matrix_id, 1, GL_FALSE, &cam.view[0][0]); |
|
|
|
|
glUniformMatrix4fv(shader.projection_matrix_id, 1, GL_FALSE, &cam.projection[0][0]); |
|
|
|
|
|
|
|
|
|
glm::mat3 normal_matrix = glm::transpose(glm::inverse(glm::mat3(cam.model))); |
|
|
|
|
glUniformMatrix3fv(shader.normal_matrix_id, 1, GL_FALSE, &normal_matrix[0][0]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void |
|
|
|
|
enableGLFloatBuffer(uint buffer_id, uint location) |
|
|
|
|
{ |
|
|
|
|
glEnableVertexAttribArray(location); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer_id); |
|
|
|
|
glVertexAttribPointer(location, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#include <sstream> // TODO: remove this and make something in util.h |
|
|
|
|
|
|
|
|
|
inline void |
|
|
|
|
updateLights(shader_program& shader, point_light* lights, uint num_lights) |
|
|
|
|
{ |
|
|
|
|
// TODO: use Uniform Buffer Objects to update light data
|
|
|
|
|
// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_uniform_buffer_object.txt
|
|
|
|
|
// https://www.khronos.org/opengl/wiki/Uniform_Buffer_Objects
|
|
|
|
|
|
|
|
|
|
glUniform1ui(shader.num_lights_id, num_lights); |
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < num_lights; i++) { |
|
|
|
|
// TODO: don't do this every frame * every render_group
|
|
|
|
|
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[i].position[0]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|