vbo.h 3.48 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
* 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;
57
58
	unsigned int m_nbElts;
	bool m_lock;
Sylvain Thery's avatar
Sylvain Thery committed
59
60
61
62
63
64
public:
	/**
	 * constructor: allocate the OGL VBO
	 */
	VBO();

65
66
67
68
69
	/**
	 * copy constructor, new VBO copy content
	 */
	VBO(const VBO& vbo);

Sylvain Thery's avatar
Sylvain Thery committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
	/**
	 * 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;}

90
91
92
93
	/**
	 * bind array vbo
	 */
	void bind() const  { glBindBuffer(GL_ARRAY_BUFFER,m_id); }
Sylvain Thery's avatar
Sylvain Thery committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
	/**
	 * 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);
110
111
112
113
114
115
116


	void* lockPtr();

	void releasePtr();

	unsigned int nbElts() {return m_nbElts;}
Sylvain Thery's avatar
Sylvain Thery committed
117
118
119
120
121
122
123
124
125
126
};

}
}

#include "Utils/vbo.hpp"

#endif