Kiwi.Renderers.GLRenderManager Class
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
Parameters:
-
game
Kiwi.GameThe game that this renderer belongs to.
Returns:
Item Index
Methods
- _init
- _switchBlendMode
- _switchRenderer
- _switchTexture
- addSharedRenderer
- addSharedRendererClone
- addTexture
- boot
- collateBatches
- collateChild
- collateRenderSequence
- endState
- initState
- objType
- render
- renderBatch
- renderBatches
- renderEntity deprecated
- requestRendererInstance
- requestSharedRenderer
- scaleViewport
- setupGLState deprecated
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
Switch blend mode to a new set of constants
Parameters:
-
gl
WebGLRenderingContext -
blendMode
Kiwi.Renderers.GLBlendMode
_switchRenderer
-
gl
-
entity
Switch renderer to the one needed by the entity that needs rendering
Parameters:
-
gl
WebGLRenderingContext -
entity
Kiwi.Entity
_switchTexture
-
gl
-
entity
Switch texture to the one needed by the entity that needs rendering
Parameters:
-
gl
WebGLRenderingContext -
entity
Kiwi.Entity
addTexture
-
gl
-
atlas
Adds a texture to the Texture Manager.
Parameters:
-
gl
WebGLRenderingContext -
atlas
Kiwi.Textures.TextureAtlas
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
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:
-
state
Kiwi.State
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:
"GLRenderManager"
render
-
camera
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
Renders a single batch
Parameters:
-
gl
WebGLRenderingContext -
batch
Object -
camera
Kiwi.Camera
renderBatches
-
gl
-
camera
Renders all the batches
Parameters:
-
gl
WebGLRenderingContext -
camera
Kiwi.Camera
renderEntity
-
gl
-
entity
-
camera
Calls the render function on a single entity
Parameters:
-
gl
WebGLRenderingContext -
entity
Kiwi.Entity -
camera
Kiwi.Camera
requestRendererInstance
-
rendererID
-
params
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
StringThe name of the requested renderer
-
params
Object
Returns:
A renderer or null if none found.
scaleViewport
-
gl
-
mode
-
width
-
height
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
NumberScale mode; should be either Kiwi.Stage.SCALE_FIT, Kiwi.Stage.SCALE_STRETCH, or Kiwi.Stage.SCALE_NONE. Defaults to Kiwi.Stage.SCALE_NONE
-
width
NumberWidth of the target space
-
height
NumberHeight of the target space
setupGLState
-
gl
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.
_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