X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fopengl%2Fmesh-gl.cc;h=531ac7888181513e6d7ff348ff4cf976590df53e;hb=f6ceb163227d00d7f97df1fc2dfbdd419c56277e;hp=dd73bf386f8d1d13e31df73a8680da236ac20fbb;hpb=47982b199010496e34eefb95044275fb231cba18;p=demo diff --git a/src/opengl/mesh-gl.cc b/src/opengl/mesh-gl.cc index dd73bf3..531ac78 100644 --- a/src/opengl/mesh-gl.cc +++ b/src/opengl/mesh-gl.cc @@ -69,12 +69,14 @@ MeshGL::~MeshGL() vertices.clear(); normals.clear(); + tex_coords.clear(); + indices.clear(); } void MeshGL::draw() const { if(!vdata_valid) { - ((MeshGL*)this)->update_vertex_data(); + ((MeshGL *)this)->update_vertex_data(); } glBindVertexArray(vao); @@ -93,12 +95,11 @@ void MeshGL::draw_normals(float scale) const glGenBuffers(1, &nvbo); glBindBuffer(GL_ARRAY_BUFFER, nvbo); - + glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(Vec3) * 2, 0, GL_STATIC_DRAW); Vec3 *data = (Vec3 *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); - for (size_t i = 0; i < normals.size(); i++) - { + for(size_t i = 0; i < normals.size(); i++) { *data++ = vertices[i]; *data++ = vertices[i] + normals[i] * scale; } @@ -107,7 +108,8 @@ void MeshGL::draw_normals(float scale) const glVertexAttribPointer(MESH_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vec3), 0); glEnableVertexAttribArray(MESH_VERTEX); glBindBuffer(GL_ARRAY_BUFFER, 0); - } else { + } + else { glBindVertexArray(nvao); } @@ -115,9 +117,10 @@ void MeshGL::draw_normals(float scale) const glBindVertexArray(0); } -void MeshGL::update_vertex_data() +bool MeshGL::update_vertex_data() { update_vbo(); + return true; } void MeshGL::update_vbo() @@ -204,11 +207,11 @@ void MeshGL::destroy_vbo() glDeleteBuffers(1, &vbo_tex_coords); if(ibo) glDeleteBuffers(1, &ibo); - if (vao) + if(vao) glDeleteVertexArrays(1, &vao); if(nvbo) glDeleteBuffers(1, &nvbo); if(nvao) glDeleteVertexArrays(1, &nvao); -} \ No newline at end of file +}