Unofficial OpenGL Software Development Kit
0.5.0
|
#include <CpuDataWriter.h>
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. | |
glmesh::CpuDataWriter::CpuDataWriter | ( | const VertexFormat & | fmt, |
size_t | vertexReserve = 0 |
||
) |
Creates a data writer with the given format.
fmt | The VertexFormat to use with this writer. |
vertexReserve | If specified, the number of vertices to reserve space for. Solely an optimization. |
std::vector<char> glmesh::CpuDataWriter::Copy | ( | ) | const |
Copies the buffer to the return value. Does not modify the internal data.
IncompleteVertexException | If 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.
IncompleteVertexException | If 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.
target | The buffer object binding point you want to bind the buffer to. |
usage | The storage usage you want to use for the call to glBufferData. |
bufferObject | The buffer object name you want to upload into. If not specified, this will create a new one. |
IncompleteVertexException | If a vertex has only been partially specified. |