From 2d7d0cf44f2e25ce4ff62b6a6064ebfa2a25092d Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 15 Jul 2015 11:10:41 +0200 Subject: [PATCH] Gain in memory - Removed the buffers of color to use attribute values instead. --- .../Scene_points_with_normal_item.cpp | 91 ++----------------- .../Scene_points_with_normal_item.h | 3 - 2 files changed, 9 insertions(+), 85 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index d566efbb601..3a862d378d5 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -111,15 +111,6 @@ void Scene_points_with_normal_item::initialize_buffers(Viewer_interface *viewer) program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); buffers[0].release(); - - - buffers[1].bind(); - buffers[1].allocate(color_lines.data(), - static_cast(color_lines.size()*sizeof(double))); - program->enableAttributeArray("colors"); - program->setAttributeBuffer("colors",GL_DOUBLE,0,3); - buffers[1].release(); - vaos[0]->release(); program->release(); } @@ -129,22 +120,12 @@ void Scene_points_with_normal_item::initialize_buffers(Viewer_interface *viewer) program->bind(); vaos[1]->bind(); - buffers[2].bind(); - buffers[2].allocate(positions_points.data(), + buffers[1].bind(); + buffers[1].allocate(positions_points.data(), static_cast(positions_points.size()*sizeof(double))); program->enableAttributeArray("vertex"); program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); - buffers[2].release(); - - - - buffers[3].bind(); - buffers[3].allocate(color_points.data(), - static_cast(color_points.size()*sizeof(double))); - program->enableAttributeArray("colors"); - program->setAttributeBuffer("colors",GL_DOUBLE,0,3); - buffers[3].release(); - + buffers[1].release(); vaos[1]->release(); program->release(); } @@ -154,21 +135,12 @@ void Scene_points_with_normal_item::initialize_buffers(Viewer_interface *viewer) program->bind(); vaos[2]->bind(); - buffers[4].bind(); - buffers[4].allocate(positions_selected_points.data(), + buffers[2].bind(); + buffers[2].allocate(positions_selected_points.data(), static_cast(positions_selected_points.size()*sizeof(double))); program->enableAttributeArray("vertex"); program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); - buffers[4].release(); - - - - buffers[5].bind(); - buffers[5].allocate(color_selected_points.data(), - static_cast(color_selected_points.size()*sizeof(double))); - program->enableAttributeArray("colors"); - program->setAttributeBuffer("colors",GL_DOUBLE,0,3); - buffers[5].release(); + buffers[2].release(); vaos[2]->release(); program->release(); @@ -182,9 +154,6 @@ void Scene_points_with_normal_item::compute_normals_and_vertices(void) positions_points.resize(0); positions_lines.resize(0); positions_selected_points.resize(0); - color_selected_points.resize(0); - color_points.resize(0); - color_lines.resize(0); normals.resize(0); tex_coords.resize(0); @@ -203,19 +172,6 @@ void Scene_points_with_normal_item::compute_normals_and_vertices(void) positions_points.push_back(p.y()); positions_points.push_back(p.z()); - if(is_selected) - { - color_points.push_back(this->color().lighter(120).redF()); - color_points.push_back(this->color().lighter(120).greenF()); - color_points.push_back(this->color().lighter(120).blueF()); - } - else - { - color_points.push_back(this->color().redF()); - color_points.push_back(this->color().greenF()); - color_points.push_back(this->color().blueF()); - } - } } @@ -233,11 +189,6 @@ void Scene_points_with_normal_item::compute_normals_and_vertices(void) positions_selected_points.push_back(p.x()); positions_selected_points.push_back(p.y()); positions_selected_points.push_back(p.z()); - - color_selected_points.push_back(1.0); - color_selected_points.push_back(0.0); - color_selected_points.push_back(0.0); - } } @@ -269,26 +220,6 @@ void Scene_points_with_normal_item::compute_normals_and_vertices(void) positions_lines.push_back(q.y()); positions_lines.push_back(q.z()); - if(is_selected) - { - color_lines.push_back(this->color().lighter(120).redF()); - color_lines.push_back(this->color().lighter(120).greenF()); - color_lines.push_back(this->color().lighter(120).blueF()); - - color_lines.push_back(this->color().lighter(120).redF()); - color_lines.push_back(this->color().lighter(120).greenF()); - color_lines.push_back(this->color().lighter(120).blueF()); - } - else - { - color_lines.push_back(this->color().redF()); - color_lines.push_back(this->color().greenF()); - color_lines.push_back(this->color().blueF()); - - color_lines.push_back(this->color().redF()); - color_lines.push_back(this->color().greenF()); - color_lines.push_back(this->color().blueF()); - } } } } @@ -311,13 +242,6 @@ void Scene_points_with_normal_item::compute_normals_and_vertices(void) positions_lines.push_back(q.y()); positions_lines.push_back(q.z()); - color_lines.push_back(1.0); - color_lines.push_back(0.0); - color_lines.push_back(0.0); - - color_lines.push_back(1.0); - color_lines.push_back(0.0); - color_lines.push_back(0.0); } } } @@ -484,6 +408,7 @@ void Scene_points_with_normal_item::draw_edges(Viewer_interface* viewer) const program=getShaderProgram(PROGRAM_WITHOUT_LIGHT); attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); program->bind(); + program->setAttributeValue("colors", this->color()); qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); vaos[0]->release(); program->release(); @@ -497,6 +422,7 @@ void Scene_points_with_normal_item::draw_points(Viewer_interface* viewer) const program=getShaderProgram(PROGRAM_WITHOUT_LIGHT); attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); program->bind(); + program->setAttributeValue("colors", this->color()); qFunc.glDrawArrays(GL_POINTS, 0, static_cast(positions_points.size()/3)); vaos[1]->release(); program->release(); @@ -509,6 +435,7 @@ void Scene_points_with_normal_item::draw_points(Viewer_interface* viewer) const program=getShaderProgram(PROGRAM_WITHOUT_LIGHT); attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); program->bind(); + program->setAttributeValue("colors", this->color().lighter(120)); qFunc.glDrawArrays(GL_POINTS, 0, static_cast(positions_selected_points.size()/3)); vaos[2]->release(); diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h index 20b142e5890..9e1294d764a 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h @@ -92,9 +92,6 @@ private: std::vector positions_lines; std::vector positions_points; std::vector positions_selected_points; - std::vector color_lines; - std::vector color_points; - std::vector color_selected_points; std::vector normals; std::vector tex_coords;