Commit c32ed9f5 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

Merge branch 'develop' of icube-forge.unistra.fr:cgogn/cgogn into develop

Conflicts:
	CGoGN/src/Utils/Shaders/shaderPhong.cpp
	CGoGN/src/Utils/Shaders/shaderSimpleFlat.cpp
parents 35f2eb18 3ae34e1a
...@@ -124,7 +124,6 @@ void MyQT::createMap() ...@@ -124,7 +124,6 @@ void MyQT::createMap()
// initialization GL callback // initialization GL callback
void MyQT::cb_initGL() void MyQT::cb_initGL()
{ {
// create the render // create the render
m_render = new Algo::Render::GL2::MapRender(); m_render = new Algo::Render::GL2::MapRender();
......
...@@ -53,7 +53,7 @@ ELSE() ...@@ -53,7 +53,7 @@ ELSE()
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${shaders_src} ) SOURCES ${shaders_src} )
ENDIF() ENDIF()
add_dependencies(shader_target shader_to_h) #ensure that shader_to_h is compiled
file( file(
GLOB # WARNING NO MORE RECURSE TO AVOID TAKING QT FILES GLOB # WARNING NO MORE RECURSE TO AVOID TAKING QT FILES
......
...@@ -65,26 +65,25 @@ public: ...@@ -65,26 +65,25 @@ public:
*/ */
enum shaderType {VERTEX_SHADER = 1, FRAGMENT_SHADER = 2, GEOMETRY_SHADER = 3 }; enum shaderType {VERTEX_SHADER = 1, FRAGMENT_SHADER = 2, GEOMETRY_SHADER = 3 };
static unsigned int CURRENT_OGL_VERSION; #ifdef CGOGN_USE_OGL_CORE_PROFILE
static const unsigned int CURRENT_OGL_VERSION = 3;
static unsigned int MAJOR_OGL_CORE; static const unsigned int MAJOR_OGL_CORE = 3;
static const unsigned int MINOR_OGL_CORE = 3;
static unsigned int MINOR_OGL_CORE; #else
static const unsigned int CURRENT_OGL_VERSION = 2;
static const unsigned int MAJOR_OGL_CORE = 2;
static const unsigned int MINOR_OGL_CORE = 1;
#endif
static std::set< std::pair<void*, GLSLShader*> >* m_registeredShaders; static std::set< std::pair<void*, GLSLShader*> >* m_registeredShaders;
// static glm::mat4* s_current_matrices;
static Utils::GL_Matrices* s_current_matrices; static Utils::GL_Matrices* s_current_matrices;
protected: protected:
static std::string DEFINES_GL2;
static std::string DEFINES_GL3;
static std::string* DEFINES_GL;
static std::string defines_Geom(const std::string& primitivesIn, const std::string& primitivesOut, int maxVert); static std::string defines_Geom(const std::string& primitivesIn, const std::string& primitivesOut, int maxVert);
static std::string defines_gl();
int m_nbMaxVertices; int m_nbMaxVertices;
GLuint m_vao; GLuint m_vao;
...@@ -210,9 +209,9 @@ public: ...@@ -210,9 +209,9 @@ public:
*/ */
virtual ~GLSLShader(); virtual ~GLSLShader();
static void setCurrentOGLVersion(unsigned int version); // static void setCurrentOGLVersion(unsigned int version);
static void setCurrentOGLVersion(unsigned int major,unsigned int minor); // static void setCurrentOGLVersion(unsigned int major,unsigned int minor);
/* /*
* search file in different path * search file in different path
......
...@@ -107,6 +107,14 @@ public: ...@@ -107,6 +107,14 @@ public:
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
QSize sizeHint() const; QSize sizeHint() const;
inline int pixelRatio() const
{
#if (QT_VERSION>>16) == 5
return this->devicePixelRatio();
#else
return 1;
#endif
}
}; };
......
...@@ -65,8 +65,6 @@ class CGoGN_UTILS_API GLWidget : public QGLWidget ...@@ -65,8 +65,6 @@ class CGoGN_UTILS_API GLWidget : public QGLWidget
public: public:
GLWidget(SimpleQT* cbs, QWidget *parent = 0); GLWidget(SimpleQT* cbs, QWidget *parent = 0);
GLWidget(SimpleQT* cbs, QGLFormat& format, QWidget *parent = 0);
~GLWidget(); ~GLWidget();
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
...@@ -250,6 +248,15 @@ protected: ...@@ -250,6 +248,15 @@ protected:
* get the focale distance * get the focale distance
*/ */
float getScale() { return scalefactor / foc; } float getScale() { return scalefactor / foc; }
inline int pixelRatio() const
{
#if (QT_VERSION>>16) == 5
return this->devicePixelRatio();
#else
return 1;
#endif
}
}; };
} // namespace QT } // namespace QT
......
...@@ -39,44 +39,43 @@ namespace CGoGN ...@@ -39,44 +39,43 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
#ifdef CGOGN_USE_OGL_CORE_PROFILE //#ifdef CGOGN_USE_OGL_CORE_PROFILE
unsigned int GLSLShader::CURRENT_OGL_VERSION = 3; //unsigned int GLSLShader::CURRENT_OGL_VERSION = 3;
unsigned int GLSLShader::MAJOR_OGL_CORE = 3; //unsigned int GLSLShader::MAJOR_OGL_CORE = 3;
unsigned int GLSLShader::MINOR_OGL_CORE = 3; //unsigned int GLSLShader::MINOR_OGL_CORE = 3;
#else //#else
unsigned int GLSLShader::CURRENT_OGL_VERSION = 2; //unsigned int GLSLShader::CURRENT_OGL_VERSION = 2;
unsigned int GLSLShader::MAJOR_OGL_CORE = 2; //unsigned int GLSLShader::MAJOR_OGL_CORE = 2;
unsigned int GLSLShader::MINOR_OGL_CORE = 1; //unsigned int GLSLShader::MINOR_OGL_CORE = 1;
#endif //#endif
std::string GLSLShader::DEFINES_GL2=\ //std::string GLSLShader::DEFINES_GL2=\
"#version 110\n" //"#version 110\n"
"#define PRECISION float pipo_PRECISION\n" //"#define PRECISION float pipo_PRECISION\n"
"#define ATTRIBUTE attribute\n" //"#define ATTRIBUTE attribute\n"
"#define VARYING_VERT varying\n" //"#define VARYING_VERT varying\n"
"#define VARYING_FRAG varying\n" //"#define VARYING_FRAG varying\n"
"#define FRAG_OUT_DEF float pipo_FRAGDEF\n" //"#define FRAG_OUT_DEF float pipo_FRAGDEF\n"
"#define FRAG_OUT gl_FragColor\n" //"#define FRAG_OUT gl_FragColor\n"
"#define INVARIANT_POS float pipo_INVARIANT\n" //"#define INVARIANT_POS float pipo_INVARIANT\n"
"#define TEXTURE2D texture2D\n" //"#define TEXTURE2D texture2D\n";
;
//std::string GLSLShader::DEFINES_GL3=\
std::string GLSLShader::DEFINES_GL3=\ //"#version 150\n"
"#version 150\n" //"#define PRECISION precision highp float\n"
"#define PRECISION precision highp float\n" //"#define ATTRIBUTE in\n"
"#define ATTRIBUTE in\n" //"#define VARYING_VERT out\n"
"#define VARYING_VERT out\n" //"#define VARYING_FRAG in\n"
"#define VARYING_FRAG in\n" //"#define FRAG_OUT_DEF out vec4 outFragColor\n"
"#define FRAG_OUT_DEF out vec4 outFragColor\n" //"#define FRAG_OUT outFragColor\n"
"#define FRAG_OUT outFragColor\n" //"#define INVARIANT_POS invariant gl_Position\n"
"#define INVARIANT_POS invariant gl_Position\n" //"#define TEXTURE2D texture\n";
"#define TEXTURE2D texture\n";
//std::string* GLSLShader::DEFINES_GL = NULL;
std::string* GLSLShader::DEFINES_GL = NULL;
std::vector<std::string> GLSLShader::m_pathes; std::vector<std::string> GLSLShader::m_pathes;
...@@ -100,8 +99,8 @@ GLSLShader::GLSLShader() : ...@@ -100,8 +99,8 @@ GLSLShader::GLSLShader() :
*m_uniMat_ModelProj = -1; *m_uniMat_ModelProj = -1;
*m_uniMat_Normal = -1; *m_uniMat_Normal = -1;
if (DEFINES_GL == NULL) // if (DEFINES_GL == NULL)
setCurrentOGLVersion(MAJOR_OGL_CORE,MINOR_OGL_CORE); // setCurrentOGLVersion(MAJOR_OGL_CORE,MINOR_OGL_CORE);
m_nbMaxVertices = 16; m_nbMaxVertices = 16;
...@@ -119,11 +118,36 @@ void GLSLShader::unregisterShader(void* ptr, GLSLShader* shader) ...@@ -119,11 +118,36 @@ void GLSLShader::unregisterShader(void* ptr, GLSLShader* shader)
m_registeredShaders->erase(std::pair<void*,GLSLShader*>(ptr, shader)); m_registeredShaders->erase(std::pair<void*,GLSLShader*>(ptr, shader));
} }
std::string GLSLShader::defines_gl()
{
#ifdef CGOGN_USE_OGL_CORE_PROFILE
return std::string("#version 330\n\
#define PRECISION precision highp float\n\
#define ATTRIBUTE in\n\
#define VARYING_VERT out\n\
#define VARYING_FRAG in\n\
#define FRAG_OUT_DEF out vec4 outFragColor\n\
#define FRAG_OUT outFragColor\n\
#define INVARIANT_POS invariant gl_Position\n\
#define TEXTURE2D texture\n");
#else
return std::string("#version 110\n \
#define PRECISION float pipo_PRECISION\n\
#define ATTRIBUTE attribute\n\
#define VARYING_VERT varying\n\
#define VARYING_FRAG varying\n\
#define FRAG_OUT_DEF float pipo_FRAGDEF\n\
#define FRAG_OUT gl_FragColor\n\
#define INVARIANT_POS float pipo_INVARIANT\n\
#define TEXTURE2D texture2D\n");
#endif
}
std::string GLSLShader::defines_Geom(const std::string& primitivesIn, const std::string& primitivesOut, int maxVert) std::string GLSLShader::defines_Geom(const std::string& primitivesIn, const std::string& primitivesOut, int maxVert)
{ {
if (CURRENT_OGL_VERSION >= 3) if (CURRENT_OGL_VERSION >= 3)
{ {
std::string str("#version 150\n"); std::string str("#version 330\n");
str.append("precision highp float;\n"); str.append("precision highp float;\n");
str.append("layout ("); str.append("layout (");
str.append(primitivesIn); str.append(primitivesIn);
...@@ -1042,26 +1066,26 @@ void GLSLShader::unbindVA(const std::string& name) ...@@ -1042,26 +1066,26 @@ void GLSLShader::unbindVA(const std::string& name)
CGoGNerr << "GLSLShader: Attribute "<<name<< " not binded"<< CGoGNendl; CGoGNerr << "GLSLShader: Attribute "<<name<< " not binded"<< CGoGNendl;
} }
void GLSLShader::setCurrentOGLVersion(unsigned int version) //void GLSLShader::setCurrentOGLVersion(unsigned int version)
{ //{
CURRENT_OGL_VERSION = version; // CURRENT_OGL_VERSION = version;
switch(version) // switch(version)
{ // {
case 2: // case 2:
DEFINES_GL = &DEFINES_GL2; // DEFINES_GL = &DEFINES_GL2;
break; // break;
case 3: // case 3:
DEFINES_GL = &DEFINES_GL3; // DEFINES_GL = &DEFINES_GL3;
break; // break;
} // }
} //}
void GLSLShader::setCurrentOGLVersion(unsigned int major,unsigned int minor) //void GLSLShader::setCurrentOGLVersion(unsigned int major,unsigned int minor)
{ //{
setCurrentOGLVersion(major); // setCurrentOGLVersion(major);
MAJOR_OGL_CORE = major; // MAJOR_OGL_CORE = major;
MINOR_OGL_CORE = minor; // MINOR_OGL_CORE = minor;
} //}
/** /**
* update projection, modelview, ... matrices * update projection, modelview, ... matrices
......
...@@ -53,7 +53,6 @@ SimpleQGLV::SimpleQGLV() : ...@@ -53,7 +53,6 @@ SimpleQGLV::SimpleQGLV() :
m_modelView_matrix(m_mat.m_matrices[1]), m_modelView_matrix(m_mat.m_matrices[1]),
m_transfo_matrix(m_mat.m_matrices[2]) m_transfo_matrix(m_mat.m_matrices[2])
{ {
QGLFormat format;
if (GLSLShader::CURRENT_OGL_VERSION >= 3) if (GLSLShader::CURRENT_OGL_VERSION >= 3)
{ {
QGLFormat glFormat; QGLFormat glFormat;
......
...@@ -167,15 +167,14 @@ void QGLView::mousePressEvent(QMouseEvent* event) ...@@ -167,15 +167,14 @@ void QGLView::mousePressEvent(QMouseEvent* event)
// clickPoint = event->pos(); // clickPoint = event->pos();
m_current_button = event->button(); m_current_button = event->button();
if (m_sqgl) if (m_sqgl)
m_sqgl->cb_mousePress(event->button(), event->x(), getHeight() - event->y()); m_sqgl->cb_mousePress(event->button(), event->x()*pixelRatio(), getHeight() - event->y()*pixelRatio());
QGLViewer::mousePressEvent(event); QGLViewer::mousePressEvent(event);
} }
void QGLView::mouseReleaseEvent(QMouseEvent* event) void QGLView::mouseReleaseEvent(QMouseEvent* event)
{ {
if (m_sqgl) if (m_sqgl)
m_sqgl->cb_mouseRelease(event->button(), event->x(), getHeight() - event->y()); m_sqgl->cb_mouseRelease(event->button(), event->x()*pixelRatio(), getHeight() - event->y()*pixelRatio());
m_current_button = 0; m_current_button = 0;
QGLViewer::mouseReleaseEvent(event); QGLViewer::mouseReleaseEvent(event);
} }
...@@ -183,13 +182,13 @@ void QGLView::mouseReleaseEvent(QMouseEvent* event) ...@@ -183,13 +182,13 @@ void QGLView::mouseReleaseEvent(QMouseEvent* event)
void QGLView::mouseClickEvent(QMouseEvent* event) void QGLView::mouseClickEvent(QMouseEvent* event)
{ {
if (m_sqgl) if (m_sqgl)
m_sqgl->cb_mouseClick(event->button(), event->x(), getHeight() - event->y()); m_sqgl->cb_mouseClick(event->button(), event->x()*pixelRatio(), getHeight() - event->y()*pixelRatio());
} }
void QGLView::mouseMoveEvent(QMouseEvent* event) void QGLView::mouseMoveEvent(QMouseEvent* event)
{ {
if (m_sqgl) if (m_sqgl)
m_sqgl->cb_mouseMove(m_current_button, event->x(), getHeight() - event->y()); m_sqgl->cb_mouseMove(m_current_button, event->x()*pixelRatio(), getHeight() - event->y()*pixelRatio());
QGLViewer::mouseMoveEvent(event); QGLViewer::mouseMoveEvent(event);
} }
......
...@@ -137,10 +137,13 @@ SimpleQT::SimpleQT(const SimpleQT& sqt): ...@@ -137,10 +137,13 @@ SimpleQT::SimpleQT(const SimpleQT& sqt):
{ {
if (GLSLShader::CURRENT_OGL_VERSION >= 3) if (GLSLShader::CURRENT_OGL_VERSION >= 3)
{ {
QGLFormat format = sqt.m_glWidget->format(); QGLFormat glFormat;
m_glWidget = new GLWidget(this,format); glFormat.setVersion( Utils::GLSLShader::MAJOR_OGL_CORE, Utils::GLSLShader::MINOR_OGL_CORE);
glFormat.setProfile( QGLFormat::CoreProfile ); // Requires >=Qt-4.8.0
glFormat.setSampleBuffers( true );
QGLFormat::setDefaultFormat(glFormat);
} }
else
m_glWidget = new GLWidget(this); m_glWidget = new GLWidget(this);
setCentralWidget(m_glWidget); setCentralWidget(m_glWidget);
...@@ -172,10 +175,13 @@ void SimpleQT::operator=(const SimpleQT& sqt) ...@@ -172,10 +175,13 @@ void SimpleQT::operator=(const SimpleQT& sqt)
{ {
if (GLSLShader::CURRENT_OGL_VERSION >= 3) if (GLSLShader::CURRENT_OGL_VERSION >= 3)
{ {
QGLFormat format = sqt.m_glWidget->format(); QGLFormat glFormat;
m_glWidget = new GLWidget(this,format); glFormat.setVersion( Utils::GLSLShader::MAJOR_OGL_CORE, Utils::GLSLShader::MINOR_OGL_CORE);
glFormat.setProfile( QGLFormat::CoreProfile ); // Requires >=Qt-4.8.0
glFormat.setSampleBuffers( true );
QGLFormat::setDefaultFormat(glFormat);
} }
else
m_glWidget = new GLWidget(this); m_glWidget = new GLWidget(this);
setCentralWidget(m_glWidget) ; setCentralWidget(m_glWidget) ;
......
...@@ -44,12 +44,7 @@ namespace QT ...@@ -44,12 +44,7 @@ namespace QT
float GLWidget::FAR_PLANE = 500.0f; float GLWidget::FAR_PLANE = 500.0f;
GLWidget::GLWidget(SimpleQT* cbs, QWidget *parent) : GLWidget::GLWidget(SimpleQT* cbs, QWidget *parent) :
#ifdef MAC_OSX QGLWidget(parent),
// QGLWidget(new Core3_2_context(QGLFormat::defaultFormat()),parent),
QGLWidget(QGLFormat(QGL::Rgba | QGL::DoubleBuffer| QGL::DepthBuffer), parent),
#else
QGLWidget(QGLFormat(QGL::Rgba | QGL::DoubleBuffer| QGL::DepthBuffer), parent),
#endif
m_cbs(cbs), m_cbs(cbs),
m_state_modifier(0), m_state_modifier(0),
allow_rotation(true) allow_rotation(true)
...@@ -70,28 +65,6 @@ GLWidget::GLWidget(SimpleQT* cbs, QWidget *parent) : ...@@ -70,28 +65,6 @@ GLWidget::GLWidget(SimpleQT* cbs, QWidget *parent) :
} }
GLWidget::GLWidget(SimpleQT* cbs, QGLFormat& format, QWidget *parent) :
QGLWidget(format, parent),
m_cbs(cbs),
m_state_modifier(0),
allow_rotation(true)
{
makeCurrent();
glewExperimental = GL_TRUE;
glewInit();
newModel = 1;
m_cbs->trans_x() = 0.;
m_cbs->trans_y() = 0.;
float f = FAR_PLANE;
m_cbs->trans_z() = -f / 5.0f;
foc = 2.0f;
// init trackball
trackball(m_cbs->curquat(), 0.0f, 0.0f, 0.0f, 0.0f);
}
GLWidget::~GLWidget() GLWidget::~GLWidget()
{ {
} }
...@@ -256,14 +229,14 @@ void GLWidget::mousePressEvent(QMouseEvent* event) ...@@ -256,14 +229,14 @@ void GLWidget::mousePressEvent(QMouseEvent* event)
m_current_button = event->button(); m_current_button = event->button();
if (m_cbs) if (m_cbs)
m_cbs->cb_mousePress(event->button(), event->x(), getHeight() - event->y()); m_cbs->cb_mousePress(event->button(), event->x()*pixelRatio(), getHeight() - event->y()*pixelRatio());
setFocus(Qt::MouseFocusReason); setFocus(Qt::MouseFocusReason);
} }
void GLWidget::mouseReleaseEvent(QMouseEvent* event) void GLWidget::mouseReleaseEvent(QMouseEvent* event)
{ {
if (m_cbs) if (m_cbs)
m_cbs->cb_mouseRelease(event->button(), event->x(), getHeight() - event->y()); m_cbs->cb_mouseRelease(event->button(), event->x()*pixelRatio(), getHeight() - event->y()*pixelRatio());
if(event->pos() == clickPoint) if(event->pos() == clickPoint)
mouseClickEvent(event) ; mouseClickEvent(event) ;
...@@ -273,15 +246,15 @@ void GLWidget::mouseClickEvent(QMouseEvent* event) ...@@ -273,15 +246,15 @@ void GLWidget::mouseClickEvent(QMouseEvent* event)
{ {
if (m_cbs) if (m_cbs)
m_cbs->cb_mouseClick(event->button(), event->x(), getHeight() - event->y()); m_cbs->cb_mouseClick(event->button(), event->x()*pixelRatio(), getHeight() - event->y()*pixelRatio());
} }
void GLWidget::mouseDoubleClickEvent(QMouseEvent* event) void GLWidget::mouseDoubleClickEvent(QMouseEvent* event)
{ {
if (event->button()==1) if (event->button()==1)
{ {
GLint x = event->x(); GLint x = event->x()*pixelRatio();
GLint y = getHeight() - event->y(); GLint y = getHeight() - event->y()*pixelRatio();
GLfloat depth; GLfloat depth;
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth); glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
if (depth < 1.0f) if (depth < 1.0f)
......
...@@ -45,10 +45,10 @@ ShaderColorPerVertex::ShaderColorPerVertex(bool withClipping, bool black_is_tran ...@@ -45,10 +45,10 @@ ShaderColorPerVertex::ShaderColorPerVertex(bool withClipping, bool black_is_tran
m_nameFS = "ShaderColorPerVertexClip_fs"; m_nameFS = "ShaderColorPerVertexClip_fs";
m_nameGS = ""; m_nameGS = "";
std::string glxvert(*GLSLShader::DEFINES_GL); std::string glxvert(GLSLShader::defines_gl());
glxvert.append(vertexShaderClipText); glxvert.append(vertexShaderClipText);
std::string glxfrag(*GLSLShader::DEFINES_GL); std::string glxfrag(GLSLShader::defines_gl());
if (black_is_transparent) if (black_is_transparent)
glxfrag.append("#define BLACK_TRANSPARENCY 1\n"); glxfrag.append("#define BLACK_TRANSPARENCY 1\n");
glxfrag.append(fragmentShaderClipText); glxfrag.append(fragmentShaderClipText);
...@@ -65,10 +65,10 @@ ShaderColorPerVertex::ShaderColorPerVertex(bool withClipping, bool black_is_tran ...@@ -65,10 +65,10 @@ ShaderColorPerVertex::ShaderColorPerVertex(bool withClipping, bool black_is_tran
m_nameFS = "ShaderColorPerVertex_fs"; m_nameFS = "ShaderColorPerVertex_fs";
m_nameGS = "ShaderColorPerVertex_gs"; m_nameGS = "ShaderColorPerVertex_gs";
std::string glxvert(*GLSLShader::DEFINES_GL); std::string glxvert(GLSLShader::defines_gl());
glxvert.append(vertexShaderText); glxvert.append(vertexShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL); std::string glxfrag(GLSLShader::defines_gl());
if (black_is_transparent) if (black_is_transparent)
glxfrag.append("#define BLACK_TRANSPARENCY 1\n"); glxfrag.append("#define BLACK_TRANSPARENCY 1\n");
glxfrag.append(fragmentShaderText); glxfrag.append(fragmentShaderText);
......
...@@ -16,13 +16,13 @@ ShaderCustom::ShaderCustom() ...@@ -16,13 +16,13 @@ ShaderCustom::ShaderCustom()
m_nameFS = "ShaderCustom_fs"; m_nameFS = "ShaderCustom_fs";
m_nameGS = "ShaderCustom_gs"; m_nameGS = "ShaderCustom_gs";
std::string glxvert(*GLSLShader::DEFINES_GL); std::string glxvert(GLSLShader::defines_gl());
glxvert.append(vertexShaderText); glxvert.append(vertexShaderText);
std::string glxgeom = GLSLShader::defines_Geom("triangles", "triangle_strip", 3); std::string glxgeom = GLSLShader::defines_Geom("triangles", "triangle_strip", 3);