Attribute

Lore. Attribute

A class representing an attribute.

Constructor

new Attribute(data, attributeLength, name)

Source:
Properties:
Name Type Attributes Default Description
type String

The type name of this object (Lore.Attribute).

data *

The data represented by the attribute in a 1D array. Usually a Float32Array.

attributeLength Number <optional>
3

The length of the attribute. '3' for Vector3f.

name String

The name of this attribut. Must be the name used by the shader.

size Number

The length of the attribute values (defined as data.length / attributeLength).

buffer WebGLBuffer

The bound WebGLBuffer.

attributeLocation GLint

The attribute location for this attribute.

bufferType GLenum

The buffer target. As of WebGL 1: gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER.

drawMode GLenum

The draw mode. As of WebGL 1: gl.STATIC_DRAW, gl.DYNAMIC_DRAW or gl.STREAM_DRAW.

stale Boolean

A boolean indicating whether or not this attribute has changed and needs to be updated.

Creates an instance of Attribute.

Parameters:
Name Type Description
data *

The data represented by the attribute in a 1D array. Usually a Float32Array.

attributeLength Number

The length of the attribute (3 for RGB, XYZ, ...).

name String

The name of the attribute.

Methods

bind(gl)

Source:

Bind the buffer of this attribute. The attribute must exist in the current shader.

Parameters:
Name Type Description
gl WebGLRenderingContext

The WebGL rendering context.

createBuffer(gl, program, bufferType, drawMode)

Source:

Create a new WebGL buffer.

Parameters:
Name Type Description
gl WebGLRenderingContext

The WebGL rendering context.

program WebGLProgram

A WebGL program.

bufferType GLenum

The buffer type.

drawMode GLenum

The draw mode.

getGlType(gl) → {Number}

Source:

Returns the gl type. Currently only float is supported.

Parameters:
Name Type Description
gl WebGLRenderingContext

The WebGL rendering context.

Returns:

The type.

Type
Number

getW(index) → {Number}

Source:

Gets the w value at a given index.

Parameters:
Name Type Description
index Number

The index.

Returns:

The w value at a given index.

Type
Number

getX(index) → {Number}

Source:

Gets the x value at a given index.

Parameters:
Name Type Description
index Number

The index.

Returns:

The x value at a given index.

Type
Number

getY(index) → {Number}

Source:

Gets the y value at a given index.

Parameters:
Name Type Description
index Number

The index.

Returns:

The y value at a given index.

Type
Number

getZ(index) → {Number}

Source:

Gets the z value at a given index.

Parameters:
Name Type Description
index Number

The index.

Returns:

The z value at a given index.

Type
Number

setFromVector(index, v)

Source:

Set the attribute value from a vector at a given index. The vector should have the same number of components as is the length of this attribute.

Parameters:
Name Type Description
index Number

The index at which to replace / set the value (is calculated as index * attributeLength).

v Lore.Vector3f

A vector.

setFromVectorArray(arr)

Source:

Set the attribute values from vectors in an array.

Parameters:
Name Type Description
arr Array.<Lore.Vector3f>

An array containing vectors. The number of components of the vectors must have the same length as the attribute length specified.

setW(index, value)

Source:

Set the w value at a given index.

Parameters:
Name Type Description
index Number

The index.

value Number

A number.

setX(index, value)

Source:

Set the x value at a given index.

Parameters:
Name Type Description
index Number

The index.

value Number

A number.

setY(index, value)

Source:

Set the y value at a given index.

Parameters:
Name Type Description
index Number

The index.

value Number

A number.

setZ(index, value)

Source:

Set the z value at a given index.

Parameters:
Name Type Description
index Number

The index.

value Number

A number.

update(gl)

Source:

Update the attribute in order for changes to take effect.

Parameters:
Name Type Description
gl WebGLRenderingContext

The WebGL rendering context.