Commit 0c420188 authored by Sylvain Thery's avatar Sylvain Thery

topoRender GL3 compatible

parent 3bf37922
......@@ -36,7 +36,10 @@
#include "Utils/vbo_base.h"
#include "Utils/svg.h"
#include "Utils/Shaders/shaderSimpleColor.h"
//#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderBoldLines.h"
#include "Utils/Shaders/shaderDarts.h"
#ifdef WIN32
......@@ -79,7 +82,8 @@ protected:
Utils::VBO* m_vbo2;
unsigned int m_vaId;
unsigned int m_vaId1;
unsigned int m_vaId2;
/**
*number of darts to draw
......@@ -121,7 +125,11 @@ protected:
Geom::Vec3f* m_bufferDartPosition;
Utils::ShaderSimpleColor* m_shader1;
//Utils::ShaderSimpleColor* m_shader1;
//Utils::ShaderPointsLines* m_shader2;
Utils::ShaderDarts* m_shader1;
Utils::ShaderBoldLines* m_shader2;
bool m_sharedShaders;
......@@ -164,13 +172,16 @@ protected:
public:
static void createShaders(std::vector<Utils::GLSLShader*>& shaders);
/**
* Constructor
* @param bs shift for boundary drawing
*/
TopoGenRender(float bs = 0.01f);
TopoGenRender(Utils::ShaderSimpleColor* ssc, float bs = 0.01f);
TopoGenRender(const std::vector<Utils::GLSLShader*>& shaders, float bs = 0.01f);
/**
* Destructor
......@@ -221,7 +232,9 @@ public:
/**
* get shader objects
*/
Utils::GLSLShader* shader1() { return static_cast<Utils::GLSLShader*>(m_shader1); }
//Utils::GLSLShader* shader1() { return static_cast<Utils::GLSLShader*>(m_shader1); }
std::vector<Utils::GLSLShader*> shaders();
/**
......@@ -308,7 +321,7 @@ public:
*/
TopoRender(float bs = 0.01f): TopoGenRender(bs) {}
TopoRender(Utils::ShaderSimpleColor* ssc, float bs = 0.01f) :TopoGenRender(ssc,bs) {}
TopoRender(const std::vector<Utils::GLSLShader*>& shaders, float bs = 0.01f) : TopoGenRender(shaders, bs) {}
/**
* Destructor
......
......@@ -36,7 +36,7 @@
#include "Algo/Geometry/normal.h"
#include "Container/containerBrowser.h"
#include "Utils/Shaders/shaderColorPerVertex.h"
#include "Utils/Shaders/shaderColorDarts.h"
namespace CGoGN
{
......@@ -60,19 +60,12 @@ void TopoRender::overdrawDart(MAP& map, Dart d, float width, float r, float g, f
if (!attIndex.isValid())
attIndex = map.template addAttribute<unsigned int, DART, MAP>(m_nameIndex);
unsigned int indexDart = attIndex[d];
m_shader1->changeVA_VBO(m_vaId, m_vbo0);
m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f));
m_shader1->setLineWidth(width);
m_shader1->enableVertexAttribs();
glLineWidth(width);
glDrawArrays(GL_LINES, indexDart, 2);
glPointSize(2.0f*width);
glDrawArrays(GL_POINTS, indexDart, 1);
m_shader1->disableVertexAttribs();
}
......@@ -84,25 +77,16 @@ void TopoRender::drawColoredDarts(MAP& map)
if (!attIndex.isValid())
return;
glLineWidth(m_topo_dart_width);
float ps = 2.0f*m_topo_dart_width;
m_shader1->changeVA_VBO(m_vaId, m_vbo0);
m_shader1->enableVertexAttribs();
for (auto it=m_coloredDarts.begin(); it != m_coloredDarts.end(); ++it)
{
unsigned int indexDart = attIndex[it->d];
m_shader1->setColor(Geom::Vec4f(it->r,it->g,it->b,0.0f));
m_shader1->enableVertexAttribs();
m_shader1->directColor(Geom::Vec4f(it->r,it->g,it->b,0.0f));
// m_shader1->bind(); // because of unbind, do a set color without bind/unbind
glDrawArrays(GL_LINES, indexDart, 2);
glPointSize(ps);
glDrawArrays(GL_POINTS, indexDart, 1);
}
m_shader1->disableVertexAttribs();
}
......@@ -528,53 +512,40 @@ Dart TopoRender::picking(MAP& map,int x, int y, bool withBoundary)
}
glUnmapBuffer(GL_ARRAY_BUFFER);
Utils::ShaderColorPerVertex shaderCol;
Utils::ShaderColorDarts shaderCol;
shaderCol.setAttributePosition(m_vbo0);
shaderCol.setAttributeColor(&vboCol);
shaderCol.updateMatrices(m_shader1);
float dw = m_topo_dart_width;
m_topo_dart_width+=2;
// save clear color and set to zero
float cc[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE,cc);
bool multi = glIsEnabled(GL_MULTISAMPLE);
if (multi)
glDisable(GL_MULTISAMPLE);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
// draw in back buffer (not shown on screen)
shaderCol.setLineWidth(m_topo_dart_width + 2);
shaderCol.enableVertexAttribs();
glLineWidth(m_topo_dart_width);
glDrawArrays(GL_LINES, 0, m_nbDarts*2);
// change the stride to take 1/2 vertices
shaderCol.enableVertexAttribs(6*sizeof(GL_FLOAT));
glPointSize(2.0f*m_topo_dart_width);
glDrawArrays(GL_POINTS, 0, m_nbDarts);
shaderCol.disableVertexAttribs();
// restore dart width
m_topo_dart_width = dw;
// read the pixel under the mouse in back buffer
glReadBuffer(GL_BACK);
float color[3];
glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color);
if (multi)
glEnable(GL_MULTISAMPLE);
glClearColor(cc[0], cc[1], cc[2], cc[3]);
Dart d = colToDart(color);
return d;
}
......
......@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_BOLD3DCOLORLINES__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h"
#include "Utils/dll.h"
......@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils
{
class CGoGN_UTILS_API ShaderBold3DColorLines : public ClippingShader
class CGoGN_UTILS_API ShaderBold3DColorLines : public ShaderPointsLines
{
protected:
// shader sources
......
......@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_BOLD3DLINES__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h"
#include "Utils/dll.h"
......@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils
{
class CGoGN_UTILS_API ShaderBold3DLines : public ClippingShader
class CGoGN_UTILS_API ShaderBold3DLines : public ShaderPointsLines
{
protected:
// shader sources
......
......@@ -14,7 +14,6 @@ void main()
vec4 A = POSITION_IN(0);
vec4 B = POSITION_IN(1);
// float nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
float nearZ = 1.0;
if (ProjectionMatrix[2][2] != 1.0)
nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
......@@ -36,11 +35,13 @@ void main()
vec3 U = vec3(lineWidths*U2,0.0);
vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0);
U2 *= (lineWidths[0]+lineWidths[1])/4.0;
// U2 *= (lineWidths[0]+lineWidths[1])/2.0;
fragClip = posClip[0];
fragColor = vcolor[0];
A -= vec4(U2,0.0,0.0);
// A -= vec4(U2,0.0,0.0);
gl_Position = vec4(A.xyz-U, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-V, 1.0);
......@@ -48,11 +49,13 @@ void main()
fragClip = posClip[1];
fragColor = vcolor[1];
B += vec4(U2,0.0,0.0);
// B += vec4(U2,0.0,0.0);
gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0);
EmitVertex();
gl_Position = vec4(B.xyz+U, 1.0);
EmitVertex();
EndPrimitive();
}
......
......@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_BOLDCOLORLINES__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h"
#include "Utils/dll.h"
......@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils
{
class CGoGN_UTILS_API ShaderBoldColorLines : public ClippingShader
class CGoGN_UTILS_API ShaderBoldColorLines : public ShaderPointsLines
{
protected:
// shader sources
......
......@@ -30,22 +30,21 @@ void main()
vec3 U = vec3(lineWidths*U2,0.0);
vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0);
U2 *= (lineWidths[0]+lineWidths[1])/4.0;
fragClip = posClip[0];
A -= vec4(U2,0.0,0.0);
gl_Position = vec4(A.xyz-U, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex();
fragClip = posClip[1];
B += vec4(U2,0.0,0.0);
gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0);
EmitVertex();
gl_Position = vec4(B.xyz+U, 1.0);
EmitVertex();
EndPrimitive();
}
}
......@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_BOLDLINES__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h"
#include "Utils/dll.h"
......@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils
{
class CGoGN_UTILS_API ShaderBoldLines : public ClippingShader
class CGoGN_UTILS_API ShaderBoldLines : public ShaderPointsLines
{
protected:
// shader sources
......
// ShaderColorDarts::fragmentShaderText
PRECISION;
VARYING_FRAG vec3 fragColor;
uniform float alpha;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF;
void main()
{
if (dot(planeClip,vec4(fragClip,1.0))>0.0)
discard;
FRAG_OUT = vec4(fragColor,alpha);
}
// ShaderColorDarts::geometryShaderText
uniform mat4 ProjectionMatrix;
uniform vec2 lineWidths;
VARYING_IN vec3 vcolor[];
VARYING_OUT vec3 fragColor;
VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip;
void main()
{
vec4 A = POSITION_IN(0);
vec4 B = POSITION_IN(1);
float nearZ = 1.0;
if (ProjectionMatrix[2][2] != 1.0)
nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
if ((A.z < nearZ) || (B.z < nearZ))
{
if (A.z >= nearZ)
A = B + (A-B)*(nearZ-B.z)/(A.z-B.z);
if (B.z >= nearZ)
B = A + (B-A)*(nearZ-A.z)/(B.z-A.z);
A = ProjectionMatrix*A;
B = ProjectionMatrix*B;
A = A/A.w;
B = B/B.w;
vec2 U2 = normalize((B.xyz - A.xyz).xy);
vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0)*3.0;
U2 *= (lineWidths[0]+lineWidths[1])/2.0;
vec3 U = vec3(U2,0.0)*3.0;
// vec3 U3 = normalize(B.xyz - A.xyz);
// U3 *= (lineWidths[0]+lineWidths[1])/2.0;
fragClip = posClip[0];
fragColor = vcolor[0];
gl_Position = vec4(A.xyz-U+V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-U-V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz+U+V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz+U-V, 1.0);
EmitVertex();
V /= 3.0;
gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex();
fragClip = posClip[1];
fragColor = vcolor[1];
gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0);
EmitVertex();
EndPrimitive();
}
}
/*
void main()
{
vec4 A = POSITION_IN(0);
vec4 B = POSITION_IN(1);
float nearZ = 1.0;
if (ProjectionMatrix[2][2] != 1.0)
nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
if ((A.z < nearZ) || (B.z < nearZ))
{
if (A.z >= nearZ)
A = B + (A-B)*(nearZ-B.z)/(A.z-B.z);
if (B.z >= nearZ)
B = A + (B-A)*(nearZ-A.z)/(B.z-A.z);
A = ProjectionMatrix*A;
B = ProjectionMatrix*B;
A = A/A.w;
B = B/B.w;
vec2 U2 = normalize((B.xyz - A.xyz).xy);
vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0);
vec3 U3 = normalize(B.xyz - A.xyz);
U3 *= (lineWidths[0]+lineWidths[1])/2.0;
fragClip = posClip[0];
A -= vec4(3.0*U3,0.0);
gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex();
A += vec4(2.0*U3,0.0);
gl_Position = vec4(A.xyz+3.0*V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-3.0*V, 1.0);
EmitVertex();
A += vec4(2.0*U3,0.0);
gl_Position = vec4(A.xyz+3.0*V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-3.0*V, 1.0);
EmitVertex();
A += vec4(2.0*U3,0.0);
gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex();
fragClip = posClip[1];
B += vec4(U3,0.0);
gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0);
EmitVertex();
EndPrimitive();
}
}
*/
\ No newline at end of file
/*******************************************************************************
* 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 __CGOGN_SHADER_COLOR_DARTS__
#define __CGOGN_SHADER_COLOR_DARTS__
#include "Utils/GLSLShader.h"
#include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h"
#include "Utils/dll.h"
namespace CGoGN
{
namespace Utils
{
class CGoGN_UTILS_API ShaderColorDarts : public ClippingShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string geometryShaderText;
static std::string fragmentShaderText;
CGoGNGLuint m_uniform_lineWidth;
CGoGNGLuint m_unif_alpha;
Geom::Vec2f m_lineWidth;
float m_opacity;
VBO* m_vboPos;
VBO* m_vboCol;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations();
void sendParams();
void restoreUniformsAttribs();
public:
ShaderColorDarts();
void setLineWidth(float pix);
void setOpacity(float op);
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeColor(VBO* vbo);
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
};
} // namespace Utils
} // namespace CGoGN
#endif
// ShaderColorDarts::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexColor;
uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 vcolor;
VARYING_VERT vec3 posClip;
INVARIANT_POS;
void main ()
{
posClip = VertexPosition;
vcolor = VertexColor;
gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0);
}
......@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_CPV__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h"
#include "Utils/dll.h"
......@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils
{
class CGoGN_UTILS_API ShaderColorPerVertex : public ClippingShader
class CGoGN_UTILS_API ShaderColorPerVertex : public ShaderPointsLines
{
protected:
// shader sources
......@@ -72,6 +72,9 @@ public:
*/
unsigned int setAttributeColor(VBO* vbo);
/// just for uniform interface with gl3 BoldLines shaders
inline void setLineWidth(float pix) { glLineWidth(pix); }
/**
* set opacity (0=transparent / 1=opaque)
*/
......@@ -80,6 +83,7 @@ public:
float getOpacity() const { return m_opacity;}
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); }
};
} // namespace Utils
......
<
// ShaderDarts::fragmentShaderText
PRECISION;
uniform vec4 lineColor;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF;