|
|
|
|
@ -204,30 +204,23 @@ rgInitEntity(gl_render_group* rg, Entity* e)
|
|
|
|
|
void |
|
|
|
|
rgDraw(gl_render_group* rg, GLenum draw_mode, glm::mat4 model_matrix, |
|
|
|
|
glm::mat4 view_matrix, glm::mat4 projection_matrix, |
|
|
|
|
glm::vec3 light_position, GLuint light_id) |
|
|
|
|
glm::vec3 light_position, GLuint light_id, bool update_vertex_data) |
|
|
|
|
{ |
|
|
|
|
glUseProgram(rg->program_id); |
|
|
|
|
glUniformMatrix4fv(rg->model_matrix_id, 1, GL_FALSE, &model_matrix[0][0]); |
|
|
|
|
glUniformMatrix4fv(rg->view_matrix_id, 1, GL_FALSE, &view_matrix[0][0]); |
|
|
|
|
glUniformMatrix4fv(rg->projection_matrix_id, 1, GL_FALSE, &projection_matrix[0][0]); |
|
|
|
|
|
|
|
|
|
// TODO: testing lighting
|
|
|
|
|
glUniform3f(light_id, light_position.x, light_position.y, light_position.z); |
|
|
|
|
glm::mat3 normal_matrix = glm::transpose(glm::inverse(glm::mat3(model_matrix))); |
|
|
|
|
glUniformMatrix3fv(rg->normal_matrix_id, 1, GL_FALSE, &normal_matrix[0][0]); |
|
|
|
|
|
|
|
|
|
// 1st attribute buffer : vertices
|
|
|
|
|
glEnableVertexAttribArray(0); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, rg->vertex_buffer.buffer_id); |
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
if (update_vertex_data) |
|
|
|
|
{ |
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, rg->vertex_buffer.buffer_len * sizeof(GLfloat), |
|
|
|
|
rg->vertex_buffer.buffer); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// 2nd attribute buffer : colors
|
|
|
|
|
if (rg->color_buffer.buffer) |
|
|
|
|
@ -246,6 +239,11 @@ rgDraw(gl_render_group* rg, GLenum draw_mode, glm::mat4 model_matrix,
|
|
|
|
|
glEnableVertexAttribArray(2); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, rg->vertex_normals.buffer_id); |
|
|
|
|
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
|
|
|
|
|
// TODO: testing lighting
|
|
|
|
|
glUniform3f(light_id, light_position.x, light_position.y, light_position.z); |
|
|
|
|
glm::mat3 normal_matrix = glm::transpose(glm::inverse(glm::mat3(model_matrix))); |
|
|
|
|
glUniformMatrix3fv(rg->normal_matrix_id, 1, GL_FALSE, &normal_matrix[0][0]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// draw
|
|
|
|
|
@ -310,23 +308,10 @@ rgFree(gl_render_group* rg)
|
|
|
|
|
if (rg == nullptr) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
gl_buffer bufs[] = {rg->vertex_buffer, rg->color_buffer}; |
|
|
|
|
for (uint i = 0; i < 2; i++) { |
|
|
|
|
gl_buffer& buf = bufs[i]; |
|
|
|
|
if (buf.buffer != nullptr) { |
|
|
|
|
std::free(buf.buffer); |
|
|
|
|
buf.buffer = nullptr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (rg->index_buffer.indices != nullptr) { |
|
|
|
|
std::free(rg->index_buffer.indices); |
|
|
|
|
rg->index_buffer.indices = nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: free vertex_normals here, and switch to using utilFree function
|
|
|
|
|
|
|
|
|
|
std::free(rg); |
|
|
|
|
rg = nullptr; |
|
|
|
|
utilSafeFree(rg->vertex_buffer.buffer); |
|
|
|
|
utilSafeFree(rg->vertex_normals.buffer); |
|
|
|
|
utilSafeFree(rg->index_buffer.indices); |
|
|
|
|
utilSafeFree(rg->color_buffer.buffer); |
|
|
|
|
utilSafeFree(rg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|