Cinder  0.9.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
cinder::gl::VboMesh Class Reference

#include <VboMesh.h>

Classes

class  Layout
 
class  MappedAttrib
 
class  MappedAttribBase
 
struct  MappedVboInfo
 

Public Types

typedef std::map< geom::Attrib, std::string > AttribGlslMap
 

Public Member Functions

void buildVao (const GlslProgRef &shader, const AttribGlslMap &attributeMapping=AttribGlslMap())
 
void buildVao (const GlslProg *shader, const AttribGlslMap &attributeMapping=AttribGlslMap())
 
uint32_t getNumVertices () const
 
uint32_t getNumIndices () const
 
GLenum getGlPrimitive () const
 
GLenum getIndexDataType () const
 
uint8_t getAttribDims (geom::Attrib attr) const
 
geom::AttribSet getAvailableAttribs () const
 
VboRef getIndexVbo ()
 
std::vector< VboRefgetVertexArrayVbos ()
 
const std::vector< std::pair< geom::BufferLayout, VboRef > > & getVertexArrayLayoutVbos () const
 
void appendVbo (const geom::BufferLayout &layout, const VboRef &vbo)
 
std::pair< geom::BufferLayout, VboRef > * findAttrib (geom::Attrib attr)
 
void bufferAttrib (geom::Attrib attrib, size_t dataSizeBytes, const void *data)
 
template<typename T >
void bufferAttrib (geom::Attrib attrib, const std::vector< T > &data)
 
void bufferIndices (size_t dataSizeBytes, const void *data)
 
MappedAttrib< float > mapAttrib1f (geom::Attrib attr, bool orphanExisting=true)
 
MappedAttrib< vec2 > mapAttrib2f (geom::Attrib attr, bool orphanExisting=true)
 
MappedAttrib< vec3 > mapAttrib3f (geom::Attrib attr, bool orphanExisting=true)
 
MappedAttrib< vec4 > mapAttrib4f (geom::Attrib attr, bool orphanExisting=true)
 
void drawImpl (GLint first=0, GLsizei count=-1)
 
geom::SourceRef createSource () const
 
void downloadIndices (uint32_t *dest) const
 
void echoVertexRange (std::ostream &os, size_t startIndex, size_t endIndex)
 
void echoIndexRange (std::ostream &os, size_t startIndex, size_t endIndex)
 

Static Public Member Functions

static VboMeshRef create (const geom::Source &source)
 
static VboMeshRef create (const geom::Source &source, const geom::AttribSet &requestedAttribs)
 
static VboMeshRef create (const geom::Source &source, const std::vector< VboMesh::Layout > &vertexArrayLayouts)
 
static VboMeshRef create (const geom::Source &source, const std::vector< std::pair< VboMesh::Layout, VboRef >> &vertexArrayLayouts, const VboRef &indexVbo=nullptr)
 
static VboMeshRef create (uint32_t numVertices, GLenum glPrimitive, const std::vector< std::pair< geom::BufferLayout, VboRef >> &vertexArrayBuffers, uint32_t numIndices=0, GLenum indexType=GL_UNSIGNED_SHORT, const VboRef &indexVbo=VboRef())
 
static VboMeshRef create (uint32_t numVertices, GLenum glPrimitive, const std::vector< Layout > &vertexArrayLayouts, uint32_t numIndices=0, GLenum indexType=GL_UNSIGNED_SHORT, const VboRef &indexVbo=VboRef())
 

Protected Member Functions

 VboMesh (const geom::Source &source, std::vector< std::pair< Layout, VboRef >> vertexArrayBuffers, const VboRef &indexArrayVbo)
 
 VboMesh (uint32_t numVertices, uint32_t numIndices, GLenum glPrimitive, GLenum indexType, const std::vector< std::pair< geom::BufferLayout, VboRef >> &vertexArrayBuffers, const VboRef &indexVbo)
 
 VboMesh (uint32_t numVertices, uint32_t numIndices, GLenum glPrimitive, GLenum indexType, const std::vector< Layout > &vertexArrayLayouts, const VboRef &indexVbo)
 
void allocateIndexVbo ()
 
void echoVertices (std::ostream &os, const std::vector< uint32_t > &indices, bool printElements)
 
template<typename T >
MappedAttrib< T > mapAttribImpl (geom::Attrib attr, int dims, bool orphanExisting)
 
void unmapVboImpl (const VboRef &vbo)
 

Protected Attributes

std::map< VboRef, MappedVboInfomMappedVbos
 
uint32_t mNumVertices
 
uint32_t mNumIndices
 
GLenum mGlPrimitive
 
GLenum mIndexType
 
std::vector< std::pair< geom::BufferLayout, VboRef > > mVertexArrayVbos
 
VboRef mIndices
 

Friends

class VboMeshGeomTarget
 
class Batch
 

Member Typedef Documentation

typedef std::map<geom::Attrib,std::string> cinder::gl::VboMesh::AttribGlslMap

Maps a geom::Attrib to a named attribute in the GlslProg.

Constructor & Destructor Documentation

cinder::gl::VboMesh::VboMesh ( const geom::Source source,
std::vector< std::pair< Layout, VboRef >>  vertexArrayBuffers,
const VboRef indexArrayVbo 
)
protected
cinder::gl::VboMesh::VboMesh ( uint32_t  numVertices,
uint32_t  numIndices,
GLenum  glPrimitive,
GLenum  indexType,
const std::vector< std::pair< geom::BufferLayout, VboRef >> &  vertexArrayBuffers,
const VboRef indexVbo 
)
protected
cinder::gl::VboMesh::VboMesh ( uint32_t  numVertices,
uint32_t  numIndices,
GLenum  glPrimitive,
GLenum  indexType,
const std::vector< Layout > &  vertexArrayLayouts,
const VboRef indexVbo 
)
protected

Member Function Documentation

VboMeshRef cinder::gl::VboMesh::create ( const geom::Source source)
static

Creates a VboMesh which represents the geom::Source source. Layout is derived from the contents of source.

VboMeshRef cinder::gl::VboMesh::create ( const geom::Source source,
const geom::AttribSet requestedAttribs 
)
static

Creates a VboMesh which represents the geom::Source source using layout.

VboMeshRef cinder::gl::VboMesh::create ( const geom::Source source,
const std::vector< VboMesh::Layout > &  vertexArrayLayouts 
)
static

Creates a VboMesh which represents the geom::Source source using 1 or more VboMesh::Layouts for vertex data.

VboMeshRef cinder::gl::VboMesh::create ( const geom::Source source,
const std::vector< std::pair< VboMesh::Layout, VboRef >> &  vertexArrayLayouts,
const VboRef indexVbo = nullptr 
)
static

Creates a VboMesh which represents the geom::Source source using 1 or more Vbo/VboMesh::Layout pairs. A null VboRef requests allocation.

static VboMeshRef cinder::gl::VboMesh::create ( uint32_t  numVertices,
GLenum  glPrimitive,
const std::vector< std::pair< geom::BufferLayout, VboRef >> &  vertexArrayBuffers,
uint32_t  numIndices = 0,
GLenum  indexType = GL_UNSIGNED_SHORT,
const VboRef indexVbo = VboRef() 
)
static

Creates a VboMesh which represents the user's vertex buffer objects. Allows optional indexVbo to enable indexed vertices; creates a static index VBO if none provided.

VboMeshRef cinder::gl::VboMesh::create ( uint32_t  numVertices,
GLenum  glPrimitive,
const std::vector< Layout > &  vertexArrayLayouts,
uint32_t  numIndices = 0,
GLenum  indexType = GL_UNSIGNED_SHORT,
const VboRef indexVbo = VboRef() 
)
static

Creates a VboMesh which represents the user's vertex buffer objects. Allows optional indexVbo to enable indexed vertices; creates a static index VBO if none provided.

void cinder::gl::VboMesh::buildVao ( const GlslProgRef shader,
const AttribGlslMap attributeMapping = AttribGlslMap() 
)

Constructs a VAO (in the currently bound VAO) that matches this to GlslProg shader, overriding the mapping of a geom::Attrib to a named attribute via the 'a attributeMapping std::map.

void cinder::gl::VboMesh::buildVao ( const GlslProg shader,
const AttribGlslMap attributeMapping = AttribGlslMap() 
)
uint32_t cinder::gl::VboMesh::getNumVertices ( ) const

Returns the number of vertices in the mesh.

uint32_t cinder::gl::VboMesh::getNumIndices ( ) const

Returns the number of indices for indexed geometry, otherwise 0.

GLenum cinder::gl::VboMesh::getGlPrimitive ( ) const

Returns the primitive type, such as GL_TRIANGLES, GL_TRIANGLE_STRIP, etc.

GLenum cinder::gl::VboMesh::getIndexDataType ( ) const

Returns the data type of the indices contained in index vbo; either GL_UNSIGNED_SHORT or GL_UNSIGNED_INT.

uint8_t cinder::gl::VboMesh::getAttribDims ( geom::Attrib  attr) const

Returns 0 if attr is not present.

geom::AttribSet cinder::gl::VboMesh::getAvailableAttribs ( ) const

Returns AttribSet of geom::Attribs present in the VboMesh.

VboRef cinder::gl::VboMesh::getIndexVbo ( )

Returns the VBO containing the indices of the mesh, or a NULL for non-indexed geometry.

std::vector< VboRef > cinder::gl::VboMesh::getVertexArrayVbos ( )

Builds and returns a vector of VboRefs for the vertex data of the mesh.

const std::vector<std::pair<geom::BufferLayout,VboRef> >& cinder::gl::VboMesh::getVertexArrayLayoutVbos ( ) const

Returns the vector of pairs of (BufferLayout,VboRef) for the vertex data of the mesh.

void cinder::gl::VboMesh::appendVbo ( const geom::BufferLayout layout,
const VboRef vbo 
)

Adds a new VBO (paired with its geom::BufferLayout) to the VboMesh.

std::pair< geom::BufferLayout, VboRef > * cinder::gl::VboMesh::findAttrib ( geom::Attrib  attr)

Returns a pair<geom::BufferLayout,VboRef>* that corresponds to attrib. Returns nullptr if not found.

void cinder::gl::VboMesh::bufferAttrib ( geom::Attrib  attrib,
size_t  dataSizeBytes,
const void *  data 
)

Fails with an error on ES 2 platforms which don't support buffer mapping when used with interleaved buffers. When multiple attributes are stored interleaved in a single VBO, this can be less efficient than calling mapAttrib*() or manipulating the VBO directly.

template<typename T >
void cinder::gl::VboMesh::bufferAttrib ( geom::Attrib  attrib,
const std::vector< T > &  data 
)

Fails with an error on ES 2 platforms which don't support buffer mapping when used with interleaved buffers. When multiple attributes are stored interleaved in a single VBO, this can be less efficient than calling mapAttrib*() or manipulating the VBO directly.

void cinder::gl::VboMesh::bufferIndices ( size_t  dataSizeBytes,
const void *  data 
)
VboMesh::MappedAttrib< float > cinder::gl::VboMesh::mapAttrib1f ( geom::Attrib  attr,
bool  orphanExisting = true 
)

Must call unmap() on the result. Throws ExcMissingAttrib if the VboMesh doesn't contain attr.

VboMesh::MappedAttrib< vec2 > cinder::gl::VboMesh::mapAttrib2f ( geom::Attrib  attr,
bool  orphanExisting = true 
)

Must call unmap() on the result. Throws ExcMissingAttrib if the VboMesh doesn't contain attr.

VboMesh::MappedAttrib< vec3 > cinder::gl::VboMesh::mapAttrib3f ( geom::Attrib  attr,
bool  orphanExisting = true 
)

Must call unmap() on the result. Throws ExcMissingAttrib if the VboMesh doesn't contain attr.

VboMesh::MappedAttrib< vec4 > cinder::gl::VboMesh::mapAttrib4f ( geom::Attrib  attr,
bool  orphanExisting = true 
)

Must call unmap() on the result. Throws ExcMissingAttrib if the VboMesh doesn't contain attr.

void cinder::gl::VboMesh::drawImpl ( GLint  first = 0,
GLsizei  count = -1 
)

Issues a glDraw* call, but without binding a VAO or sending shader vars. Consider gl::draw( VboMeshRef ) instead. Knows whether to call glDrawArrays or glDrawElements.

geom::SourceRef cinder::gl::VboMesh::createSource ( ) const

Returns a geom::Source which references 'this'. Inefficient - primarily useful for debugging. The returned geom::SourceRef should not outlive 'this' (not a shared_ptr).

void cinder::gl::VboMesh::downloadIndices ( uint32_t *  dest) const

Copies indices to dest. Requires dest to provide storage for getNumIndices() indices. Inefficient - primarily useful for debugging.

void cinder::gl::VboMesh::echoVertexRange ( std::ostream &  os,
size_t  startIndex,
size_t  endIndex 
)

Echos all vertex data in range [startIndex, endIndex) to os. Inefficient - primarily useful for debugging.

void cinder::gl::VboMesh::echoIndexRange ( std::ostream &  os,
size_t  startIndex,
size_t  endIndex 
)

Echos all vertex data for the indices in range [startIndex, endIndex) to os. No-op for non-indexed geometry. Inefficient - primarily useful for debugging.

void cinder::gl::VboMesh::allocateIndexVbo ( )
protected
void cinder::gl::VboMesh::echoVertices ( std::ostream &  os,
const std::vector< uint32_t > &  indices,
bool  printElements 
)
protected
template<typename T >
VboMesh::MappedAttrib< T > cinder::gl::VboMesh::mapAttribImpl ( geom::Attrib  attr,
int  dims,
bool  orphanExisting 
)
protected
void cinder::gl::VboMesh::unmapVboImpl ( const VboRef vbo)
protected

Friends And Related Function Documentation

friend class VboMeshGeomTarget
friend
friend class Batch
friend

Member Data Documentation

std::map<VboRef,MappedVboInfo> cinder::gl::VboMesh::mMappedVbos
protected
uint32_t cinder::gl::VboMesh::mNumVertices
protected
uint32_t cinder::gl::VboMesh::mNumIndices
protected
GLenum cinder::gl::VboMesh::mGlPrimitive
protected
GLenum cinder::gl::VboMesh::mIndexType
protected
std::vector<std::pair<geom::BufferLayout,VboRef> > cinder::gl::VboMesh::mVertexArrayVbos
protected
VboRef cinder::gl::VboMesh::mIndices
protected

The documentation for this class was generated from the following files: