Commit bde7578e authored by Pierre Kraemer's avatar Pierre Kraemer

cleaned bind/unbind on shaders

parent 5845cb12
......@@ -2,3 +2,4 @@ cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(import)
ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector)
......@@ -51,11 +51,7 @@ void ImportPlugin::cb_import()
normalVBO->updateData(normal);
// compute map bounding box
CGoGN::Geom::BoundingBox<VEC3> bb = CGoGN::Algo::Geometry::computeBoundingBox<PFP>(*m, position);
qglviewer::Vec min(bb.min()[0], bb.min()[1], bb.min()[2]);
qglviewer::Vec max(bb.max()[0], bb.max()[1], bb.max()[2]);
h->setBBmin(min);
h->setBBmax(max);
h->updateBB(position);
// compute primitive connectivity VBOs
h->updatePrimitives(CGoGN::Algo::Render::GL2::POINTS, CGoGN::allDarts);
......
......@@ -26,6 +26,11 @@ bool RenderPlugin::enable()
m_pointSprite = new CGoGN::Utils::PointSprite();
registerShader(m_flatShader);
registerShader(m_phongShader);
registerShader(m_simpleColorShader);
registerShader(m_pointSprite);
connect(m_dockTab->check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(cb_renderVerticesChanged(bool)));
connect(m_dockTab->slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_verticesScaleFactorChanged(int)));
connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool)));
......@@ -91,24 +96,12 @@ void RenderPlugin::redraw(View* view)
void RenderPlugin::viewLinked(View* view)
{
assert(!h_viewParams.contains(view));
h_viewParams.insert(view, new TabParams(1.0, false, false, true, FLAT));
CGoGN::Utils::GLSLShader::registerShader(view, m_flatShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_phongShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_simpleColorShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_pointSprite);
}
void RenderPlugin::viewUnlinked(View* view)
{
assert(h_viewParams.contains(view));
h_viewParams.remove(view);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_flatShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_phongShader);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_simpleColorShader);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_pointSprite);
}
void RenderPlugin::currentViewChanged(View* view)
......
cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/renderVector
${CMAKE_CURRENT_BINARY_DIR}
)
SET( PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/renderVector/renderVector.cpp
)
SET( PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/renderVector/renderVector.h
)
SET( PLUGIN_FORM
${SCHNApps_ROOT_DIR}/Plugins/renderVector/renderVector.ui
)
IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
ADD_DEFINITIONS(-DDEBUG)
IF(WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ELSE (WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Debug ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF (WIN32)
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( RenderVectorPluginD SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( RenderVectorPluginD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( RenderVectorPluginD SCHNAppsD )
SET_TARGET_PROPERTIES( RenderVectorPluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" )
ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
IF(WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ELSE (WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF (WIN32)
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( RenderVectorPlugin SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( RenderVectorPlugin
${CGoGN_LIBS_R}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( RenderVectorPlugin SCHNApps )
ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
#include "renderVector.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
bool RenderVectorPlugin::enable()
{
m_dockTab = new RenderVectorDockTab();
addTabInDock(m_dockTab, "RenderVector");
m_vectorShader = new Utils::ShaderVectorPerVertex() ;
m_vectorShader->setColor(Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f)) ;
registerShader(m_vectorShader);
connect(m_dockTab->slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_vectorsScaleFactorChanged(int)));
return true;
}
void RenderVectorPlugin::disable()
{
delete m_vectorShader;
}
void RenderVectorPlugin::redraw(View* view)
{
TabParams* params = h_viewParams[view];
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps)
{
CGoGN::Utils::VBO* positionVBO = m->getVBO("position");
CGoGN::Utils::VBO* normalVBO = m->getVBO("normal");
m_vectorShader->setScale(m->getBBdiagSize() / 100.0f * params->vectorsScaleFactor) ;
m_vectorShader->setAttributePosition(positionVBO) ;
m_vectorShader->setAttributeVector(normalVBO) ;
glLineWidth(1.0f) ;
m->draw(m_vectorShader, Algo::Render::GL2::POINTS) ;
}
}
void RenderVectorPlugin::viewLinked(View* view)
{
h_viewParams.insert(view, new TabParams(1.0));
}
void RenderVectorPlugin::viewUnlinked(View* view)
{
h_viewParams.remove(view);
}
void RenderVectorPlugin::currentViewChanged(View* view)
{
TabParams* params = h_viewParams[view];
m_dockTab->slider_vectorsScaleFactor->setSliderPosition(params->vectorsScaleFactor * 50.0);
}
void RenderVectorPlugin::cb_vectorsScaleFactorChanged(int i)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
params->vectorsScaleFactor = i / 50.0;
current->updateGL();
}
/**
* If we want to compile this plugin in debug mode,
* we also define a DEBUG macro at the compilation
*/
#ifndef DEBUG
// essential Qt function:
// arguments are
// - the compiled name of the plugin
// - the main class of our plugin
Q_EXPORT_PLUGIN2(RenderVectorPlugin, RenderVectorPlugin)
#else
Q_EXPORT_PLUGIN2(RenderVectorPluginD, RenderVectorPlugin)
#endif
#ifndef _RENDERVECTOR_PLUGIN_H_
#define _RENDERVECTOR_PLUGIN_H_
#include "plugin.h"
#include "ui_renderVector.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
using namespace CGoGN;
using namespace SCHNApps;
class RenderVectorDockTab : public QWidget, public Ui::RenderVectorWidget
{
public:
RenderVectorDockTab() { setupUi(this); }
};
struct TabParams
{
TabParams(float vsf) :
vectorsScaleFactor(vsf)
{}
float vectorsScaleFactor;
};
class RenderVectorPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
RenderVectorPlugin()
{
setProvidesRendering(true);
}
~RenderVectorPlugin()
{}
virtual bool enable();
virtual void disable();
virtual void redraw(View *view);
virtual void keyPress(View* view, int key) {}
virtual void keyRelease(View* view, int key) {}
virtual void mousePress(View* view, int button, int x, int y) {}
virtual void mouseRelease(View* view, int button, int x, int y) {}
virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view);
virtual void viewUnlinked(View* view);
virtual void currentViewChanged(View* view);
protected:
RenderVectorDockTab* m_dockTab;
QHash<View*, TabParams*> h_viewParams;
CGoGN::Utils::ShaderVectorPerVertex* m_vectorShader;
public slots:
void cb_vectorsScaleFactorChanged(int i);
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RenderVectorWidget</class>
<widget class="QWidget" name="RenderVectorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>174</width>
<height>397</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Vectors Size :</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="slider_vectorsScaleFactor">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>161</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -10,6 +10,7 @@
#include "Topology/generic/functor.h"
#include "Utils/vbo.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Geometry/boundingbox.h"
namespace CGoGN
{
......@@ -32,16 +33,12 @@ public:
GenericMap* getGenericMap() { return m_map; }
const qglviewer::Vec& getBBmin() const { return m_bbMin; }
void setBBmin(qglviewer::Vec& v) { m_bbMin = v; }
const qglviewer::Vec& getBBmax() const { return m_bbMax; }
void setBBmax(qglviewer::Vec& v) { m_bbMax = v; }
float getBBdiagSize() { return (m_bbMax - m_bbMin).norm(); }
float getBBdiagSize() { return m_bbDiagSize; }
bool isUsed() const { return !l_views.empty(); }
void draw(Utils::GLSLShader* shader, int primitive);
void draw(Utils::GLSLShader* shader, int primitive) { m_render->draw(shader, primitive); }
/*********************************************************
* MANAGE VBOs
......@@ -68,6 +65,7 @@ protected:
qglviewer::Vec m_bbMin;
qglviewer::Vec m_bbMax;
float m_bbDiagSize;
QList<View*> l_views;
......@@ -90,6 +88,14 @@ public:
typename PFP::MAP* getMap() { return reinterpret_cast<typename PFP::MAP*>(m_map); }
void updateBB(const VertexAttribute<typename PFP::VEC3>& position)
{
CGoGN::Geom::BoundingBox<typename PFP::VEC3> bb = CGoGN::Algo::Geometry::computeBoundingBox<PFP>(*(reinterpret_cast<typename PFP::MAP*>(m_map)), position);
m_bbMin = qglviewer::Vec(bb.min()[0], bb.min()[1], bb.min()[2]);
m_bbMax = qglviewer::Vec(bb.max()[0], bb.max()[1], bb.max()[2]);
m_bbDiagSize = (m_bbMax - m_bbMin).norm();
}
void updatePrimitives(int primitive, const FunctorSelect& good)
{
m_render->initPrimitives<PFP>(*(reinterpret_cast<typename PFP::MAP*>(m_map)), good, primitive) ;
......
......@@ -2,16 +2,9 @@
#define _PLUGIN_H_
#include <QtPlugin>
#include <QAction>
#include <iostream>
#include <list>
#include "window.h"
#include "system.h"
#include "view.h"
#include "camera.h"
#include "mapHandler.h"
#include "vboHandler.h"
#include "types.h"
namespace CGoGN
{
......@@ -19,6 +12,8 @@ namespace CGoGN
namespace SCHNApps
{
class Window;
class Plugin : public QObject
{
public:
......@@ -64,6 +59,13 @@ public:
const QList<View*>& getLinkedViews() const { return l_views; }
bool isLinkedToView(View* view) const { return l_views.contains(view); }
/*********************************************************
* MANAGE SHADERS
*********************************************************/
void registerShader(Utils::GLSLShader* shader);
void unregisterShader(Utils::GLSLShader* shader);
/*********************************************************
* MANAGE DOCK TABS
*********************************************************/
......@@ -98,6 +100,8 @@ protected:
QList<QAction*> l_menuActions;
QList<QAction*> l_toolbarActions;
QList<Utils::GLSLShader*> l_shaders;
// QList<Plugin*> l_dependencies;
// QList<Plugin*> l_dependantPlugins;
......
......@@ -4,10 +4,6 @@
#include <QWidget>
#include <QSplashScreen>
#include <unistd.h>
#include <stdarg.h>
#include <iostream>
#include "types.h"
//#include "ui_questionSessionDialog.h"
......
......@@ -11,16 +11,15 @@ unsigned int Camera::cameraCount = 0;
Camera::Camera(const QString& name, Window* window) :
m_name(name),
m_window(window),
m_draw(false),
m_drawFarPlane(false),
m_drawScale(1.0),
m_draw(true),
m_drawFarPlane(true),
m_drawScale(0.1),
m_drawPath(false),
m_drawPathAxis(false),
m_drawPathScale(1.0),
m_snapCount(0)
{
++cameraCount;
// setZClippingCoefficient(100);
}
Camera::~Camera()
......
......@@ -3,6 +3,7 @@
#include "window.h"
#include "view.h"
#include "plugin.h"
#include "mapHandler.h"
#include <QMessageBox>
#include <QMouseEvent>
......
......@@ -22,10 +22,9 @@ MapHandlerGen::~MapHandlerGen()
delete vbo;
}
void MapHandlerGen::draw(Utils::GLSLShader* shader, int primitive)
{
m_render->draw(shader, primitive);
}
/*********************************************************
* MANAGE VBOs
*********************************************************/
Utils::VBO* MapHandlerGen::getVBO(const std::string& name)
{
......
#include "plugin.h"
#include <GL/glew.h>
#include "window.h"
#include "Utils/GLSLShader.h"
namespace CGoGN
{
......@@ -32,7 +37,7 @@ Plugin::~Plugin()
}
/*********************************************************
* MANAGE VIEWS
* MANAGE LINKED VIEWS
*********************************************************/
bool Plugin::linkView(View* view)
......@@ -40,6 +45,8 @@ bool Plugin::linkView(View* view)
if(view && !l_views.contains(view))
{
l_views.push_back(view);
foreach(Utils::GLSLShader* shader, l_shaders)
Utils::GLSLShader::registerShader(view, shader);
viewLinked(view);
return true;
}
......@@ -50,7 +57,26 @@ bool Plugin::linkView(View* view)
void Plugin::unlinkView(View* view)
{
if(l_views.removeOne(view))
{
foreach(Utils::GLSLShader* shader, l_shaders)
Utils::GLSLShader::unregisterShader(view, shader);
viewUnlinked(view);
}
}
/*********************************************************
* MANAGE SHADERS
*********************************************************/
void Plugin::registerShader(Utils::GLSLShader* shader)
{
if(shader && !l_shaders.contains(shader))
l_shaders.push_back(shader);
}
void Plugin::unregisterShader(Utils::GLSLShader* shader)
{
l_shaders.removeOne(shader);
}
/*********************************************************
......
......@@ -3,6 +3,7 @@
#include "plugin.h"
#include "camera.h"
#include "viewButtonArea.h"
#include "mapHandler.h"
#include "dialogs/cameraViewDialog.h"
#include "dialogs/pluginsViewDialog.h"
......
......@@ -13,6 +13,8 @@
#include "plugin.h"
#include "view.h"
#include "texture.h"
#include "camera.h"
#include "mapHandler.h"
#include "dialogs/camerasDialog.h"
#include "dialogs/pluginsDialog.h"
......
......@@ -171,7 +171,7 @@ protected:
/**
* create the shader (attach and link shaders into program)
*/
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES, int nb_max_vertices=-1);
bool create(GLint inputGeometryPrimitive = GL_TRIANGLES, GLint outputGeometryPrimitive = GL_TRIANGLES, int nb_max_vertices = -1);
/**
* get log after compiling
......
......@@ -61,7 +61,7 @@ public:
/**
* set the VBO of color (vec3)
*/
unsigned int setAttributeColor(VBO* vbo);
unsigned int setAttributeColor(VBO* vbo);
/**
* set opacity (0=transparent / 1=opaque)
......
......@@ -119,7 +119,6 @@ public:
unsigned int setAttributeNormal(VBO* vbo);
// optional attributes
unsigned int setAttributeColor(VBO* vbo);
void unsetAttributeColor();
......
......@@ -86,9 +86,9 @@ public:
void setParams(float explodeV, float explodeF, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane);
void setAttributePosition(VBO* vbo);
unsigned int setAttributePosition(VBO* vbo);
void setAttributeColor(VBO* vbo);
unsigned int setAttributeColor(VBO* vbo);
};
} // namespace Utils
......
......@@ -68,7 +68,7 @@ public:
void setParams(float explodeV, const Geom::Vec4f& color, const Geom::Vec4f& plane);
void setAttributePosition(VBO* vbo);
unsigned int setAttributePosition(VBO* vbo);
};
} // namespace Utils
......
......@@ -72,7 +72,7 @@ public:
void setParams(float explode, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos);
void setAttributePosition(VBO* vbo);
unsigned int setAttributePosition(VBO* vbo);
};
} // namespace Utils
......
......@@ -69,9 +69,9 @@ public:
void setParams(float explode, const Geom::Vec4f& ambiant, const Geom::Vec3f& lightPos);
void setAttributePosition(VBO* vbo);
unsigned int setAttributePosition(VBO* vbo);
void setAttributeColor(VBO* vbo);
unsigned int setAttributeColor(VBO* vbo);
};
} // namespace Utils
......
......@@ -106,12 +106,12 @@ public:
/**
* Position attribute
*/
void setAttributePosition(VBO* vbo);
unsigned int setAttributePosition(VBO* vbo);
/**
* Data attribute for iso-lines must be of type float
*/
void setAttributeData(VBO* vbo);
unsigned int setAttributeData(VBO* vbo);
};
} // namespace Utils
......
......@@ -50,9 +50,9 @@ protected:
public:
ShaderScalarField();
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeScalar(VBO* vbo);
unsigned int setAttributeScalar(VBO* vbo);
};
} // namespace Utils
......