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

#include <CpuDataWriter.h>

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

Allows immediate mode drawing to a CPU buffer, rather than a buffer object.

It is frequently useful to do immediate-mode style drawing to a CPU buffer. One might be doing old-style client-side array rendering, or just compiling lots of data to eventually be uploaded to actual buffer objects.

This class does this. It stores the attribute data into a std::vector<char>, in accord with the given VertexFormat.

Unlike glmesh::Draw, this class does not require you to provide a maximum upper limit on the number of vertices ahead of time. And because this class does not do any rendering, it also does not require you to provide a primitive type. So you can write as many vertices as you want. It will still throw if you attempt to extract the vertex data when a vertex is only partially specified, but otherwise, there are no limitations.

You can extract the data by copying it into a vector<char>, by "moving" it into one, or by directly uploading it to a buffer object.

Public Member Functions

 CpuDataWriter (const VertexFormat &fmt, size_t vertexReserve=0)
 Creates a data writer with the given format. More...
 
size_t GetNumVerticesWritten () const
 Returns the number of complete vertices written to the data.
 
Data Extraction Functions

These functions all pull written data out of the writer. If you call one of these in the middle of a vertex, then the function will throw.

void Extract (std::vector< char > &output)
 Delivers vertex data by "move". More...
 
std::vector< char > Copy () const
 Copies the buffer to the return value. Does not modify the internal data. More...
 
GLuint TransferToBuffer (GLenum target, GLenum usage, GLuint bufferObject=0) const
 Uploads the data directly to an OpenGL buffer object. More...
 
- Public Member Functions inherited from glmesh::VertexWriter< CpuDataWriter >
 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< CpuDataWriter >
size_t GetCurrAttrib () const
 Retrieves the current vertex attribute index, to be used with VertexFormat::GetAttribDesc.
 

Constructor & Destructor Documentation

glmesh::CpuDataWriter::CpuDataWriter ( const VertexFormat fmt,
size_t  vertexReserve = 0 
)

Creates a data writer with the given format.

Parameters
fmtThe VertexFormat to use with this writer.
vertexReserveIf specified, the number of vertices to reserve space for. Solely an optimization.

Member Function Documentation

std::vector<char> glmesh::CpuDataWriter::Copy ( ) const

Copies the buffer to the return value. Does not modify the internal data.

Exceptions
IncompleteVertexExceptionIf a vertex has only been partially specified.
void glmesh::CpuDataWriter::Extract ( std::vector< char > &  output)

Delivers vertex data by "move".

This function swaps the internal buffer into the output argument. This method causes no copying of the data. Once you call this, you could continue writing more attributes, but all prior attributes will have been removed.

Exceptions
IncompleteVertexExceptionIf a vertex has only been partially specified.
GLuint glmesh::CpuDataWriter::TransferToBuffer ( GLenum  target,
GLenum  usage,
GLuint  bufferObject = 0 
) const

Uploads the data directly to an OpenGL buffer object.

This function uploads the data to a buffer object via a call to glBufferData. This can be a new buffer if you don't specify the third parameter, or it can be a user-created buffer object name. In either case, the old buffer's data will be completely destroyed.

The buffer binding for target in the OpenGL context will be reset to 0 if this function call is successful. If it throws, nothing in the context will be changed.

Parameters
targetThe buffer object binding point you want to bind the buffer to.
usageThe storage usage you want to use for the call to glBufferData.
bufferObjectThe buffer object name you want to upload into. If not specified, this will create a new one.
Returns
The buffer object uploaded into.
Exceptions
IncompleteVertexExceptionIf a vertex has only been partially specified.

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