video.glvertexbuffer

OpenGL vertex buffer.

struct GLVertexBuffer(Vertex) if (is(Vertex == GLVertex2DColored) || is(Vertex == GLVertex2DTextured));

Buffer storing vertices of specified type.

Also handles passing vertex data to OpenGL and drawing it.
Vertices are drawn using an index array as triangles - i.e. every 3 indices specify a triangle.

Vertex[] verticesAllocated_;

Memory allocated for vertices.

Vertex[] vertices_;

Vertex data.

uint[] indicesAllocated_;

Memory allocated for indices.

uint[] indices_;

Index data.

GLuint vbo_;

VBO handle, used in VBO mode.

GLuint ibo_;

IBO handle, used in VBO mode.

GLDrawMode mode_;

Draw mode of the buffer.

bool isNull_;

Is this vertex buffer null (uninitialized)?

this(const GLDrawMode mode, const size_t preallocate);

Construct a GLVertexBuffer.

Parameters:
GLDrawMode mode Draw mode of the buffer.
size_t preallocate Number of vertices to preallocate space for. Avoids unnecessary reallocations. Will preallocate 2 times as many indices.
void startDraw();

Start drawing with this buffer. Must be called before calls to draw().

void endDraw();

End drawing with this buffer. Must be called after calls to draw().

Vertex[] vertices();

Access vertex data as an array.

uint[] indices();

Access index data as an array.

const uint vertexCount();

Get number of vertices in the buffer.

const uint indexCount();

Get number of indices in the buffer.

void vertexCount(const size_t len);

Set number of vertices in the buffer (to add more vertices).

void indexCount(const size_t len);

Set number of indices in the buffer (to add more indices).

int draw(ref const GLVertexGroup group);

Draw a vertex group using data stored in this buffer.

Vertex group passed must be using data in this buffer, otherwise undefined behavior might occur.
This will only draw the vertices - other state such as shader, texture page or scissor rectangle must be set before this call.

Parameters:
GLVertexGroup group Vertex group to draw.
Returns:
0 if drawing was succesful. -1 if a required shader attribute was not found in group's shader.
void reset();

Reset the buffer, deleting all vertices, indices.

void initVBO();

Initialize OpenGL VBOs, only used in VertexBuffer draw mode.

void destroyVBO();

Destroy OpenGL VBOs, only used in VertexBuffer draw mode.

struct GLVertexGroup;

Vertex group.

Stores state shared by all of its vertices (texture page, shader, scissor) and can be drawn in one function call in some draw modes.
Individual draw calls are merged into vertex groups.

GLShader* shader;

Shader used to draw the group.

TexturePage!(BinaryTexturePacker,GLTextureBackend)* texturePage;

Texture page of the group if it uses texturing.

uint scissor;

Scissor index of the group. uint.max means no scissor is used.

float viewZoom;

View zoom. 1.0 is normal, > 1.0 is zoomed in, < 1.0 is zoomed out.

Vector2f viewOffset;

Current view offset in screen space.

uint offset;

Offset to index buffer used.

uint vertices;

Vertex count of the group, i.e. indices in index buffer used.

GLVertexType vertexType;

Vertex type of the group.