Skip to content

Documentation / device / AbstractDevice

Interface: AbstractDevice

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

Abstract interface for the rendering device.

Extends

Properties

[EventMapType]?

readonly optional [EventMapType]?: DeviceEventMap

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

Type-only event map marker.

Inherited from

IEventTarget.[EventMapType]


pool

pool: Pool

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

Get pool object


vSync

vSync: boolean

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

vSync


videoMemoryUsage

videoMemoryUsage: number

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

Get the video memory usage in bytes


frameInfo

frameInfo: FrameInfo

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

Get the current frame information


isRendering

isRendering: boolean

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

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


canvas

canvas: HTMLCanvasElement

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

Get the canvas element for this device


type

type: string

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

Get the device type


programBuilder

programBuilder: ProgramBuilder

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

Get the program builder


runLoopFunction

runLoopFunction: (device) => void

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

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:556

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:563

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:569

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:575

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


poolExists()

poolExists(key): boolean

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

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:2501

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:2503

Get adapter information

Returns

any


getFrameBufferSampleCount()

getFrameBufferSampleCount(): number

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

Get sample count of current frame buffer

Returns

number


isContextLost()

isContextLost(): boolean

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

Returns true if device context is lost.

Returns

boolean


getScaleX()

getScaleX(): number

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

Get the value of device pixel ratio in X axis

Returns

number


getScaleY()

getScaleY(): number

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

Get the value of device pixel ratio in Y axis

Returns

number


getDrawingBufferWidth()

getDrawingBufferWidth(): number

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

Get the width of current frame buffer

Returns

number


getDrawingBufferHeight()

getDrawingBufferHeight(): number

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

Get the height of current frame buffer

Returns

number


getBackBufferWidth()

getBackBufferWidth(): number

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

Get the width of back buffer

Returns

number


getBackBufferHeight()

getBackBufferHeight(): number

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

Get the height of back buffer

Returns

number


getDeviceCaps()

getDeviceCaps(): Immutable<DeviceCaps>

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

Get the device capabilities

Returns

Immutable<DeviceCaps>


nextFrame()

nextFrame(callback): number

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

Schedule next frame

Parameters

callback

() => void

Returns

number


cancelNextFrame()

cancelNextFrame(handle): void

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

Cancel schedule next frame

Parameters

handle

number

Returns

void


setFont()

setFont(fontName): void

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

Set font for drawText function

Parameters

fontName

string

Returns

void


setTextRenderStates()

setTextRenderStates(states): void

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

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:2537

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:2545

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:2570

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:2576

Creates a GPU timer

Returns

ITimer


beginTimestampQuery()

beginTimestampQuery(label?, options?): number

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

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:2585

End a GPU timestamp query scope.

Parameters

id

number

Returns

void


pollTimestampQuery()

pollTimestampQuery(query): TimestampQueryResult

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

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:2594

Resolve a timestamp query result asynchronously.

Parameters

query

TimestampQueryHandle

Returns

Promise<TimestampQueryResult>


collectTimestampQueries()

collectTimestampQueries(filter?): TimestampQueryResult[]

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

Collect resolved timestamp query results.

Parameters

filter?

TimestampQueryFilter

Returns

TimestampQueryResult[]


createRenderStateSet()

createRenderStateSet(): RenderStateSet

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

Creates a render state set object

Returns

RenderStateSet


createBlendingState()

createBlendingState(): BlendingState

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

Creates a blending state object

Returns

BlendingState


createColorState()

createColorState(): ColorState

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

Creates a color state object

Returns

ColorState


createRasterizerState()

createRasterizerState(): RasterizerState

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

Creates a rasterizer state object

Returns

RasterizerState


createDepthState()

createDepthState(): DepthState

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

Creates a depth state object

Returns

DepthState


createStencilState()

createStencilState(): StencilState

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

Creates a stencil state object

Returns

StencilState


createSampler()

createSampler(options): TextureSampler

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

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:2621

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:2634

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:2646

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:2660

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:2674

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:2688

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:2702

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:2712

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:2724

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:2736

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:2745

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:2749

Check if the current winding order is reversed.

Returns

boolean


createGPUProgram()

createGPUProgram(params): GPUProgram

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

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:2761

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:2768

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:2777

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:2790

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:2801

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:2811

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:2817

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:2827

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:2829

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

Returns

Immutable<DeviceViewport>


setScissor()

setScissor(scissor): void

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

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:2838

Get current scissor rectangle

Returns

Immutable<DeviceViewport>


setProgram()

setProgram(program): void

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

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:2847

Get current GPU program

Returns

GPUProgram<unknown>


setVertexLayout()

setVertexLayout(vertexData): void

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

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:2855

Get current vertex layout

Returns

VertexLayout<unknown>


setRenderStates()

setRenderStates(renderStates): void

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

Set current render states

Parameters

renderStates

RenderStateSet

The render state set

Returns

void


getRenderStates()

getRenderStates(): RenderStateSet

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

Get current render states

Returns

RenderStateSet


setFramebuffer()

Call Signature

setFramebuffer(rt): void

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

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:2882

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:2883

Parameters
colorOrRT

BaseTexture<unknown>[] | FrameBuffer<unknown>

depth?

BaseTexture

sampleCount?

number

Returns

void


getFramebuffer()

getFramebuffer(): FrameBuffer<unknown>

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

Get current frame buffer

Returns

FrameBuffer<unknown>


setBindGroup()

setBindGroup(index, bindGroup, dynamicOffsets?): void

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

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:2902

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:2904

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:2919

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:2933

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:2937

Begin capture draw commands

Returns

void


executeRenderBundle()

executeRenderBundle(renderBundle): void

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

Executes render bundle

Parameters

renderBundle

unknown

RenderBundle to be execute

Returns

void


endCapture()

endCapture(): unknown

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

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:2968

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:2975

Ends a frame for rendering

Returns

void

Remarks

All rendering call must occur between the

See

  • AbstractDevice.beginFrame and
  • AbstractDevice.endFrame methods

getVertexAttribFormat()

getVertexAttribFormat(semantic, dataType, componentCount): VertexAttribFormat

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

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:2996

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:3009

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:3021

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:3030

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


compute()

compute(workgroupCountX, workgroupCountY, workgroupCountZ): void

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

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:3044

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:3050

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:3052

Exits from current rendering loop

Returns

void


runLoop()

runLoop(func): void

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

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:3060

Get all GPU objects

Returns

GPUObjectList


getGPUObjectById()

getGPUObjectById(uid): GPUObject<unknown>

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

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:3075

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:3084

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:3093

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:3102

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:3104

Builds render program

Parameters

options

PBRenderOptions

Returns

GPUProgram<unknown>


buildComputeProgram()

buildComputeProgram(options): GPUProgram<unknown>

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

Builds compute program

Parameters

options

PBComputeOptions

Returns

GPUProgram<unknown>


pushDeviceStates()

pushDeviceStates(): void

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

Pushes current FrameBuffer state

Returns

void


popDeviceStates()

popDeviceStates(): void

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

Pops last FrameBuffer state

Returns

void

Released under the MIT License.