Commit 69eb1c3b authored by CGoGN GIT Supervisor's avatar CGoGN GIT Supervisor

Merge branch 'master' of /home/thery/CGoGN

parents 21085006 fa44ca20
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
#include "Algo/Render/vbo_MapRender.h"
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace VBO
{
MapRender_VBO::MapRender_VBO():
m_nbIndicesTri(0),
m_nbIndicesLines(0)
{
glGenBuffersARB(NB_BUFFERS, m_VBOBuffers) ;
for(unsigned int i = 0; i < NB_BUFFERS; ++i)
{
m_allocatedBuffers[i] = false ;
m_usedBuffers[i] = false ;
}
}
MapRender_VBO::~MapRender_VBO()
{
glDeleteBuffersARB(NB_BUFFERS, m_VBOBuffers);
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
// get back others from mrvbo
for(unsigned int i = POSITIONS; i < NB_BUFFERS; ++i)
{
m_allocatedBuffers[i] = mrvbo.m_allocatedBuffers[i] ;
m_usedBuffers[i] = mrvbo.m_usedBuffers[i] ;
}
}
void MapRender_VBO::enableBuffers(int buffersMask)
{
if((buffersMask & POSITIONS) && m_allocatedBuffers[POSITIONS_BUFFER])
m_usedBuffers[POSITIONS_BUFFER] = true ;
if((buffersMask & NORMALS) && m_allocatedBuffers[NORMALS_BUFFER])
m_usedBuffers[NORMALS_BUFFER] = true ;
if((buffersMask & COLORS) && m_allocatedBuffers[COLORS_BUFFER])
m_usedBuffers[COLORS_BUFFER] = true ;
}
void MapRender_VBO::disableBuffers(int buffersMask)
{
if((buffersMask & POSITIONS))
m_usedBuffers[POSITIONS_BUFFER] = false ;
if((buffersMask & NORMALS))
m_usedBuffers[NORMALS_BUFFER] = false ;
if((buffersMask & COLORS))
m_usedBuffers[COLORS_BUFFER] = false ;
}
void MapRender_VBO::initPrimitives(int prim, std::vector<GLuint>& tableIndices)
{
// indice du VBO a utiliser
int vbo_ind = 0;
switch(prim)
{
case TRIANGLES:
m_nbIndicesTri = tableIndices.size();
vbo_ind = m_VBOBuffers[TRIANGLE_INDICES];
break;
case LINES:
m_nbIndicesLines = tableIndices.size();
vbo_ind = m_VBOBuffers[LINE_INDICES];
break;
case POINTS:
m_nbIndicesPoints = tableIndices.size();
vbo_ind = m_VBOBuffers[POINT_INDICES];
break;
default:
std::cerr << "problem initializing VBO indices" << std::endl;
break;
}
int size = tableIndices.size();
// setup du buffer d'indices
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, vbo_ind);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, size*sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
}
void MapRender_VBO::drawTriangles(bool bindColors)
{
// buffer d'indices
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[TRIANGLE_INDICES]);
glEnableClientState(GL_INDEX_ARRAY);
for(unsigned int i = POSITIONS_BUFFER; i < NB_BUFFERS; ++i)
{
if(m_usedBuffers[i])
{
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[i]);
switch(i)
{
case POSITIONS_BUFFER :
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
break ;
case NORMALS_BUFFER :
glNormalPointer(GL_FLOAT, 0, 0);
glEnableClientState(GL_NORMAL_ARRAY);
break ;
case COLORS_BUFFER :
if (bindColors) {
glColorPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_COLOR_ARRAY);
}
break ;
}
}
}
glDrawElements(GL_TRIANGLES, m_nbIndicesTri, GL_UNSIGNED_INT, 0);
glDisableClientState(GL_INDEX_ARRAY);
for(unsigned int i = POSITIONS_BUFFER; i < NB_BUFFERS; ++i)
{
if(m_usedBuffers[i])
{
switch(i)
{
case POSITIONS_BUFFER :
glDisableClientState(GL_VERTEX_ARRAY);
break ;
case NORMALS_BUFFER :
glDisableClientState(GL_NORMAL_ARRAY);
break ;
case COLORS_BUFFER :
if (bindColors) {
glDisableClientState(GL_COLOR_ARRAY);
}
break ;
}
}
}
}
void MapRender_VBO::drawLines(bool bindColors)
{
// buffer d'indices
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[LINE_INDICES]);
glEnableClientState(GL_INDEX_ARRAY);
for(unsigned int i = POSITIONS_BUFFER; i < NB_BUFFERS; ++i)
{
if(m_usedBuffers[i])
{
switch(i)
{
case POSITIONS_BUFFER :
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[i]);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
break ;
case NORMALS_BUFFER :
break ;
case COLORS_BUFFER :
if (bindColors) {
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[i]);
glColorPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_COLOR_ARRAY);
}
break ;
}
}
}
glDrawElements(GL_LINES, m_nbIndicesLines, GL_UNSIGNED_INT, 0);
glDisableClientState(GL_INDEX_ARRAY);
for(unsigned int i = POSITIONS_BUFFER; i < NB_BUFFERS; ++i)
{
if(m_usedBuffers[i])
{
switch(i)
{
case POSITIONS_BUFFER :
glDisableClientState(GL_VERTEX_ARRAY);
break ;
case NORMALS_BUFFER :
break ;
case COLORS_BUFFER :
if (bindColors) {
glDisableClientState(GL_COLOR_ARRAY) ;
}
break ;
}
}
}
}
void MapRender_VBO::drawPoints(bool bindColors)
{
// buffer d'indices
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[POINT_INDICES]);
glEnableClientState(GL_INDEX_ARRAY);
for(unsigned int i = POSITIONS_BUFFER; i < NB_BUFFERS; ++i)
{
if(m_usedBuffers[i])
{
switch(i)
{
case POSITIONS_BUFFER :
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[i]);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
break ;
case NORMALS_BUFFER :
break ;
case COLORS_BUFFER :
if (bindColors) {
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[i]);
glColorPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_COLOR_ARRAY);
}
break ;
}
}
}
glDrawElements(GL_POINTS, m_nbIndicesPoints, GL_UNSIGNED_INT, 0) ;
glDisableClientState(GL_INDEX_ARRAY);
for(unsigned int i = POSITIONS_BUFFER; i < NB_BUFFERS; ++i)
{
if(m_usedBuffers[i])
{
switch(i)
{
case POSITIONS_BUFFER :
glDisableClientState(GL_VERTEX_ARRAY);
break ;
case NORMALS_BUFFER :
break ;
case COLORS_BUFFER :
if (bindColors) {
glDisableClientState(GL_COLOR_ARRAY);
}
break ;
default:
break;
}
}
}
}
void MapRender_VBO::draw(int prim, bool bindColors)
{
switch(prim)
{
case TRIANGLES:
drawTriangles(bindColors);
break;
case LINES:
drawLines(bindColors);
break;
case POINTS:
drawPoints(bindColors);
break;
case FLAT_TRIANGLES:
drawFlat();
break;
default:
break;
}
}
void MapRender_VBO::drawFlat()
{
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[FLAT_BUFFER]);
glVertexPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0);
glNormalPointer(GL_FLOAT, 6*sizeof(GL_FLOAT), (GLvoid*)(3*sizeof(GL_FLOAT)));
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, m_nbFlatElts);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
} // namespace VBO
} // namespace Render
} // namespace Algo
} // namespace CGoGN
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