@bloopjs/toodle / backends/webgl2/WebGLBackend / WebGLBackend
Class: WebGLBackend
Defined in: backends/webgl2/WebGLBackend.ts:25
WebGL 2 implementation of the render backend.
Implements
Properties
atlasSize
readonlyatlasSize:Size
Defined in: backends/webgl2/WebGLBackend.ts:28
Size of the default texture atlas
Implementation of
defaultAtlasId
readonlydefaultAtlasId:"default"="default"
Defined in: backends/webgl2/WebGLBackend.ts:29
Default atlas ID (always "default")
Implementation of
limits
readonlylimits:object
Defined in: backends/webgl2/WebGLBackend.ts:27
Engine limits (texture size, instance count, etc.)
instanceBufferFields
instanceBufferFields:
number
Maximum number of instance buffer fields - 16 minus the vertex locations used by the engine
instanceBufferSize
instanceBufferSize:
number
Maximum size of instance buffer
instanceCount
instanceCount:
number
Maximum number of rendered instances in the scene per frame
maxTextLength
maxTextLength:
number=256
Maximum length of a single piece of text
shaderCount
shaderCount:
number=32
Maximum number of vfx shaders
textureArrayLayers
textureArrayLayers:
number=64
Maximum number of layers in a texture array
textureSize
textureSize:
number
Maximum dimensions of a single texture
uniformBufferSize
uniformBufferSize:
number
Maximum size of uniforms buffer
zIndex
zIndex:
number=32
Maximum number of unique z-indexes in the scene
Implementation of
type
readonlytype:"webgl2"
Defined in: backends/webgl2/WebGLBackend.ts:26
The type of backend ("webgpu" or "webgl2")
Implementation of
Accessors
gl
Get Signature
get gl():
WebGL2RenderingContext
Defined in: backends/webgl2/WebGLBackend.ts:246
Get the WebGL 2 rendering context.
Returns
WebGL2RenderingContext
presentationFormat
Get Signature
get presentationFormat():
TextureAtlasFormat
Defined in: backends/webgl2/WebGLBackend.ts:253
Get the presentation format (of the default atlas).
Returns
textureArrayHandle
Get Signature
get textureArrayHandle():
WebGLTexture
Defined in: backends/webgl2/WebGLBackend.ts:226
Get the default texture atlas handle.
Deprecated
Use getTextureAtlas("default").handle instead
Returns
WebGLTexture
Methods
createQuadShader()
createQuadShader(
opts):IBackendShader
Defined in: backends/webgl2/WebGLBackend.ts:160
Create a quad shader for instanced rendering.
Parameters
opts
Returns
Implementation of
IRenderBackend.createQuadShader
createTextureAtlas()
createTextureAtlas(
id,options?):ITextureAtlas
Defined in: backends/webgl2/WebGLBackend.ts:170
Create a new texture atlas.
Parameters
id
string
Unique identifier for this atlas
options?
Atlas configuration (format, layers, size)
Returns
Implementation of
IRenderBackend.createTextureAtlas
destroy()
destroy():
void
Defined in: backends/webgl2/WebGLBackend.ts:234
Clean up GPU resources.
Returns
void
Implementation of
destroyTextureAtlas()
destroyTextureAtlas(
id):void
Defined in: backends/webgl2/WebGLBackend.ts:214
Destroy a texture atlas and free GPU resources.
Parameters
id
string
Atlas identifier
Returns
void
Implementation of
IRenderBackend.destroyTextureAtlas
endFrame()
endFrame():
void
Defined in: backends/webgl2/WebGLBackend.ts:104
End the current frame and submit to GPU. WebGPU: Ends render pass and submits command buffer WebGL: Flushes pending operations
Returns
void
Implementation of
getTextureAtlas()
getTextureAtlas(
id):null|ITextureAtlas
Defined in: backends/webgl2/WebGLBackend.ts:210
Get a texture atlas by ID.
Parameters
id
string
Atlas identifier or defaults to "default"
Returns
null | ITextureAtlas
The atlas, or null if not found
Implementation of
IRenderBackend.getTextureAtlas
resize()
resize(
_width,_height):void
Defined in: backends/webgl2/WebGLBackend.ts:230
Handle canvas resize.
Parameters
_width
number
_height
number
Returns
void
Implementation of
startFrame()
startFrame(
clearColor,loadOp):void
Defined in: backends/webgl2/WebGLBackend.ts:83
Begin a new frame. WebGPU: Creates command encoder and render pass WebGL: Clears the canvas if loadOp is "clear"
Parameters
clearColor
loadOp
"load" | "clear"
Returns
void
Implementation of
updateEngineUniform()
updateEngineUniform(
_uniform):void
Defined in: backends/webgl2/WebGLBackend.ts:109
Update engine uniforms (view-projection matrix, resolution). Called once per frame before shader processing.
Parameters
_uniform
Returns
void
Implementation of
IRenderBackend.updateEngineUniform
uploadAtlas()
uploadAtlas(
atlas,layerIndex,atlasId?):Promise<void>
Defined in: backends/webgl2/WebGLBackend.ts:113
Upload a CPU texture atlas to a GPU texture array layer.
Parameters
atlas
The CPU-side atlas data to upload
layerIndex
number
Which layer in the texture array to upload to
atlasId?
string
Which atlas to upload to (default: "default")
Returns
Promise<void>
Implementation of
create()
staticcreate(canvas,options):Promise<WebGLBackend>
Defined in: backends/webgl2/WebGLBackend.ts:52
Create a WebGL 2 backend attached to a canvas.
Parameters
canvas
HTMLCanvasElement
options
WebGLBackendOptions = {}
Returns
Promise<WebGLBackend>