Table of Contents

Context Properties

luma.gl provides several helper functions for testing properties of a WebGL context:

  • getContextLimits: get resource limits for a context
  • getGLContextInfo: get various properties of a gl context (using WebGL enums as keys)
  • getContextInfo: get various properties of a gl context (using strings as keys)

Usage

Check a certain limit (whether through an extension under WebGL 1 or through WebGL 2)
```js
import GL from '@luma.gl/constants';
import {getContextLimits} from '@luma.gl/webgl';
const limits = getContextLimits(gl);
if (limits[GL.MAX_COLOR_ATTACHMENTS] > 0) { // it will be 0 for WebGL 1
   ...
}

There are a few additional capability query functions sprinkled through the luma.gl API. In particular, WebGL 2 specific classes have an isSupported method that duplicates some of the queryies that can be made using the capability system

import {Query} from '@luma.gl/webgl';
if (Query.isSupported(gl)) {
  ...
}

Functions

getContextLimits(gl)

Returns an object with limits, each limit is an object with multiple values

  • value - the value of the limit in the current context
  • webgl1 - the minimum allowed value of the limit for WebGL 1 contexts
  • webgl2 - the minimum allowed value of the limit for WebGL 2 contexts

WebGL Limits

In addition to capabilities, luma.gl can also query the context for all limits.

LimitsWebGL 2WebGL 1Description
GL.ALIASED_LINE_WIDTH_RANGE[1, 1]
GL.ALIASED_POINT_SIZE_RANGE[1, 1]
GL.MAX_TEXTURE_SIZE204864
GL.MAX_CUBE_MAP_TEXTURE_SIZE16
GL.MAX_TEXTURE_IMAGE_UNITS8
GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS8
GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS0
GL.MAX_RENDERBUFFER_SIZE1
GL.MAX_VARYING_VECTORS8
GL.MAX_VERTEX_ATTRIBS8
GL.MAX_VERTEX_UNIFORM_VECTORS128
GL.MAX_FRAGMENT_UNIFORM_VECTORS16
GL.MAX_VIEWPORT_DIMS[0, 0]
GL.MAX_TEXTURE_MAX_ANISOTROPY_EXT1.01.0'EXTtexturefilter_anisotropic'
WebGL 2 LimitsWebGL 2WebGL 1 (mock)Description
GL.MAX_3D_TEXTURE_SIZE2560
GL.MAX_ARRAY_TEXTURE_LAYERS2560
GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL00
GL.MAX_COLOR_ATTACHMENTS40
GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS00
GL.MAX_COMBINED_UNIFORM_BLOCKS00
GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS00
GL.MAX_DRAW_BUFFERS40
GL.MAX_ELEMENT_INDEX00
GL.MAX_ELEMENTS_INDICES00
GL.MAX_ELEMENTS_VERTICES00
GL.MAX_FRAGMENT_INPUT_COMPONENTS00
GL.MAX_FRAGMENT_UNIFORM_BLOCKS00
GL.MAX_FRAGMENT_UNIFORM_COMPONENTS00
GL.MAX_PROGRAM_TEXEL_OFFSET00
GL.MAX_SAMPLES00
GL.MAX_SERVER_WAIT_TIMEOUT00
GL.MAX_TEXTURE_LOD_BIAS00
GL.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS00
GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS00
GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS00
GL.MAX_UNIFORM_BLOCK_SIZE00
GL.MAX_UNIFORM_BUFFER_BINDINGS00
GL.MAX_VARYING_COMPONENTS00
GL.MAX_VERTEX_OUTPUT_COMPONENTS00
GL.MAX_VERTEX_UNIFORM_BLOCKS00
GL.MAX_VERTEX_UNIFORM_COMPONENTS00
GL.MIN_PROGRAM_TEXEL_OFFSET00
GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT00

getGLContextInfo(gl)

Returns an object with following parameters as keys and corresponding value for each key.

parameter
'GL.VENDOR'
'GL.RENDERER'
'GL.UNMASKEDVENDORWEBGL'
'GL.UNMASKEDRENDERERWEBGL'
'GL.VERSION'
'GL.SHADINGLANGUAGEVERSION'

getContextInfo(gl)

Returns an object containing following details.

  • vendor: info[GL.UNMASKEDVENDORWEBGL] || info[GL.VENDOR],
  • renderer: info[GL.UNMASKEDRENDERERWEBGL] || info[GL.RENDERER],
  • version: info[GL.VERSION],
  • shadingLanguageVersion: info[GL.SHADINGLANGUAGEVERSION],
  • info,
  • limits,
  • webgl1MinLimits: gl.luma.webgl1MinLimits,
  • webgl2MinLimits: gl.luma.webgl2MinLimits

Remarks

  • WebGL 1 only supports one color buffer format (RBG32F is deprecated)
  • WebGL 2 supports multiple color buffer formats
  • Some extensions will not be enabled until they have been queries. luma always queries on startup to enable, app only needs to query again it wants to test platform.
  • The capability detection system works regardless of whether the app is running in a browser or in headless mode under Node.js.
  • Naturally, given that queries to driver and GPU are typically expensive in WebGL, the capabilities system will cache any queries.