Unofficial OpenGL Software Development Kit  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
List of all members | Classes | Public Member Functions
glmesh::VertexFormat Class Reference

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

Constructor & Destructor Documentation

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.

Exceptions
AttributeIndexMultipleRefExceptionIf any of the attribs refer to the same attribute location as any of the others.

Member Function Documentation

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:

  • The enable state of the attribute referred to by attribIx will be set to enable.
  • The attribute location for attribIx will have glVertexAttrib*Format will be called.
  • The attribute location for attribIx will have 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.

Note
No exception will be thrown if ARB_vertex_attrib_format or GL 4.3 are not available.
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:

  • The enable state of all of the attributes in the format will be set to enabled.
  • For each such attribute location, glVertexAttrib*Format will be called.
  • For each such attribute location, 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.

Parameters
bindingIndexThe buffer binding index to use for all vertex attributes.
Note
No exception will be thrown if ARB_vertex_attrib_format or GL 4.3 are not available.
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:

  • The enable state of the attribute referred to by attribIx will be set to enable.
  • The attribute location for attribIx will have glVertexAttrib*Pointer called on it.

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.

Parameters
baseOffsetThe byte offset from the start of the buffer object to where the vertex data is.
attribIxThe 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:

  • The enable state of all of the attributes in the format will be set to enabled.
  • For each such attribute location, 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.

Parameters
baseOffsetThe 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:

  • The enable state of all of the attributes in the format will be set to disabled.
size_t glmesh::VertexFormat::GetAttribByteOffset ( size_t  attribIx) const

Gets the byte offset for a particular attribute, given an index between 0 and GetNumAttribs.

Exceptions
std::out_of_rangeIf attribIx is >= GetNumAttribs.
AttribDesc glmesh::VertexFormat::GetAttribDesc ( size_t  attribIx) const

Gets the AttribDesc, given an index between 0 and GetNumAttribs.

Exceptions
std::out_of_rangeIf attribIx is >= GetNumAttribs.

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