@@ -302,7 +302,8 @@ var WebGLRenderer = new Class({
302302 * @type {Uint32Array }
303303 * @since 3.0.0
304304 */
305- this . currentScissor = new Uint32Array ( [ 0 , 0 , this . width , this . height ] ) ;
305+ // this.currentScissor = new Uint32Array([ 0, 0, this.width, this.height ]);
306+ this . currentScissor = null ;
306307
307308 /**
308309 * Index to the scissor stack top
@@ -312,7 +313,7 @@ var WebGLRenderer = new Class({
312313 * @default 0
313314 * @since 3.0.0
314315 */
315- this . currentScissorIdx = 0 ;
316+ // this.currentScissorIdx = 0;
316317
317318 /**
318319 * Stack of scissor data
@@ -321,7 +322,8 @@ var WebGLRenderer = new Class({
321322 * @type {Uint32Array }
322323 * @since 3.0.0
323324 */
324- this . scissorStack = new Uint32Array ( 4 * 1000 ) ;
325+ // this.scissorStack = new Uint32Array(4 * 1000);
326+ this . scissorStack = [ ] ;
325327
326328 // Setup context lost and restore event listeners
327329
@@ -447,7 +449,7 @@ var WebGLRenderer = new Class({
447449 {
448450 this . contextLost = true ;
449451
450- throw new Error ( 'This browser does not support WebGL. Try using the Canvas pipeline. ' ) ;
452+ throw new Error ( 'WebGL unsupported ' ) ;
451453 }
452454
453455 this . gl = gl ;
@@ -515,6 +517,9 @@ var WebGLRenderer = new Class({
515517 this . addPipeline ( 'Light2D' , new ForwardDiffuseLightPipeline ( { game : this . game , renderer : this } ) ) ;
516518
517519 this . setBlendMode ( CONST . BlendModes . NORMAL ) ;
520+
521+ // this.pushScissor(0, 0, this.width, this.height);
522+
518523 this . resize ( this . width , this . height ) ;
519524
520525 this . game . events . once ( 'ready' , this . boot , this ) ;
@@ -580,7 +585,10 @@ var WebGLRenderer = new Class({
580585 pipelines [ pipelineName ] . resize ( width , height , resolution ) ;
581586 }
582587
583- this . currentScissor . set ( [ 0 , 0 , this . width , this . height ] ) ;
588+ // if (this.currentScissor)
589+ // {
590+ // this.currentScissor = [ 0, 0, this.width, this.height ];
591+ // }
584592
585593 this . drawingBufferHeight = gl . drawingBufferHeight ;
586594
@@ -757,49 +765,29 @@ var WebGLRenderer = new Class({
757765 *
758766 * @method Phaser.Renderer.WebGL.WebGLRenderer#setScissor
759767 * @since 3.0.0
760- *
761- * @param {integer } x - [description]
762- * @param {integer } y - [description]
763- * @param {integer } w - [description]
764- * @param {integer } h - [description]
765- *
766- * @return {Phaser.Renderer.WebGL.WebGLRenderer } [description]
767768 */
768- setScissor : function ( x , y , w , h )
769+ setScissor : function ( )
769770 {
770771 var gl = this . gl ;
771- var currentScissor = this . currentScissor ;
772- var enabled = ( x === 0 && y === 0 && w === this . width && h === this . height && w >= 0 && h >= 0 ) ;
773-
774- // TODO: If new scissor is same as old scissor, skip setting it again
775- // TODO: If scissor is viewport size, skip setting altogether
776772
777- if ( currentScissor [ 0 ] !== x ||
778- currentScissor [ 1 ] !== y ||
779- currentScissor [ 2 ] !== w ||
780- currentScissor [ 3 ] !== h )
781- {
782- this . flush ( ) ;
783- }
773+ var current = this . currentScissor ;
784774
785- currentScissor [ 0 ] = x ;
786- currentScissor [ 1 ] = y ;
787- currentScissor [ 2 ] = w ;
788- currentScissor [ 3 ] = h ;
775+ var x = current [ 0 ] ;
776+ var y = current [ 1 ] ;
777+ var w = current [ 2 ] ;
778+ var h = current [ 3 ] ;
789779
790- this . currentScissorEnabled = enabled ;
780+ // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/scissor
781+ var box = gl . getParameter ( gl . SCISSOR_BOX ) ;
791782
792- if ( enabled )
783+ if ( box && ( box [ 0 ] !== x || box [ 1 ] !== y || box [ 2 ] !== w || box [ 3 ] !== h ) )
793784 {
794- gl . disable ( gl . SCISSOR_TEST ) ;
795-
796- return this ;
797- }
785+ this . flush ( ) ;
798786
799- gl . enable ( gl . SCISSOR_TEST ) ;
800- gl . scissor ( x , ( this . drawingBufferHeight - y - h ) , w , h ) ;
787+ gl . enable ( gl . SCISSOR_TEST ) ;
801788
802- return this ;
789+ gl . scissor ( x , ( this . drawingBufferHeight - y - h ) , w , h ) ;
790+ }
803791 } ,
804792
805793 /**
@@ -818,42 +806,32 @@ var WebGLRenderer = new Class({
818806 pushScissor : function ( x , y , w , h )
819807 {
820808 var scissorStack = this . scissorStack ;
821- var stackIndex = this . currentScissorIdx ;
822- var currentScissor = this . currentScissor ;
809+ var stackLength = scissorStack . length ;
823810
824- scissorStack [ stackIndex + 0 ] = currentScissor [ 0 ] ;
825- scissorStack [ stackIndex + 1 ] = currentScissor [ 1 ] ;
826- scissorStack [ stackIndex + 2 ] = currentScissor [ 2 ] ;
827- scissorStack [ stackIndex + 3 ] = currentScissor [ 3 ] ;
811+ var scissor = [ x , y , w , h ] ;
812+
813+ scissorStack . push ( scissor ) ;
828814
829- this . currentScissorIdx += 4 ;
830- this . setScissor ( x , y , w , h ) ;
815+ this . currentScissor = scissor ;
831816
832- return this ;
817+ this . setScissor ( ) ;
818+
819+ return scissor ;
833820 } ,
834821
835822 /**
836823 * Pops the last scissor state and sets it.
837824 *
838825 * @method Phaser.Renderer.WebGL.WebGLRenderer#popScissor
839826 * @since 3.0.0
840- *
841- * @return {Phaser.Renderer.WebGL.WebGLRenderer } [description]
842827 */
843828 popScissor : function ( )
844829 {
845830 var scissorStack = this . scissorStack ;
846- var stackIndex = this . currentScissorIdx - 4 ;
847831
848- var x = scissorStack [ stackIndex + 0 ] ;
849- var y = scissorStack [ stackIndex + 1 ] ;
850- var w = scissorStack [ stackIndex + 2 ] ;
851- var h = scissorStack [ stackIndex + 3 ] ;
832+ this . currentScissor = scissorStack . pop ( ) ;
852833
853- this . currentScissorIdx = stackIndex ;
854- this . setScissor ( x , y , w , h ) ;
855-
856- return this ;
834+ this . setScissor ( ) ;
857835 } ,
858836
859837 /**
@@ -1562,6 +1540,9 @@ var WebGLRenderer = new Class({
15621540 pipelines [ key ] . onPreRender ( ) ;
15631541 }
15641542
1543+ this . scissorStack = [ ] ;
1544+ this . currentScissor = null ;
1545+
15651546 this . setPipeline ( this . pipelines . TextureTintPipeline ) ;
15661547 } ,
15671548
0 commit comments