void ElementData::bind() { if (hasIndices()) { if (!ibo_) { glGenBuffers(1, &ibo_); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_); glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * indices.size(), indices.data(), GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0u); } else { if (ibo_) { glDeleteBuffers(1, &ibo_); } } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_); }
GLint ElementData::getElementIndex(int i) const { if (hasIndices()) { return indices[i]; } else { return i + offset; } }
GLint ElementData::getNumElements() const { if (hasIndices()) { return indices.size(); } else { return count; } }
void ElementData::draw() { if (hasIndices()) { glDrawElements( GL_TRIANGLES, getNumElements(), GL_UNSIGNED_INT, reinterpret_cast<GLvoid*>(0)); } else { glDrawArrays(GL_TRIANGLES, offset, getNumElements()); } }
void ofxMesh::toMesh(ofMesh & mesh){ mesh.clear(); if (hasVertices()) { mesh.getVertices()=getVertices(); } if (hasColors()) { mesh.getColors()=getColors(); } if (hasNormals()) { mesh.getNormals()=getNormals(); } if (hasTexCoords()) { mesh.getTexCoords()=getTexCoords(); } if (hasIndices()) { mesh.getIndices()=getIndices(); } }
//// Drawable functions //// void DMesh::draw( RenderInfo& r) { glPushMatrix(); glMultMatrixf(m_transform); // Material r.material( Drawable::m_material ); r.state( 1 + (getNormalPointer()? 2:0) + (getTexCoordPointer()?4:0) ); glVertexPointer(3, GL_FLOAT, getStride(), getVertexPointer()); glNormalPointer( GL_FLOAT, getStride(), getNormalPointer()); glTexCoordPointer(2, GL_FLOAT, getStride(), getTexCoordPointer()); // Tangents? if(getTangentPointer() && base::Shader::current().ready()) { base::Shader::current().AttributePointer("tangent", 3, GL_FLOAT, 0, getStride(), getTangentPointer()); } // Draw it if(hasIndices()) glDrawElements( getMode(), getSize(), GL_UNSIGNED_SHORT, getIndexPointer()); else glDrawArrays( getMode(), 0, getSize()); glPopMatrix(); }
//! Total number of elements (triangles/lines/...) size_t totalElements() const { if (hasIndices()) return indices().size() / 3; return m_vertices.size() /3; }