-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
WebGLShader.js
1095 lines (986 loc) · 37.1 KB
/
WebGLShader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../../utils/Class');
var GetFastValue = require('../../utils/object/GetFastValue');
var WEBGL_CONST = require('./const');
/**
* @classdesc
* Instances of the WebGLShader class belong to the WebGL Pipeline classes. When the pipeline is
* created it will create an instance of this class for each one of its shaders, as defined in
* the pipeline configuration.
*
* This class encapsulates everything needed to manage a shader in a pipeline, including the
* shader attributes and uniforms, as well as lots of handy methods such as `set2f`, for setting
* uniform values on this shader.
*
* Typically, you do not create an instance of this class directly, as it works in unison with
* the pipeline to which it belongs. You can gain access to this class via a pipeline's `shaders`
* array, post-creation.
*
* @class WebGLShader
* @memberof Phaser.Renderer.WebGL
* @constructor
* @since 3.50.0
*
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipeline - The WebGLPipeline to which this Shader belongs.
* @param {string} name - The name of this Shader.
* @param {string} vertexShader - The vertex shader source code as a single string.
* @param {string} fragmentShader - The fragment shader source code as a single string.
* @param {Phaser.Types.Renderer.WebGL.WebGLPipelineAttributesConfig[]} attributes - An array of attributes.
*/
var WebGLShader = new Class({
initialize:
function WebGLShader (pipeline, name, vertexShader, fragmentShader, attributes)
{
/**
* A reference to the WebGLPipeline that owns this Shader.
*
* A Shader class can only belong to a single pipeline.
*
* @name Phaser.Renderer.WebGL.WebGLShader#pipeline
* @type {Phaser.Renderer.WebGL.WebGLPipeline}
* @since 3.50.0
*/
this.pipeline = pipeline;
/**
* The name of this shader.
*
* @name Phaser.Renderer.WebGL.WebGLShader#name
* @type {string}
* @since 3.50.0
*/
this.name = name;
/**
* A reference to the WebGLRenderer instance.
*
* @name Phaser.Renderer.WebGL.WebGLShader#renderer
* @type {Phaser.Renderer.WebGL.WebGLRenderer}
* @since 3.50.0
*/
this.renderer = pipeline.renderer;
/**
* A reference to the WebGL Rendering Context the WebGL Renderer is using.
*
* @name Phaser.Renderer.WebGL.WebGLShader#gl
* @type {WebGLRenderingContext}
* @since 3.50.0
*/
this.gl = this.renderer.gl;
/**
* The WebGLProgram created from the vertex and fragment shaders.
*
* @name Phaser.Renderer.WebGL.WebGLShader#program
* @type {WebGLProgram}
* @since 3.50.0
*/
this.program = this.renderer.createProgram(vertexShader, fragmentShader);
/**
* Array of objects that describe the vertex attributes.
*
* @name Phaser.Renderer.WebGL.WebGLShader#attributes
* @type {Phaser.Types.Renderer.WebGL.WebGLPipelineAttribute[]}
* @since 3.50.0
*/
this.attributes;
/**
* The amount of vertex attribute components of 32 bit length.
*
* @name Phaser.Renderer.WebGL.WebGLShader#vertexComponentCount
* @type {number}
* @since 3.50.0
*/
this.vertexComponentCount = 0;
/**
* The size, in bytes, of a single vertex.
*
* This is derived by adding together all of the vertex attributes.
*
* For example, the Multi Pipeline has the following attributes:
*
* inPosition - (size 2 x gl.FLOAT) = 8
* inTexCoord - (size 2 x gl.FLOAT) = 8
* inTexId - (size 1 x gl.FLOAT) = 4
* inTintEffect - (size 1 x gl.FLOAT) = 4
* inTint - (size 4 x gl.UNSIGNED_BYTE) = 4
*
* The total, in this case, is 8 + 8 + 4 + 4 + 4 = 28.
*
* This is calculated automatically during the `createAttributes` method.
*
* @name Phaser.Renderer.WebGL.WebGLShader#vertexSize
* @type {number}
* @readonly
* @since 3.50.0
*/
this.vertexSize = 0;
/**
* The active uniforms that this shader has.
*
* This is an object that maps the uniform names to their WebGL location and cached values.
*
* It is populated automatically via the `createUniforms` method.
*
* @name Phaser.Renderer.WebGL.WebGLShader#uniforms
* @type {Phaser.Types.Renderer.WebGL.WebGLPipelineUniformsConfig}
* @since 3.50.0
*/
this.uniforms = {};
this.createAttributes(attributes);
this.createUniforms();
},
/**
* Takes the vertex attributes config and parses it, creating the resulting array that is stored
* in this shaders `attributes` property, calculating the offset, normalization and location
* in the process.
*
* Calling this method resets `WebGLShader.attributes`, `WebGLShader.vertexSize` and
* `WebGLShader.vertexComponentCount`.
*
* It is called automatically when this class is created, but can be called manually if required.
*
* @method Phaser.Renderer.WebGL.WebGLShader#createAttributes
* @since 3.50.0
*
* @param {Phaser.Types.Renderer.WebGL.WebGLPipelineAttributesConfig[]} attributes - An array of attributes configs.
*/
createAttributes: function (attributes)
{
var count = 0;
var offset = 0;
var result = [];
this.vertexComponentCount = 0;
for (var i = 0; i < attributes.length; i++)
{
var element = attributes[i];
var name = element.name;
var size = GetFastValue(element, 'size', 1); // i.e. 1 for a float, 2 for a vec2, 4 for a vec4, etc
var glType = GetFastValue(element, 'type', WEBGL_CONST.FLOAT);
var type = glType.enum; // The GLenum
var typeSize = glType.size; // The size in bytes of the type
var normalized = (element.normalized) ? true : false;
result.push({
name: name,
size: size,
type: type,
normalized: normalized,
offset: offset,
enabled: false,
location: -1
});
if (typeSize === 4)
{
count += size;
}
else
{
count++;
}
offset += size * typeSize;
}
this.vertexSize = offset;
this.vertexComponentCount = count;
this.attributes = result;
},
/**
* Sets the program this shader uses as being the active shader in the WebGL Renderer.
*
* This method is called every time the parent pipeline is made the current active pipeline.
*
* @method Phaser.Renderer.WebGL.WebGLShader#bind
* @since 3.50.0
*
* @param {boolean} [setAttributes=false] - Should the vertex attribute pointers be set?
* @param {boolean} [flush=false] - Flush the pipeline before binding this shader?
*
* @return {this} This WebGLShader instance.
*/
bind: function (setAttributes, flush)
{
if (setAttributes === undefined) { setAttributes = false; }
if (flush === undefined) { flush = false; }
if (flush)
{
this.pipeline.flush();
}
this.renderer.setProgram(this.program);
if (setAttributes)
{
this.setAttribPointers();
}
return this;
},
/**
* Sets the program this shader uses as being the active shader in the WebGL Renderer.
*
* Then resets all of the attribute pointers.
*
* @method Phaser.Renderer.WebGL.WebGLShader#rebind
* @since 3.50.0
*
* @return {this} This WebGLShader instance.
*/
rebind: function ()
{
this.renderer.setProgram(this.program);
this.setAttribPointers(true);
return this;
},
/**
* Sets the vertex attribute pointers.
*
* This should only be called after the vertex buffer has been bound.
*
* It is called automatically during the `bind` method.
*
* @method Phaser.Renderer.WebGL.WebGLShader#setAttribPointers
* @since 3.50.0
*
* @param {boolean} [reset=false] - Reset the vertex attribute locations?
*
* @return {this} This WebGLShader instance.
*/
setAttribPointers: function (reset)
{
if (reset === undefined) { reset = false; }
var gl = this.gl;
var vertexSize = this.vertexSize;
var attributes = this.attributes;
var program = this.program;
for (var i = 0; i < attributes.length; i++)
{
var element = attributes[i];
var size = element.size;
var type = element.type;
var offset = element.offset;
var enabled = element.enabled;
var location = element.location;
var normalized = (element.normalized) ? true : false;
if (reset)
{
var attribLocation = gl.getAttribLocation(program, element.name);
if (attribLocation >= 0)
{
gl.enableVertexAttribArray(attribLocation);
gl.vertexAttribPointer(attribLocation, size, type, normalized, vertexSize, offset);
element.enabled = true;
element.location = attribLocation;
}
else if (attribLocation !== -1)
{
gl.disableVertexAttribArray(attribLocation);
}
}
else if (enabled)
{
gl.vertexAttribPointer(location, size, type, normalized, vertexSize, offset);
}
else if (!enabled && location > -1)
{
gl.disableVertexAttribArray(location);
element.location = -1;
}
}
return this;
},
/**
* Sets up the `WebGLShader.uniforms` object, populating it with the names
* and locations of the shader uniforms this shader requires.
*
* It works by first calling `gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS)` to
* find out how many active uniforms this shader has. It then iterates through them,
* calling `gl.getActiveUniform` to get the WebGL Active Info from each one. Finally,
* the name and location are stored in the local array.
*
* This method is called automatically when this class is created.
*
* @method Phaser.Renderer.WebGL.WebGLShader#createUniforms
* @since 3.50.0
*
* @return {this} This WebGLShader instance.
*/
createUniforms: function ()
{
var gl = this.gl;
var program = this.program;
var uniforms = this.uniforms;
var i;
var name;
var location;
// Look-up all active uniforms
var totalUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
for (i = 0; i < totalUniforms; i++)
{
var info = gl.getActiveUniform(program, i);
if (info)
{
name = info.name;
location = gl.getUniformLocation(program, name);
if (location !== null)
{
uniforms[name] =
{
name: name,
location: location,
value1: null,
value2: null,
value3: null,
value4: null
};
}
// If the uniform name contains [] for an array struct,
// we'll add an entry for the non-struct name as well.
// Such as uMainSampler[12] = uMainSampler
var struct = name.indexOf('[');
if (struct > 0)
{
name = name.substr(0, struct);
if (!uniforms.hasOwnProperty(name))
{
location = gl.getUniformLocation(program, name);
if (location !== null)
{
uniforms[name] =
{
name: name,
location: location,
value1: null,
value2: null,
value3: null,
value4: null
};
}
}
}
}
}
return this;
},
/**
* Checks to see if the given uniform name exists and is active in this shader.
*
* @method Phaser.Renderer.WebGL.WebGLShader#hasUniform
* @since 3.50.0
*
* @param {string} name - The name of the uniform to check for.
*
* @return {boolean} `true` if the uniform exists, otherwise `false`.
*/
hasUniform: function (name)
{
return this.uniforms.hasOwnProperty(name);
},
/**
* Resets the cached values of the given uniform.
*
* @method Phaser.Renderer.WebGL.WebGLShader#resetUniform
* @since 3.50.0
*
* @param {string} name - The name of the uniform to reset.
*
* @return {this} This WebGLShader instance.
*/
resetUniform: function (name)
{
var uniform = this.uniforms[name];
if (uniform)
{
uniform.value1 = null;
uniform.value2 = null;
uniform.value3 = null;
uniform.value4 = null;
}
return this;
},
/**
* Sets the given uniform value/s based on the name and GL function.
*
* This method is called internally by other methods such as `set1f` and `set3iv`.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#setUniform1
* @since 3.50.0
*
* @param {function} setter - The GL function to call.
* @param {string} name - The name of the uniform to set.
* @param {(boolean|number|number[]|Float32Array)} value1 - The new value of the uniform.
*
* @return {this} This WebGLShader instance.
*/
setUniform1: function (setter, name, value1)
{
var uniform = this.uniforms[name];
if (!uniform)
{
return this;
}
if (uniform.value1 !== value1)
{
uniform.value1 = value1;
this.renderer.setProgram(this.program);
setter.call(this.gl, uniform.location, value1);
this.pipeline.currentShader = this;
}
return this;
},
/**
* Sets the given uniform value/s based on the name and GL function.
*
* This method is called internally by other methods such as `set1f` and `set3iv`.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#setUniform2
* @since 3.50.0
*
* @param {function} setter - The GL function to call.
* @param {string} name - The name of the uniform to set.
* @param {(boolean|number|number[]|Float32Array)} value1 - The new value of the uniform.
* @param {(boolean|number|number[]|Float32Array)} value2 - The new value of the uniform.
*
* @return {this} This WebGLShader instance.
*/
setUniform2: function (setter, name, value1, value2)
{
var uniform = this.uniforms[name];
if (!uniform)
{
return this;
}
if (uniform.value1 !== value1 || uniform.value2 !== value2)
{
uniform.value1 = value1;
uniform.value2 = value2;
this.renderer.setProgram(this.program);
setter.call(this.gl, uniform.location, value1, value2);
this.pipeline.currentShader = this;
}
return this;
},
/**
* Sets the given uniform value/s based on the name and GL function.
*
* This method is called internally by other methods such as `set1f` and `set3iv`.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#setUniform3
* @since 3.50.0
*
* @param {function} setter - The GL function to call.
* @param {string} name - The name of the uniform to set.
* @param {(boolean|number|number[]|Float32Array)} value1 - The new value of the uniform.
* @param {(boolean|number|number[]|Float32Array)} value2 - The new value of the uniform.
* @param {(boolean|number|number[]|Float32Array)} value3 - The new value of the uniform.
*
* @return {this} This WebGLShader instance.
*/
setUniform3: function (setter, name, value1, value2, value3)
{
var uniform = this.uniforms[name];
if (!uniform)
{
return this;
}
if (uniform.value1 !== value1 || uniform.value2 !== value2 || uniform.value3 !== value3)
{
uniform.value1 = value1;
uniform.value2 = value2;
uniform.value3 = value3;
this.renderer.setProgram(this.program);
setter.call(this.gl, uniform.location, value1, value2, value3);
this.pipeline.currentShader = this;
}
return this;
},
/**
* Sets the given uniform value/s based on the name and GL function.
*
* This method is called internally by other methods such as `set1f` and `set3iv`.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#setUniform4
* @since 3.50.0
*
* @param {function} setter - The GL function to call.
* @param {string} name - The name of the uniform to set.
* @param {(boolean|number|number[]|Float32Array)} value1 - The new value of the uniform.
* @param {(boolean|number|number[]|Float32Array)} value2 - The new value of the uniform.
* @param {(boolean|number|number[]|Float32Array)} value3 - The new value of the uniform.
* @param {(boolean|number|number[]|Float32Array)} value4 - The new value of the uniform.
*
* @return {this} This WebGLShader instance.
*/
setUniform4: function (setter, name, value1, value2, value3, value4)
{
var uniform = this.uniforms[name];
if (!uniform)
{
return this;
}
if (uniform.value1 !== value1 || uniform.value2 !== value2 || uniform.value3 !== value3 || uniform.value4 !== value4)
{
uniform.value1 = value1;
uniform.value2 = value2;
uniform.value3 = value3;
uniform.value4 = value4;
this.renderer.setProgram(this.program);
setter.call(this.gl, uniform.location, value1, value2, value3, value4);
this.pipeline.currentShader = this;
}
return this;
},
/**
* Sets a 1f uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set1f
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number} x - The new value of the `float` uniform.
*
* @return {this} This WebGLShader instance.
*/
set1f: function (name, x)
{
return this.setUniform1(this.gl.uniform1f, name, x);
},
/**
* Sets a 2f uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set2f
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number} x - The new X component of the `vec2` uniform.
* @param {number} y - The new Y component of the `vec2` uniform.
*
* @return {this} This WebGLShader instance.
*/
set2f: function (name, x, y)
{
return this.setUniform2(this.gl.uniform2f, name, x, y);
},
/**
* Sets a 3f uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set3f
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number} x - The new X component of the `vec3` uniform.
* @param {number} y - The new Y component of the `vec3` uniform.
* @param {number} z - The new Z component of the `vec3` uniform.
*
* @return {this} This WebGLShader instance.
*/
set3f: function (name, x, y, z)
{
return this.setUniform3(this.gl.uniform3f, name, x, y, z);
},
/**
* Sets a 4f uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set4f
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number} x - X component of the uniform
* @param {number} y - Y component of the uniform
* @param {number} z - Z component of the uniform
* @param {number} w - W component of the uniform
*
* @return {this} This WebGLShader instance.
*/
set4f: function (name, x, y, z, w)
{
return this.setUniform4(this.gl.uniform4f, name, x, y, z, w);
},
/**
* Sets a 1fv uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set1fv
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number[]|Float32Array} arr - The new value to be used for the uniform variable.
*
* @return {this} This WebGLShader instance.
*/
set1fv: function (name, arr)
{
return this.setUniform1(this.gl.uniform1fv, name, arr);
},
/**
* Sets a 2fv uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set2fv
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number[]|Float32Array} arr - The new value to be used for the uniform variable.
*
* @return {this} This WebGLShader instance.
*/
set2fv: function (name, arr)
{
return this.setUniform1(this.gl.uniform2fv, name, arr);
},
/**
* Sets a 3fv uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set3fv
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number[]|Float32Array} arr - The new value to be used for the uniform variable.
*
* @return {this} This WebGLShader instance.
*/
set3fv: function (name, arr)
{
return this.setUniform1(this.gl.uniform3fv, name, arr);
},
/**
* Sets a 4fv uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set4fv
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number[]|Float32Array} arr - The new value to be used for the uniform variable.
*
* @return {this} This WebGLShader instance.
*/
set4fv: function (name, arr)
{
return this.setUniform1(this.gl.uniform4fv, name, arr);
},
/**
* Sets a 1iv uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set1iv
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number[]|Float32Array} arr - The new value to be used for the uniform variable.
*
* @return {this} This WebGLShader instance.
*/
set1iv: function (name, arr)
{
return this.setUniform1(this.gl.uniform1iv, name, arr);
},
/**
* Sets a 2iv uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set2iv
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number[]|Float32Array} arr - The new value to be used for the uniform variable.
*
* @return {this} This WebGLShader instance.
*/
set2iv: function (name, arr)
{
return this.setUniform1(this.gl.uniform2iv, name, arr);
},
/**
* Sets a 3iv uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set3iv
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number[]|Float32Array} arr - The new value to be used for the uniform variable.
*
* @return {this} This WebGLShader instance.
*/
set3iv: function (name, arr)
{
return this.setUniform1(this.gl.uniform3iv, name, arr);
},
/**
* Sets a 4iv uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set4iv
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number[]|Float32Array} arr - The new value to be used for the uniform variable.
*
* @return {this} This WebGLShader instance.
*/
set4iv: function (name, arr)
{
return this.setUniform1(this.gl.uniform4iv, name, arr);
},
/**
* Sets a 1i uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set1i
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number} x - The new value of the `int` uniform.
*
* @return {this} This WebGLShader instance.
*/
set1i: function (name, x)
{
return this.setUniform1(this.gl.uniform1i, name, x);
},
/**
* Sets a 2i uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set2i
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number} x - The new X component of the `ivec2` uniform.
* @param {number} y - The new Y component of the `ivec2` uniform.
*
* @return {this} This WebGLShader instance.
*/
set2i: function (name, x, y)
{
return this.setUniform2(this.gl.uniform2i, name, x, y);
},
/**
* Sets a 3i uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set3i
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number} x - The new X component of the `ivec3` uniform.
* @param {number} y - The new Y component of the `ivec3` uniform.
* @param {number} z - The new Z component of the `ivec3` uniform.
*
* @return {this} This WebGLShader instance.
*/
set3i: function (name, x, y, z)
{
return this.setUniform3(this.gl.uniform3i, name, x, y, z);
},
/**
* Sets a 4i uniform value based on the given name on this shader.
*
* The uniform is only set if the value/s given are different to those previously set.
*
* This method works by first setting this shader as being the current shader within the
* WebGL Renderer, if it isn't already. It also sets this shader as being the current
* one within the pipeline it belongs to.
*
* @method Phaser.Renderer.WebGL.WebGLShader#set4i
* @since 3.50.0
*
* @param {string} name - The name of the uniform to set.
* @param {number} x - X component of the uniform
* @param {number} y - Y component of the uniform
* @param {number} z - Z component of the uniform
* @param {number} w - W component of the uniform
*
* @return {this} This WebGLShader instance.
*/
set4i: function (name, x, y, z, w)
{