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 | Protected Member Functions
glmesh::VertexWriter< Sink > Class Template Reference

#include <VertexWriter.h>

template<typename Sink>
class glmesh::VertexWriter< Sink >

Base class, using CRTP, that provides a framework for writing vertex attributes to arbitrary locations.

Vertex attribute writing, such as done in glmesh::Draw, has a lot of boilerplate code that can be shared among many different destinations. glmesh::Draw writes to a StreamBuffer. CpuDataWriter writes to an internal std::vector buffer. And so forth.

This provides a standard interface for all of them, as well as a solid codebase for implementing them. To use this, derive from VertexWriter using the CRTP:

class Derived : public VertexWriter<Derived> ...

Your Derived class needs to provide two methods accessible to VertexWriter. You may make this VertexWriter instantiation a friend of your Derived class, to keep these hidden. Derived must provide:

const VertexFormat &GetVertexFormat() const;
void WriteAttribute(const void *pData, size_t bytesPerComponent, size_t currAttrib);

GetVertexFormat just gets a VertexFormat instance, which represents the format of the data used for this writer. It should not change from call to call.

WriteAttribute will be called to write an attribute's data. The pData argument is a pointer to a buffer that is bytesPerComponent * 4 in size. You should copy a number of components worth of data, based on the VertexFormat and the currAttrib index. currAttrib is the current vertex attribute for the data being written.

This class provides VertexWriter::GetCurrAttrib as a protected member function. This returns the current attribute index.

Public Member Functions

 VertexWriter ()
 Creates a VertexWriter class instance.
Attribute Setting Functions

The Attrib functions set the value of the current attribute.

The Attrib series of functions are all templates based on certain types that the Draw class accepts.

If you attempt to use the wrong type for the current attribute, an exception will be thrown. The types must match exactly; there is no narrowing or expansion of shorts into bytes or ints. Nor is there conversion from signed to unsigned types.

Though the types must match, the number of components do not have to exactly match. Per OpenGL standard conventions, if you provide more components for an attribute than a vertex format allows, the extras will be ignored. If you provide fewer, then rest will be filled in with zeros, except for fourth (if applicable), which will be 1.

If you get an unresolved external error for some form of VertexWriter::Attrib, it is because you are not using the correct type. The valid types are, in the order defined in VertexDataType:

  • glm::thalf
  • GLfloat
  • GLdouble
  • GLbyte
  • GLubyte
  • GLshort
  • GLushort
  • GLint
  • GLuint

There are vector versions of these functions. They will work with glm's vector types, but only for certain ones. The 3 floating-point types (glm::hvec, glm::vec, glm::dvec) will work. And if you specifically use glm::detail::vec#<type>, then you can use vector types directly. Otherwise, you should probably stick to the overloads that take a number of scalar values.

MismatchWriterTypeExceptionIf the type you are using does not exactly match the type specified by the VertexFormat for this attribute.
template<typename BaseType >
void Attrib (BaseType x)
template<typename BaseType >
void Attrib (BaseType x, BaseType y)
template<typename BaseType >
void Attrib (const glm::detail::tvec2< BaseType > &val)
template<typename BaseType >
void Attrib (BaseType x, BaseType y, BaseType z)
template<typename BaseType >
void Attrib (const glm::detail::tvec3< BaseType > &val)
template<typename BaseType >
void Attrib (BaseType x, BaseType y, BaseType z, BaseType w)
template<typename BaseType >
void Attrib (const glm::detail::tvec4< BaseType > &val)

Protected Member Functions

size_t GetCurrAttrib () const
 Retrieves the current vertex attribute index, to be used with VertexFormat::GetAttribDesc.

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