Unofficial OpenGL Software Development Kit
0.5.0
|
#include <Draw.h>
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):
GL_ARRAY_BUFFER
binding.The VertexWriter::Attrib functions, used to write attributes, will also throw TooManyVerticesSentException if more vertices have been sent than were originally specified.
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. | |
glmesh::Draw::Draw | ( | GLenum | primType, |
size_t | vertexCount, | ||
const VertexFormat & | fmt, | ||
StreamBuffer & | buffer | ||
) |
Creates a non-copyable object for drawing.
primType | The OpenGL primitive type to render. |
vertexCount | The number of vertices you will provide. This must work with primType or an exception is thrown. |
fmt | The format of the attributes in each vertex. Taken by reference; do not destroy this before this object is destroyed. |
buffer | The streaming buffer that will be used to store the vertex data. Taken by reference; do not destroy this before this object is destroyed. |
PrimitiveTypeUnsupportedException | If primType is not supported on the OpenGL implementation. |
VertexCountPrimMismatchException | If vertexCount does not match primType's requirements. |
StreamBuffer::Map | Anything 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.
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.
TooFewVerticesSentException | If you have not provided all of the vertices promised by the vertex count. |