Skip to main content

@novorender/api / RenderContext

Class: RenderContext

Defined in: @novorender/src/core3d/context.ts:66

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.

Accessors

height

Get Signature

get height(): number;

Defined in: @novorender/src/core3d/context.ts:432

Return the current pixel height of the drawing buffer.

Returns

number


width

Get Signature

get width(): number;

Defined in: @novorender/src/core3d/context.ts:427

Return the current pixel width of the drawing buffer.

Returns

number

Methods

clearPickBuffers()

clearPickBuffers(): void;

Defined in: @novorender/src/core3d/context.ts:938

Returns

void


dispose()

dispose(): void;

Defined in: @novorender/src/core3d/context.ts:401

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

Returns

void

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[]>;

Defined in: @novorender/src/core3d/context.ts:1010

scan the pick buffer for deviation values

Returns

Promise<DeviationSample[]>

Return pixel coordinates and deviation values for any deviation on screen


getLinearDepths()

getLinearDepths(pick): IterableIterator<number>;

Defined in: @novorender/src/core3d/context.ts:999

Parameters

ParameterType
pickUint32Array

Returns

IterableIterator<number>


getNonParametricEdgeDirAtPoints()

getNonParametricEdgeDirAtPoints(points, tolerance): Promise<undefined | (null | ReadonlyVec3)[]>;

Defined in: @novorender/src/core3d/context.ts:1642

Parameters

ParameterType
pointsobject[]
tolerancenumber

Returns

Promise<undefined | (null | ReadonlyVec3)[]>


getOutlines()

getOutlines(): Promise<OutlineSample[]>;

Defined in: @novorender/src/core3d/context.ts:1066

scan the pick buffer for pixels from clipping outline

Returns

Promise<OutlineSample[]>

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


hasStateChanged()

hasStateChanged(state): boolean;

Defined in: @novorender/src/core3d/context.ts:554

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.

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?, showWatermark?): Promise<void>;

Defined in: @novorender/src/core3d/context.ts:344

Initialize render context with specified render modules.

Parameters

ParameterTypeDefault valueDescription
modules?readonly RenderModule[]undefined-
showWatermark?booleantruefalse filters out the watermark module regardless if the modules are provided or not.

Returns

Promise<void>

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;

Defined in: @novorender/src/core3d/context.ts:477

Query whether the underlying WebGL render context is currently lost.

Returns

boolean

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.


isPickBuffersRendered()

isPickBuffersRendered(): boolean;

Defined in: @novorender/src/core3d/context.ts:448

Query if pick buffers are rendered. Means pick buffer is rendered, but not yet copied to CPU.

Returns

boolean

Remarks

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


isPickBuffersUpToDate()

isPickBuffersUpToDate(): boolean;

Defined in: @novorender/src/core3d/context.ts:456

Query if pick buffers are up to date. Means it's valid and it represents current (latest) frame.

Returns

boolean

Remarks

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


isPickBuffersValid()

isPickBuffersValid(): boolean;

Defined in: @novorender/src/core3d/context.ts:440

Query if pick buffers are valid. Valid means that the buffer is filled (not just arrays with zeros) and represents correct resolution.

Returns

boolean

Remarks

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


isSceneResolved()

isSceneResolved(): boolean;

Defined in: @novorender/src/core3d/context.ts:463

The scene is considered resolved when all currently split nodes are done downloading.

Returns

boolean


makeProgramAsync()

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

Defined in: @novorender/src/core3d/context.ts:574

Compile WebGL/GLSL shader program asynchronously.

Parameters

ParameterType
resourceBinResourceBin
paramsAsyncProgramParams

Returns

Promise<WebGLProgram>


pick()

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

Defined in: @novorender/src/core3d/context.ts:1585

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.


poll()

poll(): void;

Defined in: @novorender/src/core3d/context.ts:694

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

Returns

void


render()

render(state): Promise<RenderStatistics>;

Defined in: @novorender/src/core3d/context.ts:746

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.


renderPickBuffers()

renderPickBuffers(): void;

Defined in: @novorender/src/core3d/context.ts:948

Returns

void


resourceBin()

resourceBin(name): ResourceBin;

Defined in: @novorender/src/core3d/context.ts:569

Create a new named resource bin.

Parameters

ParameterType
namestring

Returns

ResourceBin


setPolygonFillMode()

setPolygonFillMode(mode): void;

Defined in: @novorender/src/core3d/context.ts:1634

Parameters

ParameterType
mode"FILL" | "LINE"

Returns

void


updateIBLTextures()

updateIBLTextures(params): void;

Defined in: @novorender/src/core3d/context.ts:509

Explicitly update WebGL IBL textures from specified parameters.

Parameters

ParameterType
params| null | { diffuse: TextureParamsCubeUncompressed; specular: TextureParamsCubeUncompressedMipMapped; }

Returns

void


updateUniformBuffer()

updateUniformBuffer(uniformBuffer, proxy): void;

Defined in: @novorender/src/core3d/context.ts:493

Helper function to update WebGL uniform buffer from proxies.

Parameters

ParameterType
uniformBufferWebGLBuffer
proxyUniformsProxy

Returns

void


nextFrame()

static nextFrame(context): Promise<number>;

Defined in: @novorender/src/core3d/context.ts:725

Wait for the next frame to be ready for rendering.

Parameters

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

Returns

Promise<number>

Remarks

Use this function instead of requestAnimationFrame()!

Properties

buffers

buffers: RenderBuffers;

Defined in: @novorender/src/core3d/context.ts:173

WebGL render and pick buffers

Remarks

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


cameraUniforms

readonly cameraUniforms: WebGLBuffer;

Defined in: @novorender/src/core3d/context.ts:132

WebGL uniform buffer for camera related uniforms.


canvas

readonly canvas: HTMLCanvasElement;

Defined in: @novorender/src/core3d/context.ts:204

The HTML canvas used for this context.


changed

changed: boolean = true;

Defined in: @novorender/src/core3d/context.ts:166

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


clippingUniforms

readonly clippingUniforms: WebGLBuffer;

Defined in: @novorender/src/core3d/context.ts:134

WebGL uniform buffer for clipping related uniforms.


commonChunk

readonly commonChunk: string;

Defined in: @novorender/src/core3d/context.ts:70

WebGL common GLSL code header used across shaders.


currentState

currentState: undefined | DerivedRenderState;

Defined in: @novorender/src/core3d/context.ts:163

RenderState used to make the newest state available during render.


defaultIBLTextureParams

readonly defaultIBLTextureParams: TextureParamsCubeUncompressed;

Defined in: @novorender/src/core3d/context.ts:72

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


deviceProfile

readonly deviceProfile: DeviceProfile;

Defined in: @novorender/src/core3d/context.ts:202

The device profile use for this context.


gl

readonly gl: WebGL2RenderingContext;

Defined in: @novorender/src/core3d/context.ts:68

WebGL2 render context associated with this object.


iblTextures

iblTextures: object;

Defined in: @novorender/src/core3d/context.ts:181

WebGL textures used for image based lighting (IBL).

default

readonly default: boolean;

True if these are the default IBL textures.

diffuse

readonly diffuse: WebGLTexture;

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

numMipMaps

readonly numMipMaps: number;

mip maps in current specular texture.

specular

readonly specular: WebGLTexture;

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

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/


loaderWorker

readonly loaderWorker: Worker;

Defined in: @novorender/src/core3d/context.ts:193


lut_ggx

readonly lut_ggx: WebGLTexture;

Defined in: @novorender/src/core3d/context.ts:138

WebGL GGX/PBR shading lookup table texture.


lutGGXImage

readonly lutGGXImage: ImageBitmap;

Defined in: @novorender/src/core3d/context.ts:206

The lutGGX file.


outlineRenderers

outlineRenderers: WeakMap<ReadonlyVec4, OutlineRenderer>;

Defined in: @novorender/src/core3d/context.ts:153


outlineUniforms

readonly outlineUniforms: WebGLBuffer;

Defined in: @novorender/src/core3d/context.ts:136

WebGL uniform buffer for outline related uniforms.


prevState

prevState: undefined | DerivedRenderState;

Defined in: @novorender/src/core3d/context.ts:159

RenderState used to render the previous frame, if any.


samplerEnvMip

readonly samplerEnvMip: WebGLSampler;

Defined in: @novorender/src/core3d/context.ts:140

WebGL Sampler used to sample mip mapped IBL texture trilinear.


samplerMip

readonly samplerMip: WebGLSampler;

Defined in: @novorender/src/core3d/context.ts:142

WebGL Sampler used to sample mipmapped texture trilinear.


samplerMipRepeat

readonly samplerMipRepeat: WebGLSampler;

Defined in: @novorender/src/core3d/context.ts:144

WebGL Sampler used to sample mipmapped texture trilinear repeating UV.


samplerSingle

readonly samplerSingle: WebGLSampler;

Defined in: @novorender/src/core3d/context.ts:146

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


usePrepass

readonly usePrepass: false = false;

Defined in: @novorender/src/core3d/context.ts:119