Commit de2c656c authored by Sylvain Thery's avatar Sylvain Thery

resolve pb of linewidth in GL3 (new shader)

parent 4f76a792
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "Utils/gl_def.h" #include "Utils/gl_def.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Utils/Shaders/shaderColorPerVertex.h" #include "Utils/Shaders/shaderColorPerVertex.h"
#include "Utils/Shaders/shaderBoldColorLines.h"
namespace CGoGN { namespace Utils { class VBO; } } namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } } namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } }
...@@ -65,10 +66,12 @@ protected: ...@@ -65,10 +66,12 @@ protected:
std::vector<Geom::Vec3f> m_dataPos; std::vector<Geom::Vec3f> m_dataPos;
std::vector<Geom::Vec3f> m_dataCol; std::vector<Geom::Vec3f> m_dataCol;
std::vector<PrimParam> m_begins; std::vector<PrimParam> m_begins;
float m_currentWidth; float m_currentWidth;
float m_currentSize; float m_currentSize;
GLenum m_compile; GLenum m_compile;
Utils::ShaderColorPerVertex* m_shader; Utils::ShaderColorPerVertex* m_shader;
Utils::ShaderBoldColorLines* m_shader2;
public: public:
...@@ -83,7 +86,11 @@ public: ...@@ -83,7 +86,11 @@ public:
*/ */
~Drawer(); ~Drawer();
Utils::ShaderColorPerVertex* getShader(); // Utils::ShaderColorPerVertex* getShader();
std::vector<Utils::GLSLShader*> getShaders();
void updateMatrices(const glm::mat4& projection, const glm::mat4& modelview);
/** /**
* init the data structure * init the data structure
...@@ -144,12 +151,12 @@ public: ...@@ -144,12 +151,12 @@ public:
/** /**
* call a set of sub-lists * call a set of sub-lists
*/ */
void callSubLists(std::vector<int> indices, float opacity); // void callSubLists(std::vector<int> indices, float opacity);
/** /**
* call a set of sub-lists * call a set of sub-lists
*/ */
void callSubLists(int first, int nb, float opacity); // void callSubLists(int first, int nb, float opacity);
/** /**
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "Utils/vbo_base.h" #include "Utils/vbo_base.h"
#include "glm/glm.hpp" #include "glm/glm.hpp"
#include "Utils/Shaders/shaderSimpleColor.h" #include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderBoldLines.h"
#include "Utils/pickables.h" #include "Utils/pickables.h"
#include "Utils/dll.h" #include "Utils/dll.h"
...@@ -71,12 +72,13 @@ protected: ...@@ -71,12 +72,13 @@ protected:
/** /**
* VBO for color * VBO for color
*/ */
Utils::VBO* m_vboCol; // Utils::VBO* m_vboCol;
/** /**
* Shader * Shader
*/ */
Utils::ShaderSimpleColor* m_shader; Utils::ShaderSimpleColor* m_shader;
Utils::ShaderBoldLines* m_shaderBL;
/** /**
* the axis to be highlighted * the axis to be highlighted
......
...@@ -37,7 +37,9 @@ namespace CGoGN ...@@ -37,7 +37,9 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
Drawer::Drawer() : m_currentWidth(1.0f) Drawer::Drawer() :
m_currentWidth(1.0f),
m_currentSize(1.0f)
{ {
m_vboPos = new Utils::VBO(); m_vboPos = new Utils::VBO();
m_vboPos->setDataSize(3); m_vboPos->setDataSize(3);
...@@ -46,12 +48,20 @@ Drawer::Drawer() : m_currentWidth(1.0f) ...@@ -46,12 +48,20 @@ Drawer::Drawer() : m_currentWidth(1.0f)
m_vboCol->setDataSize(3); m_vboCol->setDataSize(3);
m_shader = new Utils::ShaderColorPerVertex(); m_shader = new Utils::ShaderColorPerVertex();
m_shader->setAttributePosition(m_vboPos); m_shader->setAttributePosition(m_vboPos);
m_shader->setAttributeColor(m_vboCol); m_shader->setAttributeColor(m_vboCol);
Utils::GLSLShader::registerShader(NULL, m_shader); Utils::GLSLShader::registerShader(NULL, m_shader);
if (GLSLShader::CURRENT_OGL_VERSION >=3)
{
m_shader2 = new Utils::ShaderBoldColorLines();
m_shader2->setAttributePosition(m_vboPos);
m_shader2->setAttributeColor(m_vboCol);
m_shader2->setNoClippingPlane();
Utils::GLSLShader::registerShader(NULL, m_shader2);
}
m_dataPos.reserve(128); m_dataPos.reserve(128);
m_dataCol.reserve(128); m_dataCol.reserve(128);
m_begins.reserve(16); m_begins.reserve(16);
...@@ -64,13 +74,32 @@ Drawer::~Drawer() ...@@ -64,13 +74,32 @@ Drawer::~Drawer()
delete m_vboPos; delete m_vboPos;
delete m_vboCol; delete m_vboCol;
delete m_shader; delete m_shader;
if (m_shader2)
delete m_shader2;
}
//Utils::ShaderColorPerVertex* Drawer::getShader()
//{
// return m_shader;
//}
std::vector<Utils::GLSLShader*> Drawer::getShaders()
{
std::vector<Utils::GLSLShader*> shaders;
shaders.push_back(m_shader);
if (m_shader2)
shaders.push_back(m_shader2);
return shaders;
} }
Utils::ShaderColorPerVertex* Drawer::getShader() void Drawer::updateMatrices(const glm::mat4& projection, const glm::mat4& modelview)
{ {
return m_shader; m_shader->updateMatrices(projection,modelview);
if (m_shader2)
m_shader2->updateMatrices(projection,modelview);
} }
void Drawer::lineWidth(float lw) void Drawer::lineWidth(float lw)
{ {
m_currentWidth = lw; m_currentWidth = lw;
...@@ -84,18 +113,17 @@ void Drawer::pointSize(float ps) ...@@ -84,18 +113,17 @@ void Drawer::pointSize(float ps)
int Drawer::begin(GLenum mode) int Drawer::begin(GLenum mode)
{ {
int res = int(m_begins.size()); int res = int(m_begins.size());
if (mode == GL_POINTS) if (mode == GL_POINTS)
m_begins.push_back(PrimParam(uint32(m_dataPos.size()), mode, m_currentSize)); m_begins.push_back(PrimParam(uint32(m_dataPos.size()), mode, m_currentSize));
else else
m_begins.push_back(PrimParam(uint32(m_dataPos.size()), mode, m_currentWidth)); m_begins.push_back(PrimParam(uint32(m_dataPos.size()), mode, m_currentWidth));
return res; return res;
} }
void Drawer::end() void Drawer::end()
{ {
if (m_begins.empty())
return;
m_begins.back().nb = uint32(m_dataPos.size() - m_begins.back().begin); m_begins.back().nb = uint32(m_dataPos.size() - m_begins.back().begin);
} }
...@@ -180,18 +208,47 @@ void Drawer::callList(float opacity) ...@@ -180,18 +208,47 @@ void Drawer::callList(float opacity)
if (m_begins.empty()) if (m_begins.empty())
return; return;
m_shader->setOpacity(opacity); if (GLSLShader::CURRENT_OGL_VERSION >=3)
{
m_shader->setOpacity(opacity);
m_shader->enableVertexAttribs();
for (std::vector<PrimParam>::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp)
{
if (pp->mode == GL_POINTS)
{
glPointSize(pp->width);
glDrawArrays(GL_POINTS, pp->begin, pp->nb);
}
}
m_shader->disableVertexAttribs();
m_shader->enableVertexAttribs(); m_shader2->setOpacity(opacity);
for (std::vector<PrimParam>::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp) m_shader2->enableVertexAttribs();
for (std::vector<PrimParam>::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp)
{
if (pp->mode != GL_POINTS)
{
m_shader2->setLineWidth(pp->width);
m_shader2->bind();
glDrawArrays(pp->mode, pp->begin, pp->nb);
}
}
m_shader2->disableVertexAttribs();
}
else
{ {
if (pp->mode == GL_POINTS) m_shader->setOpacity(opacity);
glPointSize(pp->width); m_shader->enableVertexAttribs();
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) for (std::vector<PrimParam>::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp)
glLineWidth(pp->width); {
glDrawArrays(pp->mode, pp->begin, pp->nb); if (pp->mode == GL_POINTS)
glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb);
}
m_shader->disableVertexAttribs();
} }
m_shader->disableVertexAttribs();
} }
...@@ -199,64 +256,82 @@ void Drawer::callSubList(int index, float opacity) ...@@ -199,64 +256,82 @@ void Drawer::callSubList(int index, float opacity)
{ {
if (index >= int(m_begins.size())) if (index >= int(m_begins.size()))
return; return;
m_shader->setOpacity(opacity);
m_shader->enableVertexAttribs();
PrimParam* pp = & (m_begins[index]); PrimParam* pp = & (m_begins[index]);
if (pp->mode == GL_POINTS) if (GLSLShader::CURRENT_OGL_VERSION >=3)
glPointSize(pp->width); {
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) if (pp->mode == GL_POINTS)
glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb);
m_shader->disableVertexAttribs();
}
void Drawer::callSubLists(int first, int nb, float opacity)
{
m_shader->setOpacity(opacity);
m_shader->enableVertexAttribs();
int last = first+nb;
for (int i = first; i< last; ++i)
if (i < int(m_begins.size()))
{ {
PrimParam* pp = & (m_begins[i]); m_shader->setOpacity(opacity);
m_shader->enableVertexAttribs();
if (pp->mode == GL_POINTS) glPointSize(pp->width);
glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb); glDrawArrays(pp->mode, pp->begin, pp->nb);
m_shader->disableVertexAttribs();
} }
else
m_shader->disableVertexAttribs();
}
void Drawer::callSubLists(std::vector<int> indices, float opacity)
{
m_shader->setOpacity(opacity);
m_shader->enableVertexAttribs();
for (std::vector<int>::iterator it = indices.begin(); it != indices.end(); ++it)
if (*it < int(m_begins.size()))
{ {
PrimParam* pp = & (m_begins[*it]); m_shader2->setOpacity(opacity);
m_shader2->enableVertexAttribs();
if (pp->mode == GL_POINTS) m_shader2->setLineWidth(pp->width);
glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb); glDrawArrays(pp->mode, pp->begin, pp->nb);
m_shader2->disableVertexAttribs();
} }
}
m_shader->disableVertexAttribs(); else
{
m_shader->setOpacity(opacity);
m_shader->enableVertexAttribs();
if (pp->mode == GL_POINTS)
glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb);
m_shader->disableVertexAttribs();
}
} }
//void Drawer::callSubLists(int first, int nb, float opacity)
//{
// m_shader->setOpacity(opacity);
// m_shader->enableVertexAttribs();
// int last = first+nb;
// for (int i = first; i< last; ++i)
// if (i < int(m_begins.size()))
// {
// PrimParam* pp = & (m_begins[i]);
// if (pp->mode == GL_POINTS)
// glPointSize(pp->width);
// if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
// glLineWidth(pp->width);
// glDrawArrays(pp->mode, pp->begin, pp->nb);
// }
// m_shader->disableVertexAttribs();
//}
//void Drawer::callSubLists(std::vector<int> indices, float opacity)
//{
// m_shader->setOpacity(opacity);
// m_shader->enableVertexAttribs();
// for (std::vector<int>::iterator it = indices.begin(); it != indices.end(); ++it)
// if (*it < int(m_begins.size()))
// {
// PrimParam* pp = & (m_begins[*it]);
// if (pp->mode == GL_POINTS)
// glPointSize(pp->width);
// if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
// glLineWidth(pp->width);
// glDrawArrays(pp->mode, pp->begin, pp->nb);
// }
// m_shader->disableVertexAttribs();
//}
void Drawer::toSVG(Utils::SVG::SVGOut& svg) void Drawer::toSVG(Utils::SVG::SVGOut& svg)
{ {
......
...@@ -59,15 +59,18 @@ FrameManipulator::FrameManipulator(): ...@@ -59,15 +59,18 @@ FrameManipulator::FrameManipulator():
m_vboPos = new VBO(); m_vboPos = new VBO();
m_vboPos->setDataSize(3); m_vboPos->setDataSize(3);
m_vboCol = new VBO(); // m_vboCol = new VBO();
m_vboCol->setDataSize(3); // m_vboCol->setDataSize(3);
m_shader = new ShaderSimpleColor(); m_shader = new ShaderSimpleColor();
m_shader->setAttributePosition(m_vboPos); m_shader->setAttributePosition(m_vboPos);
GLSLShader::registerShader(NULL, m_shader); GLSLShader::registerShader(NULL, m_shader);
m_shaderBL = new ShaderBoldLines();
m_shaderBL->setAttributePosition(m_vboPos);
GLSLShader::registerShader(NULL, m_shaderBL);
std::vector<Geom::Vec3f> points; std::vector<Geom::Vec3f> points;
points.reserve(6*nb_segments+30); points.reserve(6*nb_segments+30);
points.resize(6*nb_segments+6); points.resize(6*nb_segments+6);
...@@ -157,7 +160,7 @@ void FrameManipulator::draw() ...@@ -157,7 +160,7 @@ void FrameManipulator::draw()
Utils::GLSLShader::applyTransfo(transfoRenderFrame()); Utils::GLSLShader::applyTransfo(transfoRenderFrame());
Utils::GLSLShader::updateCurrentMatrices(); Utils::GLSLShader::updateCurrentMatrices();
glPushAttrib(GL_LINE_BIT); // glPushAttrib(GL_LINE_BIT);
m_shader->enableVertexAttribs(); m_shader->enableVertexAttribs();
if (!m_locked_axis[Xr]) if (!m_locked_axis[Xr])
...@@ -190,11 +193,49 @@ void FrameManipulator::draw() ...@@ -190,11 +193,49 @@ void FrameManipulator::draw()
glDrawArrays(GL_TRIANGLE_STRIP, 4*nb_segments+4, 2*nb_segments+2); glDrawArrays(GL_TRIANGLE_STRIP, 4*nb_segments+4, 2*nb_segments+2);
} }
if ((!m_locked_axis[CENTER]) && (m_highlighted == CENTER)) if (!m_locked_axis[Xt])
{
if (m_highlighted == Xt)
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
else
m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f));
m_shader->bind();
glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+14, 6);
}
if (!m_locked_axis[Yt])
{ {
glLineWidth(6.0f); if (m_highlighted == Yt)
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
else
m_shader->setColor(Geom::Vec4f(0.0f,1.0f,0.0f,0.0f));
m_shader->bind(); m_shader->bind();
glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+22, 6);
}
if (!m_locked_axis[Zt])
{
if (m_highlighted == Zt)
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
else
m_shader->setColor(Geom::Vec4f(0.0f,0.0f,1.0f,0.0f));
m_shader->bind();
glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+30, 6);
}
m_shader->disableVertexAttribs();
m_shaderBL->enableVertexAttribs();
if ((!m_locked_axis[CENTER]) && (m_highlighted == CENTER))
{
m_shaderBL->setLineWidth(6.0f);
m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
m_shaderBL->bind();
glDrawArrays(GL_LINES, 6*nb_segments+6, 6); glDrawArrays(GL_LINES, 6*nb_segments+6, 6);
} }
else else
...@@ -203,15 +244,15 @@ void FrameManipulator::draw() ...@@ -203,15 +244,15 @@ void FrameManipulator::draw()
{ {
if (m_highlighted == Xs) if (m_highlighted == Xs)
{ {
glLineWidth(6.0f); m_shaderBL->setLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
} }
else else
{ {
glLineWidth(3.0f); m_shaderBL->setLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); m_shaderBL->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f));
} }
m_shader->bind(); m_shaderBL->bind();
glDrawArrays(GL_LINES, 6*nb_segments+6, 2); glDrawArrays(GL_LINES, 6*nb_segments+6, 2);
} }
...@@ -219,15 +260,15 @@ void FrameManipulator::draw() ...@@ -219,15 +260,15 @@ void FrameManipulator::draw()
{ {
if (m_highlighted == Ys) if (m_highlighted == Ys)
{ {
glLineWidth(6.0f); m_shaderBL->setLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
} }
else else
{ {
glLineWidth(3.0f); m_shaderBL->setLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(0.0f,0.7f,0.0f,0.0f)); m_shaderBL->setColor(Geom::Vec4f(0.0f,0.7f,0.0f,0.0f));
} }
m_shader->bind(); m_shaderBL->bind();
glDrawArrays(GL_LINES, 6*nb_segments+8, 2); glDrawArrays(GL_LINES, 6*nb_segments+8, 2);
} }
...@@ -235,74 +276,69 @@ void FrameManipulator::draw() ...@@ -235,74 +276,69 @@ void FrameManipulator::draw()
{ {
if (m_highlighted == Zs) if (m_highlighted == Zs)
{ {
glLineWidth(6.0f); m_shaderBL->setLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
} }
else else
{ {
glLineWidth(3.0f); m_shaderBL->setLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(0.0f,0.0f,0.7f,0.0f)); m_shaderBL->setColor(Geom::Vec4f(0.0f,0.0f,0.7f,0.0f));
} }
m_shader->bind(); m_shaderBL->bind();
glDrawArrays(GL_LINES, 6*nb_segments+10, 2); glDrawArrays(GL_LINES, 6*nb_segments+10, 2);