reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofVbo.h
Go to the documentation of this file.
1#pragma once
2
3//TODO: Add edge flags?
4
6#include "ofBufferObject.h"
7#include "ofConstants.h"
8#include <unordered_map>
9
10template<typename T>
11class ofColor_;
13
14class ofVec2f;
15class ofVec3f;
16
17template<class V, class N, class C, class T>
18class ofMesh_;
20
21class ofVbo {
22public:
23
24 ofVbo();
25 ofVbo(const ofVbo & mom);
26 ofVbo & operator=(const ofVbo& mom);
27 ~ofVbo();
28
29 void setMesh(const ofMesh & mesh, int usage);
30 void setMesh(const ofMesh & mesh, int usage, bool useColors, bool useTextures, bool useNormals);
31
32 void setVertexData(const glm::vec3 * verts, int total, int usage);
33 void setVertexData(const glm::vec2 * verts, int total, int usage);
34 void setVertexData(const ofVec3f * verts, int total, int usage);
35 void setVertexData(const ofVec2f * verts, int total, int usage);
36
37 void setColorData(const ofFloatColor * colors, int total, int usage);
38 void setNormalData(const glm::vec3 * normals, int total, int usage);
39 void setNormalData(const ofVec3f * normals, int total, int usage);
40 void setTexCoordData(const glm::vec2 * texCoords, int total, int usage);
41 void setTexCoordData(const ofVec2f * texCoords, int total, int usage);
42 void setIndexData(const ofIndexType * indices, int total, int usage);
43
44 void setVertexData(const float * vert0x, int numCoords, int total, int usage, int stride=0);
45 void setColorData(const float * color0r, int total, int usage, int stride=0);
46 void setNormalData(const float * normal0x, int total, int usage, int stride=0);
47 void setTexCoordData(const float * texCoord0x, int total, int usage, int stride=0);
48
49 void setAttributeData(int location, const float * vert0x, int numCoords, int total, int usage, int stride=0);
50
51#ifndef TARGET_OPENGLES
57 void setAttributeDivisor(int location, int divisor);
58#endif
59
60 void setVertexBuffer(ofBufferObject & buffer, int numCoords, int stride, int offset=0);
61 void setColorBuffer(ofBufferObject & buffer, int stride, int offset=0);
62 void setNormalBuffer(ofBufferObject & buffer, int stride, int offset=0);
63 void setTexCoordBuffer(ofBufferObject & buffer, int stride, int offset=0);
64 void setIndexBuffer(ofBufferObject & buffer);
65
66 void setAttributeBuffer(int location, ofBufferObject & buffer, int numCoords, int stride, int offset=0);
67
73 ofBufferObject & getAttributeBuffer(int location);
74
75 const ofBufferObject & getVertexBuffer() const;
76 const ofBufferObject & getColorBuffer() const;
77 const ofBufferObject & getNormalBuffer() const;
78 const ofBufferObject & getTexCoordBuffer() const;
79 const ofBufferObject & getIndexBuffer() const;
80
81 const ofBufferObject & getAttributeBuffer(int location) const;
82
83 void updateMesh(const ofMesh & mesh);
84
85 void updateVertexData(const glm::vec3 * verts, int total);
86 void updateVertexData(const glm::vec2 * verts, int total);
87 void updateVertexData(const ofVec3f * verts, int total);
88 void updateVertexData(const ofVec2f * verts, int total);
89 void updateColorData(const ofFloatColor * colors, int total);
90 void updateNormalData(const glm::vec3 * normals, int total);
91 void updateNormalData(const ofVec3f * normals, int total);
92 void updateTexCoordData(const glm::vec2 * texCoords, int total);
93 void updateTexCoordData(const ofVec2f * texCoords, int total);
94 void updateIndexData(const ofIndexType * indices, int total);
95
96 void updateVertexData(const float * ver0x, int total);
97 void updateColorData(const float * color0r, int total);
98 void updateNormalData(const float * normal0x, int total);
99 void updateTexCoordData(const float * texCoord0x, int total);
100
101 void updateAttributeData(int location, const float * vert0x, int total);
102
103 void enableColors();
104 void enableNormals();
105 void enableTexCoords();
106 void enableIndices();
107
108 void disableColors();
109 void disableNormals();
110 void disableTexCoords();
111 void disableIndices();
112
113 GLuint getVaoId() const;
114 GLuint getVertId() const;
115 GLuint getColorId() const;
116 GLuint getNormalId() const;
117 GLuint getTexCoordId() const;
118 GLuint getIndexId() const;
119
121 GLuint getAttributeId(int AttrPos_) const;
122
123 bool getIsAllocated() const;
124 bool getUsingVerts() const;
125 bool getUsingColors() const;
126 bool getUsingNormals() const;
127 bool getUsingTexCoords() const;
128 bool getUsingIndices() const;
129
130 void draw(int drawMode, int first, int total) const;
131 void drawElements(int drawMode, int amt, int offsetelements = 0) const;
132
133 void drawInstanced(int drawMode, int first, int total, int primCount) const;
134 void drawElementsInstanced(int drawMode, int amt, int primCount) const;
135
136 void bind() const;
137 void unbind() const;
138
139 void clear();
140
141 void clearVertices();
142 void clearNormals();
143 void clearColors();
144 void clearTexCoords();
145 void clearIndices();
146
147 void clearAttribute(int attributePos_);
148
149 int getNumVertices() const;
150 int getNumIndices() const;
151
152 bool hasAttribute(int attributePos_) const;
153
154private:
155
156 struct VertexAttribute{
157 VertexAttribute();
158 bool isAllocated() const;
159 void allocate();
160 void bind() const;
161 void unbind() const;
162 void setData(GLsizeiptr bytes, const void * data, GLenum usage);
163 void updateData(GLintptr offset, GLsizeiptr bytes, const void * data);
164 void setData(const float * attrib0x, int numCoords, int total, int usage, int stride, bool normalize=false);
165 void setBuffer(ofBufferObject & buffer, int numCoords, int stride, int offset);
166 void enable() const;
167 void disable() const;
168 GLuint getId() const;
169 ofBufferObject buffer;
170 GLsizei stride;
171 GLsizeiptr offset;
172 int numCoords;
173 GLuint location;
174 bool normalize;
175 int divisor;
176 };
177
178 struct IndexAttribute{
179 IndexAttribute();
180 bool isAllocated() const;
181 void allocate();
182 void bind() const;
183 void unbind() const;
184 void setData(GLsizeiptr bytes, const void * data, GLenum usage);
185 void updateData(GLintptr offset, GLsizeiptr bytes, const void * data);
186 GLuint getId() const;
187 ofBufferObject buffer;
188 };
189
190 GLuint vaoID;
191 mutable bool vaoChanged;
192
193 IndexAttribute indexAttribute;
194
195 mutable bool bUsingVerts; // need at least vertex data
196 mutable bool bUsingTexCoords;
197 mutable bool bUsingColors;
198 mutable bool bUsingNormals;
199 mutable bool bUsingIndices;
200
201 int totalVerts;
202 int totalIndices;
203
204 VertexAttribute positionAttribute;
205 VertexAttribute colorAttribute;
206 VertexAttribute texCoordAttribute;
207 VertexAttribute normalAttribute;
208 std::unordered_map<int,VertexAttribute> customAttributes;
209
210 static bool vaoChecked;
211 static bool vaoSupported;
212
213 VertexAttribute & getOrCreateAttr(int location);
214};
Definition ofBufferObject.h:8
ofColor represents a color in openFrameworks.
Definition ofColor.h:20
Represents a set of vertices in 3D spaces with normals, colors, and texture coordinates at those poin...
Definition ofMesh.h:78
Definition ofVbo.h:21
void disableColors()
Definition ofVbo.cpp:601
void setTexCoordData(const glm::vec2 *texCoords, int total, int usage)
Definition ofVbo.cpp:379
GLuint getVaoId() const
Definition ofVbo.cpp:660
GLuint getColorId() const
Definition ofVbo.cpp:670
void clearVertices()
Definition ofVbo.cpp:1016
void updateTexCoordData(const glm::vec2 *texCoords, int total)
Definition ofVbo.cpp:520
~ofVbo()
Definition ofVbo.cpp:282
void updateIndexData(const ofIndexType *indices, int total)
Definition ofVbo.cpp:535
void updateMesh(const ofMesh &mesh)
Definition ofVbo.cpp:462
void updateNormalData(const glm::vec3 *normals, int total)
Definition ofVbo.cpp:505
bool getUsingColors() const
Definition ofVbo.cpp:640
void setAttributeBuffer(int location, ofBufferObject &buffer, int numCoords, int stride, int offset=0)
Definition ofVbo.cpp:744
void clearColors()
Definition ofVbo.cpp:1031
void disableTexCoords()
Definition ofVbo.cpp:615
void clearIndices()
Definition ofVbo.cpp:1046
void setNormalBuffer(ofBufferObject &buffer, int stride, int offset=0)
Definition ofVbo.cpp:725
bool getUsingNormals() const
Definition ofVbo.cpp:645
GLuint getVertId() const
Definition ofVbo.cpp:665
GLuint getAttributeId(int AttrPos_) const
returns OpenGL memory object id for GL buffer holding attribute data
Definition ofVbo.cpp:690
void enableColors()
Definition ofVbo.cpp:573
void draw(int drawMode, int first, int total) const
Definition ofVbo.cpp:969
void clearTexCoords()
Definition ofVbo.cpp:1039
bool getIsAllocated() const
Definition ofVbo.cpp:630
void disableNormals()
Definition ofVbo.cpp:608
void setAttributeDivisor(int location, int divisor)
Definition ofVbo.cpp:456
void drawElementsInstanced(int drawMode, int amt, int primCount) const
Definition ofVbo.cpp:984
void setColorBuffer(ofBufferObject &buffer, int stride, int offset=0)
Definition ofVbo.cpp:719
void setMesh(const ofMesh &mesh, int usage)
Definition ofVbo.cpp:287
ofVbo & operator=(const ofVbo &mom)
Definition ofVbo.cpp:252
bool hasAttribute(int attributePos_) const
Definition ofVbo.cpp:1101
void clear()
Definition ofVbo.cpp:989
void clearAttribute(int attributePos_)
Definition ofVbo.cpp:1056
void setVertexData(const glm::vec3 *verts, int total, int usage)
Definition ofVbo.cpp:325
bool getUsingVerts() const
Definition ofVbo.cpp:635
void updateAttributeData(int location, const float *vert0x, int total)
Definition ofVbo.cpp:541
void updateVertexData(const glm::vec3 *verts, int total)
Definition ofVbo.cpp:470
void updateColorData(const ofFloatColor *colors, int total)
Definition ofVbo.cpp:495
void bind() const
Definition ofVbo.cpp:839
void setAttributeData(int location, const float *vert0x, int numCoords, int total, int usage, int stride=0)
Definition ofVbo.cpp:437
int getNumIndices() const
Definition ofVbo.cpp:1087
void unbind() const
Definition ofVbo.cpp:947
void setNormalData(const glm::vec3 *normals, int total, int usage)
Definition ofVbo.cpp:363
void enableTexCoords()
Definition ofVbo.cpp:587
ofBufferObject & getColorBuffer()
Definition ofVbo.cpp:762
void drawInstanced(int drawMode, int first, int total, int primCount) const
Definition ofVbo.cpp:979
void clearNormals()
Definition ofVbo.cpp:1024
ofBufferObject & getTexCoordBuffer()
Definition ofVbo.cpp:772
void drawElements(int drawMode, int amt, int offsetelements=0) const
Definition ofVbo.cpp:974
void enableNormals()
Definition ofVbo.cpp:580
void setIndexData(const ofIndexType *indices, int total, int usage)
Definition ofVbo.cpp:396
void disableIndices()
Definition ofVbo.cpp:622
ofBufferObject & getNormalBuffer()
Definition ofVbo.cpp:767
GLuint getTexCoordId() const
Definition ofVbo.cpp:680
void setTexCoordBuffer(ofBufferObject &buffer, int stride, int offset=0)
Definition ofVbo.cpp:731
ofBufferObject & getIndexBuffer()
Definition ofVbo.cpp:777
void setVertexBuffer(ofBufferObject &buffer, int numCoords, int stride, int offset=0)
Definition ofVbo.cpp:699
void setColorData(const ofFloatColor *colors, int total, int usage)
Definition ofVbo.cpp:352
ofBufferObject & getVertexBuffer()
Definition ofVbo.cpp:757
void enableIndices()
Definition ofVbo.cpp:594
GLuint getIndexId() const
Definition ofVbo.cpp:685
bool getUsingIndices() const
Definition ofVbo.cpp:655
ofBufferObject & getAttributeBuffer(int location)
Definition ofVbo.cpp:782
GLuint getNormalId() const
Definition ofVbo.cpp:675
void setIndexBuffer(ofBufferObject &buffer)
Definition ofVbo.cpp:737
bool getUsingTexCoords() const
Definition ofVbo.cpp:650
int getNumVertices() const
Definition ofVbo.cpp:1096
ofVbo()
Definition ofVbo.cpp:207
ofVec2f is a class for storing a two dimensional vector.
Definition ofVec2f.h:72
ofVec3f is a class for storing a three dimensional vector.
Definition ofVec3f.h:79
TESSindex ofIndexType
Definition ofConstants.h:290
ofColor_< float > ofFloatColor
Definition ofVbo.h:12