UniformBuffer

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

Hierarchy

  • UniformBuffer

Index

Constructors

constructor

Find examples in Playground
  • Instantiates a new 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 :

    see

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

    Parameters

    • engine: Engine

      Define the engine the buffer is associated with

    • Optional data: number[]

      Define the data contained in the buffer

    • Optional dynamic: boolean

      Define if the buffer is updatable

    Returns UniformBuffer

Properties

isSync

Find examples in Playground
isSync: boolean

Indicates if the WebGL underlying uniform buffer is in sync with the javascript cache data.

updateColor3

Find examples in Playground
updateColor3: function

Lambda to Update vec3 of float from a Color in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, color: Color3, suffix?: string): void
    • Parameters

      • name: string
      • color: Color3
      • Optional suffix: string

      Returns void

updateColor4

Find examples in Playground
updateColor4: function

Lambda to Update vec4 of float from a Color in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, color: Color3, alpha: number, suffix?: string): void
    • Parameters

      • name: string
      • color: Color3
      • alpha: number
      • Optional suffix: string

      Returns void

updateFloat

Find examples in Playground
updateFloat: function

Lambda to Update a single float in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, x: number): void
    • Parameters

      • name: string
      • x: number

      Returns void

updateFloat2

Find examples in Playground
updateFloat2: function

Lambda to Update a vec2 of float in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, x: number, y: number, suffix?: string): void
    • Parameters

      • name: string
      • x: number
      • y: number
      • Optional suffix: string

      Returns void

updateFloat3

Find examples in Playground
updateFloat3: function

Lambda to Update a vec3 of float in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, x: number, y: number, z: number, suffix?: string): void
    • Parameters

      • name: string
      • x: number
      • y: number
      • z: number
      • Optional suffix: string

      Returns void

updateFloat4

Find examples in Playground
updateFloat4: function

Lambda to Update a vec4 of float in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, x: number, y: number, z: number, w: number, suffix?: string): void
    • Parameters

      • name: string
      • x: number
      • y: number
      • z: number
      • w: number
      • Optional suffix: string

      Returns void

updateMatrix

Find examples in Playground
updateMatrix: function

Lambda to Update a 4x4 Matrix in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, mat: Matrix): void
    • Parameters

      Returns void

updateMatrix2x2

Find examples in Playground
updateMatrix2x2: function

Lambda to Update a 2x2 Matrix in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, matrix: Float32Array): void
    • Parameters

      • name: string
      • matrix: Float32Array

      Returns void

updateMatrix3x3

Find examples in Playground
updateMatrix3x3: function

Lambda to Update a 3x3 Matrix in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, matrix: Float32Array): void
    • Parameters

      • name: string
      • matrix: Float32Array

      Returns void

updateVector3

Find examples in Playground
updateVector3: function

Lambda to Update vec3 of float from a Vector in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, vector: Vector3): void
    • Parameters

      Returns void

updateVector4

Find examples in Playground
updateVector4: function

Lambda to Update vec4 of float from a Vector in a uniform buffer. This is dynamic to allow compat with webgl 1 and 2. You will need to pass the name of the uniform as well as the value.

Type declaration

    • (name: string, vector: Vector4): void
    • Parameters

      Returns void

useUbo

Find examples in Playground
useUbo: boolean

Indicates if the buffer is using the WebGL2 UBO implementation, or just falling back on setUniformXXX calls.

Methods

addColor3

Find examples in Playground
  • addColor3(name: string, color: Color3): void
  • Adds a vec3 to the uniform buffer.

    Parameters

    • name: string

      Name of the uniform, as used in the uniform block in the shader.

    • color: Color3

      Define the vec3 from a Color

    Returns void

addColor4

Find examples in Playground
  • addColor4(name: string, color: Color3, alpha: number): void
  • Adds a vec4 to the uniform buffer.

    Parameters

    • name: string

      Name of the uniform, as used in the uniform block in the shader.

    • color: Color3

      Define the rgb components from a Color

    • alpha: number

      Define the a component of the vec4

    Returns void

addFloat2

Find examples in Playground
  • addFloat2(name: string, x: number, y: number): void
  • Adds a vec2 to the uniform buffer.

    Parameters

    • name: string

      Name of the uniform, as used in the uniform block in the shader.

    • x: number

      Define the x component value of the vec2

    • y: number

      Define the y component value of the vec2

    Returns void

addFloat3

Find examples in Playground
  • addFloat3(name: string, x: number, y: number, z: number): void
  • Adds a vec3 to the uniform buffer.

    Parameters

    • name: string

      Name of the uniform, as used in the uniform block in the shader.

    • x: number

      Define the x component value of the vec3

    • y: number

      Define the y component value of the vec3

    • z: number

      Define the z component value of the vec3

    Returns void

addMatrix

Find examples in Playground
  • addMatrix(name: string, mat: Matrix): void
  • Adds a Matrix 4x4 to the uniform buffer.

    Parameters

    • name: string

      Name of the uniform, as used in the uniform block in the shader.

    • mat: Matrix

      A 4x4 matrix.

    Returns void

addMatrix2x2

Find examples in Playground
  • addMatrix2x2(name: string): void
  • Adds a Matrix 2x2 to the uniform buffer.

    Parameters

    • name: string

      Name of the uniform, as used in the uniform block in the shader.

    Returns void

addMatrix3x3

Find examples in Playground
  • addMatrix3x3(name: string): void
  • Adds a Matrix 3x3 to the uniform buffer.

    Parameters

    • name: string

      Name of the uniform, as used in the uniform block in the shader.

    Returns void

addUniform

Find examples in Playground
  • addUniform(name: string, size: number | 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: string

      Name of the uniform, as used in the uniform block in the shader.

    • size: number | number[]

      Data size, or data directly.

    Returns void

addVector3

Find examples in Playground
  • addVector3(name: string, vector: Vector3): void
  • Adds a vec3 to the uniform buffer.

    Parameters

    • name: string

      Name of the uniform, as used in the uniform block in the shader.

    • vector: Vector3

      Define the vec3 components from a Vector

    Returns void

bindToEffect

Find examples in Playground
  • bindToEffect(effect: Effect, name: string): void
  • Binds this uniform buffer to an effect.

    Parameters

    • effect: Effect

      Define the effect to bind the buffer to

    • name: string

      Name of the uniform block in the shader.

    Returns void

create

Find examples in Playground
  • create(): void
  • Effectively creates the WebGL Uniform Buffer, once layout is completed with addUniform.

    Returns void

dispose

Find examples in Playground
  • dispose(): void
  • Disposes the uniform buffer.

    Returns void

getBuffer

Find examples in Playground
  • The underlying WebGL Uniform buffer.

    Returns Nullable<WebGLBuffer>

    the webgl buffer

getData

Find examples in Playground
  • getData(): Float32Array
  • The data cache on JS side.

    Returns Float32Array

    the underlying data as a float array

isDynamic

Find examples in Playground
  • 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.

    Returns boolean

    if Dynamic, otherwise false

setTexture

Find examples in Playground
  • Sets a sampler uniform on the effect.

    Parameters

    • name: string

      Define the name of the sampler.

    • texture: Nullable<BaseTexture>

      Define the texture to set in the sampler

    Returns void

update

Find examples in Playground
  • 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.

    Returns void

updateUniform

Find examples in Playground
  • updateUniform(uniformName: string, data: FloatArray, size: number): void
  • Updates the value of an uniform. The update method must be called afterwards to make it effective in the GPU.

    Parameters

    • uniformName: string

      Define the name of the uniform, as used in the uniform block in the shader.

    • data: FloatArray

      Define the flattened data

    • size: number

      Define the size of the data.

    Returns void

updateUniformDirectly

Find examples in Playground
  • updateUniformDirectly(uniformName: string, data: FloatArray): void
  • Directly updates the value of the uniform in the cache AND on the GPU.

    Parameters

    • uniformName: string

      Define the name of the uniform, as used in the uniform block in the shader.

    • data: FloatArray

      Define the flattened data

    Returns void

Generated using TypeDoc