GLMesh

A GLMesh stores the vertex and index buffers necessary to render a mesh.

Constructor

new L3D.GLMesh()

Properties

numTriangles number

The number of triangles to be drawn.

numVertices number

The number of points to be drawn.

Methods

static load(gl, buffers, options)GLMesh

Static method to create a mesh from a list of common streams

Parameters
gl GLContext
buffers Object
options Object
Returns
GLMesh

addBuffer(name, buffer)

Add a buffer to be used by the mesh.

Parameters
name String
buffer GLBuffer

addBuffers(vertexBuffers, indexBuffers, usage)

Adds vertex and indices buffers to a mesh

Parameters
vertexBuffers Object
indexBuffers Object
usage number

STATIC_DRAW, DYNAMIC_DRAW, STREAM_DRAW

bindBuffers(shader)

Bind all vertex buffers to the shader by attribute name

Parameters
shader GLShader

clone(gl)GLMesh

Creates a clone of the mesh, duplicating the data arrays.

Parameters
gl GLContext
Returns
GLMesh

cloneShared(gl)GLMesh

Creates a clone of the mesh, but the data arrays are shared between both meshes.

Parameters
gl GLContext
Returns
GLMesh

createIndexBuffer(name, data, usage)GLBuffer

Creates a new empty index buffer and attachs it to this mesh

Parameters
name String
data *
usage number
Returns
GLBuffer

createVertexBuffer(name, data, attribute, itemSize, usage)GLBuffer

Creates a new empty buffer and attachs it to this mesh

Parameters
name String

Name of the buffer

data ArrayBufferView

the data in typed array format [optional, if ommited it created an empty array of getNumVertices() * itemSize]

attribute String

name of the stream in the shader "a_P","a_N",... [optional, if omitted is used the common_buffers]

itemSize number

itemSize components per vertex [optional, if ommited is used the commonBuffers, if not found then uses 3]

usage number

STATIC_DRAW (default), DYNAMIC_DRAW, STREAM_DRAW

Returns
GLBuffer

deleteBuffers()

Delete all buffers used by the mesh

freeData()

Remove all local memory from the streams (leaving it only in the VRAM) to save RAM

getBuffer(name)GLBuffer

Returns a vertex buffer

Parameters
name String
Returns
GLBuffer

getIndexBuffer(name)GLBuffer

Returns an index buffer with the given name.

Parameters
name String
Returns
GLBuffer

getVertexBuffer(name)GLBuffer

Returns a vertex buffer with the given name.

Parameters
name String
Returns
GLBuffer

removeIndexBuffer(name, free)

Removes an index buffer from the mesh

Parameters
name String

The name of the buffer

free bool

if you want to remove the data from the GPU

removeVertexBuffer(name, free)

Removes a vertex buffer from the mesh

Parameters
name String

Name of the buffer

free bool

if you want to remove the data from the GPU

totalMemory() → number

Returns the amount of memory used by this mesh in bytes (sum of all buffers)

Returns
number

unbindBuffers(shader)

Unbind all vertex buffers from the shader

Parameters
shader GLShader

updateVertexBuffer(name, data, attribute, itemSize, usage)

Updates a vertex buffer

Parameters
name String
data *
attribute String
itemSize number
usage number

upload(usage)

Uploads data inside buffers to the GPU

Parameters
usage number