Moggle

moggle.xxx.vertices



class Vertices;
Manages an OpenGL vertex array object (Vao).

Keeps track of attributes of Vertices stored inside Buffers.

class Attribute;
A vertex attribute.

immutable string name;
The name of the attribute.

GenericBuffer buffer;
The Buffer in which the data is stored.

AttributeParameters parameters;
How and where the data is stored in the Buffer. (See moggle.core.vao.)

const @property GLuint index();
The index of the attribute if it is enabled, or GLuint.max if it is not.

const @property bool enabled();
Check whether the attribute is enabled or not.

void enable(GLuint index);
Enable the attribute.

Calls vao.setAttribute(index, buffer.vbo, parameters), which will call glEnableVertexAttribArray and glVertexAttribPointer.

void disable();
Disable the attribute.

If enabled, calls vao.disableAttribute(index), which will call glDisableVertexAttribArray.

const string toString();
Get a string representation of this attribute (just the name).

@property auto attributes();
The attributes of the Vertices.

Returns:
A delegate that can be foreach'ed over.

@property auto enabledAttributes();
The attributes that are enabled.

Returns:
A delegate that can be foreach'ed over.

inout auto attribute(string name, string file = __FILE__, size_t line = __LINE__);
inout auto attribute(GLuint index, string file = __FILE__, size_t line = __LINE__);
Gives you the vertex Attribute with the given name or index.

Throws:
AttributeError when there is no such attribute. The exception message doesn't only tell the name/index of the attribute that doesn't exist, but also lists the attributes that do exist.

inout auto hasAttribute(string name);
inout auto hasAttribute(GLuint index);
Gives you a pointer to the Attribute with the given name or index, or null if it doesn't exist.

Attribute setAttribute()(in string name, GenericBuffer buffer, in AttributeParameters parameters);
Attribute setAttribute(T)(in string name, Buffer!T buffer);
Add or change an attribute.

Does not yet call vao.setAttribute(...). It only stores the information in the attributes map, such that you can later call attribute(name).enable(index), which will call vao.setAttribute.

The second version automatically deduces the AttributeParameters using attributeParametersFor!T. (Defined in moggle.core.vao.)

void setAttributes(T)(Buffer!T buffer) if (is(T == struct));
void setAttributes(T)(Buffer!T buffer, string[string] names) if (is(T == struct));
Automatically calls setAttribute for each member of the struct T.

The second version takes a map that maps the names of the members of T to the names of the attributes. If a name is mapped to null, the member is ignored.

Example:
struct Vertex { HVector4f position; Vector3f normal; HVector4 color; }
auto b = new Buffer!Vertex(...);
auto v = new Vertices;

// This:
v.setAttributes(b);
// does the same as:
v.setAttribute("position", b, attributeParametersFor!(Vertex, "position"));
v.setAttribute("normal", b, attributeParametersFor!(Vertex, "normal"));
v.setAttribute("color", b, attributeParametersFor!(Vertex, "color"));

// Also, this:
v.setAttributes(b, ["position":"pos", "normal":null]);
// does the same as:
v.setAttribute("pos", b, attributeParametersFor!(Vertex, "position"));
v.setAttribute("color", b, attributeParametersFor!(Vertex, "color"));


void bind();
Bind the Vao. (Calls vao.bind().)

class AttributeError: object.Exception;
The error that is thrown when Vertices.attribute(name) doesn't find an attribute with that name.