Skip to content

Commit b33d856

Browse files
authored
ofVboMesh - Fix Updating Indices / Color (#8348)
* ofVboMesh - Add RemoveVertex/RemoveColor. Fix Updating Indices / Colors if changes * ofVboMesh updateSet to false in header
1 parent 791e812 commit b33d856

File tree

2 files changed

+60
-16
lines changed

2 files changed

+60
-16
lines changed

libs/openFrameworks/gl/ofVboMesh.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ofVboMesh::ofVboMesh(){
1212
vboNumColors = 0;
1313
vboNumTexCoords = 0;
1414
vboNumNormals = 0;
15+
updateSet = false;
1516
}
1617

1718
ofVboMesh::ofVboMesh(const ofMesh & mom)
@@ -47,34 +48,42 @@ void ofVboMesh::setUsage(int _usage){
4748

4849
void ofVboMesh::enableColors(){
4950
vbo.enableColors();
51+
ofMesh::enableColors();
5052
}
5153

5254
void ofVboMesh::enableTextures(){
5355
vbo.enableTexCoords();
56+
ofMesh::enableTextures();
5457
}
5558

5659
void ofVboMesh::enableNormals(){
5760
vbo.enableNormals();
61+
ofMesh::enableNormals();
5862
}
5963

6064
void ofVboMesh::enableIndices(){
6165
vbo.enableIndices();
66+
ofMesh::enableIndices();
6267
}
6368

6469
void ofVboMesh::disableColors(){
6570
vbo.disableColors();
71+
ofMesh::disableColors();
6672
}
6773

6874
void ofVboMesh::disableTextures(){
6975
vbo.disableTexCoords();
76+
ofMesh::disableTextures();
7077
}
7178

7279
void ofVboMesh::disableNormals(){
7380
vbo.disableNormals();
81+
ofMesh::disableNormals();
7482
}
7583

7684
void ofVboMesh::disableIndices(){
7785
vbo.disableIndices();
86+
ofMesh::disableIndices();
7887
}
7988

8089
bool ofVboMesh::usingColors() const {
@@ -156,7 +165,7 @@ void ofVboMesh::updateVbo(){
156165
if(getNumVertices()==0){
157166
vbo.clearVertices();
158167
vboNumVerts = getNumVertices();
159-
}else if(vboNumVerts<getNumVertices()){
168+
}else if(vboNumVerts<getNumVertices() || updateSet){
160169
vbo.setVertexData(getVerticesPointer(),getNumVertices(),usage);
161170
vboNumVerts = getNumVertices();
162171
}else{
@@ -168,7 +177,7 @@ void ofVboMesh::updateVbo(){
168177
if(getNumColors()==0){
169178
vbo.clearColors();
170179
vboNumColors = getNumColors();
171-
}else if(vboNumColors<getNumColors()){
180+
}else if(vboNumColors<getNumColors() || updateSet){
172181
vbo.setColorData(getColorsPointer(),getNumColors(),usage);
173182
vboNumColors = getNumColors();
174183
}else{
@@ -180,7 +189,7 @@ void ofVboMesh::updateVbo(){
180189
if(getNumNormals()==0){
181190
vbo.clearNormals();
182191
vboNumNormals = getNumNormals();
183-
}else if(vboNumNormals<getNumNormals()){
192+
}else if(vboNumNormals<getNumNormals() || updateSet){
184193
vbo.setNormalData(getNormalsPointer(),getNumNormals(),usage);
185194
vboNumNormals = getNumNormals();
186195
}else{
@@ -192,7 +201,7 @@ void ofVboMesh::updateVbo(){
192201
if(getNumTexCoords()==0){
193202
vbo.clearTexCoords();
194203
vboNumTexCoords = getNumTexCoords();
195-
}else if(vboNumTexCoords<getNumTexCoords()){
204+
}else if(vboNumTexCoords<getNumTexCoords() || updateSet){
196205
vbo.setTexCoordData(getTexCoordsPointer(),getNumTexCoords(),usage);
197206
vboNumTexCoords = getNumTexCoords();
198207
}else{
@@ -204,12 +213,39 @@ void ofVboMesh::updateVbo(){
204213
if(getNumIndices()==0){
205214
vbo.clearIndices();
206215
vboNumIndices = getNumIndices();
207-
}else if(vboNumIndices<getNumIndices()){
216+
}else if(vboNumIndices<getNumIndices() || updateSet){
208217
vbo.setIndexData(getIndexPointer(),getNumIndices(),usage);
209218
vboNumIndices = getNumIndices();
210219
}else{
211220
vbo.updateIndexData(getIndexPointer(),getNumIndices());
212221
}
213222
}
223+
if(updateSet) updateSet = false;
214224
}
215225
}
226+
227+
void ofVboMesh::removeVertex(ofIndexType index) {
228+
ofMesh::removeVertex(index);
229+
vboNumVerts = getNumVertices();
230+
updateSet = true;
231+
}
232+
233+
void ofVboMesh::removeVertex(ofIndexType startIndex, ofIndexType endIndex) {
234+
ofMesh::removeVertices(startIndex, endIndex);
235+
vboNumVerts = getNumVertices();
236+
updateSet = true;
237+
}
238+
239+
void ofVboMesh::removeColor(ofIndexType index) {
240+
ofMesh::removeColor(index);
241+
vboNumColors = getNumColors();
242+
updateSet = true;
243+
}
244+
245+
void ofVboMesh::removeColor(ofIndexType startIndex, ofIndexType endIndex) {
246+
ofMesh::removeColors(startIndex, endIndex);
247+
vboNumColors = getNumColors();
248+
updateSet = true;
249+
}
250+
251+

libs/openFrameworks/gl/ofVboMesh.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
class ofVboMesh: public ofMesh{
88
public:
9-
using ofMesh::draw;
10-
ofVboMesh();
11-
ofVboMesh(const ofMesh & mom);
9+
using ofMesh::draw;
10+
ofVboMesh();
11+
ofVboMesh(const ofMesh & mom);
1212
void operator=(const ofMesh & mom);
13-
virtual ~ofVboMesh();
14-
void setUsage(int usage);
13+
virtual ~ofVboMesh();
14+
void setUsage(int usage);
1515

1616
void enableColors();
1717
void enableTextures();
@@ -23,19 +23,26 @@ class ofVboMesh: public ofMesh{
2323
void disableNormals();
2424
void disableIndices();
2525

26+
void removeVertex(ofIndexType index);
27+
void removeVertex(ofIndexType startIndex, ofIndexType endIndex);
28+
void removeColor(ofIndexType index);
29+
void removeColor(ofIndexType startIndex, ofIndexType endIndex);
30+
2631
virtual bool usingColors() const;
2732
virtual bool usingTextures() const;
2833
virtual bool usingNormals() const;
2934
virtual bool usingIndices() const;
3035

31-
void draw(ofPolyRenderMode drawMode) const;
32-
void drawInstanced(ofPolyRenderMode drawMode, int primCount) const;
33-
34-
ofVbo & getVbo();
35-
const ofVbo & getVbo() const;
36+
void updateVbo();
37+
38+
void draw(ofPolyRenderMode drawMode) const;
39+
void drawInstanced(ofPolyRenderMode drawMode, int primCount) const;
3640

41+
ofVbo & getVbo();
42+
const ofVbo & getVbo() const;
43+
3744
private:
38-
void updateVbo();
45+
3946
void unloadVbo();
4047
ofVbo vbo;
4148
int usage;
@@ -44,4 +51,5 @@ class ofVboMesh: public ofMesh{
4451
std::size_t vboNumNormals;
4552
std::size_t vboNumTexCoords;
4653
std::size_t vboNumColors;
54+
bool updateSet = false;
4755
};

0 commit comments

Comments
 (0)