From 519aeb8c193236a6c53bf7b7b17b52f3b0d7684c Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Tue, 14 Apr 2015 13:47:32 +0200 Subject: [PATCH] update BoldLines --- Apps/Examples/frame_manip.cpp | 4 +- Apps/Examples/mcmesh.cpp | 20 +++------ .../Utils/Shaders/shaderBoldColorLines.geom | 21 +++++----- .../Utils/Shaders/shaderBoldColorLines.h | 2 +- .../Utils/Shaders/shaderBoldLines.geom | 19 +++++---- CGoGN/include/Utils/Shaders/shaderBoldLines.h | 2 +- CGoGN/include/Utils/pickables.h | 12 ++++-- .../Utils/Shaders/shaderBoldColorLines.cpp | 19 ++++----- CGoGN/src/Utils/Shaders/shaderBoldLines.cpp | 20 ++++----- CGoGN/src/Utils/pickables.cpp | 41 ++++++++++++------- 10 files changed, 82 insertions(+), 78 deletions(-) diff --git a/Apps/Examples/frame_manip.cpp b/Apps/Examples/frame_manip.cpp index 27b6b058..de913163 100644 --- a/Apps/Examples/frame_manip.cpp +++ b/Apps/Examples/frame_manip.cpp @@ -134,9 +134,9 @@ void MyQT::cb_redraw() for (std::vector::iterator it=m_pickables.begin(); it != m_pickables.end(); ++it) { if (*it == m_lastPickedObject) - glLineWidth(2.0); + (*it)->setLineWidth(3.0); else - glLineWidth(1.0); + (*it)->setLineWidth(1.0); (*it)->draw(); } diff --git a/Apps/Examples/mcmesh.cpp b/Apps/Examples/mcmesh.cpp index d8d690a7..937138ea 100644 --- a/Apps/Examples/mcmesh.cpp +++ b/Apps/Examples/mcmesh.cpp @@ -59,16 +59,14 @@ void MCMesh::cb_initGL() m_flatShader->setDiffuse(colDif); m_flatShader->setExplode(1.0f); - m_simpleColorShader = new Utils::ShaderSimpleColor(); - m_simpleColorShader->setAttributePosition(m_positionVBO); + //m_simpleColorShader = new Utils::ShaderSimpleColor(); + //m_simpleColorShader->setAttributePosition(m_positionVBO); - m_colorVBO = new Utils::VBO(); m_linesShader = new Utils::ShaderBoldLines(); m_linesShader->setAttributePosition(m_positionVBO); -// m_linesShader->setAttributeColor(m_colorVBO); registerShader(m_flatShader); - registerShader(m_simpleColorShader); +// registerShader(m_simpleColorShader); registerShader(m_linesShader); m_dr = new Utils::Drawer(); @@ -90,7 +88,7 @@ void MCMesh::cb_initGL() void MCMesh::cb_redraw() { glEnable(GL_BLEND); - m_dr->callList(0.5f); + m_dr->callList(0.1f); if (m_drawEdges) // { // glLineWidth(1.0f); @@ -107,10 +105,7 @@ glEnable(GL_BLEND); // m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES); // } { -// glLineWidth(1.0f); -// m_linesShader->setClippingPlane(Geom::Vec4f(0.03,0.03,-1.1,64)); - - m_linesShader->setLineWidth(12.0f); + m_linesShader->setLineWidth(2.0f); if (m_drawFaces) { Geom::Vec4f c(0.0f, 0.0f, 0.0f, 0.0f); @@ -200,11 +195,6 @@ void MCMesh::updateRender() m_render->initPrimitives(myMap, Algo::Render::GL2::TRIANGLES); m_positionVBO->updateData(position); - m_colorVBO->updateData(position); - Geom::Vec3f *ptr = reinterpret_cast(m_colorVBO->lockPtr()); - for (unsigned int i=0; inbElts();++i) - *ptr++ /= 130.0f; - m_colorVBO->releasePtr(); bb = Algo::Geometry::computeBoundingBox(myMap, position); diff --git a/CGoGN/include/Utils/Shaders/shaderBoldColorLines.geom b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.geom index b4e5f12a..4e6e9cd2 100644 --- a/CGoGN/include/Utils/Shaders/shaderBoldColorLines.geom +++ b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.geom @@ -1,6 +1,6 @@ // ShaderBoldColorLines::geometryShaderText -uniform float lineWidth; +uniform vec2 lineWidth; VARYING_IN vec3 vcolor[]; VARYING_OUT vec3 fragColor; @@ -10,28 +10,29 @@ VARYING_OUT vec3 fragClip; void main() { - vec3 A = POSITION_IN(0).xyz / POSITION_IN(0).w; - vec3 B = POSITION_IN(1).xyz / POSITION_IN(1).w; + + vec3 A = POSITION_IN(0).xyz / abs(POSITION_IN(0).w); + vec3 B = POSITION_IN(1).xyz / abs(POSITION_IN(1).w); vec3 U = normalize(B-A); vec3 V = cross(U,vec3(0.0,0.0,1.0)); + vec3 LW = vec3(lineWidth,1.0); fragClip = posClip[0]; - fragColor = vcolor[0]; - gl_Position = vec4(A-U*lineWidth, 1.0); + gl_Position = vec4(A-U*LW, 1.0); EmitVertex(); - gl_Position = vec4(A+V*lineWidth, 1.0); + gl_Position = vec4(A+V*LW, 1.0); EmitVertex(); - gl_Position = vec4(A-V*lineWidth, 1.0); + gl_Position = vec4(A-V*LW, 1.0); EmitVertex(); fragColor = vcolor[1]; fragClip = posClip[1]; - gl_Position = vec4(B+V*lineWidth, 1.0); + gl_Position = vec4(B+V*LW, 1.0); EmitVertex(); - gl_Position = vec4(B-V*lineWidth, 1.0); + gl_Position = vec4(B-V*LW, 1.0); EmitVertex(); - gl_Position = vec4(B+U*lineWidth, 1.0); + gl_Position = vec4(B+U*LW, 1.0); EmitVertex(); EndPrimitive(); diff --git a/CGoGN/include/Utils/Shaders/shaderBoldColorLines.h b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.h index 04c5fede..4346bdea 100644 --- a/CGoGN/include/Utils/Shaders/shaderBoldColorLines.h +++ b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.h @@ -48,7 +48,7 @@ protected: CGoGNGLuint m_uniform_lineWidth; CGoGNGLuint m_unif_alpha; - float m_lineWidth; + Geom::Vec2f m_lineWidth; float m_pixWidth; VBO* m_vboPos; diff --git a/CGoGN/include/Utils/Shaders/shaderBoldLines.geom b/CGoGN/include/Utils/Shaders/shaderBoldLines.geom index 1c9fbb87..2622b2d1 100644 --- a/CGoGN/include/Utils/Shaders/shaderBoldLines.geom +++ b/CGoGN/include/Utils/Shaders/shaderBoldLines.geom @@ -1,30 +1,31 @@ // ShaderBoldLines::geometryShaderText -uniform float lineWidth; +uniform vec2 lineWidth; VARYING_IN vec3 posClip[]; VARYING_OUT vec3 fragClip; void main() { - vec3 A = POSITION_IN(0).xyz / POSITION_IN(0).w; - vec3 B = POSITION_IN(1).xyz / POSITION_IN(1).w; + vec3 A = POSITION_IN(0).xyz / abs(POSITION_IN(0).w); + vec3 B = POSITION_IN(1).xyz / abs(POSITION_IN(1).w); vec3 U = normalize(B-A); vec3 V = cross(U,vec3(0.0,0.0,1.0)); + vec3 LW = vec3(lineWidth,1.0); fragClip = posClip[0]; - gl_Position = vec4(A-U*lineWidth, 1.0); + gl_Position = vec4(A-U*LW, 1.0); EmitVertex(); - gl_Position = vec4(A+V*lineWidth, 1.0); + gl_Position = vec4(A+V*LW, 1.0); EmitVertex(); - gl_Position = vec4(A-V*lineWidth, 1.0); + gl_Position = vec4(A-V*LW, 1.0); EmitVertex(); fragClip = posClip[1]; - gl_Position = vec4(B+V*lineWidth, 1.0); + gl_Position = vec4(B+V*LW, 1.0); EmitVertex(); - gl_Position = vec4(B-V*lineWidth, 1.0); + gl_Position = vec4(B-V*LW, 1.0); EmitVertex(); - gl_Position = vec4(B+U*lineWidth, 1.0); + gl_Position = vec4(B+U*LW, 1.0); EmitVertex(); EndPrimitive(); } diff --git a/CGoGN/include/Utils/Shaders/shaderBoldLines.h b/CGoGN/include/Utils/Shaders/shaderBoldLines.h index 44f65795..c15fb817 100644 --- a/CGoGN/include/Utils/Shaders/shaderBoldLines.h +++ b/CGoGN/include/Utils/Shaders/shaderBoldLines.h @@ -48,7 +48,7 @@ protected: CGoGNGLuint m_uniform_lineWidth; CGoGNGLuint m_uniform_color; - float m_lineWidth; + Geom::Vec2f m_lineWidth; float m_pixWidth; Geom::Vec4f m_color; diff --git a/CGoGN/include/Utils/pickables.h b/CGoGN/include/Utils/pickables.h index cc9fdbe4..f0f33eb9 100644 --- a/CGoGN/include/Utils/pickables.h +++ b/CGoGN/include/Utils/pickables.h @@ -28,8 +28,8 @@ #include "Utils/vbo_base.h" #include "glm/glm.hpp" -#include "Utils/Shaders/shaderColorPerVertex.h" -#include "Utils/Shaders/shaderSimpleColor.h" +//#include "Utils/Shaders/shaderSimpleColor.h" +#include "Utils/Shaders/shaderBoldLines.h" #include "Utils/dll.h" @@ -56,7 +56,8 @@ protected: /** * Shader */ - Utils::ShaderSimpleColor* m_shader; +// static Utils::ShaderSimpleColor* s_shader; + static Utils::ShaderBoldLines* s_shader; /** * number of indices in vbo @@ -70,6 +71,8 @@ protected: unsigned int m_sub2; + float m_lineWidth; + public: /** @@ -124,6 +127,7 @@ public: */ void getPrecisionDrawing(unsigned int& sub, unsigned int& sub2); + inline void setLineWidth(float lw) { m_lineWidth = lw; } }; @@ -288,7 +292,7 @@ public: */ Geom::Vec3f getAxisScale(unsigned int ax, float& scale); - + inline void setLineWidth(float lw) { m_drawable->setLineWidth(lw); } }; diff --git a/CGoGN/src/Utils/Shaders/shaderBoldColorLines.cpp b/CGoGN/src/Utils/Shaders/shaderBoldColorLines.cpp index 4f7be07c..bcca4072 100644 --- a/CGoGN/src/Utils/Shaders/shaderBoldColorLines.cpp +++ b/CGoGN/src/Utils/Shaders/shaderBoldColorLines.cpp @@ -23,6 +23,7 @@ *******************************************************************************/ #define CGoGN_UTILS_DLL_EXPORT 1 #include "Utils/Shaders/shaderBoldColorLines.h" +#include namespace CGoGN { @@ -74,7 +75,7 @@ void ShaderBoldColorLines::getLocations() void ShaderBoldColorLines::sendParams() { bind(); - glUniform1f(*m_uniform_lineWidth, m_lineWidth); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); glUniform1f (*m_unif_alpha, m_opacity); if (*m_unif_planeClip > 0) @@ -88,12 +89,11 @@ void ShaderBoldColorLines::setLineWidth(float pix) { glm::i32vec4 viewport; glGetIntegerv(GL_VIEWPORT, &(viewport[0])); - float lw = float(double(pix)/double(viewport[2])); - - bind(); - glUniform1f(*m_uniform_lineWidth, lw); - m_lineWidth = lw; m_pixWidth = pix; + m_lineWidth[0] = float(double(m_pixWidth) / double(viewport[2])); + m_lineWidth[1] = float(double(m_pixWidth) / double(viewport[3])); + bind(); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); unbind(); } @@ -101,11 +101,10 @@ void ShaderBoldColorLines::updatePixelWidth() { glm::i32vec4 viewport; glGetIntegerv(GL_VIEWPORT, &(viewport[0])); - float lw = float(double(m_pixWidth)/double(viewport[2])); - + m_lineWidth[0] = float(double(m_pixWidth) / double(viewport[2])); + m_lineWidth[1] = float(double(m_pixWidth) / double(viewport[3])); bind(); - glUniform1f(*m_uniform_lineWidth, lw); - m_lineWidth = lw; + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); unbind(); } diff --git a/CGoGN/src/Utils/Shaders/shaderBoldLines.cpp b/CGoGN/src/Utils/Shaders/shaderBoldLines.cpp index 2ec3cce5..3f8f6ede 100644 --- a/CGoGN/src/Utils/Shaders/shaderBoldLines.cpp +++ b/CGoGN/src/Utils/Shaders/shaderBoldLines.cpp @@ -72,7 +72,7 @@ void ShaderBoldLines::getLocations() void ShaderBoldLines::sendParams() { bind(); - glUniform1f(*m_uniform_lineWidth, m_lineWidth); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); glUniform4fv(*m_uniform_color, 1, m_color.data()); if (*m_unif_planeClip > 0) @@ -86,12 +86,11 @@ void ShaderBoldLines::setLineWidth(float pix) { glm::i32vec4 viewport; glGetIntegerv(GL_VIEWPORT, &(viewport[0])); - float lw = float(double(pix)/double(viewport[2])); - + m_pixWidth = pix; + m_lineWidth[0] = float(double(m_pixWidth) / double(viewport[2])); + m_lineWidth[1] = float(double(m_pixWidth) / double(viewport[3])); bind(); - glUniform1f(*m_uniform_lineWidth, lw); - m_lineWidth = lw; - m_pixWidth =pix; + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); unbind(); } @@ -99,11 +98,10 @@ void ShaderBoldLines::updatePixelWidth() { glm::i32vec4 viewport; glGetIntegerv(GL_VIEWPORT, &(viewport[0])); - float lw = float(double(m_pixWidth)/double(viewport[2])); - + m_lineWidth[0] = float(double(m_pixWidth) / double(viewport[2])); + m_lineWidth[1] = float(double(m_pixWidth) / double(viewport[3])); bind(); - glUniform1f(*m_uniform_lineWidth, lw); - m_lineWidth = lw; + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); unbind(); } @@ -122,8 +120,6 @@ unsigned int ShaderBoldLines::setAttributePosition(VBO* vbo) m_vboPos = vbo; bind(); unsigned int id = bindVA_VBO("VertexPosition", vbo); - - std::cout << "setAttributePosition => " << id << std::endl; unbind(); return id; } diff --git a/CGoGN/src/Utils/pickables.cpp b/CGoGN/src/Utils/pickables.cpp index c46eb95e..0740aab0 100644 --- a/CGoGN/src/Utils/pickables.cpp +++ b/CGoGN/src/Utils/pickables.cpp @@ -36,16 +36,20 @@ namespace CGoGN namespace Utils { + Utils::ShaderBoldLines* LineDrawable::s_shader = NULL; +// Utils::ShaderSimpleColor* LineDrawable::s_shader = NULL; + LineDrawable::LineDrawable() { m_vboPos = new VBO(); m_vboPos->setDataSize(3); - m_shader = new ShaderSimpleColor(); - - m_shader->setAttributePosition(m_vboPos); - m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); - GLSLShader::registerShader(NULL, m_shader); + if (s_shader == NULL) + { +// s_shader = new ShaderSimpleColor(); + s_shader = new ShaderBoldLines(); + GLSLShader::registerShader(NULL, s_shader); + } glGenBuffers(1, &(*m_ind)); } @@ -53,8 +57,8 @@ LineDrawable::LineDrawable() LineDrawable::~LineDrawable() { delete m_vboPos; - GLSLShader::unregisterShader(NULL, m_shader); - delete m_shader; +// GLSLShader::unregisterShader(NULL, s_shader); +// delete s_shader; glDeleteBuffers(1, &(*m_ind)); } @@ -63,7 +67,7 @@ LineDrawable::~LineDrawable() void LineDrawable::setColor(const Geom::Vec4f& col) { m_color=col; - m_shader->setColor(col); +// s_shader->setColor(col); } const Geom::Vec4f& LineDrawable::getColor() @@ -73,9 +77,12 @@ const Geom::Vec4f& LineDrawable::getColor() void LineDrawable::draw() { - m_shader->enableVertexAttribs(); + s_shader->setAttributePosition(m_vboPos); + s_shader->setColor(m_color); + s_shader->setLineWidth(m_lineWidth); + s_shader->enableVertexAttribs(); glDrawArrays(GL_LINES, 0, m_nb); - m_shader->disableVertexAttribs(); + s_shader->disableVertexAttribs(); } void LineDrawable::getPrecisionDrawing(unsigned int& sub, unsigned int& sub2) @@ -495,10 +502,13 @@ void Sphere::updatePrecisionDrawing(unsigned int sub, unsigned int sub2) void Sphere::draw() { - m_shader->enableVertexAttribs(); + s_shader->setAttributePosition(m_vboPos); + s_shader->setColor(m_color); + s_shader->setLineWidth(m_lineWidth); + s_shader->enableVertexAttribs(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *m_ind); glDrawElements(GL_LINES, m_nb, GL_UNSIGNED_INT, 0); - m_shader->disableVertexAttribs(); + s_shader->disableVertexAttribs(); } @@ -884,10 +894,13 @@ void Cube::updatePrecisionDrawing(unsigned int sub, unsigned int sub2) void Cube::draw() { - m_shader->enableVertexAttribs(); + s_shader->setAttributePosition(m_vboPos); + s_shader->setColor(m_color); + s_shader->setLineWidth(m_lineWidth); + s_shader->enableVertexAttribs(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *m_ind); glDrawElements(GL_LINES, m_nb, GL_UNSIGNED_INT, 0); - m_shader->disableVertexAttribs(); + s_shader->disableVertexAttribs(); } -- GitLab