66 */
77
88var Class = require ( '../../utils/Class' ) ;
9+ var DeepCopy = require ( '../../utils/object/DeepCopy' ) ;
910var GetFastValue = require ( '../../utils/object/GetFastValue' ) ;
1011var Matrix4 = require ( '../../math/Matrix4' ) ;
1112var Utils = require ( './Utils' ) ;
@@ -26,6 +27,16 @@ var WebGLShader = require('./WebGLShader');
2627 * Usually, you would not extend from this class directly, but would instead extend
2728 * from one of the core pipelines, such as the Multi Pipeline.
2829 *
30+ * The pipeline flow per render-step is as follows:
31+ *
32+ * 1) onPreRender - called once at the start of the render step
33+ * 2) onRender - call for each Scene Camera that needs to render (so can be multiple times per render step)
34+ * 3) Internal flow:
35+ * 3a) bind (only called if a Game Object is using this pipeline and it's not currently active)
36+ * 3b) onBind (called for every Game Object that uses this pipeline)
37+ * 3c) flush (can be called by a Game Object, internal method or from outside by changing pipeline)
38+ * 4) onPostRender - called once at the end of the render step
39+ *
2940 * @class WebGLPipeline
3041 * @memberof Phaser.Renderer.WebGL
3142 * @constructor
@@ -247,23 +258,14 @@ var WebGLPipeline = new Class({
247258 */
248259 this . hasBooted = false ;
249260
250- /**
251- * Array of objects that describe the vertex attributes.
252- *
253- * @name Phaser.Renderer.WebGL.WebGLPipeline#attributes
254- * @type {Phaser.Types.Renderer.WebGL.WebGLPipelineAttributesConfig }
255- * @since 3.0.0
256- */
257- this . attributes = config . attributes ;
258-
259261 /**
260262 * The amount of vertex attribute components of 32 bit length.
261263 *
262264 * @name Phaser.Renderer.WebGL.WebGLPipeline#vertexComponentCount
263265 * @type {integer }
264266 * @since 3.0.0
265267 */
266- this . vertexComponentCount = Utils . getComponentCount ( this . attributes , this . gl ) ;
268+ this . vertexComponentCount = Utils . getComponentCount ( config . attributes , this . gl ) ;
267269
268270 /**
269271 * The WebGLFramebuffer this pipeline is targeting, if any.
@@ -403,6 +405,8 @@ var WebGLPipeline = new Class({
403405
404406 this . setShadersFromConfig ( config ) ;
405407
408+ this . currentShader . bind ( ) ;
409+
406410 this . renderer . setVertexBuffer ( this . vertexBuffer ) ;
407411
408412 this . setAttribPointers ( true ) ;
@@ -513,6 +517,7 @@ var WebGLPipeline = new Class({
513517 {
514518 var i ;
515519 var shaders = this . shaders ;
520+ var renderer = this . renderer ;
516521
517522 for ( i = 0 ; i < shaders . length ; i ++ )
518523 {
@@ -522,73 +527,47 @@ var WebGLPipeline = new Class({
522527 var vName = 'vertShader' ;
523528 var fName = 'fragShader' ;
524529 var uName = 'uniforms' ;
530+ var aName = 'attributes' ;
525531
526532 var defaultVertShader = GetFastValue ( config , vName , null ) ;
527- var defaultFragShader = GetFastValue ( config , fName , null ) ;
533+ var defaultFragShader = Utils . parseFragmentShaderMaxTextures ( GetFastValue ( config , fName , null ) , renderer . maxTextures ) ;
528534 var defaultUniforms = GetFastValue ( config , uName , null ) ;
535+ var defaultAttribs = GetFastValue ( config , aName , null ) ;
529536
530537 var configShaders = GetFastValue ( config , 'shaders' , [ ] ) ;
531538
532539 var len = configShaders . length ;
533540
534541 if ( len === 0 )
535542 {
536- this . shaders = [ new WebGLShader ( this , 'default' , defaultVertShader , defaultFragShader , defaultUniforms ) ] ;
543+ this . shaders = [ new WebGLShader ( this , 'default' , defaultVertShader , defaultFragShader , DeepCopy ( defaultAttribs ) , defaultUniforms ) ] ;
537544 }
538545 else
539546 {
547+ var newShaders = [ ] ;
548+
540549 for ( i = 0 ; i < len ; i ++ )
541550 {
542551 var shaderEntry = configShaders [ i ] ;
543552
544553 var name = GetFastValue ( shaderEntry , 'name' , 'default' ) ;
545554
546555 var vertShader = GetFastValue ( shaderEntry , vName , defaultVertShader ) ;
547- var fragShader = GetFastValue ( shaderEntry , fName , defaultFragShader ) ;
556+ var fragShader = Utils . parseFragmentShaderMaxTextures ( GetFastValue ( shaderEntry , fName , defaultFragShader ) , renderer . maxTextures ) ;
557+ var attributes = GetFastValue ( shaderEntry , aName , defaultAttribs ) ;
548558 var uniforms = GetFastValue ( shaderEntry , uName , defaultUniforms ) ;
549559
550- configShaders . push ( new WebGLShader ( this , name , vertShader , fragShader , uniforms ) ) ;
560+ newShaders . push ( new WebGLShader ( this , name , vertShader , fragShader , DeepCopy ( attributes ) , uniforms ) ) ;
551561 }
552562
553- this . shaders = configShaders ;
563+ this . shaders = newShaders ;
554564 }
555565
556566 this . currentShader = this . shaders [ 0 ] ;
557567
558568 return this ;
559569 } ,
560570
561- /**
562- * Adds a description of vertex attribute to the pipeline.
563- *
564- * @method Phaser.Renderer.WebGL.WebGLPipeline#addAttribute
565- * @since 3.2.0
566- *
567- * @param {string } name - Name of the vertex attribute
568- * @param {integer } size - Vertex component size
569- * @param {integer } type - Type of the attribute
570- * @param {boolean } normalized - Is the value normalized to a range
571- * @param {integer } offset - Byte offset to the beginning of the first element in the vertex
572- *
573- * @return {this } This WebGLPipeline instance.
574- */
575- addAttribute : function ( name , size , type , normalized , offset )
576- {
577- this . attributes . push ( {
578- name : name ,
579- size : size ,
580- type : this . renderer . glFormats [ type ] ,
581- normalized : normalized ,
582- offset : offset ,
583- enabled : false ,
584- location : - 1
585- } ) ;
586-
587- this . vertexComponentCount = Utils . getComponentCount ( this . attributes , this . gl ) ;
588-
589- return this ;
590- } ,
591-
592571 /**
593572 * Sets the vertex attribute pointers.
594573 *
@@ -606,8 +585,8 @@ var WebGLPipeline = new Class({
606585 if ( reset === undefined ) { reset = false ; }
607586
608587 var gl = this . gl ;
609- var attributes = this . attributes ;
610588 var vertexSize = this . vertexSize ;
589+ var attributes = this . currentShader . attributes ;
611590 var program = this . currentShader . program ;
612591
613592 for ( var i = 0 ; i < attributes . length ; i ++ )
@@ -729,9 +708,10 @@ var WebGLPipeline = new Class({
729708 } ,
730709
731710 /**
732- * Binds the pipeline resources, including the given shader, vertex buffer and attribute pointers .
711+ * This method is called every time the Pipeline Manager makes this pipeline the currently active one .
733712 *
734- * This method is called every time this pipeline is made the current active pipeline.
713+ * It binds the resources and shader needed for this pipeline, including setting the vertex buffer
714+ * and attribute pointers.
735715 *
736716 * @method Phaser.Renderer.WebGL.WebGLPipeline#bind
737717 * @since 3.0.0
0 commit comments