Main | API | WebRender | constructor

Function

WebRender(canvas, callback, threadCount, filepath);

Constructor for a WebRender object.

Parameters

canvas - [HTML5 Canvas Element] - Semi-Optional

This is a reference to the HTML5 canvas element that is being drawn to by WebRender. If this is not provided, then the pixel array is returned to the callback function instead of drawn to the canvas. See getBuffer() for further information.

callback - [Function] - Semi-Optional

This is a reference to a callback function that will be called after a frame has been drawn. See getBuffer() for further information.

threadCount - [Unsigned Integer]

The number of threads to be used when rendering. A value of 0 will make WebRender run without any threads. See Multi-Threading for more details.

filepath - [String] - Optional

This is the filepath to the WebRender.js file that is used for the creation of threads. The path provided is relative to html file. If threads are not being used, this can be left empty.

Description

This is the main constructor for the WebRender class. It is responsible for creating a new instance of WebRender and sets the backend for rendering. Following this, a call must be made to initialise() in order to finish creating the WebRender instance and prepare it for drawing. It requires either a canvas element for internal drawing and/or a callback function. See getBuffer() for further information on the types of rendering.

The filepath is used when rendering with threads in order to load the WebRender library into each Web Worker. The path provided must be relative to the HTML file. If threads are not being used this filepath can be ignored.

Depending on how your application works, we can either have WebRender directly update the canvas by providing a reference to the canvas element, have WebRender return the pixel array to a callback function, or both. If you do not want to provide one of these (canvas or callback), then pass 'undefined' instead.

See more detailed information about multi-threading here.

Additional Notes

Developer Note: In my programs I like to have WebRender update the canvas as it is faster, and then also execute a callback. That way my program knows when a frame is complete and should begin drawing the next after a pause for other events.