UniformBuffer

Description

class UniformBuffer

Constructor

new UniformBuffer(engine, data, dynamic)

Uniform buffer objects.

     * Handles blocks of uniform on the GPU.

     * If WebGL 2 is not available, this class falls back on traditionnal setUniformXXX calls.

     * For more information, please refer to :

https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object

Parameters

Name Type Description
engine Engine
optional data number[]
optional dynamic boolean

Members

updateMatrix3x3 : (name: string, matrix: Float32Array) => void

Wrapper for updateUniform.

@method updateMatrix3x3

Parameters

Name Type Description
name string
matrix Float32Array

updateMatrix2x2 : (name: string, matrix: Float32Array) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
matrix Float32Array

updateFloat : (name: string, x: number) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
x number

updateFloat2 : (name: string, x: number, y: number, suffix: string) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
x number
y number

updateFloat3 : (name: string, x: number, y: number, z: number, suffix: string) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
x number
y number
z number

updateFloat4 : (name: string, x: number, y: number, z: number, w: number, suffix: string) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
x number
y number
z number
w number

updateMatrix : (name: string, mat: Matrix) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
mat Matrix

updateVector3 : (name: string, vector: Vector3) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
vector Vector3

updateVector4 : (name: string, vector: Vector4) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
vector Vector4

updateColor3 : (name: string, color: Color3, suffix: string) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
color Color3
optional suffix string

updateColor4 : (name: string, color: Color3, alpha: number, suffix: string) => void

Wrapper for updateUniform.

Parameters

Name Type Description
name string
color Color3
alpha number

useUbo : boolean

Indicates if the buffer is using the WebGL2 UBO implementation,

or just falling back on setUniformXXX calls.

isSync : boolean

Indicates if the WebGL underlying uniform buffer is in sync

with the javascript cache data.

Methods

isDynamic() boolean

Indicates if the WebGL underlying uniform buffer is dynamic.

Also, a dynamic UniformBuffer will disable cache verification and always

update the underlying WebGL uniform buffer to the GPU.

getData() Float32Array

The data cache on JS side.

getBuffer() Nullable<WebGLBuffer>

The underlying WebGL Uniform buffer.

addUniform(name, size, number) void

Adds an uniform in the buffer.

Warning : the subsequents calls of this function must be in the same order as declared in the shader

for the layout to be correct !

Parameters

Name Type Description
name string
size number or number

addMatrix(name, mat) void

Wrapper for addUniform.

Parameters

Name Type Description
name string
mat Matrix

addFloat2(name, x, y) void

Wrapper for addUniform.

Parameters

Name Type Description
name string
x number
y number

addFloat3(name, x, y, z) void

Wrapper for addUniform.

Parameters

Name Type Description
name string
x number
y number

addColor3(name, color) void

Wrapper for addUniform.

Parameters

Name Type Description
name string
color Color3

addColor4(name, color, alpha) void

Wrapper for addUniform.

Parameters

Name Type Description
name string
color Color3
alpha number

addVector3(name, vector) void

Wrapper for addUniform.

Parameters

Name Type Description
name string
vector Vector3

addMatrix3x3(name) void

Wrapper for addUniform.

Parameters

Name Type Description
name string

addMatrix2x2(name) void

Wrapper for addUniform.

Parameters

Name Type Description
name string

create() void

Effectively creates the WebGL Uniform Buffer, once layout is completed with addUniform.

update() void

Updates the WebGL Uniform Buffer on the GPU.

If the dynamic flag is set to true, no cache comparison is done.

Otherwise, the buffer will be updated only if the cache differs.

updateUniform(uniformName, data, size) void

Updates the value of an uniform. The update method must be called afterwards to make it effective in the GPU.

Parameters

Name Type Description
uniformName string
data FloatArray
size number

setTexture(name, texture) void

Sets a sampler uniform on the effect.

Parameters

Name Type Description
name string
texture Nullable<BaseTexture>

updateUniformDirectly(uniformName, data) void

Directly updates the value of the uniform in the cache AND on the GPU.

Parameters

Name Type Description
uniformName string
data FloatArray

bindToEffect(effect, name) void

Binds this uniform buffer to an effect.

Parameters

Name Type Description
effect Effect
name string

dispose() void

Disposes the uniform buffer.