Commit d66d638a authored by Sylvain Thery's avatar Sylvain Thery

update scene graph

parent 1b96b9f3
......@@ -186,7 +186,7 @@ void myGlutWin::myRedraw(void)
// glEnable(GL_COLOR_MATERIAL);
// glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
// glColor3f(0.0f,0.0f,0.9f);
// m_render->draw(Algo::Render::VBO::FLAT_TRIANGLES) ;
// m_render->draw(Algo::Render::VBO::TRIANGLES) ;
//
// glDisable( GL_POLYGON_OFFSET_FILL );
......@@ -214,53 +214,83 @@ int main(int argc, char **argv)
mgw.position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ;
mgw.normal = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
glewInit();
if (! Utils::GLSLShader::areShadersSupported())
{
std::cerr << "Shaders not supported"<< std::endl;
exit(1);
}
Utils::GLSLShader* phong = new Utils::GLSLShader() ;
phong->loadShaders("phong_vs.txt", "phong_ps.txt") ;
Algo::Modelisation::Polyhedron<PFP> prim1(myMap, mgw.position);
prim1.cylinder_topo(16,15, true, true);
prim1.embedCylinder(30.0f,20.0f,50.0f);
CellMarker mark1(myMap,VERTEX_CELL);
prim1.mark(mark1);
// Algo::Modelisation::Polyhedron<PFP> prim1(myMap, mgw.position);
// prim1.cylinder_topo(16,16, true, true); // topo of sphere is a closed cylinder
// prim1.embedCylinder(40.0f,40.0f,30.0f);
//
// CellMarker mark1(myMap,VERTEX_CELL);
// prim1.mark(mark1);
//
// create a sphere
Algo::Modelisation::Polyhedron<PFP> prim2(myMap, mgw.position);
prim2.cylinder_topo(16,16, true, true); // topo of sphere is a closed cylinder
prim2.cylinder_topo(16,16, true, true);
prim2.embedSphere(40.0f);
//
// CellMarker mark2(myMap,VERTEX_CELL);
// prim2.mark(mark2);
//
// Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
//
// Algo::Render::VBO::MapRender_VBO render1 = new Algo::Render::VBO::MapRender_VBO() ;
//
// render1->updateData(Algo::Render::VBO::POSITIONS, position);
// render1->updateData(Algo::Render::VBO::NORMALS, normal);
// // update flat faces primtives (warning need position buffer)
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::FLAT_TRIANGLES);
// // update smooth faces primtives
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::TRIANGLES);
// // update lines primitives
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::LINES);
//
//
CellMarker mark2(myMap,VERTEX_CELL);
prim2.mark(mark2);
// create a sphere
Algo::Modelisation::Polyhedron<PFP> prim3(myMap, mgw.position);
prim3.tore_topo(12,48);
prim3.embedTore(50.0f,10.0f);
CellMarker mark3(myMap,VERTEX_CELL);
prim3.mark(mark3);
Algo::Geometry::computeNormalVertices<PFP>(myMap, mgw.position, mgw.normal) ;
Algo::Render::VBO::MapRender_VBO* render1 = new Algo::Render::VBO::MapRender_VBO() ;
render1->updateData(Algo::Render::VBO::POSITIONS, mgw.position);
render1->updateData(Algo::Render::VBO::NORMALS, mgw.normal);
SelectorCellMarked cm1(mark1);
render1->initPrimitives<PFP>(myMap, cm1, Algo::Render::VBO::TRIANGLES);
render1->initPrimitives<PFP>(myMap, cm1, Algo::Render::VBO::FLAT_TRIANGLES);
render1->initPrimitives<PFP>(myMap, cm1, Algo::Render::VBO::LINES);
Algo::Render::VBO::MapRender_VBO* render2 = new Algo::Render::VBO::MapRender_VBO(*render1) ;
SelectorCellMarked cm2(mark2);
render2->initPrimitives<PFP>(myMap, cm2, Algo::Render::VBO::TRIANGLES);
render2->initPrimitives<PFP>(myMap, cm2, Algo::Render::VBO::FLAT_TRIANGLES);
render2->initPrimitives<PFP>(myMap, cm2, Algo::Render::VBO::POINTS);
Algo::Render::VBO::MapRender_VBO* render3 = new Algo::Render::VBO::MapRender_VBO(*render1) ;
SelectorCellMarked cm3(mark3);
render3->initPrimitives<PFP>(myMap, cm3, Algo::Render::VBO::FLAT_TRIANGLES);
render3->initPrimitives<PFP>(myMap, cm3, Algo::Render::VBO::TRIANGLES);
render3->initPrimitives<PFP>(myMap, cm3, Algo::Render::VBO::LINES);
// update renderer
mgw.updateRender();
mgw.root = new Utils::SceneGraph::Group_Node();
Utils::SceneGraph::Material_Node* mater = new Utils::SceneGraph::Material_Node();
mater->setDiffuse(Geom::Vec4f(0.3f, 1.0f, 0.0f, 1.0f));
mater->setAmbient(Geom::Vec4f(0.1f, 0.1f, 0.1f, 1.0f));
mater->setSpecular(Geom::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
mater->setShininess(100.0f);
mater->setColor(Geom::Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
mater->setShader(phong);
mgw.root->setMaterial(mater);
Utils::SceneGraph::VBO_Node* vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
Utils::SceneGraph::VBO_Node* vbon = new Utils::SceneGraph::VBO_Node(render1);
vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::LINES);
mgw.root->addChild(vbon);
......@@ -272,11 +302,10 @@ int main(int argc, char **argv)
mgw.root->addChild(group1);
vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
vbon->setPrimitives(Algo::Render::VBO::TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::LINES);
group1->addChild(vbon);
Utils::SceneGraph::VBO_Node* vbon2 = new Utils::SceneGraph::VBO_Node(render2);
vbon2->setPrimitives(Algo::Render::VBO::TRIANGLES);
vbon2->setPrimitives(Algo::Render::VBO::POINTS);
group1->addChild(vbon2);
Utils::SceneGraph::Group_Node* group2 = new Utils::SceneGraph::Group_Node();
......@@ -289,18 +318,21 @@ int main(int argc, char **argv)
mater = new Utils::SceneGraph::Material_Node();
mater->setDiffuse(Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f));
mater->setAmbient(Geom::Vec4f(0.1f, 0.1f, 0.1f, 1.0f));
mater->setSpecular(Geom::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
mater->setShininess(100.0f);
mater->setColor(Geom::Vec4f(1.0f, 1.0f, 0.0f, 1.0f));
mater->setNoShader();
group2->setMaterial(mater);
vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES);
vbon = new Utils::SceneGraph::VBO_Node(render3);
vbon->setPrimitives(Algo::Render::VBO::TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::LINES);
group2->addChild(vbon);
// compute BB and store it for object positionning in screen
// Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap,mgw.position) ;
// not possible here to compute a BB !!
mgw.gWidthObj = 200.0f;
mgw.gPosObj = Geom::Vec3f(100.0f,0.0f,0.0f);
......
......@@ -320,7 +320,7 @@ public:
* mark all darts of the Polyhedron
* @param m the CellMarker(VERTEX) to use
*/
void mark(CellMarker m);
void mark(CellMarker& m);
/**
* mark all embedded vertices of the Polyhedron
......
......@@ -971,7 +971,7 @@ void Polyhedron<PFP>::transform(const Geom::Matrix44f& matrice)
}
template <typename PFP>
void Polyhedron<PFP>::mark(CellMarker m)
void Polyhedron<PFP>::mark(CellMarker& m)
{
for(typename std::vector<Dart>::iterator di=m_tableVertDarts.begin(); di!=m_tableVertDarts.end(); ++di)
{
......
......@@ -68,10 +68,12 @@ enum bufferIndex {
TRIANGLE_INDICES = 0,
LINE_INDICES = 1,
POINT_INDICES = 2,
POSITIONS_BUFFER = 3,
NORMALS_BUFFER = 4,
COLORS_BUFFER = 5,
FLAT_BUFFER = 6
FLAT_BUFFER = 3,
POSITIONS_BUFFER = 4,
NORMALS_BUFFER = 5,
COLORS_BUFFER = 6
} ;
const unsigned int NB_BUFFERS = 7 ;
......
......@@ -239,7 +239,7 @@ void MapRender_VBO::initLinesOptimized(typename PFP::MAP& map, const FunctorSele
for (Dart dd = map.begin(); dd != map.end(); map.next(dd))
{
if (!m.isMarked(dd))
if (!m.isMarked(dd) && good(dd))
{
std::list<Dart> bound;
bound.push_back(dd);
......
......@@ -27,6 +27,7 @@
#include "Topology/generic/marker.h"
#include "Topology/generic/genericmap.h"
#include "Topology/generic/functor.h"
#define VERTEX_CELL VERTEX_ORBIT
#define EDGE_CELL EDGE_ORBIT
......@@ -231,6 +232,26 @@ protected:
{}
};
/**
* selector that say if a dart has it cell marked
*/
class SelectorCellMarked: public FunctorSelect
{
protected:
CellMarker& m_cmarker;
public:
SelectorCellMarked(CellMarker& cm): m_cmarker(cm) {}
bool operator()(Dart d) const
{
if (m_cmarker.isMarked(d))
return true;
return false;
}
};
} // namespace CGoGN
#endif
......@@ -28,6 +28,7 @@
#include <string>
#include "Geometry/matrix.h"
#include "Algo/Render/vbo_MapRender.h"
#include "Utils/GLSLShader.h"
namespace CGoGN
......@@ -106,7 +107,8 @@ protected:
bool m_has_ambient;
bool m_has_shininess;
bool m_has_color;
Utils::GLSLShader* m_shader;
bool m_disable_shader;
public:
/**
* Constructor
......@@ -143,6 +145,16 @@ public:
*/
void setColor(const Geom::Vec4f& v);
/**
* set the shader that will be used in children
*/
void setShader(Utils::GLSLShader* shader);
/**
* Explicitly disable shaders when traverse this node
*/
void setNoShader();
/**
* Rendering callback (used in traversal by renderGraph)
*/
......@@ -198,11 +210,17 @@ public:
void removeChild(Node* child);
/**
* set trnaformation matrix (4x4)
* set transformation matrix (4x4)
* @param mat matrix (copy and stored here transposed for OGL)
*/
void setMatrixTransfo(const Geom::Matrix44f& mat);
/**
* get the transformation matrix
* @ return a copy of the matrix (I if none)
*/
Geom::Matrix44f getMatrixTransfo() const;
/**
* set material
* @param v the color RGBA
......
......@@ -54,14 +54,22 @@ MapRender_VBO::~MapRender_VBO()
delete[] m_VBOBuffers ;
}
MapRender_VBO::MapRender_VBO(const MapRender_VBO& mrvbo):
m_nbIndicesTri(0),
m_nbIndicesLines(0)
{
glGenBuffersARB(3, m_VBOBuffers) ; // gen only for indices
glGenBuffersARB(4, m_VBOBuffers) ; // gen only for indices
for(unsigned int i = 0; i < POSITIONS_BUFFER; ++i)
{
m_allocatedBuffers[i] = false ;
m_usedBuffers[i] = false ;
}
// get back others from mrvbo
for(unsigned int i = POSITIONS; i < NB_BUFFERS; ++i)
for(unsigned int i = POSITIONS_BUFFER; i < NB_BUFFERS; ++i)
{
m_VBOBuffers[i] = mrvbo.m_VBOBuffers[i];
m_allocatedBuffers[i] = mrvbo.m_allocatedBuffers[i] ;
m_usedBuffers[i] = mrvbo.m_usedBuffers[i] ;
}
......
......@@ -124,6 +124,20 @@ void Group_Node::setMatrixTransfo(const Geom::Matrix44f& mat)
*m_matrix_transfo = mat.transposed();
}
Geom::Matrix44f Group_Node::getMatrixTransfo() const
{
if (m_matrix_transfo == NULL)
{
Geom::Matrix44f m;
m.identity();
return m;
}
return m_matrix_transfo->transposed();
}
void Group_Node::setMaterial(Material_Node* mat)
{
mat->ref();
......@@ -151,7 +165,7 @@ VBO_Node::VBO_Node()
VBO_Node::VBO_Node(Algo::Render::VBO::MapRender_VBO* vbo)
: m_vbo(vbo)
: m_vbo(vbo), m_primitives(0)
{}
......@@ -182,21 +196,32 @@ void VBO_Node::render()
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
glEnable(GL_LIGHTING);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
glShadeModel(GL_SMOOTH);
m_vbo->draw(Algo::Render::VBO::TRIANGLES);
}
if (m_primitives & Algo::Render::VBO::LINES)
{
GLint prg;
glGetIntegerv(GL_CURRENT_PROGRAM,&prg);
glUseProgram(0);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
m_vbo->draw(Algo::Render::VBO::LINES);
glUseProgram(prg);
}
if (m_primitives & Algo::Render::VBO::POINTS)
{
GLint prg;
glGetIntegerv(GL_CURRENT_PROGRAM,&prg);
glUseProgram(0);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
glPointSize(3.0f);
m_vbo->draw(Algo::Render::VBO::POINTS);
glUseProgram(prg);
}
if (m_primitives & Algo::Render::VBO::FLAT_TRIANGLES)
{
......@@ -218,7 +243,8 @@ Material_Node::Material_Node()
m_has_specular(false),
m_has_ambient(false),
m_has_shininess(false),
m_has_color(false)
m_has_color(false),
m_shader(NULL)
{}
void Material_Node::setDiffuse(const Geom::Vec4f& v)
......@@ -255,6 +281,16 @@ void Material_Node::setColor(const Geom::Vec4f& v)
m_has_color=true;
}
void Material_Node::setShader(Utils::GLSLShader *shader)
{
m_shader = shader;
}
void Material_Node::setNoShader()
{
m_disable_shader=true;
}
void Material_Node::render()
{
......@@ -268,6 +304,12 @@ void Material_Node::render()
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,&m_shininess);
if (m_has_color)
glColor3fv(m_color.data());
if (m_shader!=NULL)
m_shader->bind();
else
if (m_disable_shader)
glUseProgramObjectARB(0);
}
......
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