vbo.hpp 2.87 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Sylvain Thery's avatar
Sylvain Thery committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Sylvain Thery's avatar
Sylvain Thery committed
21 22 23 24 25 26
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
27

Sylvain Thery's avatar
Sylvain Thery committed
28 29 30
namespace Utils
{

31
template <unsigned int VEC_DIM, typename T>
32 33 34 35
void VBO::updateData(std::vector<T>& data)
{
	if (m_lock)
	{
36
		CGoGNerr << "VBO::updateData : Error locked VBO" << CGoGNendl;
37 38
		return;
	}
Sylvain Thery's avatar
Sylvain Thery committed
39 40 41 42

	if (data.empty())
		return;

43
	m_data_size = VEC_DIM;
Sylvain Thery's avatar
Sylvain Thery committed
44
	m_nbElts = uint32(data.size());
45
	glBindBuffer(GL_ARRAY_BUFFER, *m_id);
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

	if (sizeof(T) / sizeof(double) == VEC_DIM)
	{
		unsigned int nbf = m_nbElts * m_data_size;
		float* buffer = new float[nbf];
		float* ptr_out = buffer;
		double* ptr_in = reinterpret_cast<double*>(&(data[0]));
		for (unsigned int i=0; i<nbf; ++i)
			*ptr_out++ = float(*ptr_in++);
		glBufferData(GL_ARRAY_BUFFER, nbf * sizeof(float), buffer, GL_STREAM_DRAW);
		delete[] buffer;
		return;
	}
	if (sizeof(T) / sizeof(float) == VEC_DIM)
	{
		glBufferData(GL_ARRAY_BUFFER, m_nbElts * VEC_DIM * sizeof(float), &(data[0]), GL_STREAM_DRAW);
		return;
	}

	// we should normally never reach this code
	CGoGNerr << "VBO::updateData : Error only float, double, VecXf, VecXd" << CGoGNendl;
67 68
}

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
69
} // namespace Utils
Sylvain Thery's avatar
Sylvain Thery committed
70

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
71
} // namespace CGoGN