Moggle

moggle.core.vbo



struct GenericVbo;
A vertex buffer object.

This is a wrapper around a GLuint generated by glGenBuffers(1, &id). Initially, this id is 0. glGenBuffers is automatically called the first time bind() is called.

Vbo!void is an alias of this.

const @property GLuint id();
The id of this Vao, or 0 if it is not yet created in OpenGL.

const @property bool created();
const bool opCast(T : bool)();
Check if this Vao is already created in OpenGL.

void create();
Force the creation of a OpenGL Vbo, or do nothing if already created. (Calls glGenBuffers.)

void destroy();
Destroy the OpenGL Vbo and reset the id back to 0. (Calls glDeleteBuffers.)

void bind(GLenum buffer);
Create the OpenGL Vbo, if needed, and bind it. (Calls glBindBuffer.)

inout ref inout(SpecificVbo!T) opCast(T : SpecificVbo!T)();
Cast this GenericVbo to a specific SpecificVbo!T.

struct SpecificVbo(T);
A Vbo that knows what type of elements are stored in it.

Vbo!T is an alias of this, except for Vbo!void (which is an alias for GenericVbo).

Contains a single GenericVbo, which is aliased as this. (Which basically means that any SpecificVbo!T is also a GenericVbo.)

this(T[] data_, GLenum usage = GL_STATIC_DRAW);
void data(T[] data_, GLenum usage = GL_STATIC_DRAW);
Store the given data in the Vbo. (Calls glBufferData.)

Examples:
auto v = Vbo!int([1, 2, 3, 4, 5]);
v.data([2, 1, 0]); // Updates the Vbo with new data.


this(size_t n, GLenum usage = GL_STATIC_DRAW);
void resize(size_t size_, GLenum usage = GL_STATIC_DRAW);
Allocate a OpenGL Vbo with space for n elements. (Calls glBufferData with null.)

The contents of the Vbo are uninitialized and thus undefined.

size_t size();
The number of elements stored in this Vbo. (Calls glGetBufferParameteriv with GL_BUFFER_SIZE.)

void clear(GLenum usage = GL_STATIC_DRAW);
Calls resize(0).

auto mapReadOnly();
auto mapWriteOnly();
auto mapReadWrite();
Map the contents of the Vbo in our own memory, temporarily. (Calls glMapBuffer.)

Returns:
An object that behaves like a T[] (or const(T)[], for the read-only version), and reflects the contents of the Vbo. After this object is destructed, slices in that piece of memory are no longer valid (because glUnmapBuffer is then called).

Examples:
auto v = Vbo!int(3);
{
	auto m = v.mapWriteOnly();
	m[] = 5;
	m[1] = 2;
}
assert(v.mapReadOnly()[] == [5, 2, 5]);


template Vbo(T)
An alias for SpecificVbo!T, except that Vbo!void is an alias for GenericVbo.