//-------------------------------------------------------------- void ofVbo::setMesh(const ofMesh & mesh, int usage, bool useColors, bool useTextures, bool useNormals){ if(mesh.getVertices().empty()){ ofLogWarning("ofVbo") << "setMesh(): ignoring mesh with no vertices"; return; } setVertexData(mesh.getVerticesPointer(),mesh.getNumVertices(),usage); if(mesh.hasColors() && useColors){ setColorData(mesh.getColorsPointer(),mesh.getNumColors(),usage); enableColors(); }else{ disableColors(); } if(mesh.hasNormals() && useNormals){ setNormalData(mesh.getNormalsPointer(),mesh.getNumNormals(),usage); enableNormals(); }else{ disableNormals(); } if(mesh.hasTexCoords() && useTextures){ setTexCoordData(mesh.getTexCoordsPointer(),mesh.getNumTexCoords(),usage); enableTexCoords(); }else{ disableTexCoords(); } if(mesh.hasIndices()){ setIndexData(mesh.getIndexPointer(), mesh.getNumIndices(), usage); enableIndices(); }else{ disableIndices(); } }
//-------------------------------------------------------------- void ofVbo::setIndexData(const ofIndexType * indices, int total, int usage){ if(!indexAttribute.isAllocated()){ indexAttribute.allocate(); enableIndices(); } totalIndices = total; indexAttribute.setData(sizeof(ofIndexType) * total, &indices[0], usage); }
//-------------------------------------------------------------- void ofVbo::setIndexData(const ofIndexType * indices, int total, int usage){ if(indexId==0){ glGenBuffers(1, &(indexId)); retain(indexId); enableIndices(); } totalIndices = total; glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ofIndexType) * total, &indices[0], usage); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }
//-------------------------------------------------------------- void ofVbo::setIndexBuffer(ofBufferObject & buffer){ indexAttribute.buffer = buffer; vaoChanged = true; enableIndices(); }