Commit 519aeb8c authored by Sylvain Thery's avatar Sylvain Thery

update BoldLines

parent 495d160a
......@@ -134,9 +134,9 @@ void MyQT::cb_redraw()
for (std::vector<Utils::Pickable*>::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();
}
......
......@@ -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<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
m_positionVBO->updateData(position);
m_colorVBO->updateData(position);
Geom::Vec3f *ptr = reinterpret_cast<Geom::Vec3f*>(m_colorVBO->lockPtr());
for (unsigned int i=0; i<m_colorVBO->nbElts();++i)
*ptr++ /= 130.0f;
m_colorVBO->releasePtr();
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
......
// 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();
......
......@@ -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;
......
// 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();
}
......@@ -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;
......
......@@ -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); }
};
......
......@@ -23,6 +23,7 @@
*******************************************************************************/
#define CGoGN_UTILS_DLL_EXPORT 1
#include "Utils/Shaders/shaderBoldColorLines.h"
#include <algorithm>
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();
}
......
......@@ -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;
}
......
......@@ -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();
}
......
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