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::Draw Class Reference

#include <Draw.h>

Inheritance diagram for glmesh::Draw:
glmesh::VertexWriter< Draw >

RAII-style class for immediate-mode type rendering through a VertexFormat and StreamBuffer.

The constructor of this class is given an OpenGL primitive type and the number of vertices to use. You must then call one of the Attrib member functions for each vertex and for each attribute in the VertexFormat. The order of attributes within a vertex corresponds to the order of attributes in the VertexFormat.

The VertexWriter::Attrib specialization must match the type of the attribute from the VertexFormat exactly. The number of components however does not have to match.

Successfully constructing an object of this type will affect the following OpenGL state (note: none of this state will be touched in the event of an exception in the constructor):

Note
Do not attempt to change buffer binding state during the lifetime of any instance of this class. Also, do not attempt to create two of these objects at the same time.

The VertexWriter::Attrib functions, used to write attributes, will also throw TooManyVerticesSentException if more vertices have been sent than were originally specified.

Note
This class cannot be copied.

Public Member Functions

 Draw (GLenum primType, size_t vertexCount, const VertexFormat &fmt, StreamBuffer &buffer)
 Creates a non-copyable object for drawing. More...
 
 ~Draw ()
 Draws, if the object has not been drawn previously with a call to Render(). More...
 
bool Render ()
 Draws the vertex data provided, if the object has not previously been drawn. More...
 
- Public Member Functions inherited from glmesh::VertexWriter< Draw >
 VertexWriter ()
 Creates a VertexWriter class instance.
 
void Attrib (BaseType x)
 
void Attrib (BaseType x, BaseType y)
 
void Attrib (const glm::detail::tvec2< BaseType > &val)
 
void Attrib (BaseType x, BaseType y, BaseType z)
 
void Attrib (const glm::detail::tvec3< BaseType > &val)
 
void Attrib (BaseType x, BaseType y, BaseType z, BaseType w)
 
void Attrib (const glm::detail::tvec4< BaseType > &val)
 

Additional Inherited Members

- Protected Member Functions inherited from glmesh::VertexWriter< Draw >
size_t GetCurrAttrib () const
 Retrieves the current vertex attribute index, to be used with VertexFormat::GetAttribDesc.
 

Constructor & Destructor Documentation

glmesh::Draw::Draw ( GLenum  primType,
size_t  vertexCount,
const VertexFormat fmt,
StreamBuffer buffer 
)

Creates a non-copyable object for drawing.

Parameters
primTypeThe OpenGL primitive type to render.
vertexCountThe number of vertices you will provide. This must work with primType or an exception is thrown.
fmtThe format of the attributes in each vertex. Taken by reference; do not destroy this before this object is destroyed.
bufferThe streaming buffer that will be used to store the vertex data. Taken by reference; do not destroy this before this object is destroyed.
Exceptions
PrimitiveTypeUnsupportedExceptionIf primType is not supported on the OpenGL implementation.
VertexCountPrimMismatchExceptionIf vertexCount does not match primType's requirements.
StreamBuffer::MapAnything that this class throws, except for NotEnoughRemainingStorageForMapException.

In the event of any exceptions, nothing is mapped and the StreamBuffer is not touched.

glmesh::Draw::~Draw ( )

Draws, if the object has not been drawn previously with a call to Render().

Unlike Render, this does not throw exceptions, since throwing exceptions in a destructor is bad. By letting this fall off the stack without an explicit render, you are effectively saying that you don't care to error check.

Therefore, if not enough vertices have been provided, then nothing will be rendered.

Member Function Documentation

bool glmesh::Draw::Render ( )

Draws the vertex data provided, if the object has not previously been drawn.

You can only call this after calling the Attrib functions enough times to provide a full set of attribute data for all vertices, as specified by vertexCount in the constructor.

Returns
true if the vertex data was rendered. False if Render has already been called or if the unmapping of the buffer failed. In both cases, nothing is rendered.
Exceptions
TooFewVerticesSentExceptionIf you have not provided all of the vertices promised by the vertex count.

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