Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions libs/openFrameworks/gl/ofVboMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ofVboMesh::ofVboMesh(){
vboNumColors = 0;
vboNumTexCoords = 0;
vboNumNormals = 0;
updateSet = false;
}

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

void ofVboMesh::enableColors(){
vbo.enableColors();
ofMesh::enableColors();
}

void ofVboMesh::enableTextures(){
vbo.enableTexCoords();
ofMesh::enableTextures();
}

void ofVboMesh::enableNormals(){
vbo.enableNormals();
ofMesh::enableNormals();
}

void ofVboMesh::enableIndices(){
vbo.enableIndices();
ofMesh::enableIndices();
}

void ofVboMesh::disableColors(){
vbo.disableColors();
ofMesh::disableColors();
}

void ofVboMesh::disableTextures(){
vbo.disableTexCoords();
ofMesh::disableTextures();
}

void ofVboMesh::disableNormals(){
vbo.disableNormals();
ofMesh::disableNormals();
}

void ofVboMesh::disableIndices(){
vbo.disableIndices();
ofMesh::disableIndices();
}

bool ofVboMesh::usingColors() const {
Expand Down Expand Up @@ -156,7 +165,7 @@ void ofVboMesh::updateVbo(){
if(getNumVertices()==0){
vbo.clearVertices();
vboNumVerts = getNumVertices();
}else if(vboNumVerts<getNumVertices()){
}else if(vboNumVerts<getNumVertices() || updateSet){
vbo.setVertexData(getVerticesPointer(),getNumVertices(),usage);
vboNumVerts = getNumVertices();
}else{
Expand All @@ -168,7 +177,7 @@ void ofVboMesh::updateVbo(){
if(getNumColors()==0){
vbo.clearColors();
vboNumColors = getNumColors();
}else if(vboNumColors<getNumColors()){
}else if(vboNumColors<getNumColors() || updateSet){
vbo.setColorData(getColorsPointer(),getNumColors(),usage);
vboNumColors = getNumColors();
}else{
Expand All @@ -180,7 +189,7 @@ void ofVboMesh::updateVbo(){
if(getNumNormals()==0){
vbo.clearNormals();
vboNumNormals = getNumNormals();
}else if(vboNumNormals<getNumNormals()){
}else if(vboNumNormals<getNumNormals() || updateSet){
vbo.setNormalData(getNormalsPointer(),getNumNormals(),usage);
vboNumNormals = getNumNormals();
}else{
Expand All @@ -192,7 +201,7 @@ void ofVboMesh::updateVbo(){
if(getNumTexCoords()==0){
vbo.clearTexCoords();
vboNumTexCoords = getNumTexCoords();
}else if(vboNumTexCoords<getNumTexCoords()){
}else if(vboNumTexCoords<getNumTexCoords() || updateSet){
vbo.setTexCoordData(getTexCoordsPointer(),getNumTexCoords(),usage);
vboNumTexCoords = getNumTexCoords();
}else{
Expand All @@ -204,12 +213,39 @@ void ofVboMesh::updateVbo(){
if(getNumIndices()==0){
vbo.clearIndices();
vboNumIndices = getNumIndices();
}else if(vboNumIndices<getNumIndices()){
}else if(vboNumIndices<getNumIndices() || updateSet){
vbo.setIndexData(getIndexPointer(),getNumIndices(),usage);
vboNumIndices = getNumIndices();
}else{
vbo.updateIndexData(getIndexPointer(),getNumIndices());
}
}
if(updateSet) updateSet = false;
}
}

void ofVboMesh::removeVertex(ofIndexType index) {
ofMesh::removeVertex(index);
vboNumVerts = getNumVertices();
updateSet = true;
}

void ofVboMesh::removeVertex(ofIndexType startIndex, ofIndexType endIndex) {
ofMesh::removeVertices(startIndex, endIndex);
vboNumVerts = getNumVertices();
updateSet = true;
}

void ofVboMesh::removeColor(ofIndexType index) {
ofMesh::removeColor(index);
vboNumColors = getNumColors();
updateSet = true;
}

void ofVboMesh::removeColor(ofIndexType startIndex, ofIndexType endIndex) {
ofMesh::removeColors(startIndex, endIndex);
vboNumColors = getNumColors();
updateSet = true;
}


30 changes: 19 additions & 11 deletions libs/openFrameworks/gl/ofVboMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class ofVboMesh: public ofMesh{
public:
using ofMesh::draw;
ofVboMesh();
ofVboMesh(const ofMesh & mom);
using ofMesh::draw;
ofVboMesh();
ofVboMesh(const ofMesh & mom);
void operator=(const ofMesh & mom);
virtual ~ofVboMesh();
void setUsage(int usage);
virtual ~ofVboMesh();
void setUsage(int usage);

void enableColors();
void enableTextures();
Expand All @@ -23,19 +23,26 @@ class ofVboMesh: public ofMesh{
void disableNormals();
void disableIndices();

void removeVertex(ofIndexType index);
void removeVertex(ofIndexType startIndex, ofIndexType endIndex);
void removeColor(ofIndexType index);
void removeColor(ofIndexType startIndex, ofIndexType endIndex);

virtual bool usingColors() const;
virtual bool usingTextures() const;
virtual bool usingNormals() const;
virtual bool usingIndices() const;

void draw(ofPolyRenderMode drawMode) const;
void drawInstanced(ofPolyRenderMode drawMode, int primCount) const;

ofVbo & getVbo();
const ofVbo & getVbo() const;
void updateVbo();

void draw(ofPolyRenderMode drawMode) const;
void drawInstanced(ofPolyRenderMode drawMode, int primCount) const;

ofVbo & getVbo();
const ofVbo & getVbo() const;

private:
void updateVbo();

void unloadVbo();
ofVbo vbo;
int usage;
Expand All @@ -44,4 +51,5 @@ class ofVboMesh: public ofMesh{
std::size_t vboNumNormals;
std::size_t vboNumTexCoords;
std::size_t vboNumColors;
bool updateSet = false;
};