//-------------------------------------------------------------- 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::setNormalData(const float * normal0x, int total, int usage, int stride) { // tig: note that we set the 'Normalize' flag to true here, assuming that mesh normals need to be // normalized while being uploaded to GPU memory. // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml // Normalizing the normals on the shader is probably faster, but sending non-normalized normals is // more prone to lead to artifacts difficult to diagnose, especially with the built-in 3D primitives. // If you need to optimise this, and you've dug this far through the code, you are most probably // able to roll your own client code for binding & rendering vbos anyway... normalAttribute.setData(normal0x, 3, total, usage, stride); normalAttribute.normalize = true; enableNormals(); }
//-------------------------------------------------------------- void ofVbo::setNormalData(const float * normal0x, int total, int usage, int stride) { if(normalId==0) { glGenBuffers(1, &(normalId)); retain(normalId); enableNormals(); } normUsage = usage; normalStride = stride==0?3*sizeof(float):stride; glBindBuffer(GL_ARRAY_BUFFER, normalId); glBufferData(GL_ARRAY_BUFFER, total * stride, normal0x, usage); glBindBuffer(GL_ARRAY_BUFFER, 0); }
//-------------------------------------------------------------- void ofVbo::setNormalBuffer(ofBufferObject & buffer, int stride, int offset){ normalAttribute.setBuffer(buffer, 3, stride, offset); enableNormals(); }