Commit 5ae47e69 authored by Sylvain Thery's avatar Sylvain Thery

oubli ajout vbo.h et hpp

parent b833e0e7
/*******************************************************************************
* 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 __CGoGN_GLSL_VBO__
#define __CGoGN_GLSL_VBO__
#include <vector>
#include <GL/glew.h>
#include "Topology/generic/attributeHandler.h"
#include "Container/convert.h"
namespace CGoGN
{
namespace Utils
{
class GLSLShader;
/**
* Encaptusaltion of OpenGL Vertex Buffer Object
* Manage
* - alloc /release of GL buffer
* - ref by Shaders
* - size of data (invidual cells)
*/
class VBO
{
protected:
// VBO id
GLuint m_id;
// size of data (in floats)
unsigned int m_data_size;
// shaders that ref this vbo
std::vector<GLSLShader*> m_refs;
public:
/**
* constructor: allocate the OGL VBO
*/
VBO();
/**
* destructor: release the OGL VBO and clean references between VBO/Shaders
*/
~VBO();
/**
* get id of vbo
*/
unsigned int id() const { return m_id;}
/**
* get dataSize
*/
unsigned int dataSize() const { return m_data_size;}
/**
* set the data size (in number of float)
*/
void setDataSize(unsigned int ds) { m_data_size = ds;}
/**
* reference vbo as used by shader sh
*/
void ref(GLSLShader* sh);
/**
* update data from attribute handler to the vbo
*/
template <typename ATTR_HANDLER>
void updateData(const ATTR_HANDLER& attrib);
/**
* update data from attribute handler to the vbo, with conversion
*/
template <typename ATTR_HANDLER>
void updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv);
};
}
}
#include "Utils/vbo.hpp"
#endif
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
namespace CGoGN
{
namespace Utils
{
template <typename ATTR_HANDLER>
void VBO::updateData(const ATTR_HANDLER& attrib)
{
m_data_size = sizeof(typename ATTR_HANDLER::DATA_TYPE) / sizeof(float);
AttributeMultiVector<typename ATTR_HANDLER::DATA_TYPE>* mv = attrib.getDataVector() ;
std::vector<void*> addr;
unsigned int byteTableSize;
unsigned int nbb = mv->getBlocksPointers(addr, byteTableSize);
glBindBuffer(GL_ARRAY_BUFFER, m_id);
glBufferData(GL_ARRAY_BUFFER, nbb * byteTableSize, 0, GL_STREAM_DRAW);
unsigned int offset = 0;
for (unsigned int i = 0; i < nbb; ++i)
{
glBufferSubDataARB(GL_ARRAY_BUFFER, offset, byteTableSize, addr[i]);
offset += byteTableSize;
}
}
template <typename ATTR_HANDLER>
void VBO::updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv)
{
m_data_size = conv->sizeElt();
AttributeMultiVector<typename ATTR_HANDLER::DATA_TYPE>* mv = attrib.getDataVector() ;
std::vector<void*> addr;
unsigned int byteTableSize;
unsigned int nbb = mv->getBlocksPointers(addr, byteTableSize);
// alloue la memoire pour le buffer et initialise le conv
conv->reserve(mv->getBlockSize());
// bind buffer to update
glBindBuffer(GL_ARRAY_BUFFER, m_id);
glBufferData(GL_ARRAY_BUFFER, nbb * conv->sizeBuffer(), 0, GL_STREAM_DRAW);
unsigned int offset = 0;
for (unsigned int i = 0; i < nbb; ++i)
{
// convertit les donnees dans le buffer de conv
conv->convert(addr[i]);
// update sub-vbo
glBufferSubDataARB(GL_ARRAY_BUFFER, offset, conv->sizeBuffer(), conv->buffer());
// block suivant
offset += conv->sizeBuffer();
}
// libere la memoire de la conversion
conv->release();
}
}
}
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