API Docs for: 1.0.1
Show:

Kiwi.Renderers.GLRenderManager Class

Extends IRenderer
Module: Renderers
Parent Module: Kiwi

Manages all rendering using WebGL. Requires the inclusion of gl-matrix.js / g-matrix.min.js - https://github.com/toji/gl-matrix Directly manages renderer objects, including factory methods for their creation. Creates manager objects for shaders and textures. Manages gl state at game initialisation, at state start and end, and per frame. Runs the recursive scene graph rendering sequence every frame.

Constructor

Kiwi.Renderers.GLRenderManager

(
  • game
)
Kiwi.Renderers.GLRenderManager

Parameters:

  • game Kiwi.Game

    The game that this renderer belongs to.

Methods

_init

() private

Performs initialisation required for single game instance - happens once, at bootup Sets global GL state. Initialises managers for shaders and textures. Instantiates the default shared renderer (TextureAtlasRenderer)

_switchRenderer

(
  • gl
  • entity
)
private

Switch renderer to the one needed by the entity that needs rendering

Parameters:

_switchTexture

(
  • gl
  • entity
)
private

Switch texture to the one needed by the entity that needs rendering

Parameters:

addSharedRenderer

(
  • rendererID
  • params
)
Boolean public

Adds a renderer to the sharedRenderer array. The rendererID is a string that must match a renderer property of the Kiwi.Renderers object. If a match is found and an instance does not already exist, then a renderer is instantiated and added to the array.

Parameters:

  • rendererID String
  • params Object

Returns:

Boolean:

success

addSharedRenderer

(
  • rendererID
  • params
)
Kiwi.Renderers.Renderer public

Requests a shared renderer. A game object that wants to use a shared renderer uses this method to obtain a reference to the shared renderer instance.

Parameters:

  • rendererID String
  • params Object

Returns:

Kiwi.Renderers.Renderer:

A shared renderer or null if none found.

addTexture

(
  • gl
  • atlas
)
public

Adds a texture to the Texture Manager.

Parameters:

boot

() public

Initialises all WebGL rendering services

collateBatches

() public

Sorts the render sequence into batches. Each batch requires the same renderer/shader/texture combination.

collateChild

() public

Adds a child to the render sequence (may be a group with children of it's own)

collateRenderSequence

() public

Creates a new render sequence

initState

() public

Performs initialisation required when switching to a different state. Called when a state has been switched to. The textureManager is told to rebuild its cache of textures from the states textuer library.

initState

(
  • state
)
public

Performs cleanup required before switching to a different state. Called whwn a state is about to be switched from. The textureManager is told to empty its cache.

Parameters:

objType

() String public

The type of object that this is.

Returns:

String:

render

(
  • camera
)
public

Manages rendering of the scene graph - called once per frame. Sets up per frame gl uniforms such as the view matrix and camera offset. Clears the current renderer ready for a new batch. Initiates recursive render of scene graph starting at the root.

Parameters:

  • camera Camera

renderBatch

(
  • gl
  • batch
  • camera
)
public

Renders a single batch

Parameters:

  • gl WebGLRenderingContext
  • batch Object
  • camera Kiwi.Camera

renderBatches

(
  • gl
  • camera
)
public

Renders all the batches

Parameters:

renderEntity

(
  • gl
  • entity
  • camera
)
public

Calls the render function on a single entity

Parameters:

requestRendererInstance

(
  • rendererID
  • params
)
Kiwi.Renderers.Renderer public

Requests a new renderer instance. This factory method is the only way gameobjects should instantiate their own renderer. The rendererID is a string that must match a renderer property of the Kiwi.Renderers object. If a match is found then a renderer is instantiated and returned. Gameobjects which have rendering requirements that do not suit batch rendering use this technique.

Parameters:

  • rendererID String

    The name of the requested renderer

  • params Object

Returns:

Kiwi.Renderers.Renderer:

A renderer or null if none found.

setupGLState

(
  • gl
)
public

Ensures the atlas and renderer needed for a batch is setup

Parameters:

  • gl WebGLRenderingContext

Properties

_currentRenderer

Kiwi.Renderers.Renderer private

The renderer object that is in use during a rendering batch.

_currentTextureAtlas

TextureAtlas private

The most recently bound texture atlas.

_entityCount

Number private

Tally of number of entities rendered per frame

Default: 0

_game

Game private

The game that this renderer is used with.

_maxItems

Number private

Maximum allowable sprites to render per frame Note:Not currently used - candidate for deletion

Default: 1000

_shaderManager

Kiwi.Renderes.GLShaderManager private

The shader manager object used to allocate GL Shaders.

_sharedRenderers

Array private

An array of renderers. Shared renderers are used for batch rendering. Multiple gameobjects can use the same renderer instance and add rendering info to a batch rather than rendering individually. This means only one draw call is necessary to render a number of objects. The most common use of this is standard 2d sprite rendering, and the TextureAtlasRenderer is added by default as a shared renderer. Sprites, StaticImages and Tilemaps (core gameobjects) can all use the same renderer/shader combination and be drawn as part of the same batch. Custom gameobjects can also choose to use a shared renderer, fo example in the case that a custom gameobject's rendering requirements matched the TextureAtlasRenderer capabilities.

_stageResolution

Float32Array private

The stage resolution in pixels

_textureManager

Kiwi.Renderes.GLTextureManager private

The texture manager object used to allocate GL Textures.

numDrawCalls

Number public

Tally of number of draw calls per frame

Default: 0