Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Framebuffer

WebGL Framebuffer base implementation providing size accessors and requiring for bind, unbind, resize, validity, and initialization implementations.

@todo add usage example

Hierarchy

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 Framebuffer

Properties

Protected _buffersByAttachment

_buffersByAttachment: Map<number, Renderbuffer> = ...

Access to all attached renderbuffer objects.

Protected _clearColors

_clearColors: GLclampf4[]

Protected _clearDepth

_clearDepth: number

RGBA color, depth value, or stencil value used for clearing the associated buffer.

Protected _clearStencil

_clearStencil: number

Protected _colorClearQueue

_colorClearQueue: number[] = ...

Queue of all draw buffers that are to be cleared on clear.

Protected _context

_context: Context
see

context

Protected _drawBuffers

_drawBuffers: number[] = ...

Protected _drawBuffersChanged

_drawBuffersChanged: boolean = false

Protected _identifier

_identifier: string

Protected _object

_object: undefined | WebGLFramebuffer
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 _texturesByAttachment

_texturesByAttachment: Map<number, Texture2D> = ...

Access to all attached texture objects.

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

clear

clear: (mask: number, bind?: boolean, unbind?: boolean, colorClearQueue?: number[]) => void

Depending on the webgl version and provided bitmask, clears attachments of the framebuffer. Note that this function is set/unset to es2Clear or es3Clear on initialization/uninitialization.

param

Bitmask specifying which bits are to be cleared (and thereby which attachments).

param

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

param

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

param

allows to specify a specific queue of color attachments to be cleared. The webgl1 implementation ignores this parameter. If no parameter is given, the webgl2 implementation clears all color attachments.

Type declaration

    • (mask: number, bind?: boolean, unbind?: boolean, colorClearQueue?: number[]): void
    • Parameters

      • mask: number
      • Optional bind: boolean
      • Optional unbind: boolean
      • Optional colorClearQueue: number[]

      Returns void

Static Readonly DEFAULT_FRAMEBUFFER

DEFAULT_FRAMEBUFFER: undefined = ...

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

Accessors

context

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

    Returns Context

drawBuffers

  • get drawBuffers(): number[]
  • set drawBuffers(attachments: number[]): void
  • Used to remember which attachments are available as potential draw buffers.

    Returns number[]

  • Set one or multiple draw buffers.

    Parameters

    • attachments: number[]

      Array of attachment identifier (e.g., gl.COLOR_ATTACHMENT0).

    Returns void

height

  • get height(): number
  • Readonly access to the framebuffer height in pixel. If the height of the attachments are not all identical, the minimal height as the renderable height of this framebuffer is returned.

    Returns number

    • The minimal height of the renderable height over all attachments.

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

size

valid

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

    Returns boolean

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

width

  • get width(): number
  • Readonly access to the framebuffer width in pixel. If the width of the attachments are not all identical, the minimal width as the renderable width of this framebuffer is returned.

    Returns number

    • The minimal width of the renderable width over all attachments.

Methods

bind

  • bind(target?: number): void
  • Binds the framebuffer object as framebuffer to the provided target.

    Parameters

    • target: number = ...

      Specifying the binding point (target).

    Returns void

clearColor

  • clearColor(color: GLclampf4, drawBuffer?: number): void
  • Sets the clear color used for clearing a draw buffer. In order to have transparency working, the canvas needs to have the alpha attribute enabled. This stage also supports premultiplied alpha, which is applied automatically when the context's premultipliedAlpha attribute is set.

    Parameters

    • color: GLclampf4

      RGBA clear color.

    • Optional drawBuffer: number

      The draw buffer index. If no index is provided, the color will be applied to all buffers.

    Returns void

clearDepth

  • clearDepth(depth: number): void

clearStencil

  • clearStencil(stencil: number): void

Protected create

  • Create a framebuffer object on the GPU and attaches all given renderable objects (either renderbuffer or texture) to the framebuffer object.

    Parameters

    • attachments: [number, Renderbuffer | Texture2D][]

      tuples that associate an attachment to its actual render object, either a renderbuffer or texture, e.g., [ gl.COLOR_ATTACHMENT0, someTexture ].

    Returns undefined | WebGLFramebuffer

Protected delete

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

    Returns void

Protected es2Clear

  • es2Clear(mask: number, bind?: boolean, unbind?: boolean): void
  • WebGL1 implementation for clearing framebuffer attachments.

    Parameters

    • mask: number

      A GLbitfield bitwise OR mask that indicates the buffers to be cleared.

    • bind: boolean = true

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

    • unbind: boolean = true

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

    Returns void

Protected es3Clear

  • es3Clear(mask: number, bind?: boolean, unbind?: boolean, colorClearQueue?: number[]): void
  • WebGL2 implementation for clearing framebuffer attachments.

    Parameters

    • mask: number

      A GLbitfield bitwise OR mask that indicates the buffers to be cleared.

    • bind: boolean = true

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

    • unbind: boolean = true

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

    • Optional colorClearQueue: number[]

      Allows to specify a specific queue of color attachments to be cleared. If no parameter is given, the webgl2 implementation clears all color attachments.

    Returns void

Protected hasAttachment

  • hasAttachment(attachment: number): boolean

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

resize

  • resize(width: number, height: number, bind?: boolean, unbind?: boolean): void
  • Forwards a resize to all attachments, renderbuffers and textures.

    Parameters

    • width: number

      Targeted/new width for all attachments in px.

    • height: number

      Targeted/new height for all attachments in px.

    • bind: boolean = true

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

    • unbind: boolean = true

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

    Returns void

texture

  • texture(attachment: number): undefined | Texture2D
  • Access to attached textures, identified by a valid framebuffer attachment.

    Parameters

    • attachment: number

      The attachment to request the texture object of.

    Returns undefined | Texture2D

    • A texture object if one exists for the given attachment, otherwise undefined.

unbind

  • unbind(target?: number): void
  • Binds the default back buffer as framebuffer to the provided target.

    Parameters

    • target: number = ...

      Specifying the binding point (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 Protected statusString

  • statusString(context: Context, status: number): string
  • Returns a string describing the given status of a framebuffer object.

    Parameters

    • context: Context

      Context for valid GLenums.

    • status: number

      A framebuffer's status.

    Returns string

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