Commit de2c656c authored by Sylvain Thery's avatar Sylvain Thery

resolve pb of linewidth in GL3 (new shader)

parent 4f76a792
......@@ -29,6 +29,7 @@
#include "Utils/gl_def.h"
#include "Geometry/vector_gen.h"
#include "Utils/Shaders/shaderColorPerVertex.h"
#include "Utils/Shaders/shaderBoldColorLines.h"
namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } }
......@@ -65,10 +66,12 @@ protected:
std::vector<Geom::Vec3f> m_dataPos;
std::vector<Geom::Vec3f> m_dataCol;
std::vector<PrimParam> m_begins;
float m_currentWidth;
float m_currentSize;
GLenum m_compile;
Utils::ShaderColorPerVertex* m_shader;
Utils::ShaderBoldColorLines* m_shader2;
public:
......@@ -83,7 +86,11 @@ public:
*/
~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
......@@ -144,12 +151,12 @@ public:
/**
* 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
*/
void callSubLists(int first, int nb, float opacity);
// void callSubLists(int first, int nb, float opacity);
/**
......
......@@ -29,6 +29,7 @@
#include "Utils/vbo_base.h"
#include "glm/glm.hpp"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderBoldLines.h"
#include "Utils/pickables.h"
#include "Utils/dll.h"
......@@ -71,12 +72,13 @@ protected:
/**
* VBO for color
*/
Utils::VBO* m_vboCol;
// Utils::VBO* m_vboCol;
/**
* Shader
*/
Utils::ShaderSimpleColor* m_shader;
Utils::ShaderBoldLines* m_shaderBL;
/**
* the axis to be highlighted
......
......@@ -37,7 +37,9 @@ namespace CGoGN
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->setDataSize(3);
......@@ -46,12 +48,20 @@ Drawer::Drawer() : m_currentWidth(1.0f)
m_vboCol->setDataSize(3);
m_shader = new Utils::ShaderColorPerVertex();
m_shader->setAttributePosition(m_vboPos);
m_shader->setAttributeColor(m_vboCol);
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_dataCol.reserve(128);
m_begins.reserve(16);
......@@ -64,13 +74,32 @@ Drawer::~Drawer()
delete m_vboPos;
delete m_vboCol;
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)
{
m_currentWidth = lw;
......@@ -84,18 +113,17 @@ void Drawer::pointSize(float ps)
int Drawer::begin(GLenum mode)
{
int res = int(m_begins.size());
if (mode == GL_POINTS)
m_begins.push_back(PrimParam(uint32(m_dataPos.size()), mode, m_currentSize));
else
m_begins.push_back(PrimParam(uint32(m_dataPos.size()), mode, m_currentWidth));
return res;
}
void Drawer::end()
{
if (m_begins.empty())
return;
m_begins.back().nb = uint32(m_dataPos.size() - m_begins.back().begin);
}
......@@ -180,18 +208,47 @@ void Drawer::callList(float opacity)
if (m_begins.empty())
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();
for (std::vector<PrimParam>::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp)
m_shader2->setOpacity(opacity);
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)
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->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);
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)
{
if (index >= int(m_begins.size()))
return;
m_shader->setOpacity(opacity);
m_shader->enableVertexAttribs();
PrimParam* pp = & (m_begins[index]);
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()))
if (GLSLShader::CURRENT_OGL_VERSION >=3)
{
if (pp->mode == GL_POINTS)
{
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);
m_shader->setOpacity(opacity);
m_shader->enableVertexAttribs();
glPointSize(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb);
m_shader->disableVertexAttribs();
}
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()))
else
{
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);
m_shader2->setOpacity(opacity);
m_shader2->enableVertexAttribs();
m_shader2->setLineWidth(pp->width);
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)
{
......
......@@ -59,15 +59,18 @@ FrameManipulator::FrameManipulator():
m_vboPos = new VBO();
m_vboPos->setDataSize(3);
m_vboCol = new VBO();
m_vboCol->setDataSize(3);
// m_vboCol = new VBO();
// m_vboCol->setDataSize(3);
m_shader = new ShaderSimpleColor();
m_shader->setAttributePosition(m_vboPos);
GLSLShader::registerShader(NULL, m_shader);
m_shaderBL = new ShaderBoldLines();
m_shaderBL->setAttributePosition(m_vboPos);
GLSLShader::registerShader(NULL, m_shaderBL);
std::vector<Geom::Vec3f> points;
points.reserve(6*nb_segments+30);
points.resize(6*nb_segments+6);
......@@ -157,7 +160,7 @@ void FrameManipulator::draw()
Utils::GLSLShader::applyTransfo(transfoRenderFrame());
Utils::GLSLShader::updateCurrentMatrices();
glPushAttrib(GL_LINE_BIT);
// glPushAttrib(GL_LINE_BIT);
m_shader->enableVertexAttribs();
if (!m_locked_axis[Xr])
......@@ -190,11 +193,49 @@ void FrameManipulator::draw()
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);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
if (m_highlighted == Yt)
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();
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);
}
else
......@@ -203,15 +244,15 @@ void FrameManipulator::draw()
{
if (m_highlighted == Xs)
{
glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(6.0f);
m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
}
else
{
glLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(3.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);
}
......@@ -219,15 +260,15 @@ void FrameManipulator::draw()
{
if (m_highlighted == Ys)
{
glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(6.0f);
m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
}
else
{
glLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(0.0f,0.7f,0.0f,0.0f));
m_shaderBL->setLineWidth(3.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);
}
......@@ -235,74 +276,69 @@ void FrameManipulator::draw()
{
if (m_highlighted == Zs)
{
glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(6.0f);
m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
}
else
{
glLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(0.0f,0.0f,0.7f,0.0f));
m_shaderBL->setLineWidth(3.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);
}
}
if (!m_locked_axis[Xt])
{
if (m_highlighted == Xt)
{
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
glLineWidth(6.0f);
m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(6.0f);
}
else
{
glLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(3.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+12, 2);
glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+14, 6);
}
if (!m_locked_axis[Yt])
{
if (m_highlighted == Yt)
{
glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(6.0f);
m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
}
else
{
glLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(0.0f,1.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(3.0f);
m_shaderBL->setColor(Geom::Vec4f(0.0f,1.0f,0.0f,0.0f));
}
m_shader->bind();
m_shaderBL->bind();
glDrawArrays(GL_LINES, 6*nb_segments+20, 2);
glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+22, 6);
}
if (!m_locked_axis[Zt])
{
if (m_highlighted == Zt)
{
glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
m_shaderBL->setLineWidth(6.0f);
m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
}
else
{
glLineWidth(3.0f);
m_shader->setColor(Geom::Vec4f(0.0f,0.0f,1.0f,0.0f));
m_shaderBL->setLineWidth(3.0f);
m_shaderBL->setColor(Geom::Vec4f(0.0f,0.0f,1.0f,0.0f));
}
m_shader->bind();
m_shaderBL->bind();
glDrawArrays(GL_LINES, 6*nb_segments+28, 2);
glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+30, 6);
}
m_shader->disableVertexAttribs();
glPopAttrib();
m_shaderBL->disableVertexAttribs();
// glPopAttrib();
Utils::GLSLShader::popTransfo();
Utils::GLSLShader::updateCurrentMatrices();
......
......@@ -40,7 +40,7 @@ bool Surface_Modelisation_Plugin::enable()
m_dockTab->updateMapParameters();
m_drawer = new Utils::Drawer();
registerShader(m_drawer->getShader());
registerShader(m_drawer->getShaders());
mapNumber = 1;
......@@ -53,6 +53,7 @@ void Surface_Modelisation_Plugin::disable()
disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
unregisterShader(m_drawer->getShaders());
delete m_drawer;
}
......
......@@ -45,9 +45,9 @@ bool Surface_Selection_Plugin::enable()
m_selectionSphereVBO = new Utils::VBO();
registerShader(m_pointSprite);
registerShader(m_selectedEdgesDrawer->getShader());
registerShader(m_selectedFacesDrawer->getShader());
registerShader(m_selectingCellDrawer->getShader());
registerShader(m_selectedEdgesDrawer->getShaders());
registerShader(m_selectedFacesDrawer->getShaders());
registerShader(m_selectingCellDrawer->getShaders());
connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
connect(m_schnapps, SIGNAL(selectedCellSelectorChanged(CellSelectorGen*)), this, SLOT(updateSelectedCellsRendering()));
......@@ -69,6 +69,11 @@ bool Surface_Selection_Plugin::enable()
void Surface_Selection_Plugin::disable()
{
unregisterShader(m_pointSprite);
unregisterShader(m_selectedEdgesDrawer->getShaders());
unregisterShader(m_selectedFacesDrawer->getShaders());
unregisterShader(m_selectingCellDrawer->getShaders());
delete m_pointSprite;
delete m_selectedVerticesVBO;
......
......@@ -120,12 +120,9 @@ public slots:
float getBBdiagSize() const { return m_bbDiagSize; }
Utils::GLSLShader* getBBDrawerShader() const
inline Utils::Drawer* getBBDrawer() const
{
if(m_bbDrawer)
return m_bbDrawer->getShader();
else
return NULL;
return m_bbDrawer;
}
virtual bool transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax) = 0;
......
......@@ -58,6 +58,10 @@ protected:
void registerShader(Utils::GLSLShader* shader);
void unregisterShader(Utils::GLSLShader* shader);
void registerShader(const std::vector<Utils::GLSLShader*>& shaders);
void unregisterShader(const std::vector<Utils::GLSLShader*>& shaders);
protected:
QList<View*> l_views;
QList<Utils::GLSLShader*> l_shaders;
......
......@@ -49,6 +49,19 @@ void PluginInteraction::unregisterShader(Utils::GLSLShader* shader)
l_shaders.removeOne(shader);
}
void PluginInteraction::registerShader(const std::vector<Utils::GLSLShader*>& shaders)
{
for (auto shader: shaders)
if(shader && !l_shaders.contains(shader))
l_shaders.push_back(shader);
}
void PluginInteraction::unregisterShader(const std::vector<Utils::GLSLShader*>& shaders)
{
for (auto shader: shaders)
l_shaders.removeOne(shader);
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -371,7 +371,8 @@ void View::init()
m_frameDrawer = new Utils::Drawer();
glm::mat4 mm(1.0);
glm::mat4 pm(1.0);
m_frameDrawer->getShader()->updateMatrices(mm, pm);
// m_frameDrawer->getShader()->updateMatrices(mm, pm);
m_frameDrawer->updateMatrices(mm, pm);
m_frameDrawer->newList(GL_COMPILE);
m_frameDrawer->color3f(0.0f,1.0f,0.0f);
......@@ -449,9 +450,9 @@ void View::draw()
if(map == selectedMap)
{
Utils::GLSLShader* bbShader = map->getBBDrawerShader();
if(bbShader)
bbShader->updateMatrices(pm, map_mm);
Utils::Drawer* bbDr = map->getBBDrawer();
if(bbDr)
bbDr->updateMatrices(pm, map_mm);
map->drawBB();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment