Class: WebGLDrawer

OpenSeadragon.WebGLDrawer

Default implementation of WebGLDrawer for an OpenSeadragon.Viewer. The WebGLDrawer defines its own data type that ensures textures are correctly loaded to and deleted from the GPU memory. The drawer utilizes a context-dependent two pass drawing pipeline. For the first pass, tile composition for a given TiledImage is always done using a canvas with a WebGL context. This allows tiles to be stitched together without seams or artifacts, without requiring a tile source with overlap. If overlap is present, overlapping pixels are discarded. The second pass copies all pixel data from the WebGL context onto an output canvas with a Context2d context. This allows applications to have access to pixel data and other functionality provided by Context2d, regardless of whether the CanvasDrawer or the WebGLDrawer is used. Certain options, including compositeOperation, clip, croppingPolygons, and debugMode are implemented using Context2d operations; in these scenarios, each TiledImage is drawn onto the output canvas immediately after the tile composition step (pass 1). Otherwise, for efficiency, all TiledImages are copied over to the output canvas at once, after all tiles have been composited for all images.

Constructor

new WebGLDrawer(options)

Parameters:
Name Type Description
options Object Options for this Drawer.
Properties
Name Type Attributes Default Description
viewer OpenSeadragon.Viewer The Viewer that owns this Drawer.
viewport OpenSeadragon.Viewport Reference to Viewer viewport.
element Element Parent element.
debugGridColor Number <optional>
See debugGridColor in OpenSeadragon.Options for details.
unpackWithPremultipliedAlpha Boolean <optional>
false Whether to enable gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL when uploading textures.
Source:

Members

canvas :Element

The HTML element (canvas) that this drawer uses for drawing
Type:
  • Element
Source:

container :Element

The parent element of this Drawer instance, passed in when the Drawer was created. The parent of OpenSeadragon.WebGLDrawer#canvas.
Type:
  • Element
Source:

Methods

(static) isSupported() → {Boolean}

Functional test: true if WebGL is supported and the real first-pass shader pipeline can render (same shaders/context path used at runtime). Uses a temp context and WebglContextManager, draws known non-black pixels to an FBO, then readPixels.
Source:
Returns:
true if WebGL is supported and the pipeline renders successfully
Type
Boolean

canRotate() → {Boolean}

Source:
Returns:
true
Type
Boolean

destroy()

Clean up the renderer, removing all resources
Source:

draw(tiledImages, isRetryopt)

Parameters:
Name Type Attributes Default Description
tiledImages Array Array of TiledImage objects to draw
isRetry Boolean <optional>
false Internal flag to prevent infinite retry loops
Source:

drawDebuggingRect(rect)

Draw a rect onto the output canvas for debugging purposes
Parameters:
Name Type Description
rect OpenSeadragon.Rect
Source:

getType() → {string}

Source:
Returns:
'webgl'
Type
string

isContextRecoveryEnabled() → {Boolean}

Check if context recovery is enabled
Source:
Returns:
true if recovery is enabled, false otherwise
Type
Boolean

isWebGL2() → {Boolean}

Check if the drawer is using WebGL2
Source:
Returns:
true if WebGL2 is being used, false if WebGL1
Type
Boolean

setContextRecoveryEnabled(enabled)

Enable or disable automatic WebGL context re-initialization on context loss. When enabled, the drawer will attempt to recover from context exhaustion errors by re-initializing the WebGL context.
Parameters:
Name Type Description
enabled Boolean true to enable recovery, false to disable
Source:

setImageSmoothingEnabled(enabled)

Sets whether image smoothing is enabled or disabled
Parameters:
Name Type Description
enabled Boolean If true, uses gl.LINEAR as the TEXTURE_MIN_FILTER and TEXTURE_MAX_FILTER, otherwise gl.NEAREST.
Source:

setUnpackWithPremultipliedAlpha(enabled)

Sets whether textures are unpacked with premultiplied alpha
Parameters:
Name Type Description
enabled Boolean If true, sets gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL to true.
Source: