Skip to main content

GLType

Helper functions to work with WebGL data type constants.

WebGL type constantJavaScript Typed ArrayNotes
GL.FLOATFloat32Array
GL.DOUBLEFloat64ArrayNot yet directly usable in WebGL/GLSL
GL.UNSIGNED_SHORTUint16Array
GL.UNSIGNED_INTUint32Array
GL.UNSIGNED_BYTEUint8Array
GL.UNSIGNED_BYTEUint8ClampedArray
GL.BYTEInt8Array
GL.SHORTInt16Array
GL.INTInt32Array

Usage

import {GL, GLType} from '@loaders.gl/math';
// Returns Int8Array.BYTES_PER_ELEMENT
var size = GLType.getSizeInBytes(GL.BYTE);

Static Methods

GLType.fromTypedArray(typedArray: Typed Array | Function) : string

Returns the size, in bytes, of the corresponding datatype.

  • glType The component datatype to get the size of.

Returns

The size in bytes.

Throws

  • glType is not a valid value.

Gets the component data type for the provided TypedArray instance.

  • array The typed array.

Returns

The ComponentDatatype for the provided array, or undefined if the array is not a TypedArray.

GLType.fromName(name: String): number

Extracts name for glType from array NAME_TO_GL_TYPE

GLType.getArrayType(glType: Number) : function

Returns the constructor of the array

static GLType.getByteSize(glType: Number) : number

Returns the size in bytes of one element of the provided WebGL type.

Equivalent to GLType.getArrayType(glType).BYTES_PER_ELEMENT.

static GLType.validate(glType) : boolean

Returns true if glType is a valid WebGL data type.

static GLType.createTypedArray(glType : number, buffer : ArrayBuffer [, byteOffset : number [, length : number]]) : TypedArray

Creates a typed view of an array of bytes.

  • glType The type of typed array (ArrayBuffer view) to create.
  • buffer The buffer storage to use for the view.
  • byteOffset=0 The offset, in bytes, to the first element in the view.
  • length= The number of elements in the view. Defaults to buffer length.

Returns

Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array A typed array view of the buffer.

Throws

  • glType is not a valid value.