Unofficial OpenGL Software Development Kit  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
List of all members | Public Member Functions
glmesh::Mesh Class Reference

#include <Mesh.h>

Inherits noncopyable.

An object that represents a static collection of mesh data.

Mesh objects are represent static mesh data. Mesh objects are composed of a VAO (which sets up all of the vertex attribute commands) coupled with a series of rendering commands, provided by a RenderCmdList.

A Mesh can have multiple VAOs, each of which has a unique name. These named VAOs are called variants. The main VAO, which is unnamed, will be used when no name is given to render. All of the variants are rendered with the same sequence of rendering commands.

This object owns the VAOs it is provided with, and it will delete them. It can also be given ownership of one or more buffer objects, which it will also delete when it is deleted. It does not use these buffer objects for any purpose other than to delete them.

Rendering with this class (via any call to Render) will affect the following OpenGL state:

Note
This class cannot be copied.
This class requires OpenGL 3.2 or above. It can be used with OpenGL 3.0 so long as you don't use any rendering command that has a non-zero base vertex.
You must ensure that the OpenGL context exists when Mesh's constructor is called.
Todo:
Change the interface for Render() to use boost::optional strings and string_refs.

Public Member Functions

 Mesh (const std::vector< GLuint > &bufferObjects, GLuint mainVao, const RenderCmdList &renderCmds, const MeshVariantMap &variants=MeshVariantMap())
 Creates a mesh, given a series of buffer objects, VAOs, and rendering commands. More...
 
 ~Mesh ()
 Deletes all VAOs and buffer objects owned by this Mesh. The OpenGL context must still exist.
 
void Render () const
 Renders the main VAO. Does nothing if there is no main VAO.
 
void Render (const std::string &variantName) const
 
bool DoesMainExist () const
 Returns true if there is a main VAO.
 
bool DoesVariantExist (const std::string &variantName) const
 

Constructor & Destructor Documentation

glmesh::Mesh::Mesh ( const std::vector< GLuint > &  bufferObjects,
GLuint  mainVao,
const RenderCmdList renderCmds,
const MeshVariantMap variants = MeshVariantMap() 
)

Creates a mesh, given a series of buffer objects, VAOs, and rendering commands.

This class claims ownership of all OpenGL objects passed to it. Its destructor will delete every VAO and buffer object it is given. If you want to manage the lifetime of a buffer object elsewhere, do not pass it as a parameter. Your VAOs can still reference those buffers, but this class will not dig through VAOs to delete buffers stored in them.

Parameters
bufferObjectsA series of buffer objects to be freed when this Mesh is destroyed. The same buffer object must not be in this array multiple times.
mainVaoThe primary vertex array object, used when calling Render with no parameters. If it is 0, then the only way to render the mesh is with a named variant.
renderCmdsThe series of rendering commands to be used to render this object. This sequence will be used for every variant.
variantsA std::map of named variants for the Mesh. It is legal to use the same VAOs for the mainVao and one of the variants, or between different variants.
Todo:
bufferObjects should take an array_ref, not a vector.

Member Function Documentation

bool glmesh::Mesh::DoesVariantExist ( const std::string &  variantName) const

Returns true if the named variant exists.

Todo:
Take a string_ref.
void glmesh::Mesh::Render ( const std::string &  variantName) const

Renders a named variant. Does nothing if the named VAO does not exist.

Todo:
Take a string_ref.

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