diff --git a/Apps/Examples/viewer.cpp b/Apps/Examples/viewer.cpp index 254dfa2aa6f59646ee15d92e0f97687ddf3ebca9..701e1916de23da6a5bad9284146a9b88b168246f 100644 --- a/Apps/Examples/viewer.cpp +++ b/Apps/Examples/viewer.cpp @@ -113,7 +113,6 @@ void Viewer::cb_initGL() m_simpleColorShader->setColor(c) ; m_pointSprite = new Utils::PointSprite() ; - m_pointSprite->setAttributePosition(m_positionVBO) ; registerShader(m_phongShader) ; registerShader(m_flatShader) ; @@ -127,6 +126,7 @@ void Viewer::cb_redraw() if(m_drawVertices) { float size = vertexScaleFactor ; + m_pointSprite->setAttributePosition(m_positionVBO) ; m_pointSprite->setSize(size) ; m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ; m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ; @@ -191,6 +191,18 @@ void Viewer::cb_Save() exportMesh(filename) ; } +void Viewer::cb_keyPress(int keycode) +{ + switch(keycode) + { + case 'c' : + myMap.check(); + break; + default: + break; + } +} + void Viewer::importMesh(std::string& filename) { myMap.clear(true) ; @@ -311,21 +323,6 @@ void Viewer::slot_normalsSize(int i) updateGL() ; } -void Viewer::cb_keyPress(int keycode) -{ - switch(keycode) - { - case 'c' : - myMap.check(); - break; - default: - break; - } - - updateGLMatrices() ; - updateGL(); -} - /********************************************************************************************** * MAIN FUNCTION * **********************************************************************************************/ @@ -334,6 +331,8 @@ int main(int argc, char **argv) { QApplication app(argc, argv) ; + srand(123) ; + Viewer sqt ; sqt.setGeometry(0, 0, 1000, 800) ; sqt.show() ; diff --git a/Apps/Examples/viewer.h b/Apps/Examples/viewer.h index 0259f46c814ef5490ee8b3ac9b1dabcb5fab03ec..727330adf0e268609aa3535afcb09d27f873ccc0 100644 --- a/Apps/Examples/viewer.h +++ b/Apps/Examples/viewer.h @@ -46,6 +46,8 @@ #include "Utils/Shaders/shaderVectorPerVertex.h" #include "Utils/pointSprite.h" #include "Utils/text3d.h" +#include "Utils/vboRender.h" + #include "Utils/Qt/qtInputs.h" #include "Algo/Geometry/boundingbox.h" diff --git a/include/Algo/Render/GL2/drawerCells.h b/include/Algo/Render/GL2/drawerCells.h index c3a884b253d73f4d9b8214c3e4afb0a3f885d800..66752907b0fbdb3a7aaf9a8c702afcbcb60f919d 100644 --- a/include/Algo/Render/GL2/drawerCells.h +++ b/include/Algo/Render/GL2/drawerCells.h @@ -79,7 +79,7 @@ void drawerVertices(Utils::Drawer& dr, typename PFP::MAP& map, std::vector * @param k shrinking factor */ template -void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector& vd, const VertexAttribute& positions,float k); +void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector& vd, const VertexAttribute& positions, float k); /** * add a set of faces to a drawer @@ -90,7 +90,7 @@ void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector& v * @param k shrinking factor */ template -void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector& vd, const VertexAttribute& positions,float k); +void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector& vd, const VertexAttribute& positions, float k); /** * add a set of volumes to a drawer @@ -101,7 +101,7 @@ void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector& v * @param k shrinking factor */ template -void drawerVolumes(Utils::Drawer& dr, typename PFP::MAP& map, std::vector& vd, const VertexAttribute& positions,float k); +void drawerVolumes(Utils::Drawer& dr, typename PFP::MAP& map, std::vector& vd, const VertexAttribute& positions, float k); /** * add a vertex to a drawer @@ -121,7 +121,7 @@ void drawerVertex(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Verte * @param positions attribute of positions */ template -void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute& positions,float k); +void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute& positions, float k); /** * add a face to a drawer @@ -132,7 +132,7 @@ void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vertex * @param k shrinking factor */ template -void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute& positions,float k); +void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute& positions, float k); /** * add a volume to a drawer @@ -143,7 +143,7 @@ void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexA * @param k shrinking factor */ template -void drawerVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute& positions,float k); +void drawerVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute& positions, float k); /** * add an edge to a drawer, use between begin / end @@ -188,13 +188,13 @@ void drawerAddFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vert * @param k shrinking factor */ template -void drawerAddVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute& positions,float k); +void drawerAddVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute& positions, float k); -} +} // namespace Render -} +} // namespace Algo -} +} // namespace CGoGN #include "Algo/Render/GL2/drawerCells.hpp" diff --git a/include/Algo/Render/GL2/mapRender.h b/include/Algo/Render/GL2/mapRender.h index 9cdda3cb7b4c84d7030e230f9dc6c8267f08c40d..5360cf532331fec062ca60c0456fcc31b9ce01c7 100644 --- a/include/Algo/Render/GL2/mapRender.h +++ b/include/Algo/Render/GL2/mapRender.h @@ -100,7 +100,7 @@ protected: static bool cmpVP(VertexPoly* lhs, VertexPoly* rhs); // multiset typedef for simple writing - typedef std::multiset< VertexPoly*,bool(*)(VertexPoly*,VertexPoly*)> VPMS; + typedef std::multiset VPMS; class VertexPoly { @@ -112,9 +112,9 @@ protected: VertexPoly* next; VPMS::iterator ear; - VertexPoly(int i, float v, float l, VertexPoly* p=NULL): id(i),value(v), length(l), prev(p), next(NULL) + VertexPoly(int i, float v, float l, VertexPoly* p = NULL) : id(i), value(v), length(l), prev(p), next(NULL) { - if (prev!=NULL) + if (prev != NULL) prev->next = this; } @@ -132,7 +132,6 @@ protected: delete vp; return tmp; } - }; public: diff --git a/include/Utils/GLSLShader.h b/include/Utils/GLSLShader.h index 88fc0786894a93a7b9cdbbe84ddb3c7745b3128d..dce6b02bb11efe878c67de6968b1677255f8665d 100644 --- a/include/Utils/GLSLShader.h +++ b/include/Utils/GLSLShader.h @@ -288,7 +288,6 @@ public: virtual void updateClippingUniforms() {CGoGNerr << "Warning updateClippingUniforms not implemented"<< CGoGNendl;} - /** * */ @@ -341,7 +340,6 @@ public: */ void addPathFileSeach(const std::string& path); - /** * remove VBO index from binding */ @@ -374,7 +372,7 @@ public: * bind, enable, and set all vertex attrib pointers * @param stride: the stride parameter, number osf byte between two consecutive attributes */ - void enableVertexAttribs(unsigned int stride=0, unsigned int begin=0) const; + void enableVertexAttribs(unsigned int stride = 0, unsigned int begin = 0) const; /** * disenable all vertex attribs @@ -394,8 +392,6 @@ public: static void pushTransfo() {s_current_matrices->pushTransfo();} /// pop transformation matrix static void popTransfo() {s_current_matrices->popTransfo();} - - }; diff --git a/include/Utils/pointSprite.h b/include/Utils/pointSprite.h index 2227594091d74693968bab353214cca303836dc5..4aaca2faa80fe6102ac6b5578118116f162e0640 100644 --- a/include/Utils/pointSprite.h +++ b/include/Utils/pointSprite.h @@ -32,6 +32,7 @@ namespace CGoGN { namespace Utils { class VBO; } } namespace CGoGN { + namespace Utils { @@ -63,7 +64,7 @@ public: /** * init shaders, texture and variables */ - PointSprite(float radius=1.0f); + PointSprite(float radius = 1.0f); /** * clean shaders, texture and variables @@ -90,9 +91,10 @@ public: * set position attribute */ unsigned int setAttributePosition(VBO* vbo); +}; +} // namespace Utils + +} // namespace CGoGN -}; -} -} #endif diff --git a/include/Utils/vbo.h b/include/Utils/vbo.h index 6440cff54a4e85551236586fd87d4e7138b3736a..96dfcf816435d5fba06020c9c0575337ddfbb040 100644 --- a/include/Utils/vbo.h +++ b/include/Utils/vbo.h @@ -92,12 +92,12 @@ public: /** * get nb element in vbo (vertices, colors ...) */ - unsigned int nbElts() {return m_nbElts;} + unsigned int nbElts() { return m_nbElts; } /** * bind array vbo */ - void bind() const { glBindBuffer(GL_ARRAY_BUFFER,m_id); } + void bind() const { glBindBuffer(GL_ARRAY_BUFFER, m_id); } /** * alloc buffer of same size than parameter @@ -116,6 +116,12 @@ public: template void updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv); + /** + * update data from given data vector + */ + template + void updateData(std::vector& data); + void* lockPtr(); const void* lockPtr() const; @@ -124,8 +130,6 @@ public: void copyData(void *ptr) const; - - void allocate(unsigned int nbElts); }; diff --git a/include/Utils/vbo.hpp b/include/Utils/vbo.hpp index f8f00cf07e42a6389f64a42222efe9854426d133..1e8bf816a360493dca36e434605e6125fe07ee4c 100644 --- a/include/Utils/vbo.hpp +++ b/include/Utils/vbo.hpp @@ -33,7 +33,7 @@ void VBO::updateData(const ATTR_HANDLER& attrib) { if (m_lock) { - CGoGNerr <<" Error locked VBO"<< CGoGNendl; + CGoGNerr << "Error locked VBO" << CGoGNendl; return; } m_data_size = sizeof(typename ATTR_HANDLER::DATA_TYPE) / sizeof(float); @@ -62,7 +62,7 @@ void VBO::updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv) { if (m_lock) { - CGoGNerr <<" Error locked VBO"<< CGoGNendl; + CGoGNerr << "Error locked VBO" << CGoGNendl; return; } m_data_size = conv->sizeElt(); @@ -97,6 +97,21 @@ void VBO::updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv) conv->release(); } +template +void VBO::updateData(std::vector& data) +{ + if (m_lock) + { + CGoGNerr << "Error locked VBO" << CGoGNendl; + return; + } + m_data_size = sizeof(T) / sizeof(float); + m_nbElts = data.size(); + + glBindBuffer(GL_ARRAY_BUFFER, m_id); + glBufferData(GL_ARRAY_BUFFER, m_nbElts * sizeof(T), &(data[0]), GL_STREAM_DRAW); +} + } // namespace Utils } // namespace CGoGN diff --git a/include/Utils/vboRender.h b/include/Utils/vboRender.h new file mode 100644 index 0000000000000000000000000000000000000000..fd1944257547851c682ee6be25c6bb3806235dce --- /dev/null +++ b/include/Utils/vboRender.h @@ -0,0 +1,67 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef _VBO_RENDER_ +#define _VBO_RENDER_ + +#include + +namespace CGoGN +{ + +namespace Utils +{ + +// forward definition +class GLSLShader; + +class VBORender +{ +protected: + GLuint m_indexBuffer ; + GLuint m_nbIndices ; + int m_primitiveType ; + +public: + enum primitiveTypes + { + POINTS = 0, + LINES = 1, + TRIANGLES = 2 + } ; + + VBORender() ; + + ~VBORender() ; + + void setConnectivity(std::vector& tableIndices, int primitiveType) ; + + void draw(Utils::GLSLShader* sh) ; +}; + +} // namespace Utils + +} // namespace CGoGN + +#endif diff --git a/src/Algo/Render/mapRender.cpp b/src/Algo/Render/mapRender.cpp index 4e1a24d32850b61f43a00360f26d4c2cd2dfd3a9..6db94205555e3eeca20bfc4c2a98168deab31718 100644 --- a/src/Algo/Render/mapRender.cpp +++ b/src/Algo/Render/mapRender.cpp @@ -53,33 +53,38 @@ void MapRender::initPrimitives(int prim, std::vector& tableIndices) { // indice du VBO a utiliser int vbo_ind = 0; + int size = 0; + switch(prim) { case POINTS: m_nbIndices[POINT_INDICES] = tableIndices.size(); vbo_ind = m_indexBuffers[POINT_INDICES]; + size = m_nbIndices[POINT_INDICES]; break; case LINES: m_nbIndices[LINE_INDICES] = tableIndices.size(); vbo_ind = m_indexBuffers[LINE_INDICES]; + size = m_nbIndices[LINE_INDICES]; break; case TRIANGLES: m_nbIndices[TRIANGLE_INDICES] = tableIndices.size(); vbo_ind = m_indexBuffers[TRIANGLE_INDICES]; + size = m_nbIndices[TRIANGLE_INDICES]; break; case BOUNDARY: m_nbIndices[BOUNDARY_INDICES] = tableIndices.size(); vbo_ind = m_indexBuffers[BOUNDARY_INDICES]; + size = m_nbIndices[BOUNDARY_INDICES]; break; default: CGoGNerr << "problem initializing VBO indices" << CGoGNendl; break; } - int size = tableIndices.size(); // setup du buffer d'indices glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, vbo_ind); - glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, size*sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW); + glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, size * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW); } void MapRender::draw(Utils::GLSLShader* sh, int prim) @@ -112,10 +117,10 @@ void MapRender::draw(Utils::GLSLShader* sh, int prim) sh->disableVertexAttribs(); } - unsigned int MapRender::drawSub(Utils::GLSLShader* sh, int prim, unsigned int nb_elm) { sh->enableVertexAttribs(); + switch(prim) { case POINTS: @@ -145,7 +150,6 @@ unsigned int MapRender::drawSub(Utils::GLSLShader* sh, int prim, unsigned int nb return nb_elm; } - } // namespace GL2 } // namespace Render diff --git a/src/Utils/GLSLShader.cpp b/src/Utils/GLSLShader.cpp index 06f96cff1ba2f140bb3673786a4f42c850968840..3955297b08a400e3884d9c7345cc8eba59c67b7a 100644 --- a/src/Utils/GLSLShader.cpp +++ b/src/Utils/GLSLShader.cpp @@ -885,7 +885,7 @@ bool GLSLShader::checkShader(int shaderType) id = m_geom_shader_object; break; default: - CGoGNerr << "Error unkown shader type"<< CGoGNendl; + CGoGNerr << "Error unkown shader type" << CGoGNendl; return false; break; } @@ -946,12 +946,12 @@ void GLSLShader::unbindVA(const std::string& name) //valid ? if (idVA < 0) { - CGoGNerr << "GLSLShader: Attribute "<bind(); - for (std::vector::const_iterator it= m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it) + for (std::vector::const_iterator it = m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it) { glBindBuffer(GL_ARRAY_BUFFER, it->vbo_ptr->id()); glEnableVertexAttribArray(it->va_id); @@ -1011,7 +1011,7 @@ void GLSLShader::enableVertexAttribs(unsigned int stride, unsigned int begin) co void GLSLShader::disableVertexAttribs() const { this->bind(); - for (std::vector::const_iterator it= m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it) + for (std::vector::const_iterator it = m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it) glDisableVertexAttribArray(it->va_id); this->unbind(); } @@ -1021,8 +1021,8 @@ void GLSLShader::updateCurrentMatrices() glm::mat4 model(currentModelView()); model *= currentTransfo(); - for(std::set< std::pair >::iterator it = m_registeredShaders.begin();it != m_registeredShaders.end();++it) - it->second->updateMatrices(currentProjection(), model); + for(std::set< std::pair >::iterator it = m_registeredShaders.begin(); it != m_registeredShaders.end(); ++it) + it->second->updateMatrices(currentProjection(), model); } } // namespace Utils diff --git a/src/Utils/vbo.cpp b/src/Utils/vbo.cpp index 3493b741279d240761fb36117a5283c6b6642bf0..d378dd399f5b086ae0627efab58ba327721a6b06 100644 --- a/src/Utils/vbo.cpp +++ b/src/Utils/vbo.cpp @@ -65,8 +65,6 @@ VBO::~VBO() glDeleteBuffers(1, &m_id); } - - void VBO::sameAllocSameBufferSize(const VBO& vbo) { m_data_size = vbo.m_data_size; @@ -80,7 +78,7 @@ void* VBO::lockPtr() { if (m_lock) { - CGoGNerr <<" Error already locked VBO"<< CGoGNendl; + CGoGNerr << "Error already locked VBO" << CGoGNendl; return NULL; } @@ -93,7 +91,7 @@ const void* VBO::lockPtr() const { if (m_lock) { - CGoGNerr <<" Error already locked VBO"<< CGoGNendl; + CGoGNerr << "Error already locked VBO" << CGoGNendl; return NULL; } @@ -112,17 +110,16 @@ void VBO::releasePtr() const void VBO::copyData(void *ptr) const { glBindBuffer(GL_ARRAY_BUFFER, m_id); - glGetBufferSubData(GL_ARRAY_BUFFER,0,m_nbElts*m_data_size*sizeof(float), ptr); + glGetBufferSubData(GL_ARRAY_BUFFER, 0, m_nbElts * m_data_size * sizeof(float), ptr); } void VBO::allocate(unsigned int nbElts) { m_nbElts = nbElts; glBindBuffer(GL_ARRAY_BUFFER, m_id); - glBufferData(GL_ARRAY_BUFFER, nbElts * m_data_size*sizeof(float), 0, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, nbElts * m_data_size * sizeof(float), 0, GL_STREAM_DRAW); } - } // namespace Utils } // namespace CGoGN diff --git a/src/Utils/vboRender.cpp b/src/Utils/vboRender.cpp new file mode 100644 index 0000000000000000000000000000000000000000..500d456cefeed778cabb72a2e0a7e645e9646273 --- /dev/null +++ b/src/Utils/vboRender.cpp @@ -0,0 +1,81 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include "vector" + +#include "Utils/vboRender.h" +#include "Utils/GLSLShader.h" + +namespace CGoGN +{ + +namespace Utils +{ + +VBORender::VBORender() +{ + glGenBuffersARB(1, &m_indexBuffer) ; + m_nbIndices = 0 ; + m_primitiveType = POINTS; +} + +VBORender::~VBORender() +{ + glDeleteBuffersARB(1, &m_indexBuffer) ; +} + +void VBORender::setConnectivity(std::vector& tableIndices, int primitiveType) +{ + m_primitiveType = primitiveType ; + m_nbIndices = tableIndices.size() ; + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer) ; + glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, m_nbIndices * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW) ; +} + +void VBORender::draw(Utils::GLSLShader* sh) +{ + sh->enableVertexAttribs() ; + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer) ; + switch(m_primitiveType) + { + case POINTS: + glDrawElements(GL_POINTS, m_nbIndices, GL_UNSIGNED_INT, 0) ; + break; + case LINES: + glDrawElements(GL_LINES, m_nbIndices, GL_UNSIGNED_INT, 0); + break; + case TRIANGLES: + glDrawElements(GL_TRIANGLES, m_nbIndices, GL_UNSIGNED_INT, 0); + break; + default: + break; + } + + sh->disableVertexAttribs() ; +} + +} // namespace Utils + +} // namespace CGoGN