Skip to Content
EngineGraphicsMesh

Mesh

This is a WIP project - Expect breaking changes to occur.

Overview

Represents a 3D mesh stored in GPU memory as a Vertex Array Object.

Three vertex attribute buffers:

  • PBO - Vertex positions
  • CBO - Vertex colors
  • NBO - Vertex normals
  • UBO - Texture UVs

An index buffer (IBO) drives indexed rendering via glDrawElements.

All native buffers allocated during #create() are freed immediately after upload. They are no longer needed once the data lives on the GPU.

Mesh(...)

public Mesh(Vertex[] vertices, int[] indices) {}

Constructs a mesh from raw vertex and index data.
Call #create() after an OpenGL context is available to upload the data to the GPU.

create()

public void create() {}

Uploads the mesh data to the GPU.
Creates a VAO and three VBOs plus an IBO.

Each VBO is bound to its corresponding vertex attribute location so the shader can read them by
layout(location = N).
Must be called on the thread that owns the OpenGL context, after the context has been made current.

destroy()

public void destroy() {}

Deletes all GPU buffers associated with this mesh.
Should be called when the mesh is no longer needed, to avoid memory leaks.

Getters and Setters

getVertices()

public Vertex[] getVertices() { return vertices; }
Last updated on