Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
npm install pex-context








Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
``bash`
npm install pex-context
`js
import createContext from "pex-context";
import { mat4 } from "pex-math";
import { cube } from "primitive-geometry";
const W = 640;
const H = 480;
const ctx = createContext({ width: W, height: H });
const geom = cube();
const clearCmd = {
pass: ctx.pass({
clearColor: [0.2, 0.2, 0.2, 1],
clearDepth: 1,
}),
};
const drawCmd = {
pipeline: ctx.pipeline({
depthTest: true,
vert: / glsl /
attribute vec3 aPosition;
attribute vec3 aNormal;
uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;
varying vec4 vColor;
void main () {
vColor = vec4(aNormal * 0.5 + 0.5, 1.0);
gl_Position = uProjectionMatrix uViewMatrix vec4(aPosition, 1.0);
},
frag: / glsl /
precision highp float;
varying vec4 vColor;
void main() {
gl_FragColor = vColor;
},
}),
attributes: {
aPosition: ctx.vertexBuffer(geom.positions),
aNormal: ctx.vertexBuffer(geom.normals),
},
indices: ctx.indexBuffer(geom.cells),
uniforms: {
uProjectionMatrix: mat4.perspective(
mat4.create(),
Math.PI / 4,
W / H,
0.1,
100,
),
uViewMatrix: mat4.lookAt(mat4.create(), [2, 2, 5], [0, 0, 0], [0, 1, 0]),
},
};
ctx.frame(() => {
ctx.submit(clearCmd);
ctx.submit(drawCmd);
});
`
objectctxCreate a context object
PexResourceobjectPexResourcePexResourcePexResourceQueryOptionsPexResourceHTMLImageElement | HTMLVideoElement | HTMLCanvasElementWebGLRenderingContext.TEXTURE_2D | WebGLRenderingContext.TEXTURE_CUBE_MAP | WebGL2RenderingContext.TEXTURE_2D_ARRAY | WebGL2RenderingContext.TEXTURE_3DPexResourcePexResourcePexResourcePexResourcePexResourceobjectobjectAll resources are plain js object and once constructed their properties can be accessed directly.
Please note those props are read only. To set new values or upload new data to GPU see updating resources.
objectobjectobjectobjectobjectArray.<number>[x, y, w, h]
Array.<number>[r, g, b, a]
Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64ArrayobjectKind: global namespace
- ctx : object
- .gl
- .capabilities
- .width ⇒ number
- .height ⇒ number
- .BlendFactor
- .CubemapFace
- .DepthFunc
- .Face
- .Filter
- .PixelFormat
- .RenderbufferFloatFormat
- .Primitive
- .Usage
- .Wrap
- .QueryTarget
- .QueryState
- .set(options)
- [.debug([enabled])](#ctx.debug)
- .frame(cb)
- [.submit(cmd, [batches], [subCommand])](#ctx.submit)
- .pass(opts) ⇒ PexResource
- .pipeline(opts) ⇒ PexResource
- .vertexArray(opts) ⇒ PexResource
- .transformFeedback(opts) ⇒ PexResource
- .texture2D(opts) ⇒ PexResource
- .texture2DArray(opts) ⇒ PexResource
- .textureCube(opts) ⇒ PexResource
- .renderbuffer(opts) ⇒ PexResource
- .vertexBuffer(opts) ⇒ PexResource
- .indexBuffer(opts) ⇒ PexResource
- .query(opts) ⇒ PexResource
- .beginQuery(query)
- .endQuery(query)
- .readPixels(viewport) ⇒ Uint8Array
- .update(resource, opts)
- [.dispose([resource])](#ctx.dispose)
The RenderingContext returned by pex-gl
Kind: static property of ctx
Max capabilities and extensions availability. See Capabilities Table.
Kind: static property of ctx
Getter for gl.drawingBufferWidth
Kind: static property of ctx
Getter for gl.drawingBufferHeight
Kind: static property of ctx
Kind: static enum of ctx
Properties
| Name | Default |
| ---------------- | ----------------------------------- |
| One | gl.ONE |
| Zero | gl.ZERO |
| SrcAlpha | gl.SRC_ALPHA |
| OneMinusSrcAlpha | gl.ONE_MINUS_SRC_ALPHA |
| DstAlpha | gl.DST_ALPHA |
| OneMinusDstAlpha | gl.ONE_MINUS_DST_ALPHA |
| SrcColor | gl.SRC_COLOR |
| OneMinusSrcColor | gl.ONE_MINUS_SRC_COLOR |
| DstColor | gl.DST_COLOR |
| OneMinusDstColor | gl.ONE_MINUS_DST_COLOR |
Kind: static enum of ctx
Properties
| Name | Default |
| --------- | ------------------------------------------- |
| PositiveX | gl.TEXTURE_CUBE_MAP_POSITIVE_X |
| NegativeX | gl.TEXTURE_CUBE_MAP_NEGATIVE_X |
| PositiveY | gl.TEXTURE_CUBE_MAP_POSITIVE_Y |
| NegativeY | gl.TEXTURE_CUBE_MAP_NEGATIVE_Y |
| PositiveZ | gl.TEXTURE_CUBE_MAP_POSITIVE_Z |
| NegativeZ | gl.TEXTURE_CUBE_MAP_NEGATIVE_Z |
Kind: static enum of ctx
Properties
| Name | Default |
| ------------ | ------------------------ |
| Never | gl.NEVER |
| Less | gl.LESS |
| Equal | gl.EQUAL |
| LessEqual | gl.LEQUAL |
| Greater | gl.GREATER |
| NotEqual | gl.NOTEQUAL |
| GreaterEqual | gl.GEQUAL |
| Always | gl.ALWAYS |
Kind: static enum of ctx
Properties
| Name | Default |
| ------------ | ------------------------------ |
| Front | gl.FRONT |
| Back | gl.BACK |
| FrontAndBack | gl.FRONT_AND_BACK |
Kind: static enum of ctx
Properties
| Name | Default |
| -------------------- | -------------------------------------- |
| Nearest | gl.NEAREST |
| Linear | gl.LINEAR |
| NearestMipmapNearest | gl.NEAREST_MIPMAP_NEAREST |
| NearestMipmapLinear | gl.NEAREST_MIPMAP_LINEAR |
| LinearMipmapNearest | gl.LINEAR_MIPMAP_NEAREST |
| LinearMipmapLinear | gl.LINEAR_MIPMAP_LINEAR |
Mapping of ctx.TextureFormat keys to their string values and legacy depth formats
One of:
- Unsized: RGB, RGBA, LUMINANCE_ALPHA, LUMINANCE, ALPHA
- Sized 1 component: R8, R8_SNORM, R16F, R32F, R8UI, R8I, R16UI, R16I, R32UI, R32I
- Sized 2 components: RG8, RG8_SNORM, RG16F, RG32F, RG8UI, RG8I, RG16UI, RG16I, RG32UI, RG32I
- Sized 3 components: RGB8, RGB8_SNORM, RGB16F, RGB32F, RGB8UI, RGB8I, RGB16UI, RGB16I, RGB32UI, RGB32I
- Sized 4 components: RGBA8, RGBA8_SNORM, RGBA16F, RGBA32F, RGBA8UI, RGBA8I, RGBA16UI, RGBA16I, RGBA32UI, RGBA32I
- Sized special: SRGB8, RGB565, R11F_G11F_B10F, RGB9_E5, SRGB8_ALPHA8, RGB5_A1, RGBA4, RGB10_A2, RGB10_A2UI
- Sized depth/stencil: DEPTH_COMPONENT16, DEPTH_COMPONENT24, DEPTH_COMPONENT32F, DEPTH24_STENCIL8, DEPTH32F_STENCIL8
Kind: static enum of ctx
Kind: static enum of ctx
Properties
| Name | Default |
| -------------- | ------------- |
| RGBA32F | |
| RGBA16F | |
| R16F | |
| RG16F | |
| R32F | |
| RG32F | |
| R11F_G11F_B10F | |
Kind: static enum of ctx
Properties
| Name | Default |
| ------------- | ------------------------------ |
| Points | gl.POINTS |
| Lines | gl.LINES |
| LineStrip | gl.LINE_STRIP |
| Triangles | gl.TRIANGLES |
| TriangleStrip | gl.TRIANGLE_STRIP |
Kind: static enum of ctx
Properties
| Name | Default |
| ----------- | ---------------------------- |
| StaticDraw | gl.STATIC_DRAW |
| DynamicDraw | gl.DYNAMIC_DRAW |
| StreamDraw | gl.STREAM_DRAW |
Kind: static enum of ctx
Properties
| Name | Default |
| -------------- | ------------------------------- |
| ClampToEdge | gl.CLAMP_TO_EDGE |
| Repeat | gl.REPEAT |
| MirroredRepeat | gl.MIRRORED_REPEAT |
Kind: static enum of ctx
Properties
| Name | Default |
| ---------------------------------- | ----------------------------------------------------- |
| TimeElapsed | gl.TIME_ELAPSED |
| AnySamplesPassed | gl.ANY_SAMPLES_PASSED |
| AnySamplesPassedConservative | gl.ANY_SAMPLES_PASSED_CONSERVATIVE |
| TransformFeedbackPrimitivesWritten | gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN |
Kind: static enum of ctx
Properties
| Name | Default |
| ------- | -------------------- |
| Ready | ready |
| Active | active |
| Pending | pending |
Set the context size and pixelRatio
The new size and resolution will not be applied immediately but before drawing the next frame to avoid flickering.
Context's canvas doesn't resize automatically, even if you don't pass width/height on init and the canvas is assigned the dimensions of the window. To handle resizing use the following code:
`js`
window.addEventListener("resize", () => {
ctx.set({ width: window.innerWidth, height: window.innerHeight });
});
Kind: static method of ctx
| Param | Type |
| ------- | ---------------------------------------------------------- |
| options | PexContextSetOptions |
Enable debug mode
Kind: static method of ctx
| Param | Type |
| --------- | -------------------- |
| [enabled] | boolean |
Render Loop
Kind: static method of ctx
| Param | Type | Description |
| ----- | --------------------- | -------------------------------- |
| cb | function | Request Animation Frame callback |
Submit a command to the GPU.
Commands are plain js objects with GPU resources needed to complete a draw call.
`js`
const cmd = {
pass: Pass
pipeline: Pipeline,
attributes: { name: VertexBuffer | { buffer: VertexBuffer, offset: number, stride: number } },
indices: IndexBuffer | { buffer: IndexBuffer, offset: number, count: number },
// or
count: number,
instances: number,
uniforms: { name: number, name: Array, name: Texture2D },
viewport: [0, 0, 1920, 1080],
scissor: [0, 0, 1920, 1080]
}
_Note: Either indices or count need to be specified when drawing geometry._
_Note: Scissor region is by default set to null and scissor test disabled._
Kind: static method of ctx
| Param | Type |
| ------------ | ---------------------------------------------------------------------------------------------- |
| cmd | PexCommand |
| [batches] | PexCommand \| Array.<PexCommand> |
| [subCommand] | PexCommand |
Example
- ctx.submit(cmd, opts): submit partially updated command without modifying the original one.
`js`
// Draw mesh with custom color
ctx.submit(cmd, {
uniforms: {
uColor: [1, 0, 0, 0],
},
});
- ctx.submit(cmd, [opts1, opts2, opts3...]): submit a batch of commands differences in opts.
`js`
// Draw same mesh twice with different material and position
ctx.submit(cmd, [
{ pipeline: material1, uniforms: { uModelMatrix: position1 },
{ pipeline: material2, uniforms: { uModelMatrix: position2 }
])
- ctx.submit(cmd, cb): submit command while preserving state from another command. This approach allows to simulate state stack with automatic cleanup at the end of callback.
`js`
// Render to texture
ctx.submit(renderToFboCmd, () => {
ctx.submit(drawMeshCmd);
});
Passes are responsible for setting render targets (textures) and their clearing values.
FBOs are created internally and automatically.
Kind: static method of ctx
| Param | Type |
| ----- | ---------------------------------------- |
| opts | PassOptions |
Example
`js`
const pass = ctx.pass({
color: [Texture2D, ...]
color: [{ texture: Texture2D | TextureCube, target: CubemapFace }, ...]
depth: Texture2D
clearColor: Array | Array[],
clearDepth: number,
})
Pipelines represent the state of the GPU rendering pipeline (shaders, blending, depth test etc).
Kind: static method of ctx
| Param | Type |
| ----- | ------------------------------------------------ |
| opts | PipelineOptions |
Example
`js`
const pipeline = ctx.pipeline({
vert: string,
frag: string,
depthWrite: boolean,
depthTest: boolean,
depthFunc: DepthFunc,
blend: boolean,
blendSrcRGBFactor: BlendFactor,
blendSrcAlphaFactor: BlendFactor,
blendDstRGBFactor: BlendFactor,
blendDstAlphaFactor: BlendFactor,
cullFace: boolean,
cullFaceMode: Face,
colorMask: Array,
primitive: Primitive,
});
Create a VAO resource.
Kind: static method of ctx
| Param | Type |
| ----- | ------------------------------------------------------ |
| opts | VertexArrayOptions |
Example
`js
const vertexLayout = {
aPosition: { location: 0, type: "vec3" },
aNormal: { location: 1, type: "vec3" },
};
const drawCmd = {
pipeline: ctx.pipeline({
vertexLayout,
// ...
}),
vertexArray: ctx.vertexArray({
vertexLayout,
attributes: {
aPosition: ctx.vertexBuffer(geom.positions),
aNormal: { buffer: ctx.vertexBuffer(geom.normals) },
},
indices: ctx.indexBuffer(geom.cells),
}),
// ...
};
`
Create a transform feedback
Kind: static method of ctx
| Param | Type |
| ----- | ------------------------------------------------------------------ |
| opts | TransformFeedbackOptions |
Example
`js`
const tex = ctx.transformFeedback({
varyings: {
outPosition: positionsBuf,
},
});
Create a 2D Texture resource.
Kind: static method of ctx
| Param | Type |
| ----- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| opts | HTMLImageElement \| HTMLVideoElement \| HTMLCanvasElement \| TextureOptions |
Example
`js`
const tex = ctx.texture2D({
data: [255, 255, 255, 255, 0, 0, 0, 255],
width: 2,
height: 1,
pixelFormat: ctx.PixelFormat.RGBA8,
wrap: ctx.Wrap.Repeat,
});
Create a 2D Texture Array resource.
Kind: static method of ctx
| Param | Type |
| ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| opts | Array.<HTMLImageElement> \| Array.<HTMLVideoElement> \| Array.<HTMLCanvasElement> \| TextureOptions |
Example
`js`
const tex = ctx.texture2DArray({
data: [img, img, img],
});
Create a 2D Texture cube resource.
Kind: static method of ctx
| Param | Type |
| ----- | ------------------------------------------------------ |
| opts | TextureCubeOptions |
Example
`js`
const tex = ctx.textureCube({
data: [posx, negx, posy, negy, posz, negz],
width: 64,
height: 64
])
Renderbuffers represent pixel data store for rendering operations.
Kind: static method of ctx
| Param | Type |
| ----- | -------------------------------------------------------- |
| opts | RenderbufferOptions |
Example
`js`
const tex = ctx.renderbuffer({
width: 1280,
height: 720,
pixelFormat: ctx.PixelFormat.DEPTH_COMPONENT16,
});
Create an attribute buffer (ARRAY_BUFFER) resource. Stores vertex data in the GPU memory.
Kind: static method of ctx
| Param | Type |
| ----- | -------------------------------------------- |
| opts | BufferOptions |
Example
`js`
const vertexBuffer = ctx.vertexBuffer({
data: Array | TypedArray | ArrayBuffer,
});
Create an index buffer (ELEMENT_ARRAY_BUFFER) resource. Stores index data in the GPU memory.
Kind: static method of ctx
| Param | Type |
| ----- | -------------------------------------------- |
| opts | BufferOptions |
Example
`js`
const indexBuffer = ctx.vertexBuffer({
data: Array | TypedArray | ArrayBuffer,
});
Queries can be used for GPU timers.
Kind: static method of ctx
| Param | Type |
| ----- | ------------------------------------------ |
| opts | QueryOptions |
Example
`js`
const query = ctx.query({
target: QueryTarget,
});
Begin the query measurement.
Kind: static method of ctx
| Param | Type | Description |
| ----- | ---------------------------------- | -------------------------------------------------------- |
| query | PexQuery | _Note: There can be only one query running at the time._ |
End the query measurement.
Kind: static method of ctx
| Param | Type | Description |
| ----- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| query | PexQuery | _Note: The result is not available immediately and will be null until the state changes from ctx.QueryState.Pending to ctx.QueryState.Ready._ |
Helper to read a block of pixels from a specified rectangle of the current color framebuffer.
Kind: static method of ctx
| Param | Type |
| -------- | ------------------- |
| viewport | Object |
Update a resource.
Kind: static method of ctx
| Param | Type |
| -------- | ---------------------------------------- |
| resource | PexResource |
| opts | object |
Example
`js
ctx.update(buffer, { data: [] });
ctx.update(texture, {
width: 1,
height: 1,
data: new Uint8Array([255, 0, 0, 255]),
});
`
Delete one or all resource(s). Disposed resources are no longer valid for use.
Kind: static method of ctx
| Param | Type |
| ---------- | ---------------------------------------- |
| [resource] | PexResource |
Example
Delete all allocated resources:
`js`
ctx.dispose();
Delete a single resource:
`js`
ctx.dispose(texture);
_Note: Framebuffers are ref counted and released by Pass. Programs are also ref counted and released by Pipeline._
ctxCreate a context object
Kind: global function
| Param | Type |
| --------- | ------------------------------------------------------------------------------------------ |
| [options] | PexContextOptions \| module:pex-gl~Options |
PexResourceKind: global typedef
Properties
| Name | Type | Default |
| ------- | ---------------------------------------------------------------------------------------- | --------------------------------- |
| data | Array \| TypedArray \| ArrayBuffer | |
| [type] | ctx.DataType | |
| [usage] | Usage | ctx.Usage.StaticDraw |
| offset | number | |
objectKind: global typedef
Properties
| Name | Type |
| ------- | ---------------------------------------------- |
| texture | PexResource |
| target | WebGLRenderingContext.FRAMEBUFFER |
PexResourceKind: global typedef
Properties
| Name | Type | Description |
| ------------ | ---------------------------------------------------------------------------------------------------------------- | ------------- |
| [color] | Array.<PexTexture2D> \| Array.<Attachment> | render target |
| [depth] | PexTexture2D | render target |
| [clearColor] | Color | |
| [clearDepth] | number | |
PexResourceKind: global typedef
Properties
| Name | Type | Default | Description |
| --------------------- | -------------------------------------------- | ------------------------------------- | --------------------------------- |
| [vert] | string | null | Vertex shader code |
| [frag] | string | null | Fragment shader code |
| [depthWrite] | boolean | true | Depth write mask |
| [depthTest] | boolean | false | Depth test on/off |
| [depthFunc] | DepthFunc | ctx.DepthFunc.LessEqual | Depth test function |
| [blend] | boolean | false | Blending on/off |
| [blendSrcRGBFactor] | BlendFactor | ctx.BlendFactor.One | Blending source color factor |
| [blendSrcAlphaFactor] | BlendFactor | ctx.BlendFactor.One | Blending source alpha factor |
| [blendDstRGBFactor] | BlendFactor | ctx.BlendFactor.One | Blending destination color factor |
| [blendDstAlphaFactor] | BlendFactor | ctx.BlendFactor.One | Blending destination alpha factor |
| [cullFace] | boolean | false | Face culling on/off |
| [cullFaceMode] | Face | ctx.Face.Back | Face culling mode |
| [colorMask] | Array.<boolean> | [true, true, true, true] | Color write mask for [r, g, b, a] |
| [primitive] | Primitive | ctx.Primitive.Triangles | Geometry primitive |
PexResourceKind: global typedef
Properties
| Name | Type | Default | Description |
| -------- | -------------------------------------------- | ---------------------------------------- | ----------- |
| [target] | QueryTarget | ctx.QueryTarget.TimeElapsed | query type |
QueryOptionsKind: global typedef
Properties
| Name | Type | Default | Description |
| -------- | ------------------------------------------ | --------------------------------- | ------------------------- |
| [state] | QueryState | ctx.QueryState.Ready | |
| [result] | number | | result of the measurement |
PexResourceKind: global typedef
Properties
| Name | Type | Default | Description |
| ------------- | -------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| width | number | | |
| height | number | | |
| [pixelFormat] | PixelFormat | ctx.PixelFormat.DEPTH_COMPONENT16 | only PixelFormat.DEPTH_COMPONENT16 is currently supported for use as render pass depth storage (e.g. ctx.pass({ depth: renderbuffer })) for platforms with no WEBGL_depth_texture support. |
HTMLImageElement \| HTMLVideoElement \| HTMLCanvasElementKind: global typedef
Properties
| Name | Type |
| ------ | ------------------------------------------------------------ |
| data | Array \| TypedArray |
| width | number |
| height | number |
WebGLRenderingContext.TEXTURE_2D \| WebGLRenderingContext.TEXTURE_CUBE_MAP \| WebGL2RenderingContext.TEXTURE_2D_ARRAY \| WebGL2RenderingContext.TEXTURE_3DPexResourceKind: global typedef
Properties
| Name | Type | Default | Description |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
| [data] | HTMLImageElement \| HTMLVideoElement \| HTMLCanvasElement \| Array \| TypedArray \| TextureOptionsData | | |
| [width] | number | | |
| [height] | number | | |
| [depth] | number | | |
| [pixelFormat] | PixelFormat | ctx.PixelFormat.RGBA8 | |
| [internalFormat] | ctx.TextureFormat | ctx.TextureFormat.RGBA | |
| [type] | ctx.DataType | ctx.TextureFormat[opts.pixelFormat] | |
| [wrapS] | Wrap | ctx.Wrap.ClampToEdge | |
| [wrapT] | Wrap | ctx.Wrap.ClampToEdge | |
| [wrap] | Wrap | ctx.Wrap.ClampToEdge | |
| [min] | Filter | ctx.Filter.Nearest | |
| [mag] | Filter | ctx.Filter.Nearest | |
| [aniso] | number | 0 | requires EXT_texture_filter_anisotropic |
| [mipmap] | boolean | true | requires min to be set to ctx.Filter.LinearMipmapLinear or similar |
| [premultiplyAlpha] | boolean | false | |
| [flipY] | boolean | false | |
| [colorspaceConversion] | boolean | gl.NONE | |
| [compressed] | boolean | false | |
| [target] | TextureTarget | | |
| [offset] | number | | |
PexResourceKind: global typedef
Extends: TextureOptions
Properties
| Name | Type |
| ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [data] | Array.<HTMLImageElement> \| Array.<TextureOptionsData> \| Array.<Array> \| Array.<TypedArray> |
PexResourceKind: global typedef
Extends: TextureOptions
Properties
| Name | Type | Description |
| ------ | --------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
| [data] | Array.<HTMLImageElement> \| Array.<TypedArray> | 6 images, one for each face +X, -X, +Y, -Y, +Z, -Z |
PexResourceKind: global typedef
Properties
| Name | Type |
| ------------- | ------------------- |
| varyings | object |
| bufferMode | number |
| primitiveMode | number |
PexResourceKind: global typedef
Properties
| Name | Type |
| ------------ | ------------------- |
| vertexLayout | object |
| [attributes] | object |
| [indices] | object |
objectKind: global typedef
Properties
| Name | Type | Default |
| ------------ | ------------------------------------------------------------------------- | ----------------------------------- |
| [gl] | WebGLRenderingContext \| WebGL2RenderingContext | WebGL2RenderingContext |
| [width] | number | window.innerWidth |
| [height] | number | window.innerHeight |
| [pixelRatio] | number | 1 |
| [type] | "webgl" \| "webgl2" | "webgl2" |
| [debug] | boolean | false |
objectAll resources are plain js object and once constructed their properties can be accessed directly.
Please note those props are read only. To set new values or upload new data to GPU see updating resources.
Kind: global typedef
Properties
| Name | Type |
| ---- | ------------------- |
| name | string |
objectobjectKind: global typedef
Properties
| Name | Type | Description |
| ------------ | -------------------- | --------------------------------------- |
| buffer | object | ctx.vertexBuffer() or ctx.indexBuffer() |
| [offset] | number | |
| [stride] | number | |
| [divisor] | number | |
| [normalized] | boolean | |
objectKind: global typedef
Properties
| Name | Type | Description |
| -------------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| pass | PassOptions | |
| pipeline | PipelineOptions | |
| [attributes] | object | vertex attributes, map of attributeName: ctx.vertexBuffer() or attributeName: PexAttribute |ctx.indexBuffer()
| [indices] | object | indices, or PexAttribute |name: value
| [count] | number | number of vertices to draw |
| [instances] | number | number instances to draw |
| [uniforms] | object | shader uniforms, map of |
| [viewport] | Viewport | drawing viewport bounds |
| [scissor] | Viewport | scissor test bounds |
| [multiDraw] | MultiDrawOptions | |
| [baseVertex] | number | |
| [baseInstance] | number | |
objectKind: global typedef
See
- WEBGL_multi_draw extension
- WEBGL_draw_instanced_base_vertex_base_instance extension
- WEBGL_multi_draw_instanced_base_vertex_base_instance extension
Properties
| Name | Type |
| ---------------------- | ---------------------------------------------- |
| counts | Int32Array \| Array |
| [countsOffset] | number |
| offsets | Int32Array \| Array |
| [offsetsOffset] | number |
| firsts | Int32Array \| Array |
| [firstsOffset] | number |
| instanceCounts | Int32Array \| Array |
| [instanceCountsOffset] | number |
| baseVertices | Int32Array \| Array |
| [baseVerticesOffset] | number |
| baseInstances | UInt32Array \| Array |
| [baseInstancesOffset] | number |
| [drawCount] | number |
objectKind: global typedef
Properties
| Name | Type |
| ------------ | ------------------- |
| [width] | number |
| [height] | number |
| [pixelRatio] | number |
Array.<number>[x, y, w, h]
Array.<number>[r, g, b, a]
Int8Array \| Uint8Array \| Uint8ClampedArray \| Int16Array \| Uint16Array \| Int32Array \| Uint32Array \| Float32Array \| Float64Array \| BigInt64Array \| BigUint64ArrayKind: global typedef
Example
`js`
const maxTextureSize = ctx.capabilities.maxTextureSize;
| Name | Type |
| ---------------------------- | ------- |
| isWebGL2 | number |maxColorAttachments
| | number |maxTextureImageUnits
| | number |maxVertexTextureImageUnits
| | number |maxVertexAttribs
| | number |maxTextureSize
| | number |maxCubeMapTextureSize
| | number |depthTexture
| | boolean |shaderTextureLod
| | boolean |textureFloat
| | boolean |textureFloatLinear
| | boolean |textureHalfFloat
| | boolean |textureHalfFloatLinear
| | boolean |textureFilterAnisotropic
| | boolean |disjointTimerQuery
| | boolean |colorBufferFloat
| | boolean |colorBufferHalfFloat
| | boolean |floatBlend
| | boolean |multiDraw
| | boolean |drawInstancedBase
| | boolean |multiDrawInstancedBase` | boolean |
|
MIT. See license file.