EAGL.Buffer (eagl v0.1.0)

View Source

Helper functions for OpenGL buffer and vertex array object management. Provides convenient wrappers for common VAO/VBO/EBO operations.

Summary

Functions

Creates a VAO with VBO and EBO for indexed geometry. Returns {vao, vbo, ebo} tuple.

Creates a simple indexed VAO with position-only vertices (3 floats per vertex). Convenience wrapper for indexed geometry with positions only.

Creates a simple VAO with position-only vertices (3 floats per vertex). Convenience wrapper for the most common case.

Creates a VAO with a single VBO containing vertex data. Returns {vao, vbo} tuple.

Deletes a VAO and its associated VBO and EBO.

Deletes a VAO and its associated VBOs.

Converts a list of indices to binary format for OpenGL.

Converts a list of vertex floats to binary format for OpenGL.

Functions

create_indexed_array(vertices, indices, attribute_configs)

@spec create_indexed_array([float()], [integer()], [tuple()]) ::
  {integer(), integer(), integer()}

Creates a VAO with VBO and EBO for indexed geometry. Returns {vao, vbo, ebo} tuple.

Parameters

  • vertices: List of floats representing vertex data
  • indices: List of integers representing vertex indices
  • attribute_configs: List of attribute configurations Each config is {location, size, type, normalized, stride, offset}

Example

vertices = [0.5, 0.5, 0.0, 0.5, -0.5, 0.0, -0.5, -0.5, 0.0, -0.5, 0.5, 0.0]
indices = [0, 1, 3, 1, 2, 3]
{vao, vbo, ebo} = create_indexed_array(vertices, indices, [{0, 3, @gl_float, @gl_false, 0, 0}])

create_indexed_position_array(vertices, indices)

@spec create_indexed_position_array([float()], [integer()]) ::
  {integer(), integer(), integer()}

Creates a simple indexed VAO with position-only vertices (3 floats per vertex). Convenience wrapper for indexed geometry with positions only.

Example

vertices = [0.5, 0.5, 0.0, 0.5, -0.5, 0.0, -0.5, -0.5, 0.0, -0.5, 0.5, 0.0]
indices = [0, 1, 3, 1, 2, 3]  # Two triangles forming a rectangle
{vao, vbo, ebo} = create_indexed_position_array(vertices, indices)

create_position_array(vertices)

@spec create_position_array([float()]) :: {integer(), integer()}

Creates a simple VAO with position-only vertices (3 floats per vertex). Convenience wrapper for the most common case.

Example

vertices = [-0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.0, 0.5, 0.0]
{vao, vbo} = create_position_array(vertices)

create_vertex_array(vertices, attribute_configs)

@spec create_vertex_array([float()], [tuple()]) :: {integer(), integer()}

Creates a VAO with a single VBO containing vertex data. Returns {vao, vbo} tuple.

Parameters

  • vertices: List of floats representing vertex data
  • attribute_configs: List of attribute configurations Each config is {location, size, type, normalized, stride, offset}

Example

vertices = [-0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.0, 0.5, 0.0]
{vao, vbo} = create_vertex_array(vertices, [{0, 3, @gl_float, @gl_false, 0, 0}])

delete_indexed_array(vao, vbo, ebo)

@spec delete_indexed_array(integer(), integer(), integer()) :: :ok

Deletes a VAO and its associated VBO and EBO.

delete_vertex_array(vao, vbos)

@spec delete_vertex_array(integer(), [integer()]) :: :ok
@spec delete_vertex_array(integer(), integer()) :: :ok

Deletes a VAO and its associated VBOs.

indices_to_binary(indices)

@spec indices_to_binary([integer()]) :: binary()

Converts a list of indices to binary format for OpenGL.

vertices_to_binary(vertices)

@spec vertices_to_binary([float()]) :: binary()

Converts a list of vertex floats to binary format for OpenGL.