The Renderer object is used to render frames completely in the main thread of JavaScript as well as provide
key static functions that enable frame drawing and screen projection. The Renderer class does not rely on
WebWorkers like its child class, PerformanceRenderer, so it can offer a better level of compatibility with
older browsers; however, it is NOT recommended to animate large Scenes in real time with Renderer since it
has the potential to lock up the main thread and cause event loss in the event loop.
If you are planning to continuously animate a large Scene, it is recommended to use the PerformanceRenderer
object instead.
See also: PerformanceRenderer, Scene
Constructors
Constants
| Renderer.DRAW_HEADER_SIZE = 6 |
The number of Float32 values that are needed for constructing the header of the frame draw data.
|
| Renderer.DRAW_FRAG_SIZE = 14 |
The number of Float32 values that are needed for constructing each Fragment as frame draw data.
|
Variables
Public Variables
| backgroundColor: Color |
The background color that will be drawn over the previous image data on the canvas. If a
completely transparent color is provided, then the canvas will be cleared before drawing.
See also: Color
|
Protected Variables
| canvas: HTMLCanvasElement |
The HTMLCanvasElement that will be used to create a CanvasRenderingContext2D. Note:
This value should not be changed after initialization.
|
| ctx: CanvasRenderingContext2D |
The CanvasRenderingContext2D that will be used to render the frame image. Note: This
value should not be changed after initialization.
|
| lastDraw: ArrayBuffer |
The ArrayBuffer that stores the last frame's draw data. This is typically used to re-draw a
frame if a fullscreen render is resized.
|
| stats: Stats |
The Stats object used to record and display performance statistics for the renderer.
See also: Stats
|
| superSampling: number |
The ratio of canvas pixels to screen pixels that will be rendered. Note: This value
should not be changed after initialization.
|
Functions
Static Functions
| Renderer.draw(data: ArrayBuffer, ctx: CanvasRenderingContext2D |
OffscreenCanvasRenderingContext2D): void |
Saves the context and draws the fragment data provided to the canvas before restoring the
context at the end.
data format:
| Content |
Size (# of Float32) |
Data Order |
| HEADER DATA |
| Background Color |
4 |
red, green, blue, alpha |
| Dimensions |
2 |
width, height |
| FRAGMENT DATA (per fragment) |
| Screen Vertex 0 |
2 |
x, y |
| Screen Vertex 1 |
2 |
x, y |
| Screen Vertex 2 |
2 |
x, y |
| Fill Color |
4 |
red, green, blue, alpha |
| Wire Color |
4 |
red, green, blue, alpha |
|
| Renderer.getCameraInstance(scene: Scene, camera: Camera): FrameInstance |
Returns the FrameInstance of the Scene as seen through the given Camera. See also: FrameInstance, Scene, Camera
|
| Renderer.light(frag: Fragment, lights: List<Light>): Material |
Returns a new Material for a Fragment after being lit by a List of Lights. See also: Fragment, List, Light
|
| Renderer.project(v: Vector, fov: number, w: number, h: number): Vector |
Projects a given 3D Vector onto screen coordinates with reference to the width (w) and height
(h) given. The vector will be viewed from the origin looking down the positive X-Axis with the
given fov. See also: Vector
|
| Renderer.sortFragments(fragments: List<Fragment>): List<Fragment> |
Uses a custom bucket-sort algorithm to return a sorted List of Fragments based on their priority
in the List. See also: Fragment, List
|
Home
Copyright © 2020 Trevor Richard