Commit 69a82e95 authored by untereiner's avatar untereiner

Merge cgogn:~maire/CGoGN

parents ac0562e7 31366e50
SET(EXECUTABLE_OUTPUT_PATH ${CGoGN_ROOT_DIR}/bin)
SET (COMMON_LIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${DEVIL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBXML2_LIBRARIES} gzstream AntTweakBar openctm assimp)
BOOST_LIBS(boost_regex_lib_lists "boost_regex-mt")
SET (COMMON_LIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${DEVIL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBXML2_LIBRARIES} ${boost_regex_lib_lists} gzstream AntTweakBar openctm assimp)
SET(CGoGN_LIBS_R topology algo container utils)
......
......@@ -59,3 +59,9 @@ add_executable( viewerD ../viewer.cpp ${viewer_moc} ${viewer_ui})
target_link_libraries( viewerD
${CGoGN_LIBS_D} ${NUMERICAL_LIBS} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_UI( clipping_ui ../clipping.ui )
QT4_WRAP_CPP( clipping_moc ../clipping.h )
add_executable( clippingD ../clipping.cpp ${clipping_ui} ${clipping_moc})
target_link_libraries( clippingD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
......@@ -63,3 +63,9 @@ add_executable( viewer ../viewer.cpp ${viewer_moc} ${viewer_ui})
target_link_libraries( viewer
${CGoGN_LIBS_R} ${NUMERICAL_LIBS} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_UI( clipping_ui ../clipping.ui )
QT4_WRAP_CPP( clipping_moc ../clipping.h )
add_executable( clipping ../clipping.cpp ${clipping_ui} ${clipping_moc})
target_link_libraries( clipping
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
......@@ -22,14 +22,14 @@
* *
*******************************************************************************/
#ifndef __STAGE_SHADER_H__
#define __STAGE_SHADER_H__
#ifndef __CLIPPING_H__
#define __CLIPPING_H__
#include <iostream>
#include "Utils/qtSimple.h"
#include "ui_stage_shader.h"
#include "ui_clipping.h"
// inclure qtui.h juste après le ui_xxx.h
#include "Utils/qtui.h"
......@@ -49,11 +49,14 @@
#include "Algo/Render/GL2/topo3Render.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/frameManipulator.h"
#include "Utils/cgognStream.h"
#include "Utils/drawer.h"
#include <string>
#include <sstream>
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
......@@ -63,7 +66,7 @@ struct PFP: public PFP_STANDARD
};
class StageShader: public Utils::QT::SimpleQT
class Clipping: public Utils::QT::SimpleQT
{
Q_OBJECT
......@@ -80,12 +83,14 @@ public:
//Render
bool m_drawVertices;
bool m_drawLines;
bool m_drawFaces;
bool m_drawTopo;
bool m_drawFaces;
bool m_drawTopo;
Algo::Render::GL2::MapRender* m_render;
Algo::Render::GL2::Topo3RenderMapD* m_render_topo;
Geom::BoundingBox<PFP::VEC3> m_bb;
Utils::VBO* m_positionVBO;
Utils::ShaderSimpleColor* m_shader;
......@@ -94,13 +99,23 @@ public:
Utils::Drawer* chips_area;
Geom::Vec3f m_coeffTopoExplod;
Geom::Vec3f gPosObj ;
float gWidthObj ;
Geom::Vec3f gPosObj ;
float gWidthObj ;
//QT
Utils::QT::uiDockInterface dock;
//QT
Utils::QT::uiDockInterface dock;
StageShader();
// Picking
Utils::LineDrawable* m_planeDrawable;
Utils::LineDrawable* m_sphereDrawable;
Utils::FrameManipulator* m_frameManipulator;
unsigned int m_frameManipulatorPickedAxis;
std::vector<Utils::Pickable*> m_pickablePlanes;
std::vector<Utils::Pickable*> m_pickableSpheres;
Utils::Pickable* m_lastPickedObject;
int m_lastClickedX, m_lastClickedY;
Clipping();
void initGUI();
void cb_Open();
......@@ -108,6 +123,7 @@ public:
void cb_initGL();
void cb_redraw();
void cb_mousePress(int button, int x, int y);
void cb_mouseMove(int buttons, int x, int y);
void cb_keyPress(int code);
void importMesh(std::string& filename);
......@@ -121,7 +137,21 @@ public slots:
void slot_explodTopoPhi2(double c);
void slot_explodTopoPhi3(double c);
void dockWidget_topLevelChanged(bool isFloating);
void slot_pushButton_addPlane();
void slot_spinBox_GridResolution(int i);
void slot_pushButton_changePlanesColor();
void slot_pushButton_addSphere();
void slot_spinBox_SphereResolution(int i);
void slot_pushButton_changeSpheresColor();
void slot_doubleSpinBox_ColorAttenuationFactor(double c);
void slot_radioButton_ClippingMode(bool b);
void slot_radioButton_ColorAttenuationMode(bool b);
void slot_pushButton_deleteSelectedObject();
void button_compile();
};
......
......@@ -47,7 +47,6 @@
#include "glm/gtc/type_precision.hpp"
#include "glm/gtc/type_ptr.hpp"
using namespace CGoGN;
struct PFP: public PFP_STANDARD
......
......@@ -66,13 +66,6 @@ target_link_libraries( tuto5
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_UI( stage_shader_ui stage_shader.ui )
QT4_WRAP_CPP(stage_shader_moc stage_shader.h)
add_executable( stage_shader stage_shader.cpp ${stage_shader_ui} ${stage_shader_moc})
target_link_libraries( stage_shader
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
#add_executable( tuto_subdivision tuto_subdivision.cpp)
#target_link_libraries( tuto_subdivision
# ${CGoGN_LIBS_D} ${COMMON_LIBS} )
......
......@@ -286,6 +286,9 @@ public:
*/
virtual void restoreUniformsAttribs() {CGoGNerr << "Warning restoreUniformsAttribs not implemented"<< CGoGNendl;}
virtual void updateClippingUniforms() {CGoGNerr << "Warning updateClippingUniforms not implemented"<< CGoGNendl;}
/**
*
*/
......
......@@ -26,6 +26,7 @@
#define __CGOGN_SHADER_PHONG__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
#include <string>
......@@ -36,7 +37,7 @@ namespace CGoGN
namespace Utils
{
class ShaderPhong : public GLSLShader
class ShaderPhong : public ClippingShader
{
protected:
// flag color per vertex or not
......@@ -71,7 +72,7 @@ protected:
void restoreUniformsAttribs();
public:
ShaderPhong();
ShaderPhong(bool doubleSided = false);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
......
......@@ -26,6 +26,7 @@
#define __CGOGN_SHADER_SIMPLECOLOR__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
namespace CGoGN
......@@ -34,14 +35,14 @@ namespace CGoGN
namespace Utils
{
class ShaderSimpleColor : public GLSLShader
class ShaderSimpleColor : public ClippingShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string vertexShaderText;
static std::string fragmentShaderText;
// uniform locations
// uniform locations
GLuint m_unif_color;
Geom::Vec4f m_color;
......
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _CGoGN_SHADERMUTATOR_H_
#define _CGoGN_SHADERMUTATOR_H_
#include "Utils/cgognStream.h"
#include <boost/regex.hpp>
#include <string>
#include <sstream>
namespace CGoGN
{
namespace Utils
{
class ShaderMutator
{
public:
/// enum used to choose which shader src type to modify
enum shaderSrcType { VERTEX_SHADER, FRAGMENT_SHADER, GEOMETRY_SHADER };
/**
* constructor
* @param vertShaderSrc vertex shader source to store
* @param fragShaderSrc fragment shader source to store
* @param geomShaderSrc geometry shader source to store (optional)
*/
ShaderMutator(const std::string& shaderName, const std::string& vertShaderSrc, const std::string& fragShaderSrc, const std::string& geomShaderSrc = "");
/**
* checks if a variable is declared in the shader source
* @param srcType shader source to use
* @param variableName variable to search for
* @return true if the variable was declared
*/
bool containsVariableDeclaration(shaderSrcType srcType, const std::string& variableName);
/**
* sets or changes shading language version in the shader source
* - only if the current version is lower
* @param srcType shader source to use
* @param version version to set (110, 120, 150...)
* @return true if the version was set or changed
*/
bool setMinShadingLanguageVersion(shaderSrcType srcType, int version);
/**
* changes int constant value in the shader source
* @param srcType shader source to use
* @param newVal new constant value
* @return true on success
*/
bool changeIntConstantValue(shaderSrcType srcType, const std::string& constantName, int newVal);
/**
* changes float constant value in the shader source
* @param srcType shader source to use
* @param newVal new constant value
* @return true on success
*/
bool changeFloatConstantValue(shaderSrcType srcType, const std::string& constantName, float newValue);
/**
* inserts code before main function in the shader source
* @param srcType shader source to use
* @param insertedCode source code to insert into shader
* @return true on success
*/
bool insertCodeBeforeMainFunction(shaderSrcType srcType, const std::string& insertedCode);
/**
* inserts code at the beginning of main function in the shader source
* @param srcType shader source to use
* @param insertedCode source code to insert into shader
* @return true on success
*/
bool insertCodeAtMainFunctionBeginning(shaderSrcType srcType, const std::string& insertedCode);
/**
* inserts code at the end of main function in the shader source
* @warning takes the number of opening and closing braces of main function into account
* @param srcType shader source to use
* @param insertedCode source code to insert into shader
* @return true on success
*/
bool insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std::string& insertedCode);
/// returns the modified vertex shader source code
std::string getModifiedVertexShaderSrc() { return m_vShaderMutation; }
/// returns the modified fragment shader source code
std::string getModifiedFragmentShaderSrc() { return m_fShaderMutation; }
/// returns the modified geometry shader source code
std::string getModifiedGeometryShaderSrc() { return m_gShaderMutation; }
private:
/// processed shader name stored for log purpose
std::string m_shaderName;
/// modified version of the original vertex shader source code
std::string m_vShaderMutation;
/// modified version of the original fragment shader source code
std::string m_fShaderMutation;
/// modified version of the original geometry shader source code
std::string m_gShaderMutation;
/**
* checks if the given position is commented
* @param pos position in the source (like in a string)
* @param src source to analyze
* @return true if the given position is commented
*/
bool srcIsCommented(size_t pos, const std::string& src);
/**
* checks if the given position is one-line commented
* @param pos position in the source (like in a string)
* @param src source to analyze
* @return true if the given position is one-line commented
*/
bool srcIsOneLineCommented(size_t pos, const std::string& src);
/**
* checks if a variable is declared
* @param variableName variable to search for
* @param src source to analyze
* @return true if the variable was declared
*/
bool srcContainsVariableDeclaration(const std::string& variableName, std::string& src);
/**
* sets or changes shading language version if the current version is lower
* @param version version to set (110, 120, 150...)
* @param modifiedSrc shader source code to modify
* @return true if the version was set or changed
*/
bool srcSetMinShadingLanguageVersion(int version, std::string& modifiedSrc);
/**
* changes int constant value
* @param newVal new constant value
* @param constantName constant name as it is declared
* @param modifiedSrc shader source code to modify
* @return true on success
*/
bool srcChangeIntConstantValue(int newVal, const std::string& constantName, std::string& modifiedSrc);
/**
* changes float constant value
* @param newVal new constant value
* @param constantName constant name as it is declared
* @param modifiedSrc shader source code to modify
* @return true on success
*/
bool srcChangeFloatConstantValue(float newVal, const std::string& constantName, std::string& modifiedSrc);
/**
* inserts code before main function
* @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify
* @return true on success
*/
bool srcInsertCodeBeforeMainFunction(const std::string& insertedCode, std::string& modifiedSrc);
/**
* inserts code at the beginning of main function
* @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify
* @return true on success
*/
bool srcInsertCodeAtMainFunctionBeginning(const std::string& insertedCode, std::string& modifiedSrc);
/**
* inserts code at the end of main function
* @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify
* @return true on success
*/
bool srcInsertCodeAtMainFunctionEnd(const std::string& insertedCode, std::string& modifiedSrc);
};
} // namespace Utils
} // namespace CGoGN
#endif
......@@ -826,6 +826,8 @@ bool GLSLShader::recompile()
restoreUniformsAttribs();
updateClippingUniforms();
return true;
}
......@@ -1018,6 +1020,7 @@ void GLSLShader::enableVertexAttribs(unsigned int stride, unsigned int begin) co
void GLSLShader::disableVertexAttribs() const
{
this->bind();
for (std::vector<Utils::GLSLShader::VAStr>::const_iterator it= m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it)
glDisableVertexAttribArray(it->va_id);
this->unbind();
......
......@@ -57,6 +57,10 @@ std::string ShaderColorPerVertex::fragmentShaderText =
ShaderColorPerVertex::ShaderColorPerVertex()
{
m_nameVS = "ShaderColorPerVertex_vs";
m_nameFS = "ShaderColorPerVertex_fs";
m_nameGS = "ShaderColorPerVertex_gs";
std::string glxvert(*GLSLShader::DEFINES_GL);
glxvert.append(vertexShaderText);
......@@ -80,8 +84,10 @@ unsigned int ShaderColorPerVertex::setAttributeColor(VBO* vbo)
void ShaderColorPerVertex::restoreUniformsAttribs()
{
bind();
bindVA_VBO("VertexPosition", m_vboPos);
bindVA_VBO("VertexColor", m_vboCol);
unbind();
}
} // namespace Utils
......
......@@ -76,7 +76,15 @@ std::string ShaderPhong::fragmentShaderText =
" float lambertTerm = dot(N,L);\n"
" vec4 finalColor = materialAmbient;\n"
" if(lambertTerm > 0.0)\n"
" #ifdef DOUBLE_SIDED\n"
" if (lambertTerm < 0.0)\n"
" {\n"
" N = -1.0*N;\n"
" lambertTerm = -1.0*lambertTerm;\n"
" }\n"
" #else\n"
" if (lambertTerm > 0.0)\n"
" #endif\n"
" {\n"
" #ifndef WITH_COLOR\n"
" finalColor += materialDiffuse * lambertTerm;\n"
......@@ -92,7 +100,7 @@ std::string ShaderPhong::fragmentShaderText =
"}";
ShaderPhong::ShaderPhong():
ShaderPhong::ShaderPhong(bool doubleSided):
m_with_color(false),
m_ambiant(Geom::Vec4f(0.05f,0.05f,0.1f,0.0f)),
m_diffuse(Geom::Vec4f(0.1f,1.0f,0.1f,0.0f)),
......@@ -103,11 +111,19 @@ ShaderPhong::ShaderPhong():
m_vboNormal(NULL),
m_vboColor(NULL)
{
m_nameVS = "ShaderPhong_vs";
m_nameFS = "ShaderPhong_fs";
m_nameGS = "ShaderPhong_gs";
// get choose GL defines (2 or 3)
// ans compile shaders
std::string glxvert(*GLSLShader::DEFINES_GL);
glxvert.append(vertexShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
......@@ -232,14 +248,12 @@ void ShaderPhong::restoreUniformsAttribs()
getLocations();
bind();
sendParams();
bindVA_VBO("VertexPosition", m_vboPos);
bindVA_VBO("VertexNormal", m_vboNormal);
if (m_vboColor)
bindVA_VBO("VertexColor", m_vboColor);
unbind();
}
......
......@@ -53,6 +53,10 @@ std::string ShaderSimpleColor::fragmentShaderText =
ShaderSimpleColor::ShaderSimpleColor()
{
m_nameVS = "ShaderSimpleColor_vs";
m_nameFS = "ShaderSimpleColor_fs";
m_nameGS = "ShaderSimpleColor_gs";
// chose GL defines (2 or 3)
// and compile shaders
std::string glxvert(*GLSLShader::DEFINES_GL);
......@@ -89,6 +93,7 @@ void ShaderSimpleColor::restoreUniformsAttribs()
bind();
glUniform4fv(m_unif_color, 1, m_color.data());
bindVA_VBO("VertexPosition", m_vboPos);
unbind();
}
} // namespace Utils
......
......@@ -71,6 +71,11 @@ ShaderVectorPerVertex::ShaderVectorPerVertex() :
m_scale(1.0f),
m_color(Geom::Vec4f(1.0f, 0.0f, 0.0f, 0.0f))
{
m_nameVS = "ShaderVectorPerVertex_vs";
m_nameFS = "ShaderVectorPerVertex_fs";
m_nameGS = "ShaderVectorPerVertex_gs";
std::string glxvert(*GLSLShader::DEFINES_GL);
glxvert.append(vertexShaderText);
......@@ -130,9 +135,10 @@ void ShaderVectorPerVertex::restoreUniformsAttribs()
{
getLocations();
sendParams();
bind();
bindVA_VBO("VertexPosition", m_vboPos);
bindVA_VBO("VertexVector", m_vboVec);
unbind();
}
} // namespace Utils
......
This diff is collapsed.
This diff is collapsed.
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