vbo.h 3.62 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-2011, 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.u-strasbg.fr/                                         *
Sylvain Thery's avatar
Sylvain Thery committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
* 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
{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
36

Sylvain Thery's avatar
Sylvain Thery committed
37
38
39
40
namespace Utils
{

class GLSLShader;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
41

Sylvain Thery's avatar
Sylvain Thery committed
42
/**
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
43
 * Encapsulation of OpenGL Vertex Buffer Object
Sylvain Thery's avatar
Sylvain Thery committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 * 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;
58
	unsigned int m_nbElts;
59
	mutable bool m_lock;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
60

Sylvain Thery's avatar
Sylvain Thery committed
61
62
63
64
65
66
public:
	/**
	 * constructor: allocate the OGL VBO
	 */
	VBO();

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

Sylvain Thery's avatar
Sylvain Thery committed
72
73
74
75
76
77
78
79
	/**
	 * destructor: release the OGL VBO and clean references between VBO/Shaders
	 */
	~VBO();

	/**
	 * get id of vbo
	 */
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
80
	unsigned int id() const { return m_id; }
Sylvain Thery's avatar
Sylvain Thery committed
81
82
83
84

	/**
	 * get dataSize
	 */
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
85
	unsigned int dataSize() const { return m_data_size; }
Sylvain Thery's avatar
Sylvain Thery committed
86
87
88
89

	/**
	 * set the data size (in number of float)
	 */
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
90
	void setDataSize(unsigned int ds) { m_data_size = ds; }
Sylvain Thery's avatar
Sylvain Thery committed
91

92
93
94
95
	/**
	 * bind array vbo
	 */
	void bind() const  { glBindBuffer(GL_ARRAY_BUFFER,m_id); }
Sylvain Thery's avatar
Sylvain Thery committed
96
97
98
99
100
	/**
	 * reference vbo as used by shader sh
	 */
	void ref(GLSLShader* sh);

101
102
103

	void sameAllocSameBufferSize(const VBO& vbo);

Sylvain Thery's avatar
Sylvain Thery committed
104
105
106
107
108
109
110
111
112
113
114
	/**
	 * 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);
115
116
117

	void* lockPtr();

118
119
120
	const void* lockPtr() const;

	void releasePtr() const;
121
122

	unsigned int nbElts() {return m_nbElts;}
Sylvain Thery's avatar
Sylvain Thery committed
123
124
};

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
125
126
127
} // namespace Utils

} // namespace CGoGN
Sylvain Thery's avatar
Sylvain Thery committed
128
129
130
131

#include "Utils/vbo.hpp"

#endif