Commit be1ee120 authored by Sylvain Thery's avatar Sylvain Thery

Ajout rendu et interface OpenGL3

parent ea955ff5
......@@ -16,6 +16,7 @@ include_directories(
${CGoGN_ROOT_DIR}/ThirdParty/gzstream
${CGoGN_ROOT_DIR}/ThirdParty/OpenCTM
${CGoGN_ROOT_DIR}/ThirdParty/Assimp/include
${CGoGN_ROOT_DIR}/ThirdParty/glm
${CGoGN_ROOT_DIR}/include
)
......@@ -56,3 +57,9 @@ add_executable( tuto_mt tuto_mt.cpp)
target_link_libraries( tuto_mt
containerD topologyD utilsD algoD ${COMMON_LIBS} boost_thread)
# container topology utils algo ${COMMON_LIBS} boost_thread)
add_executable( tuto_ogl3 tuto_ogl3.cpp)
target_link_libraries( tuto_ogl3
containerD topologyD utilsD algoD ${COMMON_LIBS} )
# container topology utils algo ${COMMON_LIBS} )
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _GL3_MAP_RENDER_
#define _GL3_MAP_RENDER_
#include <GL/glew.h>
#include <vector>
#include <list>
#include "Topology/generic/dart.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/attributeHandler.h"
#include "Container/convert.h"
#include "Geometry/vector_gen.h"
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace GL3
{
enum drawingType {
TRIANGLES = 1,
LINES = 2,
POINTS = 4,
EXPLODED = 8,
FLAT_TRIANGLES = 16,
ERR = 32
} ;
enum bufferIndex {
TRIANGLE_INDICES = 0,
LINE_INDICES = 1,
POINT_INDICES = 2,
FLAT_BUFFER = 3,
FIRST_ATTRIBUTE_BUFFER = 4,
} ;
const unsigned int NB_BUFFERS = 16 ;
class MapRender
{
protected:
/**
* vbo buffers
*/
GLuint m_VBOBuffers[NB_BUFFERS] ;
// bool m_allocatedBuffers[NB_BUFFERS] ;
// bool m_usedBuffers[NB_BUFFERS] ;
bool m_allocatedAttributes[NB_BUFFERS] ;
bool m_usedAttributes[NB_BUFFERS] ;
unsigned int m_AttributesDataSize[NB_BUFFERS];
/**
* number of indices of triangles
*/
GLuint m_nbIndicesTri ;
/**
* number of indices of lines
*/
GLuint m_nbIndicesLines ;
/**
* number of indices of points
*/
GLuint m_nbIndicesPoints ;
/**
* number of elts for flat vbo
*/
GLuint m_nbFlatElts;
public:
/**
* Constructor
*/
MapRender() ;
/**
* Constructor that share vertices attributes vbo (position/normals/colors...)
*/
MapRender(const MapRender& mrvbo);
/**
* Destructor
*/
~MapRender() ;
/**
* update the data
* @param uptype that have to be updated: POSITIONS, NORMALS, COLORS, TEXCOORDS, ???
* @param attribId attribute where data is stored
* @param conv Callback of attribute conversion (NULL if direct copy, default value)
*/
template <typename ATTR_HANDLER>
void updateData(unsigned int vertex_attrib, const ATTR_HANDLER& attrib, ConvertAttrib* conv = NULL) ;
/**
* enable a vertex attribute for rendering (updateDate automatically enable attrib)
*/
void enableVertexAttrib(unsigned int index);
/**
* disable a vertex attribute for rendering
*/
void disableVertexAttrib(unsigned int index);
protected:
/**
* fill buffer directly from attribute
*/
template <typename ATTR_HANDLER>
void fillBufferDirect(unsigned int indexVBO, const ATTR_HANDLER& attrib) ;
/**
* fill buffer with conversion from attribute
*/
template <typename ATTR_HANDLER>
void fillBufferConvert(unsigned int indexVBO, const ATTR_HANDLER& attrib, ConvertAttrib* conv) ;
/**
* addition of indices table of one triangle
* @param d a dart of the triangle
* @param tableIndices the indices table
*/
template <typename PFP>
void addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices) ;
public:
/**
* creation of indices table of triangles (optimized order)
* @param tableIndices the table where indices are stored
*/
template <typename PFP>
void initTriangles(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices, unsigned int thread=0) ;
template <typename PFP>
void initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices, unsigned int thread=0) ;
/**
* creation of indices table of lines (optimized order)
* @param tableIndices the table where indices are stored
*/
template <typename PFP>
void initLines(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices, unsigned int thread=0) ;
template <typename PFP>
void initLinesOptimized(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices, unsigned int thread=0) ;
/**
* creation of indices table of points
* @param tableIndices the table where indices are stored
*/
template <typename PFP>
void initPoints(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices, unsigned int thread=0) ;
/**
* creation of VBO for flat faces rendering
*/
template <typename PFP>
void initFlatTriangles(typename PFP::MAP& map, unsigned int vertex_attrib_position, const FunctorSelect& good=SelectorTrue() , unsigned int thread=0);
/**
* initialization of the VBO indices primitives
* computed by a traversal of the map
* @param prim primitive to draw: VBO_TRIANGLES, VBO_LINES
*/
template <typename PFP>
void initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized = true, unsigned int thread=0) ;
/**
* initialization of the VBO indices primitives
* using the given table
* @param prim primitive to draw: VBO_TRIANGLES, VBO_LINES
*/
void initPrimitives(int prim, std::vector<GLuint>& tableIndices) ;
protected:
/**
* Drawing triangles function
*/
void drawTriangles(bool bindColors = true) ;
/**
* Drawing lines function
*/
void drawLines(bool bindColors = true) ;
/**
* Drawing points function
*/
void drawPoints(bool bindColors = true) ;
/**
* Drawing flat faces function
*/
void drawFlat();
public:
/**
* draw the VBO (function to call in the drawing callback)
*/
void draw(int prim, bool bindColors = true) ;
} ;
} // namespace VBO
} // namespace Render
} // namespace Algo
} // namespace CGoGN
#include "Algo/Render/gl3mapRender.hpp"
#endif
This diff is collapsed.
......@@ -323,6 +323,14 @@ void MapRender_VBO::initPrimitives(typename PFP::MAP& map, const FunctorSelect&
initLines<PFP>(map,good,tableIndices,thread) ;
m_nbIndicesLines = tableIndices.size();
vbo_ind = m_VBOBuffers[LINE_INDICES];
for (unsigned int i=0; i< tableIndices.size(); ++i)
{
std::cout << tableIndices[i]<< "/";
if (i%2 == 1) std::cout << std::endl;
}
std::cout << std::endl;
break;
case POINTS:
initPoints<PFP>(map,good,tableIndices,thread);
......
......@@ -63,6 +63,7 @@ AttribMultiVectGen* AttribMultiVect<T>::new_obj()
return new AttribMultiVect<T>;
}
template <typename T>
bool AttribMultiVect<T>::copy(const AttribMultiVectGen* atmvg)
{
......
......@@ -148,7 +148,7 @@ public:
unsigned int cell = m_marker.getCell() ;
AttribContainer& cont = m_map.getAttributeContainer(cell) ;
for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
m_map.getMarkerVector(cell)->operator[](i).setMark(m_marker);
m_map.getMarkerVector(cell,m_thread)->operator[](i).setMark(m_marker);
}
virtual void unmarkAll()
......
......@@ -99,7 +99,7 @@ public:
virtual ~DartMarker()
{
unmarkAll();
m_map.releaseMarker(m_marker);
m_map.releaseMarker(m_marker,m_thread);
}
protected:
......@@ -257,7 +257,7 @@ public:
~DartMarkerNoUnmark()
{
m_map.releaseMarker(m_marker);
m_map.releaseMarker(m_marker,m_thread);
}
protected:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -49,133 +49,235 @@ namespace Utils
////////// CLASS DECLARATION //////////
APIEXPORT class GLSLShader
class GLSLShader
{
/*********\
| TYPE(S) |
\*********/
protected:
struct Sampler
{
int location;
int tex_unit;
};
struct Uniform
{
int location;
int size;
int type;
};
public:
/**
* enum of supported shader type
*/
enum shaderType {VERTEX_SHADER = 1, FRAGMENT_SHADER = 2, GEOMETRY_SHADER = 3 };
/**************\
| ATTRIBUTE(S) |
\**************/
protected:
GLhandleARB vertex_shader_object;
GLhandleARB fragment_shader_object;
GLhandleARB geom_shader_object;
GLhandleARB program_object;
/**
* handle of vertex shader
*/
GLhandleARB m_vertex_shader_object;
// std::map<std::string,Sampler> sampler_list;
// std::map<std::string,Uniform> unif_list;
// std::map<std::string,GLuint> attrib_list;
/**
* handle of fragment shader
*/
GLhandleARB m_fragment_shader_object;
/**
* handle of geometry shader
*/
GLhandleARB m_geom_shader_object;
/****************\
| CONSTRUCTOR(S) |
\****************/
public:
GLSLShader();
/**
* handle of program
*/
GLhandleARB m_program_object;
/***********\
| METHOD(S) |
\***********/
protected:
/**
* load vertex shader
* @param vertex_shader_source src text shader
*/
bool loadVertexShaderSourceString( const char* vertex_shader_source );
/**
* load fragment shader
* @param fragment_shader_source src text shader
*/
bool loadFragmentShaderSourceString( const char* fragment_shader_source );
/**
* load geometry shader
* @param geom_shader_source src text shader
*/
bool loadGeometryShaderSourceString( const char* geom_shader_source );
/**
* load vertex shader
* @param filename file name
*/
bool loadVertexShader( const std::string& filename );
/**
* load fragment shader
* @param filename file name
*/
bool loadFragmentShader( const std::string& filename );
/**
* load geometry shader
* @param filename file name
*/
bool loadGeometryShader( const std::string& filename );
/**
* Load of source file in a char buffer
* @param source_file file name
*/
char* loadSourceFile( const std::string& source_file );
/**
* create the shader (attach and link shaders into program)
*/
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES);
/*
* search file in different path
*/
std::string findFile(const std::string filename);
/**
* get log after compiling
* @param obj what log do you want ?
* @return the log
*/
char* getInfoLog( GLhandleARB obj );
public:
/**
* constructor
*/
GLSLShader();
/**
* destructor
*/
virtual ~GLSLShader();
/**
* test support of shader
*/
static bool areShadersSupported();
/**
* test support of Vertex Buffer Object
*/
static bool areVBOSupported();
/**
* test support of geometry shader
*/
static bool areGeometryShadersSupported();
bool loadVertexShaderSourceString( const char* vertex_shader_source );
bool loadPixelShaderSourceString( const char* pixel_shader_source );
bool loadGeometryShaderSourceString( const char* pixel_shader_source );
/**
* test support of gl3
*/
static bool isGL3Supported();
bool loadVertexShader( const std::string& filename );
bool loadPixelShader( const std::string& filename );
bool loadGeometryShader( const std::string& filename );
static bool init();
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES);
/**
* load shaders (compile and link)
* @param vs vertex shader source file
* @param fs fragment shader source file
*/
bool loadShaders(const std::string& vs, const std::string& fs);
/**
* load shaders (compile and link)
* @param vs vertex shader source file
* @param fs fragment shader source file
* @param fs fragment shader source file
* @param inputGeometryPrimitive primitives used in geometry shader as input
* @param outputGeometryPrimitive primitives generated in geometry shader as output
*/
bool loadShaders(const std::string& vs, const std::string& fs, const std::string& gs, GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES);
inline bool isCreated();
bool isBinded();
virtual bool bind();
virtual void unbind();
bool setSampler( char* sampler_name, int tex_unit );
bool setUniform( char* unif_name, void* value );
GLuint getAttribIndex( char* attribName );
bool loadShaders(const std::string& vs, const std::string& ps);
bool loadShaders(const std::string& vs, const std::string& ps, const std::string& gs,GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES);
virtual void unbind();
char* loadSourceFile( const std::string& source_file );
std::string findFile(const std::string filename);
GLuint getAttribIndex( char* attribName );
GLuint program_handler() { return program_object;}
/**
* get handler of program for external use og gl functions
*/
GLuint program_handler() { return m_program_object;}
static bool init();
/**
* bind vertex attribute with its name in shaders
*/
void bindAttrib(unsigned int att, const char* name);
/************\
| DESTRUCTOR |
\************/
bool validateProgram();
bool checkProgram();
bool checkShader(int shaderType);
public:
virtual ~GLSLShader();
template<unsigned int NB>
void setuniformf( const char* name , float* val)
void setuniformf( const char* name , float* val);
template<unsigned int NB>
void setuniformi( const char* name , int* val);
};
////////// INLINE FUNCTIONS //////////
inline bool GLSLShader::isCreated()
{
return ( m_program_object != 0 );
}
template<unsigned int NB>
void GLSLShader::setuniformf( const char* name , float* val)
{
GLint uni = glGetUniformLocationARB(m_program_object,name);
if (uni>=0)
{
GLuint uni = glGetUniformLocationARB(program_object,name);
switch(NB)
{
case 1:
glUniform1fvARB( uni, 1, val) ;
break;
case 2:
glUniform2fvARB( uni, 2, val) ;
glUniform2fvARB( uni, 1, val) ;
break;
case 3:
glUniform3fvARB( uni, 3, val) ;
glUniform3fvARB( uni, 1, val) ;
break;
case 4:
glUniform4fvARB( uni, 4, val) ;
glUniform4fvARB( uni, 1, val) ;
break;
case 16:
glUniformMatrix4fv(uni, 1 , false, val);
break;
}
}
}
template<unsigned int NB>
void setuniformi( const char* name , int* val)
template<unsigned int NB>
void GLSLShader::setuniformi( const char* name , int* val)
{
GLint uni = glGetUniformLocationARB(m_program_object,name);
if (uni>=0)
{
GLuint uni = glGetUniformLocationARB(program_object,name);
switch(NB)
{
case 1:
......@@ -192,15 +294,6 @@ public:
break;
}
}
};
////////// INLINE FUNCTIONS //////////
inline bool GLSLShader::isCreated()
{
return ( program_object != 0 );
}
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free softwa