Options
All
  • Public
  • Public/Protected
  • All
Menu

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

  • 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

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

Type declaration

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

      Parameters

      • name: string
      • array: number[]

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • x: number

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • array: Float32Array

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

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

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • array: Int32Array

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • mat: Float32Array

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • mat: IMatrixLike

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • matrix: Float32Array

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • matrix: Float32Array

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • vector: IVector3Like

      Returns void

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

Type declaration

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

      Parameters

      • name: string
      • vector: IVector4Like

      Returns void

Accessors

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

    Returns boolean

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

    Returns string

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

    Returns boolean

Methods

  • 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

  • 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

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

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

  • 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

  • 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

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

    Returns void

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

    Returns void

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

    Returns void

  • The underlying WebGL Uniform buffer.

    Returns Nullable<DataBuffer>

    the webgl buffer

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

    Returns Float32Array

    the underlying data as a float array

  • 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

  • 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

  • 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

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

    Returns void

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

  • 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

  • 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 constructor
  • Static method

Settings

Theme