Skip to main content

class.RenderContext

API > RenderContext

Class: RenderContext

The view specific context for rendering and picking.

Remarks

A render context describes a view into which a RenderState can be rendered. It is tightly bound to a HTML canvas and WebGL2RenderingContext. Consequently, it will be disposed if the gl context is lost and recreated when the gl context is restored.

The render context must be initialized with an array of render modules. Unused modules may be removed and custom ones inserted here. Ordering the modules correctly is important as they are rendered in order. The TonemapModule should be last, as it will copy the HDR render buffers into the output canvas to make things visible.

Features such as async picking and shader linking requires poll to be called at regular intervals, e.g. at the start of each frame. Otherwise the promises will never be resolved.

Properties

buffers

buffers: RenderBuffers

WebGL render and pick buffers

Remarks

Note that these buffers will be recreated whenever the RenderState.output size changes.

Source

@novorender/core3d/context.ts:128


cameraUniforms

readonly cameraUniforms: WebGLBuffer

WebGL uniform buffer for camera related uniforms.

Source

@novorender/core3d/context.ts:87


canvas

readonly canvas: HTMLCanvasElement

The HTML canvas used for this context.

Source

@novorender/core3d/context.ts:152


changed

changed: boolean = true

Set to true to force a re-render when state not contained in RenderState has changed, e.g. download complete etc.

Source

@novorender/core3d/context.ts:121


clippingUniforms

readonly clippingUniforms: WebGLBuffer

WebGL uniform buffer for clipping related uniforms.

Source

@novorender/core3d/context.ts:89


commonChunk

readonly commonChunk: string

WebGL common GLSL code header used across shaders.

Source

@novorender/core3d/context.ts:40


currentState

currentState: undefined | DerivedRenderState

RenderState used to make the newest state available during render.

Source

@novorender/core3d/context.ts:118


defaultIBLTextureParams

readonly defaultIBLTextureParams: TextureParamsCubeUncompressed

WebGL basic fallback IBL textures to use while loading proper IBL textures.

Source

@novorender/core3d/context.ts:42


deviceProfile

readonly deviceProfile: DeviceProfile

The device profile use for this context.

Source

@novorender/core3d/context.ts:150


gl

readonly gl: WebGL2RenderingContext

WebGL2 render context associated with this object.

Source

@novorender/core3d/context.ts:38


iblTextures

iblTextures: object

WebGL textures used for image based lighting (IBL).

Remarks

Note that these buffers will be changed by the background module when download of the specified RenderState.background.url IBL textures completes.

The process to create the textures are similar to that of https://github.com/KhronosGroup/glTF-IBL-Sampler/

Type declaration

iblTextures.default

readonly default: boolean

True if these are the default IBL textures.

iblTextures.diffuse

readonly diffuse: WebGLTexture

WebGL cubemap texture containing the irradiance/diffuse values of current IBL environment.

iblTextures.numMipMaps

readonly numMipMaps: number

mip maps in current specular texture.

iblTextures.specular

readonly specular: WebGLTexture

WebGL cubemap texture containing the radiance/specular values of current IBL environment.

Source

@novorender/core3d/context.ts:136


imports

readonly imports: Core3DImports

Imported resources.

Source

@novorender/core3d/context.ts:154


lut_ggx

readonly lut_ggx: WebGLTexture

WebGL GGX/PBR shading lookup table texture.

Source

@novorender/core3d/context.ts:93


outlineRenderers

outlineRenderers: WeakMap\< ReadonlyVec4, OutlineRenderer >

Source

@novorender/core3d/context.ts:108


outlineUniforms

readonly outlineUniforms: WebGLBuffer

WebGL uniform buffer for outline related uniforms.

Source

@novorender/core3d/context.ts:91


prevState

prevState: undefined | DerivedRenderState

RenderState used to render the previous frame, if any.

Source

@novorender/core3d/context.ts:114


samplerEnvMip

readonly samplerEnvMip: WebGLSampler

WebGL Sampler used to sample mip mapped IBL texture trilinear.

Source

@novorender/core3d/context.ts:95


samplerMip

readonly samplerMip: WebGLSampler

WebGL Sampler used to sample mipmapped texture trilinear.

Source

@novorender/core3d/context.ts:97


samplerMipRepeat

readonly samplerMipRepeat: WebGLSampler

WebGL Sampler used to sample mipmapped texture trilinear repeating UV.

Source

@novorender/core3d/context.ts:99


samplerSingle

readonly samplerSingle: WebGLSampler

WebGL Sampler used to sample other, non-mipmapped IBL textures bilinear.

Source

@novorender/core3d/context.ts:101


usePrepass

readonly usePrepass: false = false

Source

@novorender/core3d/context.ts:74


wasm

readonly wasm: WasmInstance

Web assembly instance.

Source

@novorender/core3d/context.ts:44

Accessors

height

get height(): number

Return the current pixel height of the drawing buffer.

Returns

number

Source

@novorender/core3d/context.ts:331


width

get width(): number

Return the current pixel width of the drawing buffer.

Returns

number

Source

@novorender/core3d/context.ts:326

Methods

clearPickBuffers

clearPickBuffers(): void

Returns

void

Source

@novorender/core3d/context.ts:735


dispose

dispose(): void

Dispose of the GPU resources used by this context, effectively destroying it and freeing up memory.

Returns

void

Source

@novorender/core3d/context.ts:306

Remarks

Calling this method is optional as the garbage collection of the underlying WebGL render context will do the same thing. This may take some time, however, so calling this function is recommended if you plan to create a new context shortly thereafter.


getDeviations

getDeviations(): Promise\< DeviationSample[] >

scan the pick buffer for deviation values

Returns

Promise\< DeviationSample[] >

Return pixel coordinates and deviation values for any deviation on screen

Source

@novorender/core3d/context.ts:799


getLinearDepths

getLinearDepths(pick): IterableIterator\< number >

Parameters

ParameterType
pickUint32Array

Returns

IterableIterator\< number >

Source

@novorender/core3d/context.ts:788


getOutlines

getOutlines(): Promise\< OutlineSample[] >

scan the pick buffer for pixels from clipping outline

Returns

Promise\< OutlineSample[] >

Return pixel coordinates and world position for any clipping outline on screen

Source

@novorender/core3d/context.ts:845


hasStateChanged

hasStateChanged(state): boolean

Helper function to check for changes in render state.

Parameters

ParameterTypeDescription
statePartial\< DerivedRenderState >The parts of the render state to check for changes.

Returns

boolean

True if any of the specified parts has changed since last frame.

Source

@novorender/core3d/context.ts:407

Remarks

Since the render state is immutable, any changes will automatically trickle up to the container object as well. Thus, this function does a shallow strict equality of the parts of the renderstate specified in the state parameter.

Example

Example of how to check for changes in either camera or output render state.

const {camera, output} = renderState;
if(renderContext.hasStateChanged({camera, output})) {
// update related GPU state here...
}

init

init(modules?): Promise\< void >

Initialize render context with specified render modules.

Parameters

ParameterType
modules?readonly RenderModule[]

Returns

Promise\< void >

Source

@novorender/core3d/context.ts:253

Remarks

The default/built-in render modules can be retrieved using createDefaultModules. These will be used if no modules are specified. Developers may introduce their own render modules here. Note that the order of the modules matters, as this is the order by which they will be rendered.


isContextLost

isContextLost(): boolean

Query whether the underlying WebGL render context is currently lost.

Returns

boolean

Source

@novorender/core3d/context.ts:347

Remarks

This could occur when too many resources are allocated or when browser window is dragged across screens. Loss and restoration of WebGL contexts is supported by this API automatically.


isPickBuffersValid

isPickBuffersValid(): boolean

Query if pick buffers are valid.

Returns

boolean

Source

@novorender/core3d/context.ts:338

Remarks

This could be useful for optimistic/non-async picking.


makeProgramAsync

makeProgramAsync(resourceBin, params): Promise\< WebGLProgram >

Compile WebGL/GLSL shader program asynchronously.

Parameters

ParameterType
resourceBinResourceBin
paramsAsyncProgramParams

Returns

Promise\< WebGLProgram >

Source

@novorender/core3d/context.ts:427


pick

pick( x, y, options?): Promise\< PickSample[] >

Pick information about underlying object and geometry.

Parameters

ParameterTypeDescription
xnumberCenter x coordinate in CSS pixels.
ynumberCenter y coordinate in CSS pixels.
options?PickOptionsMore details of pick operation.

Returns

Promise\< PickSample[] >

A set of pick samples of the specified sample disc.

Source

@novorender/core3d/context.ts:1034


poll

poll(): void

Poll the status of WebGL pick fences and timers and resolve associated promises when possible.

Returns

void

Source

@novorender/core3d/context.ts:533


render

render(state): Promise\< RenderStatistics >

Render a new frame using the specified render state.

Parameters

ParameterTypeDescription
stateRenderStateAn object describing what the frame should look like.

Returns

Promise\< RenderStatistics >

A promise to the performance related statistics involved in rendering this frame.

Source

@novorender/core3d/context.ts:582


renderPickBuffers

renderPickBuffers(): void

Returns

void

Source

@novorender/core3d/context.ts:740


resourceBin

resourceBin(name): ResourceBin

Create a new named resource bin.

Parameters

ParameterType
namestring

Returns

ResourceBin

Source

@novorender/core3d/context.ts:422


setPolygonFillMode

setPolygonFillMode(mode): void

Parameters

ParameterType
mode"FILL" | "LINE"

Returns

void

Source

@novorender/core3d/context.ts:1070


updateIBLTextures

updateIBLTextures(params): void

Explicitly update WebGL IBL textures from specified parameters.

Parameters

ParameterType
paramsnull | {
diffuse: TextureParamsCubeUncompressed;
specular: TextureParamsCubeUncompressedMipMapped;
}

Returns

void

Source

@novorender/core3d/context.ts:370


updateUniformBuffer

updateUniformBuffer(uniformBuffer, proxy): void

Helper function to update WebGL uniform buffer from proxies.

Parameters

ParameterType
uniformBufferWebGLBuffer
proxyUniformsProxy

Returns

void

Source

@novorender/core3d/context.ts:361


nextFrame

static nextFrame(context): Promise\< number >

Wait for the next frame to be ready for rendering.

Parameters

ParameterTypeDescription
contextundefined | RenderContextrender context to wait for, if any.

Returns

Promise\< number >

Source

@novorender/core3d/context.ts:561

Remarks

Use this function instead of requestAnimationFrame()!