WebGLBlock¶
Overview¶
Renders a visual layer of WebGL drawables.
@author Jonathan Olson <jonathan.olson@colorado.edu> @author Sam Reid (PhET Interactive Simulations) @author Sharfudeen Ashraf (For Ghent University)
Class WebGLBlock¶
Constructor¶
new WebGLBlock( display, renderer, transformRootInstance, filterRootInstance )¶
Instance Methods¶
initialize( display, renderer, transformRootInstance, filterRootInstance )¶
@param {Display} display @param {number} renderer @param {Instance} transformRootInstance - All transforms of this instance and its ancestors will already have been applied. This block will only be responsible for applying transforms of this instance's descendants. @param {Instance} filterRootInstance - All filters (visibility/opacity/filters) of this instance and its ancestors will already have been applied. This block will only be responsible for applying filters of this instance's descendants. @returns {WebGLBlock} - For chaining
rebuildCanvas()¶
Forces a rebuild of the Canvas and its context (as long as a context can be obtained). @private
This can be necessary when the browser won't restore our context that was lost (and we need to create another canvas to get a valid context).
setupContext( gl )¶
Takes a fresh WebGL context switches the WebGL block over to use it. @private
@param {WebGLRenderingContext} gl
delayedRebuildCanvas()¶
Attempts to force a Canvas rebuild to get a new Canvas/context pair. @private
onContextLoss( domEvent )¶
Callback for whenever our WebGL context is lost. @private
@param {WebGLContextEvent} domEvent
onContextRestoration( domEvent )¶
Callback for whenever our WebGL context is restored. @private
@param {WebGLContextEvent} domEvent
getContextFromCanvas( canvas )¶
Attempts to get a WebGL context from a Canvas. @private
@param {HTMLCanvasElement} @returns {WebGLRenderingContext|*} - If falsy, it did not succeed.
setSizeFullDisplay()¶
setSizeFitBounds()¶
update()¶
Updates the DOM appearance of this drawable (whether by preparing/calling draw calls, DOM element updates, etc.) @public @override
@returns {boolean} - Whether the update should continue (if false, further updates in supertype steps should not be done).
dispose()¶
Releases references @public
markDirtyDrawable( drawable )¶
@param {Drawable} drawable
addDrawable( drawable )¶
@param {Drawable} drawable
removeDrawable( drawable )¶
@param {Drawable} drawable
addSpriteSheetImage( image, width, height )¶
Ensures we have an allocated part of a SpriteSheet for this image. If a SpriteSheet already contains this image, we'll just increase the reference count. Otherwise, we'll attempt to add it into one of our SpriteSheets. If it doesn't fit, we'll add a new SpriteSheet and add the image to it. @public
@param {HTMLImageElement | HTMLCanvasElement} image @param {number} width @param {number} height
@returns {Sprite} - Throws an error if we can't accommodate the image
removeSpriteSheetImage( sprite )¶
Removes the reference to the sprite in our spritesheets. @public
@param {Sprite} sprite
onIntervalChange( firstDrawable, lastDrawable )¶
@param {Drawable} firstDrawable @param {Drawable} lastDrawable
onPotentiallyMovedDrawable( drawable )¶
@param {Drawable} drawable
toString()¶
Returns a string form of this object @public
@returns {string}
Source Code¶
See the source for WebGLBlock.js in the scenery repository.