@@ -518,8 +518,6 @@ var WebGLRenderer = new Class({
518518
519519 this . setBlendMode ( CONST . BlendModes . NORMAL ) ;
520520
521- // this.pushScissor(0, 0, this.width, this.height);
522-
523521 this . resize ( this . width , this . height ) ;
524522
525523 this . game . events . once ( 'ready' , this . boot , this ) ;
@@ -584,11 +582,6 @@ var WebGLRenderer = new Class({
584582 {
585583 pipelines [ pipelineName ] . resize ( width , height , resolution ) ;
586584 }
587-
588- // if (this.currentScissor)
589- // {
590- // this.currentScissor = [ 0, 0, this.width, this.height ];
591- // }
592585
593586 this . drawingBufferHeight = gl . drawingBufferHeight ;
594587
@@ -760,36 +753,6 @@ var WebGLRenderer = new Class({
760753 return pipelineInstance ;
761754 } ,
762755
763- /**
764- * Sets the current scissor state
765- *
766- * @method Phaser.Renderer.WebGL.WebGLRenderer#setScissor
767- * @since 3.0.0
768- */
769- setScissor : function ( )
770- {
771- var gl = this . gl ;
772-
773- var current = this . currentScissor ;
774-
775- var x = current [ 0 ] ;
776- var y = current [ 1 ] ;
777- var w = current [ 2 ] ;
778- var h = current [ 3 ] ;
779-
780- // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/scissor
781- var box = gl . getParameter ( gl . SCISSOR_BOX ) ;
782-
783- if ( box && ( box [ 0 ] !== x || box [ 1 ] !== y || box [ 2 ] !== w || box [ 3 ] !== h ) )
784- {
785- this . flush ( ) ;
786-
787- gl . enable ( gl . SCISSOR_TEST ) ;
788-
789- gl . scissor ( x , ( this . drawingBufferHeight - y - h ) , w , h ) ;
790- }
791- } ,
792-
793756 /**
794757 * Pushes a new scissor state. This is used to set nested scissor states.
795758 *
@@ -806,19 +769,44 @@ var WebGLRenderer = new Class({
806769 pushScissor : function ( x , y , w , h )
807770 {
808771 var scissorStack = this . scissorStack ;
809- var stackLength = scissorStack . length ;
810772
811773 var scissor = [ x , y , w , h ] ;
812774
813775 scissorStack . push ( scissor ) ;
814776
815- this . currentScissor = scissor ;
777+ this . setScissor ( x , y , w , h ) ;
816778
817- this . setScissor ( ) ;
779+ this . currentScissor = scissor ;
818780
819781 return scissor ;
820782 } ,
821783
784+ /**
785+ * Sets the current scissor state
786+ *
787+ * @method Phaser.Renderer.WebGL.WebGLRenderer#setScissor
788+ * @since 3.0.0
789+ */
790+ setScissor : function ( x , y , w , h )
791+ {
792+ var gl = this . gl ;
793+
794+ var current = this . currentScissor ;
795+
796+ var cx = current [ 0 ] ;
797+ var cy = current [ 1 ] ;
798+ var cw = current [ 2 ] ;
799+ var ch = current [ 3 ] ;
800+
801+ if ( cx !== x || cy !== y || cw !== w || ch !== h )
802+ {
803+ this . flush ( ) ;
804+
805+ // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/scissor
806+ gl . scissor ( x , ( this . drawingBufferHeight - y - h ) , w , h ) ;
807+ }
808+ } ,
809+
822810 /**
823811 * Pops the last scissor state and sets it.
824812 *
@@ -829,9 +817,11 @@ var WebGLRenderer = new Class({
829817 {
830818 var scissorStack = this . scissorStack ;
831819
832- this . currentScissor = scissorStack . pop ( ) ;
820+ var scissor = scissorStack . pop ( ) ;
821+
822+ this . setScissor ( scissor [ 0 ] , scissor [ 1 ] , scissor [ 2 ] , scissor [ 3 ] ) ;
833823
834- this . setScissor ( ) ;
824+ this . currentScissor = scissor ;
835825 } ,
836826
837827 /**
@@ -1540,8 +1530,18 @@ var WebGLRenderer = new Class({
15401530 pipelines [ key ] . onPreRender ( ) ;
15411531 }
15421532
1543- this . scissorStack = [ ] ;
1544- this . currentScissor = null ;
1533+ // TODO - Find a way to stop needing to create these arrays every frame
1534+ // and equally not need a huge array buffer created to hold them
1535+
1536+ this . currentScissor = [ 0 , 0 , this . width , this . height ] ;
1537+ this . scissorStack = [ this . currentScissor ] ;
1538+
1539+ if ( this . game . scene . customViewports )
1540+ {
1541+ gl . enable ( gl . SCISSOR_TEST ) ;
1542+
1543+ gl . scissor ( 0 , ( this . drawingBufferHeight - this . height ) , this . width , this . height ) ;
1544+ }
15451545
15461546 this . setPipeline ( this . pipelines . TextureTintPipeline ) ;
15471547 } ,
0 commit comments