|
|
|
|
@ -199,24 +199,11 @@ rgDraw(render_group* rg, glm::mat4 model_matrix,
|
|
|
|
|
ro->vertex_buffer.buffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2nd attribute buffer : colors
|
|
|
|
|
if (ro->color_buffer.buffer) |
|
|
|
|
{ |
|
|
|
|
glEnableVertexAttribArray(1); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, ro->color_buffer.buffer_id); |
|
|
|
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
|
|
|
|
|
if (update_color_data) { |
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, ro->color_buffer.buffer_len * sizeof(GLfloat), |
|
|
|
|
ro->color_buffer.buffer); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 3rd attribute buffer: normals
|
|
|
|
|
// 2rd attribute buffer: normals
|
|
|
|
|
if (rg->use_normals) { |
|
|
|
|
glEnableVertexAttribArray(2); |
|
|
|
|
glEnableVertexAttribArray(1); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, ro->normal_buffer.buffer_id); |
|
|
|
|
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
|
|
|
|
|
glm::mat3 normal_matrix = glm::transpose(glm::inverse(glm::mat3(model_matrix))); |
|
|
|
|
glUniformMatrix3fv(rg->shader.normal_matrix_id, 1, GL_FALSE, &normal_matrix[0][0]); |
|
|
|
|
@ -236,11 +223,11 @@ rgDraw(render_group* rg, glm::mat4 model_matrix,
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 4th attribute buffer: UV coordinates
|
|
|
|
|
// 3rd attribute buffer: UV coordinates
|
|
|
|
|
if (ro->use_texture) { |
|
|
|
|
glEnableVertexAttribArray(3); |
|
|
|
|
glEnableVertexAttribArray(2); |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, ro->uv_buffer.buffer_id); |
|
|
|
|
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ro->tex_id); |
|
|
|
|
glUniform1i(rg->shader.sampler_id, 0); |
|
|
|
|
|
|
|
|
|
@ -260,12 +247,10 @@ rgDraw(render_group* rg, glm::mat4 model_matrix,
|
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
glDisableVertexAttribArray(0); |
|
|
|
|
if (ro->color_buffer.buffer) |
|
|
|
|
glDisableVertexAttribArray(1); |
|
|
|
|
if (rg->use_normals) |
|
|
|
|
glDisableVertexAttribArray(2); |
|
|
|
|
glDisableVertexAttribArray(1); |
|
|
|
|
if (ro->use_texture) |
|
|
|
|
glDisableVertexAttribArray(3); |
|
|
|
|
glDisableVertexAttribArray(2); |
|
|
|
|
|
|
|
|
|
glUseProgram(0); |
|
|
|
|
} |
|
|
|
|
@ -301,8 +286,6 @@ allocateRenderObject(uint buffer_len, uint index_len)
|
|
|
|
|
ro->vertex_buffer.buffer_len = buffer_len; |
|
|
|
|
ro->normal_buffer.buffer = UTIL_ALLOC(buffer_len, GLfloat); |
|
|
|
|
ro->normal_buffer.buffer_len = buffer_len; |
|
|
|
|
ro->color_buffer.buffer = UTIL_ALLOC(buffer_len, GLfloat); |
|
|
|
|
ro->color_buffer.buffer_len = buffer_len; |
|
|
|
|
ro->uv_buffer.buffer = UTIL_ALLOC(buffer_len, GLfloat); |
|
|
|
|
ro->uv_buffer.buffer_len = buffer_len; |
|
|
|
|
|
|
|
|
|
@ -313,7 +296,6 @@ allocateRenderObject(uint buffer_len, uint index_len)
|
|
|
|
|
|
|
|
|
|
if (ro->vertex_buffer.buffer == nullptr || |
|
|
|
|
ro->normal_buffer.buffer == nullptr || |
|
|
|
|
ro->color_buffer.buffer == nullptr || |
|
|
|
|
((index_len > 0) && (ro->vertex_buffer.buffer == nullptr))) |
|
|
|
|
{ |
|
|
|
|
freeRenderObject(ro); |
|
|
|
|
@ -334,7 +316,6 @@ freeRenderObject(render_object* ro)
|
|
|
|
|
glDeleteTextures(1, &ro->tex_id); |
|
|
|
|
utilSafeFree(ro->vertex_buffer.buffer); |
|
|
|
|
utilSafeFree(ro->normal_buffer.buffer); |
|
|
|
|
utilSafeFree(ro->color_buffer.buffer); |
|
|
|
|
utilSafeFree(ro->uv_buffer.buffer); |
|
|
|
|
utilSafeFree(ro->index_buffer.buffer); |
|
|
|
|
utilSafeFree(ro); |
|
|
|
|
@ -345,12 +326,11 @@ convertMeshInfo(meMeshInfo* mesh, render_object* ro, bool use_normals, bool use_
|
|
|
|
|
{ |
|
|
|
|
uint vertex_buf_len = mesh->num_vertices * 3; |
|
|
|
|
GLfloat* vertex_buf = ro->vertex_buffer.buffer; |
|
|
|
|
GLfloat* color_buf = ro->color_buffer.buffer; |
|
|
|
|
GLfloat* normal_buf = ro->normal_buffer.buffer; |
|
|
|
|
GLfloat* uv_buf = ro->uv_buffer.buffer; |
|
|
|
|
uint* index_buf = ro->index_buffer.buffer; |
|
|
|
|
|
|
|
|
|
if (!vertex_buf || !color_buf || !normal_buf || !index_buf) |
|
|
|
|
if (!vertex_buf || !normal_buf || !index_buf) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
// dump vertices, colors, normals, and texture coords into render_group buffers
|
|
|
|
|
@ -384,7 +364,6 @@ convertMeshInfo(meMeshInfo* mesh, render_object* ro, bool use_normals, bool use_
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
color_buf[i] = mesh->diffuse_color[vertex_prop_index]; |
|
|
|
|
vertex_prop_index++; |
|
|
|
|
|
|
|
|
|
if (vertex_prop_index == 3) { |
|
|
|
|
@ -398,7 +377,6 @@ convertMeshInfo(meMeshInfo* mesh, render_object* ro, bool use_normals, bool use_
|
|
|
|
|
index_buf[i] = mesh->indices[i]; |
|
|
|
|
|
|
|
|
|
rgBufferData(&ro->vertex_buffer, GL_DYNAMIC_DRAW, GL_ARRAY_BUFFER); |
|
|
|
|
rgBufferData(&ro->color_buffer, GL_STATIC_DRAW, GL_ARRAY_BUFFER); |
|
|
|
|
if (use_normals) |
|
|
|
|
rgBufferData(&ro->normal_buffer, GL_STATIC_DRAW, GL_ARRAY_BUFFER); |
|
|
|
|
if (use_texture) |
|
|
|
|
|