@@ -9,13 +9,11 @@ var GetFastValue = require('../../../utils/object/GetFastValue');
99var MultiPipeline = require ( './MultiPipeline' ) ;
1010var ShaderSourceFS = require ( '../shaders/Single-frag.js' ) ;
1111var ShaderSourceVS = require ( '../shaders/Single-vert.js' ) ;
12- var WebGLPipeline = require ( '../WebGLPipeline' ) ;
1312
1413/**
1514 * @classdesc
16- *
1715 * The Single Pipeline is a special version of the Multi Pipeline that only ever
18- * uses one single texture, bound to texture unit zero. Although not as efficient as the
16+ * uses one texture, bound to texture unit zero. Although not as efficient as the
1917 * Multi Pipeline, it provides an easier way to create custom pipelines that only require
2018 * a single bound texture.
2119 *
@@ -28,8 +26,9 @@ var WebGLPipeline = require('../WebGLPipeline');
2826 *
2927 * `inPosition` (vec2, offset 0)
3028 * `inTexCoord` (vec2, offset 8)
31- * `inTintEffect` (float, offset 16)
32- * `inTint` (vec4, offset 20, normalized)
29+ * `inTexId` (float, offset 16) - this value is always zero in the Single Pipeline
30+ * `inTintEffect` (float, offset 20)
31+ * `inTint` (vec4, offset 24, normalized)
3332 *
3433 * The default shader uniforms for this pipeline are:
3534 *
@@ -54,266 +53,12 @@ var SinglePipeline = new Class({
5453
5554 function SinglePipeline ( config )
5655 {
57- var gl = config . game . renderer . gl ;
58-
5956 config . fragShader = GetFastValue ( config , 'fragShader' , ShaderSourceFS ) ,
6057 config . vertShader = GetFastValue ( config , 'vertShader' , ShaderSourceVS ) ,
61- config . vertexSize = GetFastValue ( config , 'vertexSize' , 24 ) ,
62- config . attributes = GetFastValue ( config , 'attributes' , [
63- {
64- name : 'inPosition' ,
65- size : 2 ,
66- type : gl . FLOAT ,
67- normalized : false ,
68- offset : 0 ,
69- enabled : false ,
70- location : - 1
71- } ,
72- {
73- name : 'inTexCoord' ,
74- size : 2 ,
75- type : gl . FLOAT ,
76- normalized : false ,
77- offset : 8 ,
78- enabled : false ,
79- location : - 1
80- } ,
81- {
82- name : 'inTintEffect' ,
83- size : 1 ,
84- type : gl . FLOAT ,
85- normalized : false ,
86- offset : 16 ,
87- enabled : false ,
88- location : - 1
89- } ,
90- {
91- name : 'inTint' ,
92- size : 4 ,
93- type : gl . UNSIGNED_BYTE ,
94- normalized : true ,
95- offset : 20 ,
96- enabled : false ,
97- location : - 1
98- }
99- ] ) ;
10058
10159 MultiPipeline . call ( this , config ) ;
10260
10361 this . forceZero = true ;
104- } ,
105-
106- /**
107- * Adds the vertices data into the batch and flushes if full.
108- *
109- * Assumes 6 vertices in the following arrangement:
110- *
111- * ```
112- * 0----3
113- * |\ B|
114- * | \ |
115- * | \ |
116- * | A \|
117- * | \
118- * 1----2
119- * ```
120- *
121- * Where tx0/ty0 = 0, tx1/ty1 = 1, tx2/ty2 = 2 and tx3/ty3 = 3
122- *
123- * @method Phaser.Renderer.WebGL.Pipelines.SinglePipeline#batchQuad
124- * @since 3.50.0
125- *
126- * @param {number } x0 - The top-left x position.
127- * @param {number } y0 - The top-left y position.
128- * @param {number } x1 - The bottom-left x position.
129- * @param {number } y1 - The bottom-left y position.
130- * @param {number } x2 - The bottom-right x position.
131- * @param {number } y2 - The bottom-right y position.
132- * @param {number } x3 - The top-right x position.
133- * @param {number } y3 - The top-right y position.
134- * @param {number } u0 - UV u0 value.
135- * @param {number } v0 - UV v0 value.
136- * @param {number } u1 - UV u1 value.
137- * @param {number } v1 - UV v1 value.
138- * @param {number } tintTL - The top-left tint color value.
139- * @param {number } tintTR - The top-right tint color value.
140- * @param {number } tintBL - The bottom-left tint color value.
141- * @param {number } tintBR - The bottom-right tint color value.
142- * @param {(number|boolean) } tintEffect - The tint effect for the shader to use.
143- * @param {WebGLTexture } [texture] - WebGLTexture that will be assigned to the current batch if a flush occurs.
144- * @param {integer } [unit=0] - This parameter isn't used by this pipeline, but is retained for TTP support.
145- *
146- * @return {boolean } `true` if this method caused the batch to flush, otherwise `false`.
147- */
148- batchQuad : function ( x0 , y0 , x1 , y1 , x2 , y2 , x3 , y3 , u0 , v0 , u1 , v1 , tintTL , tintTR , tintBL , tintBR , tintEffect , texture , unit )
149- {
150- if ( unit === undefined ) { unit = this . currentUnit ; }
151-
152- var hasFlushed = false ;
153-
154- if ( this . shouldFlush ( 6 ) )
155- {
156- this . flush ( ) ;
157-
158- hasFlushed = true ;
159-
160- unit = this . setTexture2D ( texture ) ;
161- }
162-
163- var vertexViewF32 = this . vertexViewF32 ;
164- var vertexViewU32 = this . vertexViewU32 ;
165-
166- var vertexOffset = ( this . vertexCount * this . vertexComponentCount ) - 1 ;
167-
168- vertexViewF32 [ ++ vertexOffset ] = x0 ;
169- vertexViewF32 [ ++ vertexOffset ] = y0 ;
170- vertexViewF32 [ ++ vertexOffset ] = u0 ;
171- vertexViewF32 [ ++ vertexOffset ] = v0 ;
172- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
173- vertexViewU32 [ ++ vertexOffset ] = tintTL ;
174-
175- vertexViewF32 [ ++ vertexOffset ] = x1 ;
176- vertexViewF32 [ ++ vertexOffset ] = y1 ;
177- vertexViewF32 [ ++ vertexOffset ] = u0 ;
178- vertexViewF32 [ ++ vertexOffset ] = v1 ;
179- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
180- vertexViewU32 [ ++ vertexOffset ] = tintBL ;
181-
182- vertexViewF32 [ ++ vertexOffset ] = x2 ;
183- vertexViewF32 [ ++ vertexOffset ] = y2 ;
184- vertexViewF32 [ ++ vertexOffset ] = u1 ;
185- vertexViewF32 [ ++ vertexOffset ] = v1 ;
186- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
187- vertexViewU32 [ ++ vertexOffset ] = tintBR ;
188-
189- vertexViewF32 [ ++ vertexOffset ] = x0 ;
190- vertexViewF32 [ ++ vertexOffset ] = y0 ;
191- vertexViewF32 [ ++ vertexOffset ] = u0 ;
192- vertexViewF32 [ ++ vertexOffset ] = v0 ;
193- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
194- vertexViewU32 [ ++ vertexOffset ] = tintTL ;
195-
196- vertexViewF32 [ ++ vertexOffset ] = x2 ;
197- vertexViewF32 [ ++ vertexOffset ] = y2 ;
198- vertexViewF32 [ ++ vertexOffset ] = u1 ;
199- vertexViewF32 [ ++ vertexOffset ] = v1 ;
200- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
201- vertexViewU32 [ ++ vertexOffset ] = tintBR ;
202-
203- vertexViewF32 [ ++ vertexOffset ] = x3 ;
204- vertexViewF32 [ ++ vertexOffset ] = y3 ;
205- vertexViewF32 [ ++ vertexOffset ] = u1 ;
206- vertexViewF32 [ ++ vertexOffset ] = v0 ;
207- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
208- vertexViewU32 [ ++ vertexOffset ] = tintTR ;
209-
210- this . vertexCount += 6 ;
211-
212- return hasFlushed ;
213- } ,
214-
215- /**
216- * Adds the vertices data into the batch and flushes if full.
217- *
218- * Assumes 3 vertices in the following arrangement:
219- *
220- * ```
221- * 0
222- * |\
223- * | \
224- * | \
225- * | \
226- * | \
227- * 1-----2
228- * ```
229- *
230- * @method Phaser.Renderer.WebGL.Pipelines.SinglePipeline#batchTri
231- * @since 3.50.0
232- *
233- * @param {number } x1 - The bottom-left x position.
234- * @param {number } y1 - The bottom-left y position.
235- * @param {number } x2 - The bottom-right x position.
236- * @param {number } y2 - The bottom-right y position.
237- * @param {number } x3 - The top-right x position.
238- * @param {number } y3 - The top-right y position.
239- * @param {number } u0 - UV u0 value.
240- * @param {number } v0 - UV v0 value.
241- * @param {number } u1 - UV u1 value.
242- * @param {number } v1 - UV v1 value.
243- * @param {number } tintTL - The top-left tint color value.
244- * @param {number } tintTR - The top-right tint color value.
245- * @param {number } tintBL - The bottom-left tint color value.
246- * @param {(number|boolean) } tintEffect - The tint effect for the shader to use.
247- * @param {WebGLTexture } [texture] - WebGLTexture that will be assigned to the current batch if a flush occurs.
248- * @param {integer } [unit=0] - This parameter isn't used by this pipeline, but is retained for TTP support.
249- *
250- * @return {boolean } `true` if this method caused the batch to flush, otherwise `false`.
251- */
252- batchTri : function ( x1 , y1 , x2 , y2 , x3 , y3 , u0 , v0 , u1 , v1 , tintTL , tintTR , tintBL , tintEffect , texture , unit )
253- {
254- if ( unit === undefined ) { unit = this . currentUnit ; }
255-
256- var hasFlushed = false ;
257-
258- if ( this . shouldFlush ( 3 ) )
259- {
260- this . flush ( ) ;
261-
262- hasFlushed = true ;
263-
264- unit = this . setTexture2D ( texture ) ;
265- }
266-
267- var vertexViewF32 = this . vertexViewF32 ;
268- var vertexViewU32 = this . vertexViewU32 ;
269-
270- var vertexOffset = ( this . vertexCount * this . vertexComponentCount ) - 1 ;
271-
272- vertexViewF32 [ ++ vertexOffset ] = x1 ;
273- vertexViewF32 [ ++ vertexOffset ] = y1 ;
274- vertexViewF32 [ ++ vertexOffset ] = u0 ;
275- vertexViewF32 [ ++ vertexOffset ] = v0 ;
276- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
277- vertexViewU32 [ ++ vertexOffset ] = tintTL ;
278-
279- vertexViewF32 [ ++ vertexOffset ] = x2 ;
280- vertexViewF32 [ ++ vertexOffset ] = y2 ;
281- vertexViewF32 [ ++ vertexOffset ] = u0 ;
282- vertexViewF32 [ ++ vertexOffset ] = v1 ;
283- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
284- vertexViewU32 [ ++ vertexOffset ] = tintTR ;
285-
286- vertexViewF32 [ ++ vertexOffset ] = x3 ;
287- vertexViewF32 [ ++ vertexOffset ] = y3 ;
288- vertexViewF32 [ ++ vertexOffset ] = u1 ;
289- vertexViewF32 [ ++ vertexOffset ] = v1 ;
290- vertexViewF32 [ ++ vertexOffset ] = tintEffect ;
291- vertexViewU32 [ ++ vertexOffset ] = tintBL ;
292-
293- this . vertexCount += 3 ;
294-
295- return hasFlushed ;
296- } ,
297-
298- /**
299- * Called every time the pipeline is bound by the renderer.
300- * Sets the shader program, vertex buffer and other resources.
301- * Should only be called when changing pipeline.
302- *
303- * @method Phaser.Renderer.WebGL.Pipelines.SinglePipeline#bind
304- * @since 3.50.0
305- *
306- * @param {boolean } [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear?
307- *
308- * @return {this } This WebGLPipeline instance.
309- */
310- bind : function ( reset )
311- {
312- if ( reset === undefined ) { reset = false ; }
313-
314- WebGLPipeline . prototype . bind . call ( this , reset ) ;
315-
316- return this ;
31762 }
31863
31964} ) ;
0 commit comments