API Docs for: 1.4.0
Show:

Kiwi.Renderers.GLRenderManager Class

Extends IRenderer
Module: Renderers
Parent Module: Kiwi

Manages all rendering using WebGL. 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)

_switchBlendMode

(
  • gl
  • blendMode
)
private

Defined in src\render\GLRenderManager.ts:704

Available since 1.1.0

Switch blend mode to a new set of constants

Parameters:

_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

addSharedRendererClone

(
  • rendererID
  • cloneID
  • params
)
Boolean public

Defined in src\render\GLRenderManager.ts:219

Available since 1.1.0

Adds a cloned renderer to the sharedRenderer array. The rendererID is a string that must match a renderer property of the Kiwi.Renderers object. The cloneID is the name for the cloned renderer.

If a match is found and an instance does not already exist, then a renderer is instantiated and added to the array.

Cloned shared renderers are useful if some items in your scene will use a special shader or blend mode, but others will not. You can subsequently access the clones with a normal requestSharedRenderer() call. You should use this instead of requestRendererInstance() whenever possible, because shared renderers are more efficient than instances.

Parameters:

  • rendererID String
  • cloneID String
  • params Object

Returns:

Boolean:

success

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 its own).

collateRenderSequence

() public

Creates a new render sequence

endState

(
  • 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:

initState

() public

Performs initialisation required when switching to a different state. Called when a state has been switched to. The textureManager is told to clear its contents from video memory, then rebuild its cache of textures from the state's texture library.

objType

() String public

The type of object that this is.

Returns:

String:

"GLRenderManager"

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
)
deprecated public

Defined in src\render\GLRenderManager.ts:654

Deprecated: Used internally; should not be called from external functions

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.

requestSharedRenderer

(
  • 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.

scaleViewport

(
  • gl
  • mode
  • width
  • height
)
public

Defined in src\render\GLRenderManager.ts:377

Available since 1.1.1

Scales the viewport according to a scale mode and space dimensions.

This is used internally for compatibility with CocoonJS and should not be called.

Parameters:

  • gl WebGLRenderingContext
  • mode Number

    Scale mode; should be either Kiwi.Stage.SCALE_FIT, Kiwi.Stage.SCALE_STRETCH, or Kiwi.Stage.SCALE_NONE. Defaults to Kiwi.Stage.SCALE_NONE

  • width Number

    Width of the target space

  • height Number

    Height of the target space

setupGLState

(
  • gl
)
deprecated public

Defined in src\render\GLRenderManager.ts:667

Deprecated: Used internally; should not be called from external functions.

Ensures the atlas and renderer needed for a batch is setup

Parameters:

  • gl WebGLRenderingContext

Properties

_camMatrixOffset

Kiwi.Geom.Matrix private

Geometry data used to create camMatrix

_currentBlendMode

Kiwi.Renderers.GLBlendMode private

Defined in src\render\GLRenderManager.ts:97

Available since 1.1.0

The current blend mode.

_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.

camMatrix

Float32Array public

Camera matrix used on graphics card

numDrawCalls

Number public

Tally of number of draw calls per frame

Default: 0