@@ -13,34 +13,16 @@ PIXI.instances = [];
1313 *
1414 * @class WebGLRenderer
1515 * @constructor
16- * @param [width=0] {Number} the width of the canvas view
17- * @param [height=0] {Number} the height of the canvas view
18- * @param [options] {Object} The optional renderer parameters
19- * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional
20- * @param [options.transparent=false] {Boolean} If the render view is transparent, default false
21- * @param [options.autoResize=false] {Boolean} If the render view is automatically resized, default false
22- * @param [options.antialias=false] {Boolean} sets antialias (only applicable in chrome at the moment)
23- * @param [options.preserveDrawingBuffer=false] {Boolean} enables drawing buffer preservation, enable this if you need to call toDataUrl on the webgl context
24- * @param [options.resolution=1] {Number} the resolution of the renderer retina would be 2
16+ * @param game {Phaser.Game} A reference to the Phaser Game instance
2517 */
26- PIXI . WebGLRenderer = function ( width , height , options )
27- {
28- if ( options )
29- {
30- for ( var i in PIXI . defaultRenderOptions )
31- {
32- if ( options [ i ] === undefined ) options [ i ] = PIXI . defaultRenderOptions [ i ] ;
33- }
34- }
35- else
36- {
37- options = PIXI . defaultRenderOptions ;
38- }
18+ PIXI . WebGLRenderer = function ( game ) {
3919
40- if ( ! PIXI . defaultRenderer )
41- {
42- PIXI . defaultRenderer = this ;
43- }
20+ /**
21+ * @property {Phaser.Game } game - A reference to the Phaser Game instance.
22+ */
23+ this . game = game ;
24+
25+ PIXI . defaultRenderer = this ;
4426
4527 /**
4628 * @property type
@@ -55,33 +37,31 @@ PIXI.WebGLRenderer = function(width, height, options)
5537 * @type Number
5638 * @default 1
5739 */
58- this . resolution = options . resolution ;
59-
60- // do a catch.. only 1 webGL renderer..
40+ this . resolution = game . resolution ;
6141
6242 /**
6343 * Whether the render view is transparent
6444 *
6545 * @property transparent
6646 * @type Boolean
6747 */
68- this . transparent = options . transparent ;
48+ this . transparent = game . transparent ;
6949
7050 /**
7151 * Whether the render view should be resized automatically
7252 *
7353 * @property autoResize
7454 * @type Boolean
7555 */
76- this . autoResize = options . autoResize || false ;
56+ this . autoResize = false ;
7757
7858 /**
7959 * The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering.
8060 *
8161 * @property preserveDrawingBuffer
8262 * @type Boolean
8363 */
84- this . preserveDrawingBuffer = options . preserveDrawingBuffer ;
64+ this . preserveDrawingBuffer = game . preserveDrawingBuffer ;
8565
8666 /**
8767 * This sets if the WebGLRenderer will clear the context texture or not before the new render pass. If true:
@@ -93,33 +73,31 @@ PIXI.WebGLRenderer = function(width, height, options)
9373 * @type Boolean
9474 * @default
9575 */
96- this . clearBeforeRender = options . clearBeforeRender ;
76+ this . clearBeforeRender = game . clearBeforeRender ;
9777
9878 /**
9979 * The width of the canvas view
10080 *
10181 * @property width
10282 * @type Number
103- * @default 800
10483 */
105- this . width = width || 800 ;
84+ this . width = game . width ;
10685
10786 /**
10887 * The height of the canvas view
10988 *
11089 * @property height
11190 * @type Number
112- * @default 600
11391 */
114- this . height = height || 600 ;
92+ this . height = game . height ;
11593
11694 /**
11795 * The canvas element that everything is drawn to
11896 *
11997 * @property view
12098 * @type HTMLCanvasElement
12199 */
122- this . view = options . view || document . createElement ( ' canvas' ) ;
100+ this . view = game . canvas ;
123101
124102 /**
125103 * @property _contextOptions
@@ -128,10 +106,10 @@ PIXI.WebGLRenderer = function(width, height, options)
128106 */
129107 this . _contextOptions = {
130108 alpha : this . transparent ,
131- antialias : options . antialias , // SPEED UP??
109+ antialias : game . antialias ,
132110 premultipliedAlpha : this . transparent && this . transparent !== 'notMultiplied' ,
133111 stencil : true ,
134- preserveDrawingBuffer : options . preserveDrawingBuffer
112+ preserveDrawingBuffer : this . preserveDrawingBuffer
135113 } ;
136114
137115 /**
@@ -144,7 +122,7 @@ PIXI.WebGLRenderer = function(width, height, options)
144122 * @property offset
145123 * @type Point
146124 */
147- this . offset = new PIXI . Point ( 0 , 0 ) ;
125+ this . offset = new PIXI . Point ( ) ;
148126
149127 // time to create the render managers! each one focuses on managing a state in webGL
150128
@@ -191,11 +169,12 @@ PIXI.WebGLRenderer = function(width, height, options)
191169 this . blendModeManager = new PIXI . WebGLBlendModeManager ( ) ;
192170
193171 /**
194- * TODO remove
195172 * @property renderSession
196173 * @type Object
197174 */
198175 this . renderSession = { } ;
176+
177+ this . renderSession . game = this . game ;
199178 this . renderSession . gl = this . gl ;
200179 this . renderSession . drawCount = 0 ;
201180 this . renderSession . shaderManager = this . shaderManager ;
@@ -223,6 +202,7 @@ PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer;
223202PIXI . WebGLRenderer . prototype . initContext = function ( )
224203{
225204 var gl = this . view . getContext ( 'webgl' , this . _contextOptions ) || this . view . getContext ( 'experimental-webgl' , this . _contextOptions ) ;
205+
226206 this . gl = gl ;
227207
228208 if ( ! gl ) {
@@ -266,14 +246,6 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
266246 // no point rendering if our context has been blown up!
267247 if ( this . contextLost ) return ;
268248
269- // if rendering a new stage clear the batches..
270- if ( this . __stage !== stage )
271- {
272- // TODO make this work
273- // dont think this is needed any more?
274- this . __stage = stage ;
275- }
276-
277249 // update the scene graph
278250 stage . updateTransform ( ) ;
279251
@@ -296,10 +268,10 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
296268 gl . clearColor ( stage . backgroundColorSplit [ 0 ] , stage . backgroundColorSplit [ 1 ] , stage . backgroundColorSplit [ 2 ] , 1 ) ;
297269 }
298270
299- gl . clear ( gl . COLOR_BUFFER_BIT ) ;
271+ gl . clear ( gl . COLOR_BUFFER_BIT ) ;
300272 }
301273
302- this . renderDisplayObject ( stage , this . projection ) ;
274+ this . renderDisplayObject ( stage , this . projection ) ;
303275} ;
304276
305277/**
0 commit comments