Пример #1
0
 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_);
 }
Пример #2
0
 GLint ElementData::getElementIndex(int i) const
 {
     if (hasIndices())
     {
         return indices[i];
     }
     else
     {
         return i + offset;
     }
 }
Пример #3
0
 GLint ElementData::getNumElements() const
 {
     if (hasIndices())
     {
         return indices.size();
     }
     else
     {
         return count;
     }
 }
Пример #4
0
    void ElementData::draw()
    {
        if (hasIndices())
        {
            glDrawElements(
                    GL_TRIANGLES, 
                    getNumElements(), 
                    GL_UNSIGNED_INT,
                    reinterpret_cast<GLvoid*>(0));

        }
        else
        {
            glDrawArrays(GL_TRIANGLES, offset, getNumElements());
        }
    }
Пример #5
0
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();
    }
}
Пример #6
0
//// 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();
}
Пример #7
0
		//! Total number of elements (triangles/lines/...)
		size_t totalElements() const {
			if (hasIndices())
				return indices().size() / 3;
			return m_vertices.size() /3;
		}