Unofficial OpenGL Software Development Kit: glmesh::Draw Class Reference

Unofficial OpenGL Software Development Kit 0.5.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
List of all members | Public Member Functions
glmesh::Draw Class Reference
Immediate Mesh Drawing

`#include <Draw.h>`

Inheritance diagram for glmesh::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):

- The current `GL_ARRAY_BUFFER` binding.
- If VAOs are available, the current VAO will be affected. The current VAO after this object is destroyed will be VAO 0. The VAO used to render will be the communal one stored in the StreamBuffer.
- If VAOs are not available, the current attribute array state will be modified as VertexFormat::Enable does. Note that you should make sure that all attributes are disabled before constructing this object. Otherwise, badness can result.

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

  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.

Exceptions

  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.

## 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

  TooFewVerticesSentException | If you have not provided all of the vertices promised by the vertex count.

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

- C:/Projects/distro/glsdk_0_5_1/glmesh/include/glmesh/Draw.h