Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TextureCube

Wrapper for an WebGL cube texture providing size accessors and requiring for bind, unbind, resize, validity, and initialization implementations. The texture cube object is created on initialization and deleted on uninitialization. After being initialized, the texture cube can be resized, reformated, and data can set directly or via load:

const cubeMap = new TextureCube(context, 'CubeMap');
cubeMap.initialize(512, gl.RGB8, gl.RGB, gl.UNSIGNED_BYTE);
cubeMap.load({
    positiveX: 'data/cubemap.px.png', negativeX: 'data/cubemap.nx.png',
    positiveY: 'data/cubemap.py.png', negativeY: 'data/cubemap.ny.png',
    positiveZ: 'data/cubemap.pz.png', negativeZ: 'data/cubemap.nz.png',
}).then(() => this.invalidate(true);

Please note that each of the six textures of a texture cube is required to be of the exact same, square dimensions. This is reflected within this classes interface by providing a single size property in favor to width and height.

Hierarchy

Implements

Index

Constructors

constructor

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

    Parameters

    • context: Context

      Valid context to create the object for.

    • Optional identifier: undefined | string

      Meaningful name for identification of this instance.

    Returns TextureCube

Properties

Protected _bytes

_bytes: Array<GLsizei> = [0, 0, 0, 0, 0, 0]

For tracking approximate use of GPU storage in bytes per face.

Protected _context

_context: Context
see

context

Protected _format

_format: GLenum = 0
see

format

Protected _identifier

_identifier: string

Protected _internalFormat

_internalFormat: GLenum = 0

Protected _object

_object: WebGLTexture | undefined
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 _size

_size: GLsizei = 0
see

size

Protected _type

_type: GLenum = 0
see

type

Protected _valid

_valid: boolean = false
see

valid

Static DEFAULT_TEXTURE

DEFAULT_TEXTURE: undefined = undefined

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

Accessors

bytes

  • get bytes(): GLsizei
  • Returns the number of bytes this object approximately allocates on the GPU. The size will be zero when no image data was passed to the texture object.

    Returns GLsizei

context

format

  • get format(): GLenum
  • Cached format of the data provided to the texture object for efficient resize. This is set on initialization and might change on data transfers.

    Returns GLenum

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

internalFormat

  • get internalFormat(): GLenum
  • Cached internal format of the texture for efficient resize. This can only be changed by re-initialization.

    Returns GLenum

object

  • get object(): WebGLTexture

size

  • get size(): GLsizei
  • The width/height of the texture object (each cube map face is required to be a square).

    Returns GLsizei

type

  • get type(): GLenum
  • Cached type of the data provided to the texture used for efficient resize. This is set on initialization and might change on data transfers.

    Returns GLenum

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

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.

    Returns void

Protected assertUninitialized

  • assertUninitialized(): undefined
  • 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.

    Returns undefined

bind

  • bind(unit?: GLenum): void
  • Bind the texture object to a texture unit.

    Parameters

    • Optional unit: GLenum

    Returns void

Protected create

  • create(size: GLsizei, internalFormat: GLenum, format: GLenum, type: GLenum): WebGLTexture | undefined
  • Create a texture object on the GPU.

    Parameters

    • size: GLsizei

      Initial size (width/height) of each face, which are required to be a square texture.

    • internalFormat: GLenum

      Internal format of the texture object.

    • format: GLenum

      Format of the texture data even though no data is passed.

    • type: GLenum

      Data type of the texel data.

    Returns WebGLTexture | undefined

data

  • Pass data of six images to the texture cube object.

    Parameters

    • data: PerFaceData | [GLenum, TexImage2DData]

      Per face texel data that will be copied into the objects data store. Either provided via object or as tuple, providing the data associated to the targeted face (as GLenum).

    • Default value bind: boolean = true

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

    • Default value unbind: boolean = true

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

    Returns void

Protected delete

  • delete(): void

Protected faceID

  • faceID(face: GLenum): GLint
  • Provides an ID for each of the six texture cube identifier (0: +x, 1: -x, 2: +y, 3: -y, 4: +z, 5: -z).

    Parameters

    • face: GLenum

      Texture cube face identifier, e.g., TEXTURE_CUBE_MAP_POSITIVE_X.

    Returns GLint

    • Face ID in the following sequence: 0: +x, 1: -x, 2: +y, 3: -y, 4: +z, 5: -z.

filter

  • filter(mag: GLenum, min: GLenum, bind?: boolean, unbind?: boolean): void
  • Sets the texture object's magnification and minification filter.

    Parameters

    • mag: GLenum

      Value for the TEXTURE_MAG_FILTER parameter.

    • min: GLenum

      Value for the TEXTURE_MIN_FILTER parameter.

    • Default value bind: boolean = true

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

    • Default value unbind: boolean = true

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

    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

load

  • load(urisByFace: PerFaceURI, crossOrigin?: boolean): Promise<void>
  • Asynchronous load of multiple images (specified per texture cube face) via URI or data URI. Please note that the texture will not be resized and is assumed to be resized upfront accordingly.

    Parameters

    • urisByFace: PerFaceURI

      URI linking the image that should be loaded for a specific face. Data URI is also supported.

    • Default value crossOrigin: boolean = false

      Enable cross origin data loading.

    Returns Promise<void>

    • Promise for handling images load status.

ref

  • ref(): void

reformat

  • reformat(internalFormat: GLenum, format?: GLenum, type?: GLenum, bind?: boolean, unbind?: boolean): void
  • This can be used to reformat the texture image without creating a new texture object. Please note that this resets the texture's image data to undefined. @see data for setting new image data.

    Parameters

    • internalFormat: GLenum

      Internal format of the texture object.

    • Optional format: GLenum

      Format of the texture data even though no data is passed.

    • Optional type: GLenum

      Data type of the texel data.

    • Default value bind: boolean = true

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

    • Default value unbind: boolean = true

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

    Returns void

resize

  • resize(size: GLsizei, bind?: boolean, unbind?: boolean): void
  • This should be used to efficiently resize the texture.

    Parameters

    • size: GLsizei

      Targeted/new size (width/height) of the texture in px.

    • Default value bind: boolean = true

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

    • Default value unbind: boolean = true

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

    Returns void

unbind

  • unbind(unit?: GLenum): 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

wrap

  • wrap(wrap_s: GLenum, wrap_t: GLenum, bind?: boolean, unbind?: boolean): void
  • Sets the texture object's wrapping function for s and t coordinates.

    Parameters

    • wrap_s: GLenum

      Value for the TEXTURE_WRAP_S parameter.

    • wrap_t: GLenum

      Value for the TEXTURE_WRAP_T parameter.

    • Default value bind: boolean = true

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

    • Default value unbind: boolean = true

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

    Returns void

Static Protected assertInitializedFalse

Static Protected assertUninitializedFalse

Static assert_initialized

Static assert_uninitialized

Static initialize

  • 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

  • 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