Class: WebglContextManager

WebglContextManager

Handles the webgl context, isolating it from the rest of the DrawerBase API. Manages WebGL context lifecycle, shaders, textures, framebuffers, and other WebGL resources.

Constructor

new WebglContextManager(options)

Parameters:
Name Type Description
options Object Options for the context manager
Properties
Name Type Attributes Default Description
renderingCanvas HTMLCanvasElement The canvas element to use for WebGL context
unpackWithPremultipliedAlpha Boolean <optional>
false Whether to enable gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL
imageSmoothingEnabled Boolean <optional>
true Whether image smoothing is enabled
Source:

Methods

createTexture(data, options) → {WebGLTexture|null}

Create and upload a texture for a tile
Parameters:
Name Type Description
data HTMLImageElement | HTMLCanvasElement | ImageData Image data to upload
options Object Texture options
Properties
Name Type Attributes Description
unpackWithPremultipliedAlpha Boolean <optional>
Override default unpack setting
Source:
Returns:
The created texture, or null on error
Type
WebGLTexture | null

deleteTexture(texture)

Delete a texture
Parameters:
Name Type Description
texture WebGLTexture The texture to delete
Source:

destroy()

Destroy the WebGL context and all resources
Source:

getContext() → {WebGLRenderingContext|WebGL2RenderingContext|null}

Get the WebGL context
Source:
Returns:
The WebGL context
Type
WebGLRenderingContext | WebGL2RenderingContext | null

getFirstPass() → {Object|null}

Get the first pass shader program and resources
Source:
Returns:
The first pass object with shader program, buffers, and uniforms
Type
Object | null

getFrameBuffer() → {WebGLFramebuffer|null}

Get the render-to-texture framebuffer
Source:
Returns:
The framebuffer
Type
WebGLFramebuffer | null

getMaxTextures() → {Number}

Get the maximum number of texture units
Source:
Returns:
MAX_TEXTURE_IMAGE_UNITS value
Type
Number

getRenderingCanvas() → {HTMLCanvasElement}

Get the rendering canvas element
Source:
Returns:
The canvas element
Type
HTMLCanvasElement

getRenderToTexture() → {WebGLTexture|null}

Get the render-to-texture texture
Source:
Returns:
The texture
Type
WebGLTexture | null

getSecondPass() → {Object|null}

Get the second pass shader program and resources
Source:
Returns:
The second pass object with shader program, buffers, and uniforms
Type
Object | null

getTextureFilter() → {Number}

Get the texture filter constant (LINEAR or NEAREST)
Source:
Returns:
gl.LINEAR or gl.NEAREST
Type
Number

getUnitQuad() → {Float32Array}

Get the unit quad vertex buffer
Source:
Returns:
The unit quad buffer
Type
Float32Array

isDestroyed() → {Boolean}

Check if this context manager has been destroyed
Source:
Returns:
true if destroyed, false otherwise
Type
Boolean

isWebGL2() → {Boolean}

Check if using WebGL2
Source:
Returns:
true if WebGL2, false if WebGL1
Type
Boolean

makeQuadVertexBuffer(left, right, top, bottom) → {Float32Array}

Make a quad vertex buffer
Parameters:
Name Type Description
left Number Left coordinate
right Number Right coordinate
top Number Top coordinate
bottom Number Bottom coordinate
Source:
Returns:
Vertex buffer
Type
Float32Array

resizeRenderer(width, height)

Resize the render-to-texture when canvas size changes
Parameters:
Name Type Description
width Number New canvas width
height Number New canvas height
Source:

setImageSmoothingEnabled(enabled)

Set image smoothing enabled state
Parameters:
Name Type Description
enabled Boolean Whether image smoothing is enabled
Source:

setUnpackWithPremultipliedAlpha(enabled)

Set unpack with premultiplied alpha state
Parameters:
Name Type Description
enabled Boolean Whether to use premultiplied alpha
Source:

setupRenderer(width, height)

Set up the renderer: create shaders, textures, and framebuffers
Parameters:
Name Type Description
width Number Canvas width
height Number Canvas height
Source: