Class: DrawContext

DrawContext(gl)

Provides current state during rendering. The current draw context is passed to most rendering methods in order to make those methods aware of current state.

Constructor

new DrawContext(gl)

Constructs a DrawContext. Applications do not call this constructor. A draw context is created by a WorldWindow during its construction.
Parameters:
Name Type Description
gl WebGLRenderingContext The WebGL rendering context this draw context is associated with.
Source:
Throws:
If the specified WebGL rendering context is null or undefined.
Type
ArgumentError

Members

canvas2D :HTMLElement

A 2D canvas for creating texture maps.
Type:
  • HTMLElement
Source:

clearColor :Color

The current clear color.
Type:
Default Value:
  • Color.TRANSPARENT (red = 0, green = 0, blue = 0, alpha = 0)
Source:

ctx2D

A 2D context for this draw context's canvas property.
Source:

currentFramebuffer :FramebufferTexture

The current WebGL framebuffer. Null indicates that the default WebGL framebuffer is active.
Type:
Source:

currentGlContext :WebGLRenderingContext

The current WebGL rendering context.
Type:
  • WebGLRenderingContext
Source:

currentLayer :Layer

The layer being rendered.
Type:
Source:

currentProgram :GpuProgram

The current WebGL program. Null indicates that no WebGL program is active.
Type:
Source:

deepPicking :Boolean

Indicates that picking will return all objects at the pick point, if any. The top-most object will have its isOnTop flag set to true. If deep picking is false, the default, only the top-most object is returned, plus the picked-terrain object if the pick point is over the terrain.
Type:
  • Boolean
Default Value:
  • false
Source:

eyePosition :Position

The current eye position.
Type:
Source:

fadeTime :Number

The number of milliseconds over which to fade shapes that support fading. Fading is most typically used during decluttering.
Type:
  • Number
Default Value:
  • 500
Source:

frameStatistics :FrameStatistics

Frame statistics.
Type:
Source:

globe :Globe

The globe being rendered.
Type:
Source:

globeStateKey :String

A copy of the current globe's state key. Provided here to avoid having to recompute it every time it's needed.
Type:
  • String
Source:

gpuResourceCache :GpuResourceCache

The GPU resource cache, which tracks WebGL resources.
Type:
Source:

layers :Array.<Layer>

The layers being rendered.
Type:
Source:
The current state of the associated navigator.
Type:
Source:

(readonly) objectsAtPickPoint :PickedObjectList

The objects at the current pick point.
Type:
Source:

orderedRenderables :Array

The list of ordered renderables.
Type:
  • Array
Source:

orderedRenderingMode :Boolean

Indicates whether this draw context is in ordered rendering mode.
Type:
  • Boolean
Source:

(readonly) pickFramebuffer :FramebufferTexture

The off-screen WebGL framebuffer used during picking.
Type:
Source:

(readonly) pickFrustum :Frustum

The current pick frustum, created anew each picking frame.
Type:
Source:

pickingMode :Boolean

Indicates whether the frame is being drawn for picking.
Type:
  • Boolean
Source:

pickPoint :Vec2

The current pick point, in screen coordinates.
Type:
Source:

pickRectangle :Rectangle

The current pick rectangle, in WebGL (lower-left origin) screen coordinates.
Type:
Source:

pickTerrainOnly :Boolean

Indicates that picking will return only the terrain object, if the pick point is over the terrain.
Type:
  • Boolean
Default Value:
  • false
Source:

(readonly) previousRedrawTimestamp :Number

The time stamp of the last visible frame, in milliseconds. This indicates the time stamp that was current during the WorldWindow's last frame, ignoring frames associated with a picking operation. The difference between the previous redraw time stamp and the current time stamp indicates the duration between visible frames, e.g. timeStamp - previousRedrawTimestamp.
Type:
  • Number
Source:

redrawRequested :Boolean

Indicates whether a redraw has been requested during the current frame. When true, this causes the World Window associated with this draw context to redraw after the current frame.
Type:
  • Boolean
Source:

regionPicking :Boolean

Indicates that picking will return all objects that intersect the pick region, if any. Visible objects will have the isOnTop flag set to true.
Type:
  • Boolean
Default Value:
  • false
Source:

screenCreditController :ScreenCreditController

The screen credit controller responsible for collecting and drawing screen credits.
Type:
Source:

screenProjection :Matrix

The current screen projection matrix.
Type:
Source:

screeRenderables :Array

The list of screen renderables.
Type:
  • Array
Source:

surfaceOpacity :Number

The opacity to apply to terrain and surface shapes. Should be a number between 0 and 1.
Type:
  • Number
Default Value:
  • 1
Source:

surfaceRenderables :Array

The list of surface renderables.
Type:
  • Array
Source:

surfaceShapeTileBuilder :SurfaceShapeTileBuilder

The surface shape tile builder used to create and draw surface shapes.
Type:
  • SurfaceShapeTileBuilder
Source:

surfaceShapeTileController :FramebufferTileController

Provides access to a multi-resolution WebGL framebuffer arranged as adjacent tiles in a pyramid. Surface shapes use these tiles internally to draw on the terrain surface.
Type:
Source:

surfaceTileRenderer :SurfaceTileRenderer

The surface-tile-renderer to use for drawing surface tiles.
Type:
Source:

terrain :Terrain

The terrain for the current frame.
Type:
Source:

textSupport :TextSupport

A shared TextSupport instance.
Type:
Source:

(readonly) timestamp :Number

The starting time of the current frame, in milliseconds. The frame timestamp is updated immediately before the WorldWindow associated with this draw context is rendered, either as a result of redrawing or as a result of a picking operation.
Type:
  • Number
Source:

verticalExaggeration :Number

The current vertical exaggeration.
Type:
  • Number
Source:

Methods

addOrderedRenderable(orderedRenderable, eyeDistance)

Adds an ordered renderable to this draw context's ordered renderable list.
Parameters:
Name Type Description
orderedRenderable OrderedRenderable The ordered renderable to add. May be null, in which case the current ordered renderable list remains unchanged.
eyeDistance Number An optional argument indicating the ordered renderable's eye distance. If this parameter is not specified then the ordered renderable must have an eyeDistance property.
Source:

addOrderedRenderableToBack(orderedRenderable)

Adds an ordered renderable to the end of this draw context's ordered renderable list, denoting it as the most distant from the eye point.
Parameters:
Name Type Description
orderedRenderable OrderedRenderable The ordered renderable to add. May be null, in which case the current ordered renderable list remains unchanged.
Source:

addPickedObject(pickedObject)

Adds an object to the current picked-object list. The list identifies objects that are at the pick point but not necessarily the top-most object.
Parameters:
Name Type Description
pickedObject PickedObject The object to add.
Source:

addSurfaceRenderable(surfaceRenderable)

Adds a surface renderable to this draw context's surface renderable list.
Parameters:
Name Type Description
surfaceRenderable SurfaceRenderable The surface renderable to add. May be null, in which case the current surface renderable list remains unchanged.
Source:

bindFramebuffer(framebuffer)

Binds a specified WebGL framebuffer. This function also makes the framebuffer the active framebuffer.
Parameters:
Name Type Description
framebuffer FramebufferTexture The framebuffer to bind. May be null or undefined, in which case the default WebGL framebuffer is made active.
Source:

bindProgram(program)

Binds a specified WebGL program. This function also makes the program the current program.
Parameters:
Name Type Description
program GpuProgram The program to bind. May be null or undefined, in which case the currently bound program is unbound.
Source:

contextLost()

Notifies this draw context that the current WebGL rendering context has been lost. This function removes all cached WebGL resources and resets all properties tracking the current WebGL state.
Source:

contextRestored()

Notifies this draw context that the current WebGL rendering context has been restored. This function prepares this draw context to resume rendering.
Source:

findAndBindProgram(programConstructor) → {GpuProgram}

Binds a potentially cached WebGL program, creating and caching it if it isn't already cached. This function also makes the program the current program.
Parameters:
Name Type Description
programConstructor function The constructor to use to create the program.
Source:
Throws:
If the specified constructor is null or undefined.
Type
ArgumentError
Returns:
The bound program.
Type
GpuProgram

isSmall(extent, numPixels) → {Boolean}

Indicates whether an extent is smaller than a specified number of pixels.
Parameters:
Name Type Description
extent BoundingBox The extent to test.
numPixels Number The number of pixels below which the extent is considered small.
Source:
Returns:
True if the extent is smaller than the specified number of pixels, otherwise false. Returns false if the extent is null or undefined.
Type
Boolean

makePickFramebuffer()

Creates an off-screen WebGL framebuffer for use during picking and stores it in this draw context. The framebuffer width and height match the WebGL rendering context's drawingBufferWidth and drawingBufferHeight.
Source:

makePickFrustum() → {Boolean}

Creates a pick frustum for the current pick point and stores it in this draw context. If this context's pick rectangle is null or undefined then a pick rectangle is also computed and assigned to this context. If the existing pick rectangle extends beyond the viewport then it is truncated by this method to fit within the viewport. This method assumes that this draw context's pick point or pick rectangle has been set. It returns false if neither one of these exists.
Source:
Returns:
true if the pick frustum could be created, otherwise false.
Type
Boolean

nextScreenRenderable() → {OrderedRenderable}

Returns the ordered renderable at the head of the ordered renderable list and removes it from the list.
Source:
Returns:
The first ordered renderable in this draw context's ordered renderable list, or null if the ordered renderable list is empty.
Type
OrderedRenderable

peekOrderedRenderable() → {OrderedRenderable}

Returns the ordered renderable at the head of the ordered renderable list without removing it from the list.
Source:
Returns:
The first ordered renderable in this draw context's ordered renderable list, or null if the ordered renderable list is empty.
Type
OrderedRenderable

peekSurfaceRenderable() → {SurfaceRenderable}

Returns the surface renderable at the head of the surface renderable list without removing it from the list.
Source:
Returns:
The first surface renderable in this draw context's surface renderable list, or null if the surface renderable list is empty.
Type
SurfaceRenderable

popOrderedRenderable() → {OrderedRenderable}

Returns the ordered renderable at the head of the ordered renderable list and removes it from the list.
Source:
Returns:
The first ordered renderable in this draw context's ordered renderable list, or null if the ordered renderable list is empty.
Type
OrderedRenderable

popSurfaceRenderable() → {SurfaceRenderable}

Returns the surface renderable at the head of the surface renderable list and removes it from the list.
Source:
Returns:
The first surface renderable in this draw context's surface renderable list, or null if the surface renderable list is empty.
Type
SurfaceRenderable

readPickColor(pickPoint) → {Color}

Reads the color from the current render buffer at a specified point. Used during picking to identify the item most recently affecting the pixel at the specified point.
Parameters:
Name Type Description
pickPoint Vec2 The current pick point.
Source:
Returns:
The color at the pick point.
Type
Color

readPickColors(pickRectangle) → {Object}

Reads the current pick buffer colors in a specified rectangle. Used during region picking to identify the items not occluded.
Parameters:
Name Type Description
pickRectangle Rectangle The rectangle for which to read the colors.
Source:
Returns:
An object containing the unique colors in the specified rectangle, excluding the current clear color. The colors are referenced by their byte string (see Color.toByteString.
Type
Object

reset()

Prepare this draw context for the drawing of a new frame.
Source:

resolvePick(pickableObject) → {null}

Determines whether a specified picked object is under the pick point, and if it is adds it to this draw context's list of picked objects. This method should be called by shapes during ordered rendering after the shape is drawn. If this draw context is in single-picking mode, the specified pickable object is added to the list of picked objects whether or not it is under the pick point.
Parameters:
Name Type Description
pickableObject
Source:
Returns:
Type
null

reverseSurfaceRenderables()

Reverses the surface renderable list in place. After this function completes, the functions peekSurfaceRenderable and popSurfaceRenderable return renderables in the order in which they were added to the surface renderable list.
Source:

sortOrderedRenderables()

Sorts the ordered renderable list from nearest to the eye point to farthest from the eye point.
Source:

surfacePointForMode(latitude, longitude, offset, altitudeMode, result) → {Vec3}

Computes a Cartesian point at a location on the surface of this terrain according to a specified altitude mode. If there is no current terrain, this function approximates the returned point by assuming the terrain is the globe's ellipsoid.
Parameters:
Name Type Description
latitude Number The location's latitude.
longitude Number The location's longitude.
offset Number Distance above the terrain, in meters relative to the specified altitude mode, at which to compute the point.
altitudeMode String The altitude mode to use to compute the point. Recognized values are WorldWind.ABSOLUTE, WorldWind.CLAMP_TO_GROUND and WorldWind.RELATIVE_TO_GROUND. The mode WorldWind.ABSOLUTE is used if the specified mode is null, undefined or unrecognized, or if the specified location is outside this terrain.
result Vec3 A pre-allocated Vec3 in which to return the computed point.
Source:
Throws:
If the specified result argument is null or undefined.
Type
ArgumentError
Returns:
The specified result parameter, set to the coordinates of the computed point.
Type
Vec3

uniquePickColor() → {Color}

Computes a unique color to use as a pick color.
Source:
Returns:
A unique color.
Type
Color

unitCubeBuffer() → {Object}

Returns the VBO ID of an array buffer containing a unit cube expressed as eight 3D vertices at (0, 1, 0), (0, 0, 0), (1, 1, 0), (1, 0, 0), (0, 1, 1), (0, 0, 1), (1, 1, 1) and (1, 0, 1). The buffer is created on first use and cached. Subsequent calls to this method return the cached buffer.
Source:
Returns:
The VBO ID identifying the array buffer.
Type
Object

unitCubeElements() → {Object}

Returns the VBO ID of a element array buffer containing the tessellation of a unit cube expressed as a single buffer containing both triangle indices and line indices. This is intended for use in conjunction with unitCubeBuffer. The unit cube's interior and outline may be rasterized as shown in the following WebGL pseudocode:
// Assumes that the VBO returned by unitCubeBuffer is used as the source of vertex positions.
bindBuffer(ELEMENT_ARRAY_BUFFER, drawContext.unitCubeElements());
drawElements(TRIANGLES, 36, UNSIGNED_SHORT, 0); // draw the unit cube interior
drawElements(LINES, 24, UNSIGNED_SHORT, 72); // draw the unit cube outline
The buffer is created on first use and cached. Subsequent calls to this method return the cached buffer.
Source:
Returns:
The VBO ID identifying the element array buffer.
Type
Object

unitQuadBuffer() → {Object}

Returns the VBO ID of a buffer containing a unit quadrilateral expressed as four 2D vertices at (0, 1), (0, 0), (1, 1) and (1, 0). The four vertices are in the order required by a triangle strip. The buffer is created on first use and cached. Subsequent calls to this method return the cached buffer.
Source:
Returns:
The VBO ID identifying the vertex buffer.
Type
Object

unitQuadBuffer3() → {Object}

Returns the VBO ID of a buffer containing a unit quadrilateral expressed as four 3D vertices at (0, 1, 0), (0, 0, 0), (1, 1, 0) and (1, 0, 0). The four vertices are in the order required by a triangle strip. The buffer is created on first use and cached. Subsequent calls to this method return the cached buffer.
Source:
Returns:
The VBO ID identifying the vertex buffer.
Type
Object

update()

Computes any values necessary to render the upcoming frame. Called after all draw context state for the frame has been set.
Source: