Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UniformBuffer

Uniform buffer objects.

Handles blocks of uniform on the GPU.

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

For more information, please refer to : https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object

Hierarchy

  • UniformBuffer

Index

Constructors

constructor

  • new UniformBuffer(engine: ThinEngine, data?: number[], dynamic?: boolean, name?: string, forceNoUniformBuffer?: boolean): UniformBuffer
  • Instantiates a new Uniform buffer objects.

    Handles blocks of uniform on the GPU.

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

    For more information, please refer to :

    see

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

    Parameters

    • engine: ThinEngine

      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

    • Optional name: string

      to assign to the buffer (debugging purpose)

    • Optional forceNoUniformBuffer: boolean

      define that this object must not rely on UBO objects

    Returns UniformBuffer

Properties

updateArraySearch playground for updateArray

updateArray: (name: string, array: number[]) => void

Lambda to Update an array of number 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, array: number[]): void
    • Parameters

      • name: string
      • array: number[]

      Returns void

updateColor3Search playground for updateColor3

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

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: IColor3Like, suffix?: string): void
    • Parameters

      • name: string
      • color: IColor3Like
      • Optional suffix: string

      Returns void

updateColor4Search playground for updateColor4

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

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: IColor3Like, alpha: number, suffix?: string): void
    • Parameters

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

      Returns void

updateDirectColor4Search playground for updateDirectColor4

updateDirectColor4: (name: string, color: IColor4Like, suffix?: string) => void

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: IColor4Like, suffix?: string): void
    • Parameters

      • name: string
      • color: IColor4Like
      • Optional suffix: string

      Returns void

updateFloatSearch playground for updateFloat

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

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

updateFloat2Search playground for updateFloat2

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

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

updateFloat3Search playground for updateFloat3

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

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

updateFloat4Search playground for updateFloat4

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

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

updateFloatArraySearch playground for updateFloatArray

updateFloatArray: (name: string, array: Float32Array) => void

Lambda to Update an array 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, array: Float32Array): void
    • Parameters

      • name: string
      • array: Float32Array

      Returns void

updateIntSearch playground for updateInt

updateInt: (name: string, x: number, suffix?: string) => void

Lambda to Update a int 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, suffix?: string): void
    • Parameters

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

      Returns void

updateInt2Search playground for updateInt2

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

Lambda to Update a vec2 of int 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

updateInt3Search playground for updateInt3

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

Lambda to Update a vec3 of int 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

updateInt4Search playground for updateInt4

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

Lambda to Update a vec4 of int 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

updateIntArraySearch playground for updateIntArray

updateIntArray: (name: string, array: Int32Array) => void

Lambda to Update an array of number 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, array: Int32Array): void
    • Parameters

      • name: string
      • array: Int32Array

      Returns void

updateMatricesSearch playground for updateMatrices

updateMatrices: (name: string, mat: Float32Array) => void

Lambda to Update an array of 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: Float32Array): void
    • Parameters

      • name: string
      • mat: Float32Array

      Returns void

updateMatrixSearch playground for updateMatrix

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

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: IMatrixLike): void
    • Parameters

      • name: string
      • mat: IMatrixLike

      Returns void

updateMatrix2x2Search playground for updateMatrix2x2

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

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

updateMatrix3x3Search playground for updateMatrix3x3

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

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

updateVector3Search playground for updateVector3

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

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: IVector3Like): void
    • Parameters

      • name: string
      • vector: IVector3Like

      Returns void

updateVector4Search playground for updateVector4

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

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: IVector4Like): void
    • Parameters

      • name: string
      • vector: IVector4Like

      Returns void

Accessors

isSync

  • get isSync(): boolean
  • Indicates if the WebGL underlying uniform buffer is in sync with the javascript cache data.

    Returns boolean

name

  • get name(): string
  • Gets the name of this buffer

    Returns string

useUbo

  • get useUbo(): boolean
  • Indicates if the buffer is using the WebGL2 UBO implementation, or just falling back on setUniformXXX calls.

    Returns boolean

Methods

addColor3Search playground for addColor3

  • addColor3(name: string, color: IColor3Like): 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: IColor3Like

      Define the vec3 from a Color

    Returns void

addColor4Search playground for addColor4

  • addColor4(name: string, color: IColor3Like, 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: IColor3Like

      Define the rgb components from a Color

    • alpha: number

      Define the a component of the vec4

    Returns void

addFloat2Search playground for addFloat2

  • 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

addFloat3Search playground for addFloat3

  • 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

addMatrixSearch playground for addMatrix

  • addMatrix(name: string, mat: IMatrixLike): 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: IMatrixLike

      A 4x4 matrix.

    Returns void

addMatrix2x2Search playground for addMatrix2x2

  • 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

addMatrix3x3Search playground for addMatrix3x3

  • 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

addUniformSearch playground for addUniform

  • addUniform(name: string, size: number | number[], arraySize?: 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 ! The addUniform function only handles types like float, vec2, vec3, vec4, mat4, meaning size=1,2,3,4 or 16. It does not handle struct types.

    Parameters

    • name: string

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

    • size: number | number[]

      Data size, or data directly.

    • Optional arraySize: number

      The number of elements in the array, 0 if not an array.

    Returns void

addVector3Search playground for addVector3

  • addVector3(name: string, vector: IVector3Like): 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: IVector3Like

      Define the vec3 components from a Vector

    Returns void

bindToEffectSearch playground for bindToEffect

  • bindToEffect(effect: Effect, name: string): void
  • Associates an effect to this uniform buffer

    Parameters

    • effect: Effect

      Define the effect to associate the buffer to

    • name: string

      Name of the uniform block in the shader.

    Returns void

bindUniformBufferSearch playground for bindUniformBuffer

  • bindUniformBuffer(): void
  • Binds the current (GPU) buffer to the effect

    Returns void

createSearch playground for create

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

    Returns void

disposeSearch playground for dispose

  • dispose(): void
  • Disposes the uniform buffer.

    Returns void

getBufferSearch playground for getBuffer

  • The underlying WebGL Uniform buffer.

    Returns Nullable<DataBuffer>

    the webgl buffer

getDataSearch playground for getData

  • getData(): Float32Array
  • The data cache on JS side.

    Returns Float32Array

    the underlying data as a float array

isDynamicSearch playground for isDynamic

  • 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

setDataBufferSearch playground for setDataBuffer

  • Sets the current state of the class (_bufferIndex, _buffer) to point to the data buffer passed in parameter if this buffer is one of the buffers handled by the class (meaning if it can be found in the _buffers array) This method is meant to be able to update a buffer at any time: just call setDataBuffer to set the class in the right state, call some updateXXX methods and then call udpate() => that will update the GPU buffer on the graphic card

    Parameters

    Returns boolean

    true if the buffer has been found and the class internal state points to it, else false

setTextureSearch playground for setTexture

  • Sets a sampler uniform on the effect.

    Parameters

    • name: string

      Define the name of the sampler.

    • texture: Nullable<ThinTexture>

      Define the texture to set in the sampler

    Returns void

unbindEffectSearch playground for unbindEffect

  • unbindEffect(): void
  • Dissociates the current effect from this uniform buffer

    Returns void

updateSearch playground for update

  • 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

updateUniformSearch playground for updateUniform

  • 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

updateUniformArraySearch playground for updateUniformArray

  • updateUniformArray(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

updateUniformDirectlySearch playground for updateUniformDirectly

  • 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

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method