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.
| 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:
|
| 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. |
| 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. |
| 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. |
| lightingWorker: LightingWorker | The LightingWorker object used to calculate pre-render lighting data. |
| 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. |
| projectingWorker: ProjectingWorker | The ProjectingWorker object used to calculate pre-render point-projection data. |
| renderWorker: RenderWorker | The RenderWorker object used to draw frames to an offscreenCanvas element.
|
| scene: Scene | Stores the current Scene that is being rendered. |
| sortCache: Float32Array | The results of the current SortingWorker pre-render data. |
| sortingWorker: SortingWorker | The SortingWorker object used to sort pre-render data. |
| 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. |
| lightCallback(data: Float32Array): void | Callback for 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. |
| projectCallback(data: Float32Array): void | Callback for ProjectingWorker. |
| sortCallback(data: Float32Array): void | Callback for 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. |
| renderCallback(): void | Callback for 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. |
| stop(): void | Stops rendering the current animation. |
| 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(). |
|---|---|
| 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. |
| 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. |
Copyright © 2020 Trevor Richard