forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Context.js
2733 lines (2434 loc) · 113 KB
/
Context.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
/*global define*/
define([
'../Core/clone',
'../Core/defaultValue',
'../Core/defined',
'../Core/DeveloperError',
'../Core/destroyObject',
'../Core/defineProperties',
'../Core/Color',
'../Core/ComponentDatatype',
'../Core/IndexDatatype',
'../Core/RuntimeError',
'../Core/PrimitiveType',
'../Core/Geometry',
'../Core/GeometryAttribute',
'../Core/createGuid',
'../Core/Matrix4',
'../Core/Math',
'./Buffer',
'./BufferUsage',
'./CubeMap',
'./DrawCommand',
'./Framebuffer',
'./PixelDatatype',
'./PixelFormat',
'./PickFramebuffer',
'./Renderbuffer',
'./RenderbufferFormat',
'./RenderState',
'./ShaderCache',
'./ShaderProgram',
'./Texture',
'./TextureAtlas',
'./TextureMagnificationFilter',
'./TextureMinificationFilter',
'./TextureWrap',
'./UniformState',
'./VertexArray',
'./VertexLayout',
'./ClearCommand',
'./PassState',
'../Shaders/ViewportQuadVS'
], function(
clone,
defaultValue,
defined,
DeveloperError,
destroyObject,
defineProperties,
Color,
ComponentDatatype,
IndexDatatype,
RuntimeError,
PrimitiveType,
Geometry,
GeometryAttribute,
createGuid,
Matrix4,
CesiumMath,
Buffer,
BufferUsage,
CubeMap,
DrawCommand,
Framebuffer,
PixelDatatype,
PixelFormat,
PickFramebuffer,
Renderbuffer,
RenderbufferFormat,
RenderState,
ShaderCache,
ShaderProgram,
Texture,
TextureAtlas,
TextureMagnificationFilter,
TextureMinificationFilter,
TextureWrap,
UniformState,
VertexArray,
VertexLayout,
ClearCommand,
PassState,
ViewportQuadVS) {
"use strict";
/*global WebGLRenderingContext*/
function _errorToString(gl, error) {
var message = 'OpenGL Error: ';
switch (error) {
case gl.INVALID_ENUM:
message += 'Invalid enumeration';
break;
case gl.INVALID_VALUE:
message += 'Invalid value';
break;
case gl.INVALID_OPERATION:
message += 'Invalid operation';
break;
case gl.OUT_OF_MEMORY:
message += 'Out of memory';
break;
case gl.CONTEXT_LOST_WEBGL:
message += 'Context lost';
break;
default:
message += 'Unknown';
}
return message;
}
function _createErrorMessage(gl, glFunc, glFuncArguments, error) {
var message = _errorToString(gl, error) + ': ' + glFunc.name + '(';
for ( var i = 0; i < glFuncArguments.length; ++i) {
if (i !== 0) {
message += ', ';
}
message += glFuncArguments[i];
}
message += ');';
return message;
}
function throwOnError(gl, glFunc, glFuncArguments) {
var error = gl.getError();
if (error !== gl.NO_ERROR) {
throw new RuntimeError(_createErrorMessage(gl, glFunc, glFuncArguments, error));
}
}
function makeGetterSetter(gl, propertyName, logFunc) {
return {
get : function() {
var value = gl[propertyName];
logFunc(gl, 'get: ' + propertyName, value);
return gl[propertyName];
},
set : function(value) {
gl[propertyName] = value;
logFunc(gl, 'set: ' + propertyName, value);
}
};
}
function wrapGL(gl, logFunc) {
if (!logFunc) {
return gl;
}
function wrapFunction(property) {
return function() {
var result = property.apply(gl, arguments);
logFunc(gl, property, arguments);
return result;
};
}
var glWrapper = {};
/*jslint forin: true*/
/*jshint forin: false*/
// JSLint normally demands that a for..in loop must directly contain an if,
// but in our loop below, we actually intend to iterate all properties, including
// those in the prototype.
for ( var propertyName in gl) {
var property = gl[propertyName];
// wrap any functions we encounter, otherwise just copy the property to the wrapper.
if (typeof property === 'function') {
glWrapper[propertyName] = wrapFunction(property);
} else {
Object.defineProperty(glWrapper, propertyName, makeGetterSetter(gl, propertyName, logFunc));
}
}
return glWrapper;
}
function getExtension(gl, names) {
var length = names.length;
for (var i = 0; i < length; ++i) {
var extension = gl.getExtension(names[i]);
if (extension) {
return extension;
}
}
return undefined;
}
/**
* @private
*/
var Context = function(canvas, options) {
// this check must use typeof, not defined, because defined doesn't work with undeclared variables.
if (typeof WebGLRenderingContext === 'undefined') {
throw new RuntimeError('The browser does not support WebGL. Visit http://get.webgl.org.');
}
//>>includeStart('debug', pragmas.debug);
if (!defined(canvas)) {
throw new DeveloperError('canvas is required.');
}
//>>includeEnd('debug');
this._canvas = canvas;
options = clone(options, true);
options = defaultValue(options, {});
options.allowTextureFilterAnisotropic = defaultValue(options.allowTextureFilterAnisotropic, true);
var webglOptions = defaultValue(options.webgl, {});
// Override select WebGL defaults
webglOptions.alpha = defaultValue(webglOptions.alpha, false); // WebGL default is true
// TODO: WebGL default is false. This works around a bug in Canary and can be removed when fixed: https://code.google.com/p/chromium/issues/detail?id=335273
webglOptions.stencil = defaultValue(webglOptions.stencil, false);
webglOptions.failIfMajorPerformanceCaveat = defaultValue(webglOptions.failIfMajorPerformanceCaveat, true); // WebGL default is false
this._originalGLContext = canvas.getContext('webgl', webglOptions) || canvas.getContext('experimental-webgl', webglOptions) || undefined;
if (!defined(this._originalGLContext)) {
throw new RuntimeError('The browser supports WebGL, but initialization failed.');
}
this._id = createGuid();
// Validation and logging disabled by default for speed.
/**
* DOC_TBA
* @performance DOC_TBA: slow.
* @type {Boolean}
*/
this.validateFramebuffer = false;
/**
* DOC_TBA
* @performance DOC_TBA: slow.
* @type {Boolean}
*/
this.validateShaderProgram = false;
/**
* DOC_TBA
* @type {Boolean}
*/
this.logShaderCompilation = false;
this._throwOnWebGLError = false;
this._shaderCache = new ShaderCache(this);
var gl = this._gl = this._originalGLContext;
this._version = gl.getParameter(gl.VERSION);
this._shadingLanguageVersion = gl.getParameter(gl.SHADING_LANGUAGE_VERSION);
this._vendor = gl.getParameter(gl.VENDOR);
this._renderer = gl.getParameter(gl.RENDERER);
this._redBits = gl.getParameter(gl.RED_BITS);
this._greenBits = gl.getParameter(gl.GREEN_BITS);
this._blueBits = gl.getParameter(gl.BLUE_BITS);
this._alphaBits = gl.getParameter(gl.ALPHA_BITS);
this._depthBits = gl.getParameter(gl.DEPTH_BITS);
this._stencilBits = gl.getParameter(gl.STENCIL_BITS);
this._maximumCombinedTextureImageUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS); // min: 8
this._maximumCubeMapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); // min: 16
this._maximumFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); // min: 16
this._maximumTextureImageUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); // min: 8
this._maximumRenderbufferSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE); // min: 1
this._maximumTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); // min: 64
this._maximumVaryingVectors = gl.getParameter(gl.MAX_VARYING_VECTORS); // min: 8
this._maximumVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); // min: 8
this._maximumVertexTextureImageUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); // min: 0
this._maximumVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); // min: 128
this._aliasedLineWidthRange = gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE); // must include 1
this._aliasedPointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE); // must include 1
this._maximumViewportDimensions = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
this._antialias = gl.getContextAttributes().antialias;
// Query and initialize extensions
this._standardDerivatives = getExtension(gl, ['OES_standard_derivatives']);
this._elementIndexUint = getExtension(gl, ['OES_element_index_uint']);
this._depthTexture = getExtension(gl, ['WEBGL_depth_texture', 'WEBKIT_WEBGL_depth_texture']);
this._textureFloat = getExtension(gl, ['OES_texture_float']);
var textureFilterAnisotropic = options.allowTextureFilterAnisotropic ? getExtension(gl, ['EXT_texture_filter_anisotropic', 'WEBKIT_EXT_texture_filter_anisotropic']) : undefined;
this._textureFilterAnisotropic = textureFilterAnisotropic;
this._maximumTextureFilterAnisotropy = defined(textureFilterAnisotropic) ? gl.getParameter(textureFilterAnisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1.0;
this._vertexArrayObject = getExtension(gl, ['OES_vertex_array_object']);
this._fragDepth = getExtension(gl, ['EXT_frag_depth']);
this._drawBuffers = getExtension(gl, ['WEBGL_draw_buffers']);
this._maximumDrawBuffers = defined(this._drawBuffers) ? gl.getParameter(this._drawBuffers.MAX_DRAW_BUFFERS_WEBGL) : 1;
this._maximumColorAttachments = defined(this._drawBuffers) ? gl.getParameter(this._drawBuffers.MAX_COLOR_ATTACHMENTS_WEBGL) : 1; // min when supported: 4
var cc = gl.getParameter(gl.COLOR_CLEAR_VALUE);
this._clearColor = new Color(cc[0], cc[1], cc[2], cc[3]);
this._clearDepth = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
this._clearStencil = gl.getParameter(gl.STENCIL_CLEAR_VALUE);
var us = new UniformState();
var ps = new PassState(this);
var rs = this.createRenderState();
this._defaultPassState = ps;
this._defaultRenderState = rs;
this._defaultTexture = undefined;
this._defaultCubeMap = undefined;
this._us = us;
this._currentRenderState = rs;
this._currentFramebuffer = undefined;
this._maxFrameTextureUnitIndex = 0;
this._pickObjects = {};
this._nextPickColor = new Uint32Array(1);
/**
* Returns the read-only options used to create this context. The <code>webgl</code> property corresponds to the
* <a href='http://www.khronos.org/registry/webgl/specs/latest/#5.2'>WebGLContextAttributes</a> object used to
* create the WebGL context. Default values are shown in the code example below.
* <p>
* <code>options.webgl.alpha</code> defaults to false, which can improve performance compared to the standard WebGL default
* of true. If an application needs to composite Cesium above other HTML elements using alpha-blending, set
* <code>options.webgl.alpha</code> to true.
* </p>
* <p>
* <code>options.webgl.failIfMajorPerformanceCaveat</code> defaults to true, which ensures a context is not successfully created
* if the system has a major performance issue such as only supporting software rendering. The standard WebGL default is false,
* which is not appropriate for almost any Cesium app.
* </p>
* <p>
* The other <code>options.webgl</code> properties match the WebGL defaults for <a href='http://www.khronos.org/registry/webgl/specs/latest/#5.2'>WebGLContextAttributes</a>.
* </p>
* <p>
* <code>options.allowTextureFilterAnisotropic</code> defaults to true, which enables anisotropic texture filtering when the
* WebGL extension is supported. Check {@link Context#getTextureFilterAnisotropic}. Setting this to false will improve
* performance, but hurt visual quality, especially for horizon views.
* </p>
*
* @type {Object}
* @constant
*
* @example
* {
* webgl : {
* alpha : false,
* depth : true,
* stencil : false,
* antialias : true,
* premultipliedAlpha : true,
* preserveDrawingBuffer : false
* failIfMajorPerformanceCaveat : true
* },
* allowTextureFilterAnisotropic : true
* }
*/
this.options = options;
/**
* A cache of objects tied to this context. Just before the Context is destroyed,
* <code>destroy</code> will be invoked on each object in this object literal that has
* such a method. This is useful for caching any objects that might otherwise
* be stored globally, except they're tied to a particular context, and to manage
* their lifetime.
*
* @private
* @type {Object}
*/
this.cache = {};
RenderState.apply(gl, rs, ps);
};
defineProperties(Context.prototype, {
/**
* A unique ID for this context.
* @memberof Context.prototype
* @type {String}
*/
id : {
get : function() {
return this._id;
}
},
/**
* The canvas assoicated with this context.
* @memberof Context.prototype
* @type {HTMLCanvasElement}
*/
canvas : {
get : function() {
return this._canvas;
}
},
/**
* DOC_TBA
* @memberof Context.prototype
* @type {ShaderCache}
*/
shaderCache : {
get : function() {
return this._shaderCache;
}
},
/**
* DOC_TBA
* @memberof Context.prototype
* @type {UniformState}
*/
uniformState : {
get : function() {
return this._us;
}
},
/**
* The WebGL version or release number of the form <WebGL><space><version number><space><vendor-specific information>.
* @memberof Context.prototype
* @type {String}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetString.xml'>glGetString</a> with <code>VERSION</code>.
*/
version : {
get : function() {
return this._version;
}
},
/**
* The version or release number for the shading language of the form WebGL<space>GLSL<space>ES<space><version number><space><vendor-specific information>.
* @memberof Context.prototype
* @type {String}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetString.xml'>glGetString</a> with <code>SHADING_LANGUAGE_VERSION</code>.
*/
shadingLanguageVersion : {
get : function() {
return this._shadingLanguageVersion;
}
},
/**
* The company responsible for the WebGL implementation.
* @memberof Context.prototype
* @type {String}
*/
vendor : {
get : function() {
return this._vendor;
}
},
/**
* The name of the renderer/configuration/hardware platform. For example, this may be the model of the
* video card, e.g., 'GeForce 8800 GTS/PCI/SSE2', or the browser-dependent name of the GL implementation, e.g.
* 'Mozilla' or 'ANGLE.'
* @memberof Context.prototype
* @type {String}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetString.xml'>glGetString</a> with <code>RENDERER</code>.
* @see <a href='http://code.google.com/p/angleproject/'>ANGLE</a>
*/
renderer : {
get : function() {
return this._renderer;
}
},
/**
* The number of red bits per component in the default framebuffer's color buffer. The minimum is eight.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>RED_BITS</code>.
*/
redBits : {
get : function() {
return this._redBits;
}
},
/**
* The number of green bits per component in the default framebuffer's color buffer. The minimum is eight.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>GREEN_BITS</code>.
*/
greenBits : {
get : function() {
return this._greenBits;
}
},
/**
* The number of blue bits per component in the default framebuffer's color buffer. The minimum is eight.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>BLUE_BITS</code>.
*/
blueBits : {
get : function() {
return this._blueBits;
}
},
/**
* The number of alpha bits per component in the default framebuffer's color buffer. The minimum is eight.
* <br /><br />
* The alpha channel is used for GL destination alpha operations and by the HTML compositor to combine the color buffer
* with the rest of the page.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALPHA_BITS</code>.
*/
alphaBits : {
get : function() {
return this._alphaBits;
}
},
/**
* The number of depth bits per pixel in the default bound framebuffer. The minimum is 16 bits; most
* implementations will have 24 bits.
* @memberof Context.protoytpe
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>DEPTH_BITS</code>.
*/
depthBits : {
get : function() {
return this._depthBits;
}
},
/**
* The number of stencil bits per pixel in the default bound framebuffer. The minimum is eight bits.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>STENCIL_BITS</code>.
*/
stencilBits : {
get : function() {
return this._stencilBits;
}
},
/**
* The maximum number of texture units that can be used from the vertex and fragment
* shader with this WebGL implementation. The minimum is eight. If both shaders access the
* same texture unit, this counts as two texture units.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_COMBINED_TEXTURE_IMAGE_UNITS</code>.
*/
maximumCombinedTextureImageUnits : {
get : function() {
return this._maximumCombinedTextureImageUnits;
}
},
/**
* The approximate maximum cube mape width and height supported by this WebGL implementation.
* The minimum is 16, but most desktop and laptop implementations will support much larger sizes like 8,192.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_CUBE_MAP_TEXTURE_SIZE</code>.
*/
maximumCubeMapSize : {
get : function() {
return this._maximumCubeMapSize;
}
},
/**
* Rhe maximum number of <code>vec4</code>, <code>ivec4</code>, and <code>bvec4</code>
* uniforms that can be used by a fragment shader with this WebGL implementation. The minimum is 16.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_FRAGMENT_UNIFORM_VECTORS</code>.
*/
maximumFragmentUniformVectors : {
get : function() {
return this._maximumFragmentUniformVectors;
}
},
/**
* The maximum number of texture units that can be used from the fragment shader with this WebGL implementation. The minimum is eight.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_TEXTURE_IMAGE_UNITS</code>.
*/
maximumTextureImageUnits : {
get : function() {
return this._maximumTextureImageUnits;
}
},
/**
* The maximum renderbuffer width and height supported by this WebGL implementation.
* The minimum is 16, but most desktop and laptop implementations will support much larger sizes like 8,192.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_RENDERBUFFER_SIZE</code>.
*/
maximumRenderbufferSize : {
get : function() {
return this._maximumRenderbufferSize;
}
},
/**
* The approximate maximum texture width and height supported by this WebGL implementation.
* The minimum is 64, but most desktop and laptop implementations will support much larger sizes like 8,192.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_TEXTURE_SIZE</code>.
*/
maximumTextureSize : {
get : function() {
return this._maximumTextureSize;
}
},
/**
* The maximum number of <code>vec4</code> varying variables supported by this WebGL implementation.
* The minimum is eight. Matrices and arrays count as multiple <code>vec4</code>s.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VARYING_VECTORS</code>.
*/
maximumVaryingVectors : {
get : function() {
return this._maximumVaryingVectors;
}
},
/**
* The maximum number of <code>vec4</code> vertex attributes supported by this WebGL implementation. The minimum is eight.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VERTEX_ATTRIBS</code>.
*/
maximumVertexAttributes : {
get : function() {
return this._maximumVertexAttributes;
}
},
/**
* The maximum number of texture units that can be used from the vertex shader with this WebGL implementation.
* The minimum is zero, which means the GL does not support vertex texture fetch.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VERTEX_TEXTURE_IMAGE_UNITS</code>.
*/
maximumVertexTextureImageUnits : {
get : function() {
return this._maximumVertexTextureImageUnits;
}
},
/**
* The maximum number of <code>vec4</code>, <code>ivec4</code>, and <code>bvec4</code>
* uniforms that can be used by a vertex shader with this WebGL implementation. The minimum is 16.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VERTEX_UNIFORM_VECTORS</code>.
*/
maximumVertexUniformVectors : {
get : function() {
return this._maximumVertexUniformVectors;
}
},
/**
* The minimum aliased line width, in pixels, supported by this WebGL implementation. It will be at most one.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALIASED_LINE_WIDTH_RANGE</code>.
*/
minimumAliasedLineWidth : {
get : function() {
return this._aliasedLineWidthRange[0];
}
},
/**
* The maximum aliased line width, in pixels, supported by this WebGL implementation. It will be at least one.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALIASED_LINE_WIDTH_RANGE</code>.
*/
maximumAliasedLineWidth : {
get : function() {
return this._aliasedLineWidthRange[1];
}
},
/**
* The minimum aliased point size, in pixels, supported by this WebGL implementation. It will be at most one.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALIASED_POINT_SIZE_RANGE</code>.
*/
minimumAliasedPointSize : {
get : function() {
return this._aliasedPointSizeRange[0];
}
},
/**
* The maximum aliased point size, in pixels, supported by this WebGL implementation. It will be at least one.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALIASED_POINT_SIZE_RANGE</code>.
*/
maximumAliasedPointSize : {
get : function() {
return this._aliasedPointSizeRange[1];
}
},
/**
* The maximum supported width of the viewport. It will be at least as large as the visible width of the associated canvas.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VIEWPORT_DIMS</code>.
*/
maximumViewportWidth : {
get : function() {
return this._maximumViewportDimensions[0];
}
},
/**
* The maximum supported height of the viewport. It will be at least as large as the visible height of the associated canvas.
* @memberof Context.prototype
* @type {Number}
* @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VIEWPORT_DIMS</code>.
*/
maximumViewportHeight : {
get : function() {
return this._maximumViewportDimensions[1];
}
},
/**
* <code>true</code> if the WebGL context supports antialiasing. By default
* antialiasing is requested, but it is not supported by all systems.
* @memberof Context.prototype
* @type {Boolean}
*/
antialias : {
get : function() {
return this._antialias;
}
},
/**
* <code>true</code> if the OES_standard_derivatives extension is supported. This
* extension provides access to <code>dFdx<code>, <code>dFdy<code>, and <code>fwidth<code>
* functions from GLSL. A shader using these functions still needs to explicitly enable the
* extension with <code>#extension GL_OES_standard_derivatives : enable</code>.
* @memberof Context.prototype
* @type {Boolean}
* @see <a href='http://www.khronos.org/registry/gles/extensions/OES/OES_standard_derivatives.txt'>OES_standard_derivatives</a>
*/
standardDerivatives : {
get : function() {
return !!this._standardDerivatives;
}
},
/**
* <code>true</code> if the OES_element_index_uint extension is supported. This
* extension allows the use of unsigned int indices, which can improve performance by
* eliminating batch breaking caused by unsigned short indices.
* @memberof Context.prototype
* @type {Boolean}
* @see <a href='http://www.khronos.org/registry/webgl/extensions/OES_element_index_uint/'>OES_element_index_uint</a>
*/
elementIndexUint : {
get : function() {
return !!this._elementIndexUint;
}
},
/**
* <code>true</code> if WEBGL_depth_texture is supported. This extension provides
* access to depth textures that, for example, can be attached to framebuffers for shadow mapping.
* @memberof Context.prototype
* @type {Boolean}
* @see <a href='http://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/'>WEBGL_depth_texture</a>
*/
depthTexture : {
get : function() {
return !!this._depthTexture;
}
},
/**
* <code>true</code> if OES_texture_float is supported. This extension provides
* access to floating point textures that, for example, can be attached to framebuffers for high dynamic range.
* @memberof Context.prototype
* @type {Boolean}
* @see <a href='http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt'>OES_texture_float</a>
*/
floatingPointTexture : {
get : function() {
return !!this._textureFloat;
}
},
/**
* DOC_TBA
* @memberof Context.prototype
* @type {Boolean}
* @see <a href='http://www.khronos.org/registry/webgl/extensions/EXT_texture_filter_anisotropic/'>EXT_texture_filter_anisotropic</a>
*/
textureFilterAnisotropic : {
get : function() {
return !!this._textureFilterAnisotropic;
}
},
/**
* DOC_TBA
* @memberof Context.prototype
*/
maximumTextureFilterAnisotropy : {
get : function() {
return this._maximumTextureFilterAnisotropy;
}
},
/**
* <code>true</code> if the OES_vertex_array_object extension is supported. This
* extension can improve performance by reducing the overhead of switching vertex arrays.
* When enabled, this extension is automatically used by {@link VertexArray}.
* @memberof Context.prototype
* @type {Boolean}
* @see <a href='http://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/'>OES_vertex_array_object</a>
*/
vertexArrayObject : {
get : function() {
return !!this._vertexArrayObject;
}
},
/**
* <code>true</code> if the EXT_frag_depth extension is supported. This
* extension provides access to the <code>gl_FragDepthEXT<code> built-in output variable
* from GLSL fragment shaders. A shader using these functions still needs to explicitly enable the
* extension with <code>#extension GL_EXT_frag_depth : enable</code>.
* @memberof Context.prototype
* @type {Boolean}
* @see <a href='http://www.khronos.org/registry/webgl/extensions/EXT_frag_depth/'>EXT_frag_depth</a>
*/
fragmentDepth : {
get : function() {
return !!this._fragDepth;
}
},
/**
* <code>true</code> if the WEBGL_draw_buffers extension is supported. This
* extensions provides support for multiple render targets. The framebuffer object can have mutiple
* color attachments and the GLSL fragment shader can write to the built-in output array <code>gl_FragData</code>.
* A shader using this feature needs to explicitly enable the extension with
* <code>#extension GL_EXT_draw_buffers : enable</code>.
* @memberof Context.prototype
* @type {Boolean}
* @see <a href='http://www.khronos.org/registry/webgl/extensions/WEBGL_draw_buffers/'>WEBGL_draw_buffers</a>
*/
drawBuffers : {
get : function() {
return !!this._drawBuffers;
}
},
/**
* The maximum number of simultaneous outputs that may be written in a fragment shader.
* @memberof Context.prototype
* @type {Number}
*/
maximumDrawBuffers : {
get : function() {
return this._maximumDrawBuffers;
}
},
/**
* The maximum number of color attachments supported.
* @memberof Context.prototype
* @type {Number}
*/
maximumColorAttachments : {
get : function() {
return this._maximumColorAttachments;
}
},
/**
* DOC_TBA
* @memberof Context.prototype
* @type {Boolean}
*/
throwOnWebGLError : {
get : function() {
return this._throwOnWebGLError;
},
set : function(value) {
this._throwOnWebGLError = value;
this._gl = wrapGL(this._originalGLContext, value ? throwOnError : null);
}
},
/**
* A 1x1 RGBA texture initialized to [255, 255, 255, 255]. This can
* be used as a placeholder texture while other textures are downloaded.
* @memberof Context.prototype
* @type {Texture}
*/
defaultTexture : {
get : function() {
if (this._defaultTexture === undefined) {
this._defaultTexture = this.createTexture2D({
source : {
width : 1,
height : 1,
arrayBufferView : new Uint8Array([255, 255, 255, 255])
}
});
}
return this._defaultTexture;
}
},
/**
* A cube map, where each face is a 1x1 RGBA texture initialized to
* [255, 255, 255, 255]. This can be used as a placeholder cube map while
* other cube maps are downloaded.
* @memberof Context.prototype
* @type {CubeMap}
*/
defaultCubeMap : {
get : function() {
if (this._defaultCubeMap === undefined) {
var face = {
width : 1,
height : 1,
arrayBufferView : new Uint8Array([255, 255, 255, 255])
};
this._defaultCubeMap = this.createCubeMap({
source : {
positiveX : face,
negativeX : face,
positiveY : face,
negativeY : face,
positiveZ : face,
negativeZ : face
}
});
}
return this._defaultCubeMap;
}
},
/**
* The drawingBufferWidth of the underlying GL context.
* @memberof Context.prototype
* @type {Number}
* @see <a href='https://www.khronos.org/registry/webgl/specs/1.0/#DOM-WebGLRenderingContext-drawingBufferWidth'>drawingBufferWidth</a>
*/
drawingBufferHeight : {
get : function() {
return this._gl.drawingBufferHeight;
}
},
/**
* The drawingBufferHeight of the underlying GL context.
* @memberof Context.prototype
* @type {Number}
* @see <a href='https://www.khronos.org/registry/webgl/specs/1.0/#DOM-WebGLRenderingContext-drawingBufferHeight'>drawingBufferHeight</a>
*/
drawingBufferWidth : {
get : function() {
return this._gl.drawingBufferWidth;
}
}