Unofficial OpenGL Software Development Kit
0.5.0
|
#include <VertexFormat.h>
Describes the layout for a sequence of vertex attributes, to be used for rendering.
VertexFormat creates an interleaved layout, where each attribute is interleaved with each other. The attributes always have 4 byte alignment, as there are some hardware that really doesn't like misaligned data. Double-precision attributes have 8-byte alignment.
The byte offset of each attribute from the beginning of the vertex can be queried. This is useful if all of the attributes come from the same buffer object's source.
Note that the order of the attribute sequence is the same as the order of the AttributeList. This means that the order is not the order of the OpenGL attribute location. The attribute sequence order, as defined by the AttributeList, is the order the attributes will be stored in within the buffer object.
Any function that takes an attribIx parameter is taking an index into the attribute sequence order, not an OpenGL attribute location.
You may use VertexFormat::Enable to perform all of the glEnableVertexAttribArray
and glVertexAttrib*Pointer
calls to associate a buffer object with this format. It is a RAII class, so the destructor will call glDisableVertexAttribArray
to disable the arrays.
This class uses value semantics and is copyable.
Classes | |
class | Enable |
RAII-style class for binding a VertexFormat to the OpenGL context. More... | |
Public Member Functions | |
VertexFormat () | |
Creates an empty vertex format. You should fill it with data via copy assignment. More... | |
VertexFormat (const AttributeList &attribs) | |
Creates a VertexFormat from a sequence of AttribDesc objects. More... | |
size_t | GetVertexByteSize () const |
Retrieves the size of an entire vertex, including any padding. | |
size_t | GetNumAttribs () const |
Gets the number of vertex attributes. | |
AttribDesc | GetAttribDesc (size_t attribIx) const |
size_t | GetAttribByteOffset (size_t attribIx) const |
void | BindAttributes (size_t baseOffset) const |
Binds the VertexFormat to the context. More... | |
void | BindAttribute (size_t baseOffset, size_t attribIx) const |
Binds the attribute given by the attribute index to the context. More... | |
void | BindAttribFormats (GLuint bindingIndex) const |
Binds the VertexFormat using ARB_vertex_attrib_format. More... | |
void | BindAttribFormat (size_t attribIx, GLuint bindingIndex) const |
Binds the attribute given by the attribute index using ARB_vertex_attrib_format. More... | |
void | DisableAttributes () const |
Disables the attributes. More... | |
glmesh::VertexFormat::VertexFormat | ( | ) |
Creates an empty vertex format. You should fill it with data via copy assignment.
This exists mainly to make it easy to store these.
glmesh::VertexFormat::VertexFormat | ( | const AttributeList & | attribs | ) |
Creates a VertexFormat from a sequence of AttribDesc objects.
The order of the sequence of attributes will match the order of attribs.
AttributeIndexMultipleRefException | If any of the attribs refer to the same attribute location as any of the others. |
void glmesh::VertexFormat::BindAttribFormat | ( | size_t | attribIx, |
GLuint | bindingIndex | ||
) | const |
Binds the attribute given by the attribute index using ARB_vertex_attrib_format.
This function assumes that a valid VAO is bound (if one is needed).
The following OpenGL state is touched by this function:
glVertexAttrib*Format
will be called.glVertexAttribBinding
called with bindingIndex.This function uses the offsets computed by GetAttribByteOffset(), so it assumes that all vertex attributes come from a single buffer object. You can bind the buffer later with glBindVertexBuffer
.
void glmesh::VertexFormat::BindAttribFormats | ( | GLuint | bindingIndex | ) | const |
Binds the VertexFormat using ARB_vertex_attrib_format.
This function assumes that a valid VAO is bound (if one is needed).
The following OpenGL state is touched by this function:
glVertexAttrib*Format
will be called.glVertexAttribBinding
will be called with bindingIndex.This function uses the offsets computed by GetAttribByteOffset(), so it assumes that all vertex attributes come from a single buffer object. You can bind the buffer later with glBindVertexBuffer
.
bindingIndex | The buffer binding index to use for all vertex attributes. |
void glmesh::VertexFormat::BindAttribute | ( | size_t | baseOffset, |
size_t | attribIx | ||
) | const |
Binds the attribute given by the attribute index to the context.
This function assumes that a valid VAO is bound (if one is needed), as well as GL_ARRAY_BUFFER
.
The following OpenGL state is touched by this function:
This function assumes that all vertex attributes come from the buffer object currently bound to GL_ARRAY_BUFFER
. Therefore, you can only use it with a single buffer object.
baseOffset | The byte offset from the start of the buffer object to where the vertex data is. |
attribIx | The index of the attribute to bind. |
void glmesh::VertexFormat::BindAttributes | ( | size_t | baseOffset | ) | const |
Binds the VertexFormat to the context.
This function assumes that a valid VAO is bound (if one is needed), as well as GL_ARRAY_BUFFER
.
The following OpenGL state is touched by this function:
glVertexAttrib*Pointer
will be called.This function assumes that all vertex attributes come from the buffer object currently bound to GL_ARRAY_BUFFER
. Therefore, you can only use it with a single buffer object.
baseOffset | The byte offset from the start of the buffer object to where the vertex data is. |
void glmesh::VertexFormat::DisableAttributes | ( | ) | const |
Disables the attributes.
The following OpenGL state is touched by this function:
size_t glmesh::VertexFormat::GetAttribByteOffset | ( | size_t | attribIx | ) | const |
Gets the byte offset for a particular attribute, given an index between 0 and GetNumAttribs.
std::out_of_range | If attribIx is >= GetNumAttribs. |
AttribDesc glmesh::VertexFormat::GetAttribDesc | ( | size_t | attribIx | ) | const |
Gets the AttribDesc, given an index between 0 and GetNumAttribs.
std::out_of_range | If attribIx is >= GetNumAttribs. |