forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebglrenderingcontext.jsdoc
More file actions
7995 lines (5825 loc) · 183 KB
/
Copy pathwebglrenderingcontext.jsdoc
File metadata and controls
7995 lines (5825 loc) · 183 KB
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
WebGLRenderingContext : Object
<p>
The **WebGLRenderingContext** is an object that is used to issue WebGL
rendering commands to a canvas. The WebGLRenderingContext is obtained by passing
**'webgl'** to
the %%HTMLCanvasElement#getContext|**HTMLCanvasElement.getContext()**%%
method.
See %%WebGLContextAttributes|**WebGLContextAttributes**%% for configuration
options you can specify when calling **getContext()**.
</p>
<p>
For detailed information on the shader language used by WebGL, see the
%%http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf|GLSL Specification%%.
</p>
<p>
While developing with WebGL, you can use the debug context to easily
find errors in your code. The samples below use the debug context
to help catch errors but you should remove it in production code. See
%%http://www.khronos.org/webgl/wiki/Debugging|http://www.khronos.org/webgl/wiki/Debugging%%
for more details.
</p>
Spec:
http://www.khronos.org/registry/webgl/specs/latest/#5.14
IDL:
http://www.khronos.org/registry/webgl/specs/latest/webgl.idl
----
instance.canvas : HTMLCanvasElement
The canvas that owns this WebGL context.
<htmlexample>
<canvas id='canvas'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
console.log(gl.canvas === canvas);
</script>
</htmlexample>
ReadOnly:
true
Spec:
http://www.khronos.org/registry/webgl/specs/latest/#5.14.1
----
prototype.getContextAttributes() : WebGLContextAttributes
Returns the attributes used to construct this context. To modify these
attributes, pass in the desired attributes to the first call to
%%HTMLCanvasElement#getContext|**HTMLCanvasElement.getContext('webgl', attributes)**%%.
<htmlexample>
<canvas id='canvas'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
var attr = gl.getContextAttributes();
for (var p in attr) {
console.log(p + ': ' + attr[p]);
}
</script>
</htmlexample>
----
instance.drawingBufferWidth : Number
Returns the width of the owner canvas in pixels.
<htmlexample>
<canvas id='canvas' width='150' height='75'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
console.log(gl.drawingBufferWidth);
</script>
</htmlexample>
ReadOnly:
true
----
instance.drawingBufferHeight : Number
Returns the height of the owner canvas in pixels.
<htmlexample>
<canvas id='canvas' width='150' height='75'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
console.log(gl.drawingBufferHeight);
</script>
</htmlexample>
ReadOnly:
true
----
prototype.isContextLost() : Boolean
IDL:
boolean isContextLost();
----
prototype.getSupportedExtensions() : Array<String>
Returns an **Array** of %%String|**String**s%% that indicate
which extensions this canvas supports. See %%#getExtension|**getExtension()**%%.
<htmlexample>
<canvas id='canvas'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
gl.getSupportedExtensions().forEach(function(ext) {
console.log(ext);
});
</script>
</htmlexample>
----
prototype.getExtension(name : String) : Object
Enables the specified extension and returns an object that contains
any constants or functions provided by the extension. Call
%%#getSupportedExtensions|**getSupportedExtensions()**%%
to get an array of valid extension names. If **name** is not
in the %%/Array|**Array**%% returned by %%#getSupportedExtensions|**getSupportedExtensions()**%%,
**getExtension()** will return null.
<htmlexample>
<canvas id='canvas'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
gl.getSupportedExtensions().forEach(function(extName) {
console.log(extName);
var ext = gl.getExtension(extName);
for (var n in ext) {
console.log(' ' + n + ' = ' + ext[n]);
}
});
</script>
</htmlexample>
IDL:
object getExtension(DOMString name);
----
prototype.activeTexture(unit : Number) : undefined
Set the texture unit subsequent texture operations apply to.
<html>
<dl>
<dt>
**unit**
<dd>
must be
one of %%#TEXTURE0|**TEXTURE0**%%, %%#TEXTURE1|**TEXTURE1**%%, to
**%%#getParameter|getParameter%%(gl.%%#MAX_COMBINED_TEXTURE_IMAGE_UNITS|MAX_COMBINED_TEXTURE_IMAGE_UNITS%%) - 1**.
</dl>
</html>
The default value is **TEXTURE0**.
A texture must be bound to the active texture unit using
%%#bindTexture|**bindTexture()**%%.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glActiveTexture.xml
----
prototype.attachShader(program : WebGLProgram, shader : WebGLShader) : undefined
Attaches **shader** to **program**. A program must have both a
%%#VERTEX_SHADER|**VERTEX_SHADER**%%
and
%%#FRAGMENT_SHADER|**FRAGMENT_SHADER**%% before it can be used.
**shader** can be attached before its souce has been set.
See also %%#detachShader|**detachShader()**%%.
<htmlexample>
<canvas id='canvas' width='100' height='100'></canvas>
<script id="vertexShader" type="x-shader/x-vertex">
attribute vec2 vertexPosition;
void main() {
gl_Position = vec4(vertexPosition, 0.0, 1.0);
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
void main() {
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // green
}
</script>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
// Create Vertex Shader
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, document.getElementById('vertexShader').textContent);
gl.compileShader(vertexShader);
// Create Fragment Shader
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, document.getElementById('fragmentShader').textContent);
gl.compileShader(fragmentShader);
// Create Shader Program
var program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
gl.useProgram(program);
// Create a buffer with 3 points to form a triangle
var triangleBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
var vertices = [
-0.5, -0.5,
0.5, -0.5,
0.0, 0.5];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
// Bind the triangles to the vertex shader's 'vertexPosition' attribute and draw it
var vertexPositionLocation = gl.getAttribLocation(program, 'vertexPosition');
gl.vertexAttribPointer(vertexPositionLocation, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vertexPositionLocation);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 3);
</script>
</htmlexample>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glAttachShader.xml
IDL:
void attachShader(WebGLProgram program, WebGLShader shader);
----
prototype.bindAttribLocation(program : WebGLProgram, location : Number, attributeName : String) : undefined
Associates a number (**location**) with an attribute (a shader input such as
vertex position) in **program**.
Other webgl functions (such as %%#enableVertexAttribArray|**enableVertexAttribArray()**%%
or %%#vertexAttribPointer|**vertexAttribPointer()**%%) deal with an
attribute location number instead of the name used in the program and **bindAttribLocation**
is used to choose the number used for that attribute.
Locations are automatically assigned if you do not call **bindAttribLocation**
so this method is only necessary if you wish to assign a specific
location for an attribute. Use %%#getAttribLocation|**getAttribLocation()**%% to
retrieve the automatically assigned location.
**bindAttribLocation()** must be called before calling %%#linkProgram|**linkProgram(program)**%%
and
**location** must be an integer in the range **0** to
**%%#getParameter|getParameter%%(%%#MAX_VERTEX_ATTRIBS|gl.MAX_VERTEX_ATTRIBS%%) - 1**.
<htmlexample>
<!-- Demonstrates binding the 'vertexPosition' attribute to a
fixed location (in this case 7) -->
<canvas id='canvas' width='100' height='100'></canvas>
<script id="vertexShader" type="x-shader/x-vertex">
attribute vec2 vertexPosition;
void main() {
gl_Position = vec4(vertexPosition, 0.0, 1.0);
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
void main() {
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // green
}
</script>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
// Create Vertex Shader
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, document.getElementById('vertexShader').textContent);
gl.compileShader(vertexShader);
// Create Fragment Shader
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, document.getElementById('fragmentShader').textContent);
gl.compileShader(fragmentShader);
// Create Shader Program
var program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
// Bind the 'vertexPosition' attribute before linking
var vertexPositionLocation = 7;
gl.bindAttribLocation(program, vertexPositionLocation, 'vertexPosition');
gl.linkProgram(program);
gl.useProgram(program);
console.log('expected location: ' + vertexPositionLocation);
vertexPositionLocation = gl.getAttribLocation(program, 'vertexPosition');
console.log('actual location: ' + vertexPositionLocation);
// Create a buffer with 3 points to form a triangle
var triangleBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
var vertices = [
-0.5, -0.5,
0.5, -0.5,
0.0, 0.5];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
// Bind the triangles to the vertex shader's 'vertexPosition' attribute and draw it
gl.vertexAttribPointer(vertexPositionLocation, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vertexPositionLocation);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 3);
</script>
</htmlexample>
IDL:
void bindAttribLocation(WebGLProgram program, GLuint index, DOMString name);
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindAttribLocation.xml
----
prototype.bindBuffer(target : Number, buffer : WebGLBuffer) : undefined
Sets the current buffer for **target** to **buffer**. **target**
must be either
%%#ARRAY_BUFFER|**ARRAY_BUFFER**%% or
%%#ELEMENT_ARRAY_BUFFER|**ELEMENT_ARRAY_BUFFER**%%.
Use %%#bufferData|**bufferData()**%% to fill the bound buffer with data.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindBuffer.xml
IDL:
void bindBuffer(GLenum target, WebGLBuffer buffer);
----
prototype.bindFramebuffer(target : Number, framebuffer : WebGLFramebuffer) : undefined
Sets the current framebuffer to **framebuffer**. **target** must be
%%#FRAMEBUFFER|**FRAMEBUFFER**%%.
See %%#createFramebuffer|**createFramebuffer()**%%
for an example of using **bindFramebuffer()**.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindFramebuffer.xml
IDL:
void bindFramebuffer(GLenum target, WebGLFramebuffer framebuffer);
----
prototype.bindRenderbuffer(target : Number, renderbuffer : WebGLRenderbuffer) : undefined
Sets the current renderbuffer to **renderbuffer**. **target** must be
%%#RENDERBUFFER|**RENDERBUFFER**%%.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindRenderbuffer.xml
IDL:
void bindRenderbuffer(GLenum target, WebGLRenderbuffer renderbuffer);
----
prototype.bindTexture(target : Number, texture : WebGLTexture) : undefined
Sets the specified **target** and **texture** (created with
%%#createTexture|**createTexture**%%) for
the bound texture in the active texture unit
(set through %%#activeTexture|**activeTexture()**%%
and %%#bindTexture|**bindTexture()**%%).
**target** must be one of
%%#TEXTURE_2D|**TEXTURE_2D**%% or
%%#TEXTURE_CUBE_MAP|**TEXTURE_CUBE_MAP**%%
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindTexture.xml
IDL:
void bindTexture(GLenum target, WebGLTexture texture);
----
prototype.blendColor(red : Number, green : Number, blue : Number, alpha : Number) : undefined
Specifies the blend color used with %%#blendFunc|**blendFunc()**%%.
Each component must be in the range **0.0** to **1.0**.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendColor.xml
IDL:
void blendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
----
prototype.blendEquation(mode : Number) : undefined
Same as %%#blendEquationSeparate|**blendEquationSeparate(mode, mode)**%%.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendEquation.xml
IDL:
void blendEquation(GLenum mode);
----
prototype.blendEquationSeparate(modeRGB : Number, modeAlpha : Number) : undefined
Sets how the newly rendered pixel color and alpha (src) is combined with the
existing framebuffer color and alpha (dst) before storing in the framebuffer.
<html>
<dl>
<dt>
**modeRGB** and **modeAlpha**
<dd>
must be one of
%%#FUNC_ADD|**FUNC_ADD**%%,
%%#FUNC_SUBTRACT|**FUNC_SUBTRACT**%%, or
%%#FUNC_REVERSE_SUBTRACT|**FUNC_REVERSE_SUBTRACT**%%.
</dl>
</html>
If the mode is **FUNC_ADD**, the destination color will be src + dst.
If the mode is **FUNC_SUBTRACT**, the destination color will be src - dst.
If the mode is **FUNC_REVERSE_SUBTRACT**, the destination color will be dst - src.
Both **modeRGB** and **modeAlpha** default to **FUNC_ADD**.
Use
**%%#getParameter|getParameter%%(gl.%%#BLEND_EQUATION_RGB|BLEND_EQUATION_RGB%%)**
and
**%%#getParameter|getParameter%%(gl.%%#BLEND_EQUATION_ALPHA|BLEND_EQUATION_ALPHA%%)**
to get the current values.
See %%#blendFuncSeparate|**blendFuncSeparate()**%% for how src and dst are computed.
Blending must be enabled with
**%%#enable|enable%%(%%#BLEND|BLEND%%)**.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendEquationSeparate.xml
IDL:
void blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
----
prototype.blendFunc(srcFactor : Number, dstFactor : Number) : undefined
Same as %%#blendFuncSeparate|**blendFuncSeparate(srcFactor, dstFactor, srcFactor, dstFactor)**%%.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFunc.xml
IDL:
void blendFunc(GLenum sfactor, GLenum dfactor);
----
prototype.blendFuncSeparate(srcRGB : Number, dstRGB : Number, srcAlpha : Number, dstAlpha : Number) : undefined
Adjusts the newly rendered pixel color and alpha (src) and existing framebuffer
color and alpha in the framebuffer (dst) before being combined
using %%#blendEquationSeparate|**blendEquationSeparate()**%%.
<html>
<dl>
<dt>
**srcRGB**, **dstRGB**, **srcAlpha**, and **dstAlpha**
<dd>
must be one of
%%#ZERO|**ZERO**%%, %%#ONE|**ONE**%%, %%#SRC_COLOR|**SRC_COLOR**%%,
%%#ONE_MINUS_SRC_COLOR|**ONE_MINUS_SRC_COLOR**%%, %%#DST_COLOR|**DST_COLOR**%%,
%%#ONE_MINUS_DST_COLOR|**ONE_MINUS_DST_COLOR**%%, %%#SRC_ALPHA|**SRC_ALPHA**%%,
%%#ONE_MINUS_SRC_ALPHA|**ONE_MINUS_SRC_ALPHA**%%, %%#DST_ALPHA|**DST_ALPHA**%%,
%%#ONE_MINUS_DST_ALPHA|**ONE_MINUS_DST_ALPHA**%%, %%#CONSTANT_COLOR|**CONSTANT_COLOR**%%,
%%#ONE_MINUS_CONSTANT_COLOR|**ONE_MINUS_CONSTANT_COLOR**%%,
%%#CONSTANT_ALPHA|**CONSTANT_ALPHA**%%,
%%#ONE_MINUS_CONSTANT_ALPHA|**ONE_MINUS_CONSTANT_ALPHA**%%, or
%%#SRC_ALPHA_SATURATE|**SRC_ALPHA_SATURATE**%%
</dl>
</html>
**srcRGB** and **srcAlpha** default to %%#ONE|**ONE**%%.
**dstRGB** and **dstAlpha** default to %%#NONE|**NONE**%%.
<p>
For traditional alpha blending, use: <br>
**gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ZERO)**.
</p>
<p>
For premultiplied alpha blending, use: <br>
**gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ZERO)**.
</p>
<p>
Use
**%%#getParameter|getParameter%%(gl.%%#BLEND_SRC_RGB|BLEND_SRC_RGB%%)**,
**%%#getParameter|getParameter%%(gl.%%#BLEND_DST_RGB|BLEND_DST_RGB%%)**,
**%%#getParameter|getParameter%%(gl.%%#BLEND_SRC_ALPHA|BLEND_SRC_ALPHA%%)**,
and
**%%#getParameter|getParameter%%(gl.%%#BLEND_DST_ALPHA|BLEND_DST_ALPHA%%)**
to get the current values.
</p>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFuncSeparate.xml
IDL:
void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
----
prototype.bufferData(target : Number, size : Number, usage : Number) : undefined
Creates the storage for the currently bound buffer.
<html>
<dl>
<dt>
**target**
<dd>
must be one of %%#ARRAY_BUFFER|**ARRAY_BUFFER**%% or %%#ELEMENT_ARRAY_BUFFER|**ELEMENT_ARRAY_BUFFER**%%.
<dt>
**size**
<dd>
the size in bytes of the buffer to allocate.
<dt>
**usage**
<dd>
must be one of
%%#STREAM_DRAW|**STREAM_DRAW**%%,
%%#STATIC_DRAW|**STATIC_DRAW**%%,
or
%%#DYNAMIC_DRAW|**DYNAMIC_DRAW**%%.
</dl>
</html>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferData.xml
IDL:
void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
----
prototype.bufferData(target : Number, data : ArrayBufferView, usage : Number) : undefined
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferData.xml
IDL:
void bufferData(GLenum target, ArrayBufferView data, GLenum usage);
----
prototype.bufferData(target : Number, data : ArrayBuffer, usage : Number) : undefined
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferData.xml
IDL:
void bufferData(GLenum target, ArrayBuffer data, GLenum usage);
----
prototype.bufferSubData(target : Number, offset : Number, data : ArrayBufferView) : undefined
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferSubData.xml
IDL:
void bufferSubData(GLenum target, GLintptr offset, ArrayBufferView data);
----
prototype.bufferSubData(target : Number, offset : Number, data : ArrayBuffer) : undefined
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferSubData.xml
IDL:
void bufferSubData(GLenum target, GLintptr offset, ArrayBuffer data);
----
prototype.checkFramebufferStatus(target : Number) : Number
Returns one of the following to indicate the current status of the framebuffer:
%%#FRAMEBUFFER_COMPLETE|**FRAMEBUFFER_COMPLETE**%%,
%%#FRAMEBUFFER_INCOMPLETE_ATTACHMENT|**FRAMEBUFFER_INCOMPLETE_ATTACHMENT**%%,
%%#FRAMEBUFFER_INCOMPLETE_DIMENSIONS|**FRAMEBUFFER_INCOMPLETE_DIMENSIONS**%%,
%%#FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT|**FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT**%%,
or
%%#FRAMEBUFFER_UNSUPPORTED|**FRAMEBUFFER_UNSUPPORTED**%%.
**target** must be set to %%#FRAMEBUFFER|**gl.FRAMEBUFFER**%%.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCheckFramebufferStatus.xml
IDL:
GLenum checkFramebufferStatus(GLenum target);
----
prototype.clear(mask : Number) : undefined
Clears the buffers specified by **mask** where **mask** is the bitwise
OR (**|**) of one or more of the following values:
%%#COLOR_BUFFER_BIT|**COLOR_BUFFER_BIT**%%,
%%#STENCIL_BUFFER_BIT|**STENCIL_BUFFER_BIT**%%, and
%%#DEPTH_BUFFER_BIT|**DEPTH_BUFFER_BIT**%%.
<htmlexample>
<canvas id='canvas'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
gl.clearColor(0, 1, 0, 1);
gl.clearDepth(1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
</script>
</htmlexample>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glClear.xml
----
prototype.clearColor(red : Number, green : Number, blue : Number, alpha : Number) : undefined
Specifies the color to fill the color buffer when %%#clear|**clear()**%% is
called with the %%#COLOR_BUFFER_BIT|**COLOR_BUFFER_BIT**%%. The parameters
are clamped to the range **0** to **1**.
<htmlexample>
<canvas id='canvas'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
gl.clearColor(0, 1, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
</script>
</htmlexample>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glClearColor.xml
----
prototype.clearDepth(depth : Number) : undefined
Specifies the value to fill the depth buffer when %%#clear|**clear()**%% is called
with the %%#DEPTH_BUFFER_BIT|**DEPTH_BUFFER_BIT**%%. **depth** is clamped to
the range **0** (near) to **1** (far). Defaults to **1** if not specified.
<htmlexample>
<canvas id='canvas'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
gl.clearDepth(1);
gl.clear(gl.COLOR_BUFFER_BIT);
</script>
</htmlexample>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glClearDepthf.xml
----
prototype.clearStencil(s : Number) : undefined
Specifies the value (integer) to fill the depth buffer when %%#clear|**clear()**%% is called
with the %%#STENCIL_BUFFER_BIT|**STENCIL_BUFFER_BIT**%%.
<htmlexample>
<canvas id='canvas'></canvas>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
gl.clearStencil(0);
gl.clear(gl.STENCIL_BUFFER_BIT);
</script>
</htmlexample>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glClearStencil.xml
----
prototype.colorMask(red : Boolean, green : Boolean, blue : Boolean, alpha : Boolean) : undefined
Turns on or off writing to the specified channels of the frame buffer.
Defaults to **true** for all channels.
Use **%%#getParameter|getParameter%%(gl.%%#COLOR_WRITEMASK|COLOR_WRITEMASK%%)**
to get the current value.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glColorMask.xml
IDL:
void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
----
prototype.compileShader(shader : WebGLShader) : undefined
Compiles the specified shader. Must be called after setting the source with
%%#shaderSource|**shaderSource()**%%.
If the shader had errors during compilation,
**%%#getShaderParameter|gl.getShaderParameter%%(shader, %%#COMPILE_STATUS|gl.COMPILE_STATUS%%)**
will return **false** and you can use
%%#getShaderInfoLog|**getShaderInfoLog()**%%
to get details about the error.
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCompileShader.xml
IDL:
void compileShader(WebGLShader shader);
----
prototype.copyTexImage2D(target : Number, level : Number, internalformat : Number, x : Number, y : Number, width : Number, height : Number, border : Number) : undefined
Copies pixels from the framebuffer to
the bound texture in the active texture unit
(set through %%#activeTexture|**activeTexture()**%%
and %%#bindTexture|**bindTexture()**%%).
<html>
<dl>
<dt>
**target**
<dd>
must be one of %%#TEXTURE_2D|**TEXTURE_2D**%%,
%%#TEXTURE_CUBE_MAP_POSITIVE_X|**TEXTURE_CUBE_MAP_POSITIVE_X**%%,
%%#TEXTURE_CUBE_MAP_NEGATIVE_X|**TEXTURE_CUBE_MAP_NEGATIVE_X**%%,
%%#TEXTURE_CUBE_MAP_POSITIVE_Y|**TEXTURE_CUBE_MAP_POSITIVE_Y**%%,
%%#TEXTURE_CUBE_MAP_NEGATIVE_Y|**TEXTURE_CUBE_MAP_NEGATIVE_Y**%%,
%%#TEXTURE_CUBE_MAP_POSITIVE_Z|**TEXTURE_CUBE_MAP_POSITIVE_Z**%%,
or %%#TEXTURE_CUBE_MAP_NEGATIVE_Z|**TEXTURE_CUBE_MAP_NEGATIVE_Z**%%.
<dt>
**level**
<dd>
specifies the mipmap level to copy into.
<dt>
**internalformat**
<dd>
%%#ALPHA|**ALPHA**%%,
%%#LUMINANCE|**LUMINANCE**%%,
%%#LUMINANCE_ALPHA|**LUMINANCE_ALPHA**%%,
%%#RGB|**RGB**%%,
or %%#RGBA|**RGBA**%%.
<dt>
**x**, **y**, **width**, **height**
<dd>
the rectangle in framebuffer to copy.
<dt>
**border**
<dd>
must be **0**.
</dl>
</html>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml
IDL:
void copyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
----
prototype.copyTexSubImage2D(target : Number, level : Number, textureX : Number, textureY : Number, framebufferX : Number, framebufferY : Number, width : Number, height : Number) : undefined
Copies pixels from the framebuffer to a subregion of
the bound texture in the active texture unit
(set through %%#activeTexture|**activeTexture()**%%
and %%#bindTexture|**bindTexture()**%%).
<html>
<dl>
<dt>
**target**
<dd>
must be one of %%#TEXTURE_2D|**TEXTURE_2D**%%,
%%#TEXTURE_CUBE_MAP_POSITIVE_X|**TEXTURE_CUBE_MAP_POSITIVE_X**%%,
%%#TEXTURE_CUBE_MAP_NEGATIVE_X|**TEXTURE_CUBE_MAP_NEGATIVE_X**%%,
%%#TEXTURE_CUBE_MAP_POSITIVE_Y|**TEXTURE_CUBE_MAP_POSITIVE_Y**%%,
%%#TEXTURE_CUBE_MAP_NEGATIVE_Y|**TEXTURE_CUBE_MAP_NEGATIVE_Y**%%,
%%#TEXTURE_CUBE_MAP_POSITIVE_Z|**TEXTURE_CUBE_MAP_POSITIVE_Z**%%,
or %%#TEXTURE_CUBE_MAP_NEGATIVE_Z|**TEXTURE_CUBE_MAP_NEGATIVE_Z**%%.
<dt>
**level**
<dd>
specifies the mipmap level to copy into.
<dt>
**textureX**, **textureY**
<dd>
the position in the texture to store the copied pixels.
<dt>
**framebufferX**, **framebufferY**
<dd>
the position in the framebuffer to read the pixels to copy.
<dt>
**width**, **height**
<dd>
the size of the region to copy.
</dl>
</html>
Spec:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexSubImage2D.xml
IDL:
void copyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
----
prototype.createBuffer() : WebGLBuffer
Creates a buffer. A buffer is memory used to store data
passed to the shader program through attributes.
See also
%%#bindBuffer|**bindBuffer()**%%,
%%#bufferData|**bufferData()**%%,
%%#bufferSubData|**bufferSubData()**%%,
%%#deleteBuffer|**deleteBuffer()**%%,
%%#isBuffer|**isBuffer()**%%,
%%#vertexAttribPointer|**vertexAttribPointer()**%%
and
%%#enableVertexAttribArray|**enableVertexAttribArray()**%%.
<htmlexample>
<canvas id='canvas' width='100' height='100'></canvas>
<script id="vertexShader" type="x-shader/x-vertex">
attribute vec2 vertexPosition;
void main() {
gl_Position = vec4(vertexPosition, 0.0, 1.0);
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
void main() {
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // green
}
</script>
<script src='/webgl-debug.js'></script>
<script>
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl = WebGLDebugUtils.makeDebugContext(gl); // Remove this in production code
// Create Vertex Shader
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, document.getElementById('vertexShader').textContent);
gl.compileShader(vertexShader);
// Create Fragment Shader
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, document.getElementById('fragmentShader').textContent);
gl.compileShader(fragmentShader);
// Create Shader Program
var program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
gl.useProgram(program);
// Create a buffer with 3 points to form a triangle
var triangleBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
var vertices = [
-0.5, -0.5,
0.5, -0.5,
0.0, 0.5];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
// Bind the triangles to the vertex shader's 'vertexPosition' attribute and draw it
var vertexPositionLocation = gl.getAttribLocation(program, 'vertexPosition');
gl.vertexAttribPointer(vertexPositionLocation, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vertexPositionLocation);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 3);
</script>
</htmlexample>
IDL:
WebGLBuffer createBuffer();
----
prototype.createFramebuffer() : WebGLFramebuffer
Creates a framebuffer that can be used for offscreen rendering.
The actual content of the surface is stored in a either a
%%WebGLRenderbuffer|**WebGLRenderbuffer**%% or
%%WebGLTexture|**WebGLTexture**%%.
See also
%%#bindFramebuffer|**bindFramebuffer()**%%,
%%#checkFramebufferStatus|**checkFramebufferStatus()**%%,
%%#deleteFramebuffer|**deleteFramebuffer()**%%,
%%#framebufferRenderbuffer|**framebufferRenderbuffer()**%%,
%%#framebufferTexture2D|**framebufferTexture2D()**%%,
%%#getFramebufferAttachmentParameter|**getFramebufferAttachmentParameter()**%%,
and
%%#isFramebuffer|**isFramebuffer()**%%.
<htmlexample>
<!-- This example draws an image to a framebuffer (backed
by a texture) as black and white. Then it draws the
framebuffer texture to the canvas. -->
<canvas id='canvas' width='200' height='200'></canvas>
<script id="vertexShader" type="x-shader/x-vertex">
attribute vec2 vertexPosition;
varying vec2 textureCoord;
void main() {
gl_Position = vec4(vertexPosition, 0.0, 1.0);
// gl_Position is [-1,-1] to [1,1], translate to [0,0] to [1,1] for texture
textureCoord = vec2(vertexPosition.x / 2.0 + 0.5, vertexPosition.y / 2.0 + 0.5);
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
precision mediump float;