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

topoRender GL3 compatible

parent 3bf37922
...@@ -36,7 +36,10 @@ ...@@ -36,7 +36,10 @@
#include "Utils/vbo_base.h" #include "Utils/vbo_base.h"
#include "Utils/svg.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 #ifdef WIN32
...@@ -79,7 +82,8 @@ protected: ...@@ -79,7 +82,8 @@ protected:
Utils::VBO* m_vbo2; Utils::VBO* m_vbo2;
unsigned int m_vaId; unsigned int m_vaId1;
unsigned int m_vaId2;
/** /**
*number of darts to draw *number of darts to draw
...@@ -121,7 +125,11 @@ protected: ...@@ -121,7 +125,11 @@ protected:
Geom::Vec3f* m_bufferDartPosition; 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; bool m_sharedShaders;
...@@ -164,13 +172,16 @@ protected: ...@@ -164,13 +172,16 @@ protected:
public: public:
static void createShaders(std::vector<Utils::GLSLShader*>& shaders);
/** /**
* Constructor * Constructor
* @param bs shift for boundary drawing * @param bs shift for boundary drawing
*/ */
TopoGenRender(float bs = 0.01f); 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 * Destructor
...@@ -221,7 +232,9 @@ public: ...@@ -221,7 +232,9 @@ public:
/** /**
* get shader objects * 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: ...@@ -308,7 +321,7 @@ public:
*/ */
TopoRender(float bs = 0.01f): TopoGenRender(bs) {} 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 * Destructor
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "Algo/Geometry/normal.h" #include "Algo/Geometry/normal.h"
#include "Container/containerBrowser.h" #include "Container/containerBrowser.h"
#include "Utils/Shaders/shaderColorPerVertex.h" #include "Utils/Shaders/shaderColorDarts.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -60,19 +60,12 @@ void TopoRender::overdrawDart(MAP& map, Dart d, float width, float r, float g, f ...@@ -60,19 +60,12 @@ void TopoRender::overdrawDart(MAP& map, Dart d, float width, float r, float g, f
if (!attIndex.isValid()) if (!attIndex.isValid())
attIndex = map.template addAttribute<unsigned int, DART, MAP>(m_nameIndex); attIndex = map.template addAttribute<unsigned int, DART, MAP>(m_nameIndex);
unsigned int indexDart = attIndex[d]; 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->setColor(Geom::Vec4f(r,g,b,0.0f));
m_shader1->setLineWidth(width);
m_shader1->enableVertexAttribs(); m_shader1->enableVertexAttribs();
glLineWidth(width);
glDrawArrays(GL_LINES, indexDart, 2); glDrawArrays(GL_LINES, indexDart, 2);
glPointSize(2.0f*width);
glDrawArrays(GL_POINTS, indexDart, 1);
m_shader1->disableVertexAttribs(); m_shader1->disableVertexAttribs();
} }
...@@ -84,25 +77,16 @@ void TopoRender::drawColoredDarts(MAP& map) ...@@ -84,25 +77,16 @@ void TopoRender::drawColoredDarts(MAP& map)
if (!attIndex.isValid()) if (!attIndex.isValid())
return; 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(); m_shader1->enableVertexAttribs();
for (auto it=m_coloredDarts.begin(); it != m_coloredDarts.end(); ++it) for (auto it=m_coloredDarts.begin(); it != m_coloredDarts.end(); ++it)
{ {
unsigned int indexDart = attIndex[it->d]; unsigned int indexDart = attIndex[it->d];
m_shader1->setColor(Geom::Vec4f(it->r,it->g,it->b,0.0f)); m_shader1->directColor(Geom::Vec4f(it->r,it->g,it->b,0.0f));
m_shader1->enableVertexAttribs(); // m_shader1->bind(); // because of unbind, do a set color without bind/unbind
glDrawArrays(GL_LINES, indexDart, 2); glDrawArrays(GL_LINES, indexDart, 2);
glPointSize(ps);
glDrawArrays(GL_POINTS, indexDart, 1);
} }
m_shader1->disableVertexAttribs(); m_shader1->disableVertexAttribs();
} }
...@@ -528,53 +512,40 @@ Dart TopoRender::picking(MAP& map,int x, int y, bool withBoundary) ...@@ -528,53 +512,40 @@ Dart TopoRender::picking(MAP& map,int x, int y, bool withBoundary)
} }
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
Utils::ShaderColorDarts shaderCol;
Utils::ShaderColorPerVertex shaderCol;
shaderCol.setAttributePosition(m_vbo0); shaderCol.setAttributePosition(m_vbo0);
shaderCol.setAttributeColor(&vboCol); shaderCol.setAttributeColor(&vboCol);
shaderCol.updateMatrices(m_shader1); shaderCol.updateMatrices(m_shader1);
float dw = m_topo_dart_width;
m_topo_dart_width+=2;
// save clear color and set to zero // save clear color and set to zero
float cc[4]; float cc[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); 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); glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING); shaderCol.setLineWidth(m_topo_dart_width + 2);
// draw in back buffer (not shown on screen)
shaderCol.enableVertexAttribs(); shaderCol.enableVertexAttribs();
glLineWidth(m_topo_dart_width);
glDrawArrays(GL_LINES, 0, m_nbDarts*2); 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(); shaderCol.disableVertexAttribs();
// restore dart width
m_topo_dart_width = dw;
// read the pixel under the mouse in back buffer // read the pixel under the mouse in back buffer
glReadBuffer(GL_BACK); glReadBuffer(GL_BACK);
float color[3]; float color[3];
glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color);
if (multi)
glEnable(GL_MULTISAMPLE);
glClearColor(cc[0], cc[1], cc[2], cc[3]); glClearColor(cc[0], cc[1], cc[2], cc[3]);
Dart d = colToDart(color); Dart d = colToDart(color);
return d; return d;
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_BOLD3DCOLORLINES__ #define __CGOGN_SHADER_BOLD3DCOLORLINES__
#include "Utils/GLSLShader.h" #include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h" #include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Utils/dll.h" #include "Utils/dll.h"
...@@ -37,7 +37,7 @@ namespace CGoGN ...@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
class CGoGN_UTILS_API ShaderBold3DColorLines : public ClippingShader class CGoGN_UTILS_API ShaderBold3DColorLines : public ShaderPointsLines
{ {
protected: protected:
// shader sources // shader sources
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_BOLD3DLINES__ #define __CGOGN_SHADER_BOLD3DLINES__
#include "Utils/GLSLShader.h" #include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h" #include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Utils/dll.h" #include "Utils/dll.h"
...@@ -37,7 +37,7 @@ namespace CGoGN ...@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
class CGoGN_UTILS_API ShaderBold3DLines : public ClippingShader class CGoGN_UTILS_API ShaderBold3DLines : public ShaderPointsLines
{ {
protected: protected:
// shader sources // shader sources
......
...@@ -14,7 +14,6 @@ void main() ...@@ -14,7 +14,6 @@ void main()
vec4 A = POSITION_IN(0); vec4 A = POSITION_IN(0);
vec4 B = POSITION_IN(1); vec4 B = POSITION_IN(1);
// float nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
float nearZ = 1.0; float nearZ = 1.0;
if (ProjectionMatrix[2][2] != 1.0) if (ProjectionMatrix[2][2] != 1.0)
nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0); nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
...@@ -36,11 +35,13 @@ void main() ...@@ -36,11 +35,13 @@ void main()
vec3 U = vec3(lineWidths*U2,0.0); vec3 U = vec3(lineWidths*U2,0.0);
vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 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]; fragClip = posClip[0];
fragColor = vcolor[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); gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = vec4(A.xyz-V, 1.0); gl_Position = vec4(A.xyz-V, 1.0);
...@@ -48,11 +49,13 @@ void main() ...@@ -48,11 +49,13 @@ void main()
fragClip = posClip[1]; fragClip = posClip[1];
fragColor = vcolor[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); gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0); gl_Position = vec4(B.xyz-V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = vec4(B.xyz+U, 1.0);
EmitVertex();
EndPrimitive(); EndPrimitive();
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_BOLDCOLORLINES__ #define __CGOGN_SHADER_BOLDCOLORLINES__
#include "Utils/GLSLShader.h" #include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h" #include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Utils/dll.h" #include "Utils/dll.h"
...@@ -37,7 +37,7 @@ namespace CGoGN ...@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
class CGoGN_UTILS_API ShaderBoldColorLines : public ClippingShader class CGoGN_UTILS_API ShaderBoldColorLines : public ShaderPointsLines
{ {
protected: protected:
// shader sources // shader sources
......
...@@ -30,22 +30,21 @@ void main() ...@@ -30,22 +30,21 @@ void main()
vec3 U = vec3(lineWidths*U2,0.0); vec3 U = vec3(lineWidths*U2,0.0);
vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0); vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0);
U2 *= (lineWidths[0]+lineWidths[1])/4.0;
fragClip = posClip[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); gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = vec4(A.xyz-V, 1.0); gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex(); EmitVertex();
fragClip = posClip[1]; fragClip = posClip[1];
B += vec4(U2,0.0,0.0);
gl_Position = vec4(B.xyz+V, 1.0); gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0); gl_Position = vec4(B.xyz-V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = vec4(B.xyz+U, 1.0);
EmitVertex();
EndPrimitive(); EndPrimitive();
} }
} }
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#define __CGOGN_SHADER_BOLDLINES__ #define __CGOGN_SHADER_BOLDLINES__
#include "Utils/GLSLShader.h" #include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h" #include "Utils/Shaders/shaderPointsLines.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Utils/dll.h" #include "Utils/dll.h"
...@@ -37,7 +37,7 @@ namespace CGoGN ...@@ -37,7 +37,7 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
class CGoGN_UTILS_API ShaderBoldLines : public ClippingShader class CGoGN_UTILS_API ShaderBoldLines : public ShaderPointsLines
{ {
protected: protected:
// shader sources // 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();