PerformanceRenderer

Home

The PerformanceRenderer object is an extension of the Renderer class and provides improved real time animation capabilities through the use of synchronized WebWorkers, event sequencing, and optional offscreenCanvas rendering with a seamless standard canvas fallback.

See also: Renderer, UrchinWorker, SortingWorker, LightingWorker, ProjectingWorker, RenderWorker

Constructors

PerformanceRenderer( ): PerformanceRenderer Initializes with default attribute values.
PerformanceRenderer( { canvas?: HTMLCanvasElement, backgroundColor?: Color, frameCallback?: Function, fullscreen?: boolean, superSampling?: number, showPerformance?: boolean, offscreenDraw?: boolean, suspendOnBlur?: boolean } ): PerformanceRenderer Initializes with the given attribute values if set. Default values are:

canvas Default from Renderer constructor. See also: Renderer
backgroundColor Default from Renderer constructor. See also: Renderer
frameCallback undefined The callback function that will be called after every frame render. This can be used to move animations or queue events and often replaces the need for window.requestAnimationFrame.
fullscreen false If true, the canvas element will be resized to fit the size of the window on initialization as well as every time the window is resized.

Note: If a RenderWorker exists, a message will be sent to the RenderWorker to resize the canvas instead.

See also: RenderWorker
superSampling Default from Renderer constructor. See also: Renderer
showPerformance Default from Renderer constructor. See also: Renderer
offscreenDraw true If true and the browser supports transferControlToOffscreen for canvas elements, a RenderWorker will be created and given control of the canvas element so that all of the drawing can be done off of the main thread.

Note: If the browser does not support the feature, the constructor will automatically fallback to a standard canvas and drawing procedure.

See also: RenderWorker
suspendOnBlur true If true, the renderer will not render any frames when the window is not focused by the user and a 'focus' event listener will be added to the window to resume rendering when the window is active.

Variables

Private Variables

callbackCount: number Keeps track of the number of callbacks this object has received from the WebWorkers. When the callback count reaches 3, the data is drawn.
camera: Camera Stores the current Camera Urbject that is being rendered. See also: Camera
drawing: boolean Used by the renderer to keep track of when data is being drawn to the canvas.
height: number The current height of the canvas in pixels. This data is stored in its own variable since we may not have access to the canvas in the DOM if it is being controlled offscreen.
instanceQueue: FrameInstance Acts as a "most frequent request" for frame renders that is pulled when the pre-rendering workers are ready for a new frame. Some frames will be lost if a new frame is requested before an older frame is pulled, but this promoted a lower latency system. See also: FrameInstance
lastFrameTime: number The millisecond timestamp for the last frame render used to calculate FPS for render stats.
lightCache: Float32Array The results of the current LightingWorker pre-render data. See also: LightingWorker
lightingWorker: LightingWorker The LightingWorker object used to calculate pre-render lighting data. See also: LightingWorker
preRendering: boolean A variable to keep track of when the workers are working on pre-render tasks.
projectCache: Float32Array The results of the current ProjectingWorker pre-render data. See also: ProjectingWorker
projectingWorker: ProjectingWorker The ProjectingWorker object used to calculate pre-render point-projection data. See also: ProjectingWorker
renderWorker: RenderWorker The RenderWorker object used to draw frames to an offscreenCanvas element. See also: RenderWorker
scene: Scene Stores the current Scene that is being rendered. See also: Scene
sortCache: Float32Array The results of the current SortingWorker pre-render data. See also: SortingWorker
sortingWorker: SortingWorker The SortingWorker object used to sort pre-render data. See also: SortingWorker
width: number The current width of the canvas in pixels. This data is stored in its own variable since we may not have access to the canvas in the DOM if it is being controlled offscreen.

Functions

Public Functions

lightCallback(data: Float32Array): void Callback for LightingWorker. See also: LightingWorker
project(v: Vector, camera: Camera, superSamplePosition?: boolean): Vector Projects a given 3D Vector onto screen coordinates as seen through the given Camera. If superSamplePosition is true, then the image pixel coordinates are returned instead of canvas screen coordinates. superSamplePosition is false by default. See also: Vector, Camera
projectCallback(data: Float32Array): void Callback for ProjectingWorker. See also: ProjectingWorker
sortCallback(data: Float32Array): void Callback for SortingWorker. See also: SortingWorker
render(scene: Scene, camera: Camera): void Requests the workers to render one frame of a Scene through the given Camera view. This should only be used for single-frame renders or controlled frame-rate animations. See also: Scene, Camera
renderCallback(): void Callback for RenderWorker. See also: RenderWorker
resize(width?: number, height?: number): void Resizes the canvas image size to the given values or the window size if values are omitted.
start(scene: Scene, camera: Camera): void Starts rendering the Scene through the perspective of the given Camera. The renderer will draw frames as fast as it can process the data and call the frameCallback() function that was set in the constructor after each frame is drawn. See also: Scene, Camera
stop(): void Stops rendering the current animation.

Private Functions

buildDrawData(s: Float32Array, p: Float32Array, l: Float32Array): ArrayBuffer Builds and returns the frame draw data from the given pre-render data Arrays. Outputs an ArrayBuffer in the same format as specified in Renderer.draw(). See also: Renderer
callbackCheck(): void Called after each pre-render callback to check if all the pre-render data is ready to be built and sent to be rendered.
draw(data: ArrayBuffer): void Draws the given data by sending it to the RenderWorker if it exists, or drawing it in the main thread otherwise.
requestPreRender(instance?: FrameInstance): void Requests a pre-render from the workers for the given FrameInstance or the instanceQueue if instance is not set. See also: FrameInstance
renderSync(): void Syncs the pre-render workers with the render worker to ensure that the pre-renderers are working at the same pace as the renderer.

Home

Copyright © 2020 Trevor Richard