Skip to content

Documentation / device / AbstractDevice

Interface: AbstractDevice ​

Defined in: libs/device/src/base_types.ts:2502

Abstract interface for the rendering device.

Extends ​

Properties ​

[EventMapType]? ​

readonly optional [EventMapType]?: DeviceEventMap

Defined in: libs/base/dist/index.d.ts:585

Type-only event map marker.

Inherited from ​

IEventTarget.[EventMapType]


pool ​

pool: Pool

Defined in: libs/device/src/base_types.ts:2504

Get pool object


vSync ​

vSync: boolean

Defined in: libs/device/src/base_types.ts:2506

vSync


fixedFrameTime ​

fixedFrameTime: number

Defined in: libs/device/src/base_types.ts:2511

The fixed per-frame time step in milliseconds, or null when using wall-clock timing. See AbstractDevice.setFixedFrameTime.


clipSpaceZeroToOne ​

readonly clipSpaceZeroToOne: boolean

Defined in: libs/device/src/base_types.ts:2555

True if the device clip space maps depth to [0, 1] (zero-to-one).

Always true on WebGPU. On WebGL this becomes true when the engine runs with the reverse-Z convention and the EXT_clip_control extension has been activated; otherwise the clip space is GL style [-1, 1].


videoMemoryUsage ​

videoMemoryUsage: number

Defined in: libs/device/src/base_types.ts:2983

Get the video memory usage in bytes


frameInfo ​

frameInfo: FrameInfo

Defined in: libs/device/src/base_types.ts:2985

Get the current frame information


maxFramesInFlight ​

maxFramesInFlight: number

Defined in: libs/device/src/base_types.ts:3004

Upper bound on frames the CPU may run ahead of the GPU, or 0 for no bound.

Remarks ​

When the GPU is the bottleneck the browser lets the CPU keep submitting, and the queue of unfinished frames grows to several frames. Everything that waits on the GPU then pays for that whole queue: readbacks such as BaseTexture.readPixels resolve only after every frame ahead of them has finished, and so does the picture on screen. With a bound set, a frame whose turn comes while that many earlier frames are still unfinished is skipped, so the CPU falls in step with the GPU and readback and display latency drop to about the bound. Throughput is unchanged, because the GPU was already the limit. Two is a good value; one trades some GPU idle time for the lowest latency.

Only WebGPU enforces this. WebGL has no way to learn when a frame's work finished without stalling, so it ignores the setting.


isRendering ​

isRendering: boolean

Defined in: libs/device/src/base_types.ts:3006

Check if the device is running a rendering loop by calling AbstractDevice.runLoop


canvas ​

canvas: HTMLCanvasElement

Defined in: libs/device/src/base_types.ts:3008

Get the canvas element for this device


type ​

type: string

Defined in: libs/device/src/base_types.ts:3010

Get the device type


programBuilder ​

programBuilder: ProgramBuilder

Defined in: libs/device/src/base_types.ts:3012

Get the program builder


runLoopFunction ​

runLoopFunction: (device) => void

Defined in: libs/device/src/base_types.ts:3014

Get the run loop callback function

Parameters ​

device ​

AbstractDevice

Returns ​

void

Methods ​

on() ​

on<K>(type, listener, context?): void

Defined in: libs/base/dist/index.d.ts:592

Sets up a function that will be called whenever the specified event is delivered to the target

Type Parameters ​

K ​

K extends keyof DeviceEventMap

Parameters ​

type ​

K

The event type to listen for

listener ​

EventListener<DeviceEventMap, K>

The callback function

context? ​

unknown

Context object of the listener function

Returns ​

void

Inherited from ​

IEventTarget.on


once() ​

once<K>(type, listener, context?): void

Defined in: libs/base/dist/index.d.ts:599

Sets up a function that will be called only once when the specified event is delivered to the target

Type Parameters ​

K ​

K extends keyof DeviceEventMap

Parameters ​

type ​

K

The event type to listen for

listener ​

EventListener<DeviceEventMap, K>

The callback function

context? ​

unknown

Context object of the listener function

Returns ​

void

Inherited from ​

IEventTarget.once


off() ​

off<K>(type, listener?, context?): void

Defined in: libs/base/dist/index.d.ts:605

Removes an event listener function previously registered.

Type Parameters ​

K ​

K extends keyof DeviceEventMap

Parameters ​

type ​

K

The event type for which to remove an event listener

listener? ​

EventListener<DeviceEventMap>

The callback function to be removed

context? ​

unknown

Returns ​

void

Inherited from ​

IEventTarget.off


dispatchEvent() ​

dispatchEvent<K>(type, ...args): void

Defined in: libs/base/dist/index.d.ts:611

Synchronously invoke the affected event listeners with an event object

Type Parameters ​

K ​

K extends keyof DeviceEventMap

Parameters ​

type ​

K

args ​

...DeviceEventMap[K]

Returns ​

void

false if the event was canceled, otherwise true

Inherited from ​

IEventTarget.dispatchEvent


setFixedFrameTime() ​

setFixedFrameTime(ms): void

Defined in: libs/device/src/base_types.ts:2523

Sets a fixed per-frame time step in milliseconds for deterministic playback, or null to restore wall-clock timing. Default is null.

Parameters ​

ms ​

number

Fixed frame time in milliseconds, or null to disable.

Returns ​

void

Remarks ​

Affects frameInfo.elapsedFrame/elapsedOverall/frameTimestamp only; frame scheduling is unchanged. While enabled, FPS and CPU time statistics are derived from the synthetic clock and no longer reflect wall-clock time.


poolExists() ​

poolExists(key): boolean

Defined in: libs/device/src/base_types.ts:2525

Check if a pool with given key exists

Parameters ​

key ​

string | symbol

Returns ​

boolean


getPool() ​

getPool(key): Pool

Defined in: libs/device/src/base_types.ts:2527

Get the pool with given key, or create a new one if not exists

Parameters ​

key ​

string | symbol

Returns ​

Pool


getAdapterInfo() ​

getAdapterInfo(): any

Defined in: libs/device/src/base_types.ts:2529

Get adapter information

Returns ​

any


getFrameBufferSampleCount() ​

getFrameBufferSampleCount(): number

Defined in: libs/device/src/base_types.ts:2531

Get sample count of current frame buffer

Returns ​

number


isContextLost() ​

isContextLost(): boolean

Defined in: libs/device/src/base_types.ts:2533

Returns true if device context is lost.

Returns ​

boolean


getScaleX() ​

getScaleX(): number

Defined in: libs/device/src/base_types.ts:2535

Get the value of device pixel ratio in X axis

Returns ​

number


getScaleY() ​

getScaleY(): number

Defined in: libs/device/src/base_types.ts:2537

Get the value of device pixel ratio in Y axis

Returns ​

number


getDrawingBufferWidth() ​

getDrawingBufferWidth(): number

Defined in: libs/device/src/base_types.ts:2539

Get the width of current frame buffer

Returns ​

number


getDrawingBufferHeight() ​

getDrawingBufferHeight(): number

Defined in: libs/device/src/base_types.ts:2541

Get the height of current frame buffer

Returns ​

number


getBackBufferWidth() ​

getBackBufferWidth(): number

Defined in: libs/device/src/base_types.ts:2543

Get the width of back buffer

Returns ​

number


getBackBufferHeight() ​

getBackBufferHeight(): number

Defined in: libs/device/src/base_types.ts:2545

Get the height of back buffer

Returns ​

number


getDeviceCaps() ​

getDeviceCaps(): Immutable<DeviceCaps>

Defined in: libs/device/src/base_types.ts:2547

Get the device capabilities

Returns ​

Immutable<DeviceCaps>


nextFrame() ​

nextFrame(callback): number

Defined in: libs/device/src/base_types.ts:2557

Schedule next frame

Parameters ​

callback ​

() => void

Returns ​

number


cancelNextFrame() ​

cancelNextFrame(handle): void

Defined in: libs/device/src/base_types.ts:2559

Cancel schedule next frame

Parameters ​

handle ​

number

Returns ​

void


setFont() ​

setFont(fontName): void

Defined in: libs/device/src/base_types.ts:2561

Set font for drawText function

Parameters ​

fontName ​

string

Returns ​

void


setTextRenderStates() ​

setTextRenderStates(states): void

Defined in: libs/device/src/base_types.ts:2563

Set render states to be used when drawing text. If not set, default states will be used.

Parameters ​

states ​

RenderStateSet

Returns ​

void


drawText() ​

Call Signature ​

drawText(text, x, y, color): void

Defined in: libs/device/src/base_types.ts:2571

Draw a string

Parameters ​
text ​

string

The string that will be drawn

x ​

number

x coordinate in pixels related to the viewport origin

y ​

number

y coordinate in pixels related to the viewport origin

color ​

string | Vector4 | Vector3

A CSS color value

Returns ​

void

Call Signature ​

drawText(text, rect, color, options?): void

Defined in: libs/device/src/base_types.ts:2579

Draw a string inside a rectangle with layout and clipping

Parameters ​
text ​

string

The string that will be drawn

rect ​

Immutable<Rect>

Layout rectangle in pixels related to the viewport origin

color ​

string | Vector4 | Vector3

A CSS color value

options? ​

DrawTextLayoutOptions

Text layout options

Returns ​

void


clearFrameBuffer() ​

clearFrameBuffer(clearColor, clearDepth, clearStencil): void

Defined in: libs/device/src/base_types.ts:2604

Clears the current frame buffer.

Parameters ​

clearColor ​

Vector4 | readonly Vector4[]

Color clear value, per-target color clear values, or null to skip color clears.

clearDepth ​

number

If not null, the depth buffer will be cleared to this value.

clearStencil ​

number

If not null, the stencil buffer will be cleared to this value.

Returns ​

void

Remarks ​

Color, depth and stencil clears are independent. Passing null or undefined for one component leaves that component unchanged.

For color clears, a single Vector4 clears every current color target to the same value. Passing an array switches to per-target behavior: array element i clears color target i, and a null, undefined or missing element skips that target. Therefore [color] is equivalent to color only when the current frame buffer has exactly one color target. If the array contains more entries than the current color target count, the extra entries are ignored after reporting an error.


createGPUTimer() ​

createGPUTimer(): ITimer

Defined in: libs/device/src/base_types.ts:2610

Creates a GPU timer

Returns ​

ITimer


beginTimestampQuery() ​

beginTimestampQuery(label?, options?): number

Defined in: libs/device/src/base_types.ts:2617

Begin a GPU timestamp query scope.

Parameters ​

label? ​

string

options? ​

TimestampQueryOptions

Returns ​

number

Remarks ​

The returned id is the only unique handle. Labels are only for grouping/debugging.


endTimestampQuery() ​

endTimestampQuery(id): void

Defined in: libs/device/src/base_types.ts:2619

End a GPU timestamp query scope.

Parameters ​

id ​

number

Returns ​

void


pollTimestampQuery() ​

pollTimestampQuery(query): TimestampQueryResult

Defined in: libs/device/src/base_types.ts:2626

Poll a timestamp query result. Returns null when the query is still pending.

Parameters ​

query ​

TimestampQueryHandle

Returns ​

TimestampQueryResult

Remarks ​

Passing a numeric id is unambiguous. Passing a label resolves the latest matching scope.


resolveTimestampQuery() ​

resolveTimestampQuery(query): Promise<TimestampQueryResult>

Defined in: libs/device/src/base_types.ts:2628

Resolve a timestamp query result asynchronously.

Parameters ​

query ​

TimestampQueryHandle

Returns ​

Promise<TimestampQueryResult>


collectTimestampQueries() ​

collectTimestampQueries(filter?): TimestampQueryResult[]

Defined in: libs/device/src/base_types.ts:2630

Collect resolved timestamp query results.

Parameters ​

filter? ​

TimestampQueryFilter

Returns ​

TimestampQueryResult[]


createRenderStateSet() ​

createRenderStateSet(): RenderStateSet

Defined in: libs/device/src/base_types.ts:2632

Creates a render state set object

Returns ​

RenderStateSet


createBlendingState() ​

createBlendingState(): BlendingState

Defined in: libs/device/src/base_types.ts:2634

Creates a blending state object

Returns ​

BlendingState


createColorState() ​

createColorState(): ColorState

Defined in: libs/device/src/base_types.ts:2636

Creates a color state object

Returns ​

ColorState


createRasterizerState() ​

createRasterizerState(): RasterizerState

Defined in: libs/device/src/base_types.ts:2638

Creates a rasterizer state object

Returns ​

RasterizerState


createDepthState() ​

createDepthState(): DepthState

Defined in: libs/device/src/base_types.ts:2640

Creates a depth state object

Returns ​

DepthState


createStencilState() ​

createStencilState(): StencilState

Defined in: libs/device/src/base_types.ts:2642

Creates a stencil state object

Returns ​

StencilState


createSampler() ​

createSampler(options): TextureSampler

Defined in: libs/device/src/base_types.ts:2648

Creates a texture sampler object

Parameters ​

options ​

SamplerOptions

The creation options

Returns ​

TextureSampler

The created texture sampler


createTextureFromMipmapData() ​

createTextureFromMipmapData<T>(data, sRGB, options?): T

Defined in: libs/device/src/base_types.ts:2655

Creates a texture from given mipmap data

Type Parameters ​

T ​

T extends BaseTexture<unknown> = BaseTexture<unknown>

Parameters ​

data ​

TextureMipmapData

Mipmap data

sRGB ​

boolean

options? ​

TextureCreationOptions

Texture creation options

Returns ​

T

The created texture


createTexture2D() ​

createTexture2D(format, width, height, options?): Texture2D<unknown>

Defined in: libs/device/src/base_types.ts:2668

Creates a 2d texture

Parameters ​

format ​

TextureFormat

The texture format

width ​

number

Pixel width of the texture

height ​

number

Pixel height of the texture

options? ​

TextureCreationOptions

The creation options

Returns ​

Texture2D<unknown>

The created 2D texture


createTexture2DFromImage() ​

createTexture2DFromImage(element, sRGB, options?): Texture2D<unknown>

Defined in: libs/device/src/base_types.ts:2680

Creates a 2d texture from a image element

Parameters ​

element ​

TextureImageElement

The image element

sRGB ​

boolean

options? ​

TextureCreationOptions

The creation options

Returns ​

Texture2D<unknown>

The created 2D texture.


createTexture2DArray() ​

createTexture2DArray(format, width, height, depth, options?): Texture2DArray<unknown>

Defined in: libs/device/src/base_types.ts:2694

Creates a 2d array texture

Parameters ​

format ​

TextureFormat

The texture format

width ​

number

Pixel width of the texture

height ​

number

Pixel height of the texture

depth ​

number

Array length of the texture

options? ​

TextureCreationOptions

The creation options

Returns ​

Texture2DArray<unknown>

The created 2D array texture.


createTexture2DArrayFromImages() ​

createTexture2DArrayFromImages(elements, sRGB, options?): Texture2DArray<unknown>

Defined in: libs/device/src/base_types.ts:2708

Creates a 2d array texture from a seris of image elements

Parameters ​

elements ​

TextureImageElement[]

image elements

sRGB ​

boolean

options? ​

TextureCreationOptions

The creation options

Returns ​

Texture2DArray<unknown>

The created 2D array texture.

Remarks ​

image elements must have the same size.


createTexture3D() ​

createTexture3D(format, width, height, depth, options?): Texture3D<unknown>

Defined in: libs/device/src/base_types.ts:2722

Creates a 3D texture

Parameters ​

format ​

TextureFormat

The texture format

width ​

number

Pixel width of the texture

height ​

number

Pixel height of the texture

depth ​

number

Pixel depth of the texture

options? ​

TextureCreationOptions

The creation options

Returns ​

Texture3D<unknown>

The created 3D texture.


createCubeTexture() ​

createCubeTexture(format, size, options?): TextureCube<unknown>

Defined in: libs/device/src/base_types.ts:2736

Creates a cube texture

Parameters ​

format ​

TextureFormat

The texture format

size ​

number

Pixel width of the texture

options? ​

TextureCreationOptions

The creation options

Returns ​

TextureCube<unknown>

The created cube texture.


createTextureVideo() ​

createTextureVideo(el, samplerOptions?): TextureVideo

Defined in: libs/device/src/base_types.ts:2746

Creates a video texture from a video element

Parameters ​

el ​

HTMLVideoElement

The video element

samplerOptions? ​

SamplerOptions

Returns ​

TextureVideo

The created video texture.


copyTexture2D() ​

copyTexture2D(src, srcLevel, dst, dstLevel): void

Defined in: libs/device/src/base_types.ts:2758

Copies a 2d texture to another texture.

Parameters ​

src ​

Texture2D

Texture that will be copied from.

srcLevel ​

number

Which mipmap level to be copied from.

dst ​

Texture2D

Texture that will be copied to.

dstLevel ​

number

Which mipmap level to be copied to.

Returns ​

void

Remarks ​

The two textures must have the same size and format


copyFramebufferToTexture2D() ​

copyFramebufferToTexture2D(src, index, dst, level): void

Defined in: libs/device/src/base_types.ts:2770

Copies a color attachment of a framebuffer to a mipmap level of a texture.

Parameters ​

src ​

FrameBuffer

Framebuffer that will be copied from.

index ​

number

Color attachment index of the framebuffer.

dst ​

Texture2D

Texture that will be copied to.

level ​

number

Which mipmap level should be copied to.

Returns ​

void

Remarks ​

The color attachment and the mipmap level must have the same size and format


reverseVertexWindingOrder() ​

reverseVertexWindingOrder(reverse): void

Defined in: libs/device/src/base_types.ts:2779

Set wether to reverse the winding order

Parameters ​

reverse ​

boolean

true if the winding order should be reversed.

Returns ​

void

Remarks ​

The default winding order is counter-clockwise.


isWindingOrderReversed() ​

isWindingOrderReversed(): boolean

Defined in: libs/device/src/base_types.ts:2783

Check if the current winding order is reversed.

Returns ​

boolean


createGPUProgram() ​

createGPUProgram(params): GPUProgram

Defined in: libs/device/src/base_types.ts:2789

Creates a gpu program

Parameters ​

params ​

GPUProgramConstructParams

The creation options

Returns ​

GPUProgram

The created program.


createBindGroup() ​

createBindGroup(layout): BindGroup

Defined in: libs/device/src/base_types.ts:2795

Creates a bind group

Parameters ​

layout ​

Immutable<BindGroupLayout>

Layout of the bind group

Returns ​

BindGroup

The created bind group.


createBuffer() ​

createBuffer(sizeInBytes, options): GPUDataBuffer

Defined in: libs/device/src/base_types.ts:2802

Creates a gpu buffer

Parameters ​

sizeInBytes ​

number

Size of the buffer in bytes

options ​

BufferCreationOptions

The creation options

Returns ​

GPUDataBuffer

The created buffer.


copyBuffer() ​

copyBuffer(sourceBuffer, destBuffer, srcOffset, dstOffset, bytes): void

Defined in: libs/device/src/base_types.ts:2811

Copies a buffer to another buffer

Parameters ​

sourceBuffer ​

GPUDataBuffer

Source buffer

destBuffer ​

GPUDataBuffer

destination buffer

srcOffset ​

number

Source offset in bytes

dstOffset ​

number

Destination offset in bytes

bytes ​

number

How many bytes to be copy

Returns ​

void


createIndexBuffer() ​

createIndexBuffer(data, options?): IndexBuffer

Defined in: libs/device/src/base_types.ts:2824

Creates an index buffer

Parameters ​

data ​

Uint16Array<ArrayBuffer> | Uint32Array<ArrayBuffer>

Data of the index buffer

options? ​

BufferCreationOptions

The creation options

Returns ​

IndexBuffer

The created index buffer.


createStructuredBuffer() ​

createStructuredBuffer(structureType, options, data?): StructuredBuffer

Defined in: libs/device/src/base_types.ts:2835

Creates a structured buffer

Parameters ​

structureType ​

PBStructTypeInfo

The structure type

options ​

BufferCreationOptions

The creation options

data? ​

TypedArray

Data to be filled with

Returns ​

StructuredBuffer

The created structured buffer.


createVertexLayout() ​

createVertexLayout(options): VertexLayout

Defined in: libs/device/src/base_types.ts:2845

Creates a vertex layout object.

Parameters ​

options ​

VertexLayoutOptions

The creation options

Returns ​

VertexLayout

The created vertex layout object.


createFrameBuffer() ​

createFrameBuffer(colorAttachments, depthAttachment, options?): FrameBuffer

Defined in: libs/device/src/base_types.ts:2851

Creates a frame buffer

Parameters ​

colorAttachments ​

BaseTexture<unknown>[]

depthAttachment ​

BaseTexture<unknown>

options? ​

FrameBufferOptions

The creation options

Returns ​

FrameBuffer

The created framebuffer.


setViewport() ​

setViewport(vp): void

Defined in: libs/device/src/base_types.ts:2861

Set viewport from an array that contains the position and size

Parameters ​

vp ​

Immutable<number[] | DeviceViewport>

The viewport position and size, if not specified, the viewport will be set to [0, 0, drawingBufferWidth, drawingBufferHeight]

Returns ​

void


getViewport() ​

getViewport(): Immutable<DeviceViewport>

Defined in: libs/device/src/base_types.ts:2863

Get current viewport as [x, y, width, height]

Returns ​

Immutable<DeviceViewport>


setScissor() ​

setScissor(scissor): void

Defined in: libs/device/src/base_types.ts:2868

Set scissor rectangle from an array that contains the position and size

Parameters ​

scissor ​

Immutable<number[] | DeviceViewport>

The scissor rectangle position and size, if not specified, the scissor rectangle will be set to [0, 0, drawingBufferWidth,drawingBufferHeight]

Returns ​

void


getScissor() ​

getScissor(): Immutable<DeviceViewport>

Defined in: libs/device/src/base_types.ts:2872

Get current scissor rectangle

Returns ​

Immutable<DeviceViewport>


setProgram() ​

setProgram(program): void

Defined in: libs/device/src/base_types.ts:2877

Set current GPU program

Parameters ​

program ​

GPUProgram<unknown>

The GPU program to be set

Returns ​

void


getProgram() ​

getProgram(): GPUProgram<unknown>

Defined in: libs/device/src/base_types.ts:2881

Get current GPU program

Returns ​

GPUProgram<unknown>


setVertexLayout() ​

setVertexLayout(vertexData): void

Defined in: libs/device/src/base_types.ts:2887

Set current vertex layout

Parameters ​

vertexData ​

VertexLayout<unknown>

The vertex layout to be set

Returns ​

void


getVertexLayout() ​

getVertexLayout(): VertexLayout<unknown>

Defined in: libs/device/src/base_types.ts:2889

Get current vertex layout

Returns ​

VertexLayout<unknown>


setRenderStates() ​

setRenderStates(renderStates): void

Defined in: libs/device/src/base_types.ts:2895

Set current render states

Parameters ​

renderStates ​

RenderStateSet

The render state set

Returns ​

void


getRenderStates() ​

getRenderStates(): RenderStateSet

Defined in: libs/device/src/base_types.ts:2897

Get current render states

Returns ​

RenderStateSet


setFramebuffer() ​

Call Signature ​

setFramebuffer(rt): void

Defined in: libs/device/src/base_types.ts:2903

Sets the current framebuffer to the specified FrameBuffer object.

Parameters ​
rt ​

FrameBuffer<unknown>

The FrameBuffer object to set as the current framebuffer.

Returns ​

void

Call Signature ​

setFramebuffer(color, depth?, sampleCount?): void

Defined in: libs/device/src/base_types.ts:2916

Sets the current framebuffer specifying complex color attachments, an optional depth attachment, MIP level, face, and sample count.

Parameters ​
color ​

BaseTexture<unknown>[]

An array of BaseTextures or objects containing a BaseTexture and optional properties. Each BaseTexture or object will serve as a color attachment. - If an object is provided, it can specify: - texture: The BaseTexture to use. - miplevel: Optional MIP level for this specific texture. default is 0. - face: Optional face index for cube map textures, specifying the cube face this texture is attached to. default is 0. - layer: Optional layer index, useful for texture arrays. default is 0.

depth? ​

BaseTexture

Optional BaseTexture to serve as the depth attachment.

sampleCount? ​

number

Optional sample count defining the number of samples for multisampling.

Returns ​

void

Call Signature ​

setFramebuffer(colorOrRT, depth?, sampleCount?): void

Defined in: libs/device/src/base_types.ts:2917

Parameters ​
colorOrRT ​

BaseTexture<unknown>[] | FrameBuffer<unknown>

depth? ​

BaseTexture

sampleCount? ​

number

Returns ​

void


getFramebuffer() ​

getFramebuffer(): FrameBuffer<unknown>

Defined in: libs/device/src/base_types.ts:2923

Get current frame buffer

Returns ​

FrameBuffer<unknown>


setBindGroup() ​

setBindGroup(index, bindGroup, dynamicOffsets?): void

Defined in: libs/device/src/base_types.ts:2931

Set current bind group

Parameters ​

index ​

number

index of the bind group

bindGroup ​

BindGroup

The bind group to be set

dynamicOffsets? ​

Iterable<number>

dynamic uniform buffer offsets of the bind group or null

Returns ​

void


getBindGroup() ​

getBindGroup(index): [BindGroup, Iterable<number, any, any>]

Defined in: libs/device/src/base_types.ts:2936

Get current bind group

Parameters ​

index ​

number

index of the bind group to get

Returns ​

[BindGroup, Iterable<number, any, any>]


flush() ​

flush(): void

Defined in: libs/device/src/base_types.ts:2938

Flush the gpu command buffer

Returns ​

void


readPixels() ​

readPixels(index, x, y, w, h, buffer): Promise<void>

Defined in: libs/device/src/base_types.ts:2953

Read pixel values from current frame buffer

Parameters ​

index ​

number

color attachment index

x ​

number

x position of the reading area

y ​

number

y position of the reading area

w ​

number

width of the reading area

h ​

number

height of the reading area

buffer ​

TypedArray

The output buffer

Returns ​

Promise<void>

Remarks ​

This method reads the data asynchronously to prevent GPU stall. For WebGL1 devices, the GPU stall is still inevitable.


readPixelsToBuffer() ​

readPixelsToBuffer(index, x, y, w, h, buffer): void

Defined in: libs/device/src/base_types.ts:2967

Read pixel values from current frame buffer to a GPU buffer

Parameters ​

index ​

number

color attachment index

x ​

number

x position of the reading area

y ​

number

y position of the reading area

w ​

number

width of the reading area

h ​

number

height of the reading area

buffer ​

GPUDataBuffer

The output buffer

Returns ​

void

Remarks ​

This method does not support WebGL1 device


beginCapture() ​

beginCapture(): void

Defined in: libs/device/src/base_types.ts:2971

Begin capture draw commands

Returns ​

void


executeRenderBundle() ​

executeRenderBundle(renderBundle): void

Defined in: libs/device/src/base_types.ts:2976

Executes render bundle

Parameters ​

renderBundle ​

unknown

RenderBundle to be execute

Returns ​

void


endCapture() ​

endCapture(): unknown

Defined in: libs/device/src/base_types.ts:2981

End capture draw commands

Returns ​

unknown

A RenderBundle that holds the captured draw commands


beginFrame() ​

beginFrame(): boolean

Defined in: libs/device/src/base_types.ts:3021

Begins a frame for rendering

Returns ​

boolean

Remarks ​

All rendering call must occur between the

See ​

  • AbstractDevice.beginFrame and
  • AbstractDevice.endFrame methods

endFrame() ​

endFrame(): void

Defined in: libs/device/src/base_types.ts:3028

Ends a frame for rendering

Returns ​

void

Remarks ​

All rendering call must occur between the

See ​

  • AbstractDevice.beginFrame and
  • AbstractDevice.endFrame methods

inFrame() ​

inFrame(): boolean

Defined in: libs/device/src/base_types.ts:3034

Whether currently inside a beginFrame()/endFrame() pair

Returns ​

boolean

true if currently inside a beginFrame()endFrame() pair


getVertexAttribFormat() ​

getVertexAttribFormat(semantic, dataType, componentCount): VertexAttribFormat

Defined in: libs/device/src/base_types.ts:3042

Get the vertex attribute format from vertex semantic and data type

Parameters ​

semantic ​

VertexSemantic

The vertex semantic

dataType ​

DataType

The data type

componentCount ​

number

The component count

Returns ​

VertexAttribFormat


createInterleavedVertexBuffer() ​

createInterleavedVertexBuffer(attribFormats, data, options?): StructuredBuffer<unknown>

Defined in: libs/device/src/base_types.ts:3055

Creates an interleaved vertex buffer

Parameters ​

attribFormats ​

VertexAttribFormat[]

The vertex attribute formats for each vertex stream in the vertex buffer

data ​

TypedArray

Data to be filled with

options? ​

BufferCreationOptions

The creation options

Returns ​

StructuredBuffer<unknown>

The created vertex buffer.


createVertexBuffer() ​

createVertexBuffer(attribFormat, data, options?): StructuredBuffer<unknown>

Defined in: libs/device/src/base_types.ts:3068

Creates a non-interleaved vertex buffer

Parameters ​

attribFormat ​

VertexAttribFormat

The vertex attribute format

data ​

TypedArray

Data to be filled with

options? ​

BufferCreationOptions

The creation options

Returns ​

StructuredBuffer<unknown>

The created vertex buffer


draw() ​

draw(primitiveType, first, count): void

Defined in: libs/device/src/base_types.ts:3080

Draw primitives

Parameters ​

primitiveType ​

PrimitiveType

The primitive type

first ​

number

The vertex offset (or index offset if an index buffer exists)

count ​

number

The vertex count (or index count if an index buffer exists) to be drawn

Returns ​

void


drawInstanced() ​

drawInstanced(primitiveType, first, count, numInstances): void

Defined in: libs/device/src/base_types.ts:3089

Draw multiple instances of primitives

Parameters ​

primitiveType ​

PrimitiveType

The primitive type

first ​

number

The vertex offset (or index offset if an index buffer exists)

count ​

number

The vertex count (or index count if an index buffer exists) to be drawn

numInstances ​

number

How many instances to be drawn

Returns ​

void


drawIndirect() ​

drawIndirect(primitiveType, indirectBuffer, indirectOffset?): void

Defined in: libs/device/src/base_types.ts:3102

Draw primitives, reading the draw arguments from a GPU buffer

Parameters ​

primitiveType ​

PrimitiveType

The primitive type

indirectBuffer ​

GPUDataBuffer

The buffer holding the draw arguments

indirectOffset? ​

number

Byte offset of the draw arguments within the buffer, must be a multiple of 4

Returns ​

void

Remarks ​

Requires MiscCaps.supportDrawIndirect. The buffer must be created with the 'indirect' usage and contain a tightly packed group of 4 uint32 values: vertexCount, instanceCount, firstVertex, firstInstance.


drawIndexedIndirect() ​

drawIndexedIndirect(primitiveType, indirectBuffer, indirectOffset?): void

Defined in: libs/device/src/base_types.ts:3115

Draw indexed primitives, reading the draw arguments from a GPU buffer

Parameters ​

primitiveType ​

PrimitiveType

The primitive type

indirectBuffer ​

GPUDataBuffer

The buffer holding the draw arguments

indirectOffset? ​

number

Byte offset of the draw arguments within the buffer, must be a multiple of 4

Returns ​

void

Remarks ​

Requires MiscCaps.supportDrawIndirect. The buffer must be created with the 'indirect' usage and contain a tightly packed group of 5 uint32 values: indexCount, instanceCount, firstIndex, baseVertex, firstInstance.


compute() ​

compute(workgroupCountX, workgroupCountY, workgroupCountZ): void

Defined in: libs/device/src/base_types.ts:3127

Dispatches a compute task to the GPU

Parameters ​

workgroupCountX ​

number

X dimension of the grid of workgroups to be dispatch

workgroupCountY ​

number

Y dimension of the grid of workgroups to be dispatch

workgroupCountZ ​

number

Z dimension of the grid of workgroups to be dispatch

Returns ​

void


runNextFrame() ​

runNextFrame(f): void

Defined in: libs/device/src/base_types.ts:3133

Schedules a function to be executed at the beginning of the next frame

Parameters ​

f ​

() => void

The function to be scheduled

Returns ​

void


runNextFrameAsync() ​

runNextFrameAsync(f): Promise<void>

Defined in: libs/device/src/base_types.ts:3139

Asyncronized version of scheduling a function to be executed at the beginning of the next frame

Parameters ​

f ​

() => void

The function to be scheduled

Returns ​

Promise<void>


exitLoop() ​

exitLoop(): void

Defined in: libs/device/src/base_types.ts:3141

Exits from current rendering loop

Returns ​

void


runLoop() ​

runLoop(func): void

Defined in: libs/device/src/base_types.ts:3147

Begins a rendering loop

Parameters ​

func ​

(device) => void

The function to be executed at every frame

Returns ​

void


getGPUObjects() ​

getGPUObjects(): GPUObjectList

Defined in: libs/device/src/base_types.ts:3149

Get all GPU objects

Returns ​

GPUObjectList


getGPUObjectById() ​

getGPUObjectById(uid): GPUObject<unknown>

Defined in: libs/device/src/base_types.ts:3155

Get GPU object by id

Parameters ​

uid ​

number

id of the GPU object

Returns ​

GPUObject<unknown>


screenXToDevice() ​

screenXToDevice(val): number

Defined in: libs/device/src/base_types.ts:3164

Calculates the actual position of current frame buffer from screen position in X axis.

Parameters ​

val ​

number

The screen position in pixels

Returns ​

number

Remarks ​

If current frame buffer is the back buffer, the value will be scaled by the device pixel ratio.


deviceXToScreen() ​

deviceXToScreen(val): number

Defined in: libs/device/src/base_types.ts:3173

Calculates the screen position from position of current frame buffer in X axis.

Parameters ​

val ​

number

The position of current frame buffer in pixels

Returns ​

number

Remarks ​

If current frame buffer is the back buffer, the value will be divided by the device pixel ratio.


screenYToDevice() ​

screenYToDevice(val): number

Defined in: libs/device/src/base_types.ts:3182

Calculates the actual position of current frame buffer from screen position in Y axis.

Parameters ​

val ​

number

The screen position in pixels

Returns ​

number

Remarks ​

If current frame buffer is the back buffer, the value will be scaled by the device pixel ratio.


deviceYToScreen() ​

deviceYToScreen(val): number

Defined in: libs/device/src/base_types.ts:3191

Calculates the screen position from position of current frame buffer in Y axis.

Parameters ​

val ​

number

The position of current frame buffer in pixels

Returns ​

number

Remarks ​

If current frame buffer is the back buffer, the value will be divided by the device pixel ratio.


buildRenderProgram() ​

buildRenderProgram(options): GPUProgram<unknown>

Defined in: libs/device/src/base_types.ts:3193

Builds render program

Parameters ​

options ​

PBRenderOptions

Returns ​

GPUProgram<unknown>


buildComputeProgram() ​

buildComputeProgram(options): GPUProgram<unknown>

Defined in: libs/device/src/base_types.ts:3195

Builds compute program

Parameters ​

options ​

PBComputeOptions

Returns ​

GPUProgram<unknown>


pushDeviceStates() ​

pushDeviceStates(): void

Defined in: libs/device/src/base_types.ts:3197

Pushes current FrameBuffer state

Returns ​

void


popDeviceStates() ​

popDeviceStates(): void

Defined in: libs/device/src/base_types.ts:3199

Pops last FrameBuffer state

Returns ​

void

Released under the MIT License.