@novorender/web_app / 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.
Accessors
height
get height(): number
Return the current pixel height of the drawing buffer.
Returns
number
Defined in
@novorender/core3d/context.ts:332
width
get width(): number
Return the current pixel width of the drawing buffer.
Returns
number
Defined in
@novorender/core3d/context.ts:327
Methods
clearPickBuffers()
clearPickBuffers(): void
Returns
void
Defined in
@novorender/core3d/context.ts:748
dispose()
dispose(): void
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.
Defined in
@novorender/core3d/context.ts:307
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
Defined in
@novorender/core3d/context.ts:812
getLinearDepths()
getLinearDepths(pick): IterableIterator<number>
Parameters
Parameter | Type |
---|---|
pick | Uint32Array |
Returns
IterableIterator
<number
>
Defined in
@novorender/core3d/context.ts:801
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
Defined in
@novorender/core3d/context.ts:858
hasStateChanged()
hasStateChanged(state): boolean
Helper function to check for changes in render state.
Parameters
Parameter | Type | Description |
---|---|---|
state | Partial <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...
}
Defined in
@novorender/core3d/context.ts:420
init()
init(modules?): Promise<void>
Initialize render context with specified render modules.
Parameters
Parameter | Type |
---|---|
modules ? | readonly RenderModule [] |
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.
Defined in
@novorender/core3d/context.ts:254
isContextLost()
isContextLost(): boolean
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.
Defined in
@novorender/core3d/context.ts:360
isPickBuffersValid()
isPickBuffersValid(): boolean
Query if pick buffers are valid.
Returns
boolean
Remarks
This could be useful for optimistic/non-async picking.
Defined in
@novorender/core3d/context.ts:339
isSceneResolved()
isSceneResolved(): boolean
The scene is considered resolved when all currently split nodes are done downloading.
Returns
boolean
Defined in
@novorender/core3d/context.ts:346
makeProgramAsync()
makeProgramAsync(resourceBin, params): Promise<WebGLProgram>
Compile WebGL/GLSL shader program asynchronously.
Parameters
Parameter | Type |
---|---|
resourceBin | ResourceBin |
params | AsyncProgramParams |
Returns
Promise
<WebGLProgram
>
Defined in
@novorender/core3d/context.ts:440
pick()
pick(
x,
y,
options?): Promise<PickSample[]>
Pick information about underlying object and geometry.
Parameters
Parameter | Type | Description |
---|---|---|
x | number | Center x coordinate in CSS pixels. |
y | number | Center y coordinate in CSS pixels. |
options ? | PickOptions | More details of pick operation. |
Returns
Promise
<PickSample
[]>
A set of pick samples of the specified sample disc.
Defined in
@novorender/core3d/context.ts:1173
poll()
poll(): void
Poll the status of WebGL pick fences and timers and resolve associated promises when possible.
Returns
void
Defined in
@novorender/core3d/context.ts:546
render()
render(state): Promise<RenderStatistics>
Render a new frame using the specified render state.
Parameters
Parameter | Type | Description |
---|---|---|
state | RenderState | An object describing what the frame should look like. |
Returns
Promise
<RenderStatistics
>
A promise to the performance related statistics involved in rendering this frame.
Defined in
@novorender/core3d/context.ts:595
renderPickBuffers()
renderPickBuffers(): void
Returns
void
Defined in
@novorender/core3d/context.ts:753
resourceBin()
resourceBin(name): ResourceBin
Create a new named resource bin.
Parameters
Parameter | Type |
---|---|
name | string |
Returns
ResourceBin
Defined in
@novorender/core3d/context.ts:435
setPolygonFillMode()
setPolygonFillMode(mode): void
Parameters
Parameter | Type |
---|---|
mode | "FILL" | "LINE" |
Returns
void
Defined in
@novorender/core3d/context.ts:1209
updateIBLTextures()
updateIBLTextures(params): void
Explicitly update WebGL IBL textures from specified parameters.
Parameters
Parameter | Type |
---|---|
params | null | object |
Returns
void
Defined in
@novorender/core3d/context.ts:383
updateUniformBuffer()
updateUniformBuffer(uniformBuffer, proxy): void
Helper function to update WebGL uniform buffer from proxies.
Parameters
Parameter | Type |
---|---|
uniformBuffer | WebGLBuffer |
proxy | UniformsProxy |
Returns
void
Defined in
@novorender/core3d/context.ts:374
nextFrame()
static nextFrame(context): Promise<number>
Wait for the next frame to be ready for rendering.
Parameters
Parameter | Type | Description |
---|---|---|
context | undefined | RenderContext | render context to wait for, if any. |
Returns
Promise
<number
>
Remarks
Use this function instead of requestAnimationFrame()!
Defined in
@novorender/core3d/context.ts:574
Properties
buffers
buffers: RenderBuffers;
WebGL render and pick buffers
Remarks
Note that these buffers will be recreated whenever the RenderState.output size changes.
Defined in
@novorender/core3d/context.ts:129
cameraUniforms
readonly cameraUniforms: WebGLBuffer;
WebGL uniform buffer for camera related uniforms.
Defined in
@novorender/core3d/context.ts:88
canvas
readonly canvas: HTMLCanvasElement;
The HTML canvas used for this context.
Defined in
@novorender/core3d/context.ts:153
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.
Defined in
@novorender/core3d/context.ts:122
clippingUniforms
readonly clippingUniforms: WebGLBuffer;
WebGL uniform buffer for clipping related uniforms.
Defined in
@novorender/core3d/context.ts:90
commonChunk
readonly commonChunk: string;
WebGL common GLSL code header used across shaders.
Defined in
@novorender/core3d/context.ts:40
currentState
currentState: undefined | DerivedRenderState;
RenderState used to make the newest state available during render.
Defined in
@novorender/core3d/context.ts:119
defaultIBLTextureParams
readonly defaultIBLTextureParams: TextureParamsCubeUncompressed;
WebGL basic fallback IBL textures to use while loading proper IBL textures.
Defined in
@novorender/core3d/context.ts:42
deviceProfile
readonly deviceProfile: DeviceProfile;
The device profile use for this context.
Defined in
@novorender/core3d/context.ts:151
gl
readonly gl: WebGL2RenderingContext;
WebGL2 render context associated with this object.
Defined in
@novorender/core3d/context.ts:38
iblTextures
iblTextures: object;
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/
Defined in
@novorender/core3d/context.ts:137
imports
readonly imports: Core3DImports;
Imported resources.
Defined in
@novorender/core3d/context.ts:155
lut_ggx
readonly lut_ggx: WebGLTexture;
WebGL GGX/PBR shading lookup table texture.
Defined in
@novorender/core3d/context.ts:94
outlineRenderers
outlineRenderers: WeakMap<ReadonlyVec4, OutlineRenderer>;
Defined in
@novorender/core3d/context.ts:109
outlineUniforms
readonly outlineUniforms: WebGLBuffer;
WebGL uniform buffer for outline related uniforms.
Defined in
@novorender/core3d/context.ts:92
prevState
prevState: undefined | DerivedRenderState;
RenderState used to render the previous frame, if any.
Defined in
@novorender/core3d/context.ts:115
samplerEnvMip
readonly samplerEnvMip: WebGLSampler;
WebGL Sampler used to sample mip mapped IBL texture trilinear.
Defined in
@novorender/core3d/context.ts:96
samplerMip
readonly samplerMip: WebGLSampler;
WebGL Sampler used to sample mipmapped texture trilinear.
Defined in
@novorender/core3d/context.ts:98
samplerMipRepeat
readonly samplerMipRepeat: WebGLSampler;
WebGL Sampler used to sample mipmapped texture trilinear repeating UV.
Defined in
@novorender/core3d/context.ts:100
samplerSingle
readonly samplerSingle: WebGLSampler;
WebGL Sampler used to sample other, non-mipmapped IBL textures bilinear.
Defined in
@novorender/core3d/context.ts:102
usePrepass
readonly usePrepass: false = false;
Defined in
@novorender/core3d/context.ts:75
wasm
readonly wasm: WasmInstance;
Web assembly instance.