Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Buffer

Wrapper around an OpenGL array or element array buffer. This buffer may be used to be attached to multiple VAOs.

Hierarchy

  • AbstractObject<WebGLBuffer>
    • Buffer

Implements

  • Bindable

Index

Constructors

constructor

  • Object constructor, requires a context and a valid identifier.

    Parameters

    • context: Context

      Valid context to create the object for.

    • Optional identifier: string

      Meaningful name for identification of this instance.

    Returns Buffer

Properties

Protected _context

_context: Context
see

context

Protected _identifier

_identifier: string

Protected _object

_object: undefined | WebGLBuffer
see

object

Protected _referenceCount

_referenceCount: number = 0

Number of references to this object. If at least a single reference was counted, this object can neither be initialized (and thus created) nor uninitialized (and thus deleted). The reference count is controlled via ref() and unref() functions.

Protected _target

_target: undefined | number = ...
see

target

Protected _valid

_valid: boolean = false
see

valid

Protected assertInitialized

assertInitialized: () => void = ...

Asserts the objects initialization status to be true. Note that the implementation is cached and forwarded to either an empty function when initialized and to an acutal assert(false) otherwise.

Type declaration

    • (): void
    • Returns void

Protected assertUninitialized

assertUninitialized: () => void = ...

Asserts the objects initialization status to be false. Note that the implementation is cached and forwarded to either an empty function when uninitialized and to an acutal assert(false) otherwise.

Type declaration

    • (): void
    • Returns void

Static Readonly DEFAULT_BUFFER

DEFAULT_BUFFER: undefined = ...

Default buffer, e.g., used for unbind.

Accessors

bytes

  • get bytes(): number
  • Returns the number of bytes this object approximately allocates on the GPU.

    Returns number

context

  • Read-only access to the objects context, used to get context information and WebGL API access.

    Returns Context

identifier

  • get identifier(): string
  • Every GPU asset that allocates memory should provide a human readable identifier for GPU allocation tracking and debugging purposes. Please note that the identifier might changed on initialization due to the generation and assignment of a unique identifier.

    Returns string

    • This assets identifier used for gpu allocation tracking and debugging.

initialized

  • get initialized(): boolean
  • Property getter for readonly access to the initialization status of an initializable instance.

    Returns boolean

object

  • get object(): T

target

  • get target(): undefined | number
  • Target to which the buffer object is bound (either GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER). Readonly access to the target (as specified on initialization) the buffer will be bound to.

    Returns undefined | number

valid

  • get valid(): boolean
  • Cached object status used to derive validity when initialized.

    Returns boolean

    • True if the object status is complete, false otherwise.

Methods

attribDisable

  • attribDisable(index: number, bind?: boolean, unbind?: boolean): void
  • Disables a buffer binding point.

    Parameters

    • index: number

      Index of the vertex attribute that is to be disabled.

    • bind: boolean = true

      Allows to skip binding the object (e.g., when binding is handled outside).

    • unbind: boolean = true

      Allows to skip unbinding the object (e.g., when binding is handled outside).

    Returns void

attribEnable

  • attribEnable(index: number, size: number, type: number, normalized?: boolean, stride?: number, offset?: number, bind?: boolean, unbind?: boolean): void
  • Specifies the memory layout of the buffer for a binding point. Integer data will be cast to float according to "normalized".

    see

    attribEnableInt

    Parameters

    • index: number

      Index of the vertex attribute that is to be setup and enabled.

    • size: number

      Number of components per vertex attribute.

    • type: number

      Data type of each component in the array.

    • normalized: boolean = false

      Whether integer data values should be normalized when being casted to a float.

    • stride: number = 0

      Offset in bytes between the beginning of consecutive vertex attributes.

    • offset: number = 0

      Offset in bytes of the first component in the vertex attribute array.

    • bind: boolean = true

      Allows to skip binding the object (e.g., when binding is handled outside).

    • unbind: boolean = true

      Allows to skip unbinding the object (e.g., when binding is handled outside).

    Returns void

attribEnableInt

  • attribEnableInt(index: number, size: number, type: number, stride?: number, offset?: number, bind?: boolean, unbind?: boolean): void
  • Specifies the memory layout of the buffer for a binding point. Only to be used for integers.

    see

    attribEnable

    Parameters

    • index: number

      Index of the vertex attribute that is to be setup and enabled.

    • size: number

      Number of components per vertex attribute.

    • type: number

      Data type of each component in the array.

    • stride: number = 0

      Offset in bytes between the beginning of consecutive vertex attributes.

    • offset: number = 0

      Offset in bytes of the first component in the vertex attribute array.

    • bind: boolean = true

      Allows to skip binding the object (e.g., when binding is handled outside).

    • unbind: boolean = true

      Allows to skip unbinding the object (e.g., when binding is handled outside).

    Returns void

bind

  • bind(): void
  • Binds the buffer object as buffer to predefined target.

    Returns void

Protected create

  • create(target: number): undefined | WebGLBuffer
  • Create a buffer object on the GPU.

    Parameters

    • target: number

    Returns undefined | WebGLBuffer

data

  • data(data: number | ArrayBufferView | ArrayBuffer, usage: number, bind?: boolean, unbind?: boolean): void
  • Creates the buffer object's data store and updates the objects status.

    Parameters

    • data: number | ArrayBufferView | ArrayBuffer

      Data that will be copied into the objects data store.

    • usage: number

      Usage pattern of the data store.

    • bind: boolean = true

      Allows to skip binding the object (e.g., when binding is handled outside).

    • unbind: boolean = true

      Allows to skip unbinding the object (e.g., when binding is handled outside).

    Returns void

Protected delete

  • delete(): void
  • Delete the buffer object on the GPU. This should have the reverse effect of create.

    Returns void

initialize

  • initialize(...args: any[]): boolean
  • override

    Ensure that an object handle is created at the point of initialization. When overriding this function super.initialize() has to be invoked immediately/first. Please note that initialization of invalid object raises an assertion in order to prevent further actions without a valid WebGL object. After object creation the valid property is expected to be set accordingly.

    Parameters

    • Rest ...args: any[]

    Returns boolean

ref

  • ref(): void
  • Increment the reference count of this object.

    Returns void

subData

  • subData(dstByteOffset: number, srcData: ArrayBufferView | ArrayBuffer, srcOffset?: number, length?: number, bind?: boolean, unbind?: boolean): void
  • Updates a subset of a buffer object's data store.

    Parameters

    • dstByteOffset: number

      Offset in bytes where the data replacement will start.

    • srcData: ArrayBufferView | ArrayBuffer

      Data that will be copied into the data store.

    • srcOffset: number = 0

      Element index offset where to start reading the buffer.

    • length: number = 0

      Length of the data to copy into the data store.

    • bind: boolean = true

      Allows to skip binding the object (e.g., when binding is handled outside).

    • unbind: boolean = true

      Allows to skip unbinding the object (e.g., when binding is handled outside).

    Returns void

unbind

  • unbind(): void
  • Binds null as current buffer to predefined target;

    Returns void

uninitialize

  • uninitialize(): void
  • override

    Ensure that an object handle is deleted, invalidated, and its allocated GPU resources are set to zero. When overriding this function super.uninitialize() has to be invoked last/at the end. Note that an object cannot be uninitialized if it is referenced (reference count > 0).

    Returns void

unref

  • unref(): void
  • Decrement the reference count of this object.

    Returns void

Static Protected Readonly assertInitializedFalse

Static Protected Readonly assertUninitializedFalse

Static assert_initialized

  • assert_initialized(): MethodDecorator
  • Method decorator for asserting the initialization status of an initializable to be true.

    see

    assertInitialized

    Returns MethodDecorator

Static assert_uninitialized

  • assert_uninitialized(): MethodDecorator

Static discard

  • discard(): MethodDecorator
  • Method decorator for discarding of Initializable inheritors. This decorator asserts the initialization status of the instance that is to be discarded, invokes its uninitialization, and falsifies the initialization status. In order to encourage the use of assertInitialized and assertUninitialized they are dynamically bound to a static, always-failing assert and an empty/undefined function respectively.

    Returns MethodDecorator

Static initialize

  • initialize(): MethodDecorator
  • Method decorator for initialization of Initializable inheritors. This decorator asserts the initialization status of the instance that is to be initialized, invokes its initialization with arbitrary number of parameters, and sets the initialization status to the initialization success (either false or true). In order to encourage the use of assertInitialized and assertUninitialized they are dynamically bound to either a static, always-failing assert or an empty/undefined function.

    Returns MethodDecorator

Static uninitialize

  • uninitialize(): MethodDecorator
  • Method decorator for uninitialization of Initializable inheritors. This decorator asserts the initialization status of the instance that is to be uninitialized, invokes its uninitialization, and falsifies the initialization status. In order to encourage the use of assertInitialized and assertUninitialized they are dynamically bound to a static, always-failing assert and an empty/undefined function respectively.

    Returns MethodDecorator