OSDN Git Service

three.jsをThirdPartyに追加
[webglgame/webgl_framework.git] / webglFramework / Thirdparty / three.js-master / src / renderers / webgl / WebGLState.js
1 /**
2  * @author mrdoob / http://mrdoob.com/
3  */
4
5 import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, DoubleSide, BackSide } from '../../constants';
6 import { Vector4 } from '../../math/Vector4';
7
8 function WebGLState( gl, extensions, utils ) {
9
10         function ColorBuffer() {
11
12                 var locked = false;
13
14                 var color = new Vector4();
15                 var currentColorMask = null;
16                 var currentColorClear = new Vector4( 0, 0, 0, 0 );
17
18                 return {
19
20                         setMask: function ( colorMask ) {
21
22                                 if ( currentColorMask !== colorMask && ! locked ) {
23
24                                         gl.colorMask( colorMask, colorMask, colorMask, colorMask );
25                                         currentColorMask = colorMask;
26
27                                 }
28
29                         },
30
31                         setLocked: function ( lock ) {
32
33                                 locked = lock;
34
35                         },
36
37                         setClear: function ( r, g, b, a, premultipliedAlpha ) {
38
39                                 if ( premultipliedAlpha === true ) {
40
41                                         r *= a; g *= a; b *= a;
42
43                                 }
44
45                                 color.set( r, g, b, a );
46
47                                 if ( currentColorClear.equals( color ) === false ) {
48
49                                         gl.clearColor( r, g, b, a );
50                                         currentColorClear.copy( color );
51
52                                 }
53
54                         },
55
56                         reset: function () {
57
58                                 locked = false;
59
60                                 currentColorMask = null;
61                                 currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
62
63                         }
64
65                 };
66
67         }
68
69         function DepthBuffer() {
70
71                 var locked = false;
72
73                 var currentDepthMask = null;
74                 var currentDepthFunc = null;
75                 var currentDepthClear = null;
76
77                 return {
78
79                         setTest: function ( depthTest ) {
80
81                                 if ( depthTest ) {
82
83                                         enable( gl.DEPTH_TEST );
84
85                                 } else {
86
87                                         disable( gl.DEPTH_TEST );
88
89                                 }
90
91                         },
92
93                         setMask: function ( depthMask ) {
94
95                                 if ( currentDepthMask !== depthMask && ! locked ) {
96
97                                         gl.depthMask( depthMask );
98                                         currentDepthMask = depthMask;
99
100                                 }
101
102                         },
103
104                         setFunc: function ( depthFunc ) {
105
106                                 if ( currentDepthFunc !== depthFunc ) {
107
108                                         if ( depthFunc ) {
109
110                                                 switch ( depthFunc ) {
111
112                                                         case NeverDepth:
113
114                                                                 gl.depthFunc( gl.NEVER );
115                                                                 break;
116
117                                                         case AlwaysDepth:
118
119                                                                 gl.depthFunc( gl.ALWAYS );
120                                                                 break;
121
122                                                         case LessDepth:
123
124                                                                 gl.depthFunc( gl.LESS );
125                                                                 break;
126
127                                                         case LessEqualDepth:
128
129                                                                 gl.depthFunc( gl.LEQUAL );
130                                                                 break;
131
132                                                         case EqualDepth:
133
134                                                                 gl.depthFunc( gl.EQUAL );
135                                                                 break;
136
137                                                         case GreaterEqualDepth:
138
139                                                                 gl.depthFunc( gl.GEQUAL );
140                                                                 break;
141
142                                                         case GreaterDepth:
143
144                                                                 gl.depthFunc( gl.GREATER );
145                                                                 break;
146
147                                                         case NotEqualDepth:
148
149                                                                 gl.depthFunc( gl.NOTEQUAL );
150                                                                 break;
151
152                                                         default:
153
154                                                                 gl.depthFunc( gl.LEQUAL );
155
156                                                 }
157
158                                         } else {
159
160                                                 gl.depthFunc( gl.LEQUAL );
161
162                                         }
163
164                                         currentDepthFunc = depthFunc;
165
166                                 }
167
168                         },
169
170                         setLocked: function ( lock ) {
171
172                                 locked = lock;
173
174                         },
175
176                         setClear: function ( depth ) {
177
178                                 if ( currentDepthClear !== depth ) {
179
180                                         gl.clearDepth( depth );
181                                         currentDepthClear = depth;
182
183                                 }
184
185                         },
186
187                         reset: function () {
188
189                                 locked = false;
190
191                                 currentDepthMask = null;
192                                 currentDepthFunc = null;
193                                 currentDepthClear = null;
194
195                         }
196
197                 };
198
199         }
200
201         function StencilBuffer() {
202
203                 var locked = false;
204
205                 var currentStencilMask = null;
206                 var currentStencilFunc = null;
207                 var currentStencilRef = null;
208                 var currentStencilFuncMask = null;
209                 var currentStencilFail = null;
210                 var currentStencilZFail = null;
211                 var currentStencilZPass = null;
212                 var currentStencilClear = null;
213
214                 return {
215
216                         setTest: function ( stencilTest ) {
217
218                                 if ( stencilTest ) {
219
220                                         enable( gl.STENCIL_TEST );
221
222                                 } else {
223
224                                         disable( gl.STENCIL_TEST );
225
226                                 }
227
228                         },
229
230                         setMask: function ( stencilMask ) {
231
232                                 if ( currentStencilMask !== stencilMask && ! locked ) {
233
234                                         gl.stencilMask( stencilMask );
235                                         currentStencilMask = stencilMask;
236
237                                 }
238
239                         },
240
241                         setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
242
243                                 if ( currentStencilFunc !== stencilFunc ||
244                                      currentStencilRef  !== stencilRef  ||
245                                      currentStencilFuncMask !== stencilMask ) {
246
247                                         gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
248
249                                         currentStencilFunc = stencilFunc;
250                                         currentStencilRef = stencilRef;
251                                         currentStencilFuncMask = stencilMask;
252
253                                 }
254
255                         },
256
257                         setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
258
259                                 if ( currentStencilFail  !== stencilFail        ||
260                                      currentStencilZFail !== stencilZFail ||
261                                      currentStencilZPass !== stencilZPass ) {
262
263                                         gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
264
265                                         currentStencilFail = stencilFail;
266                                         currentStencilZFail = stencilZFail;
267                                         currentStencilZPass = stencilZPass;
268
269                                 }
270
271                         },
272
273                         setLocked: function ( lock ) {
274
275                                 locked = lock;
276
277                         },
278
279                         setClear: function ( stencil ) {
280
281                                 if ( currentStencilClear !== stencil ) {
282
283                                         gl.clearStencil( stencil );
284                                         currentStencilClear = stencil;
285
286                                 }
287
288                         },
289
290                         reset: function () {
291
292                                 locked = false;
293
294                                 currentStencilMask = null;
295                                 currentStencilFunc = null;
296                                 currentStencilRef = null;
297                                 currentStencilFuncMask = null;
298                                 currentStencilFail = null;
299                                 currentStencilZFail = null;
300                                 currentStencilZPass = null;
301                                 currentStencilClear = null;
302
303                         }
304
305                 };
306
307         }
308
309         //
310
311         var colorBuffer = new ColorBuffer();
312         var depthBuffer = new DepthBuffer();
313         var stencilBuffer = new StencilBuffer();
314
315         var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
316         var newAttributes = new Uint8Array( maxVertexAttributes );
317         var enabledAttributes = new Uint8Array( maxVertexAttributes );
318         var attributeDivisors = new Uint8Array( maxVertexAttributes );
319
320         var capabilities = {};
321
322         var compressedTextureFormats = null;
323
324         var currentProgram = null;
325
326         var currentBlending = null;
327         var currentBlendEquation = null;
328         var currentBlendSrc = null;
329         var currentBlendDst = null;
330         var currentBlendEquationAlpha = null;
331         var currentBlendSrcAlpha = null;
332         var currentBlendDstAlpha = null;
333         var currentPremultipledAlpha = false;
334
335         var currentFlipSided = null;
336         var currentCullFace = null;
337
338         var currentLineWidth = null;
339
340         var currentPolygonOffsetFactor = null;
341         var currentPolygonOffsetUnits = null;
342
343         var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
344
345         var version = parseFloat( /^WebGL\ ([0-9])/.exec( gl.getParameter( gl.VERSION ) )[ 1 ] );
346         var lineWidthAvailable = parseFloat( version ) >= 1.0;
347
348         var currentTextureSlot = null;
349         var currentBoundTextures = {};
350
351         var currentScissor = new Vector4();
352         var currentViewport = new Vector4();
353
354         function createTexture( type, target, count ) {
355
356                 var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
357                 var texture = gl.createTexture();
358
359                 gl.bindTexture( type, texture );
360                 gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
361                 gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
362
363                 for ( var i = 0; i < count; i ++ ) {
364
365                         gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
366
367                 }
368
369                 return texture;
370
371         }
372
373         var emptyTextures = {};
374         emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
375         emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
376
377         // init
378
379         colorBuffer.setClear( 0, 0, 0, 1 );
380         depthBuffer.setClear( 1 );
381         stencilBuffer.setClear( 0 );
382
383         enable( gl.DEPTH_TEST );
384         depthBuffer.setFunc( LessEqualDepth );
385
386         setFlipSided( false );
387         setCullFace( CullFaceBack );
388         enable( gl.CULL_FACE );
389
390         enable( gl.BLEND );
391         setBlending( NormalBlending );
392
393         //
394
395         function initAttributes() {
396
397                 for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
398
399                         newAttributes[ i ] = 0;
400
401                 }
402
403         }
404
405         function enableAttribute( attribute ) {
406
407                 newAttributes[ attribute ] = 1;
408
409                 if ( enabledAttributes[ attribute ] === 0 ) {
410
411                         gl.enableVertexAttribArray( attribute );
412                         enabledAttributes[ attribute ] = 1;
413
414                 }
415
416                 if ( attributeDivisors[ attribute ] !== 0 ) {
417
418                         var extension = extensions.get( 'ANGLE_instanced_arrays' );
419
420                         extension.vertexAttribDivisorANGLE( attribute, 0 );
421                         attributeDivisors[ attribute ] = 0;
422
423                 }
424
425         }
426
427         function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
428
429                 newAttributes[ attribute ] = 1;
430
431                 if ( enabledAttributes[ attribute ] === 0 ) {
432
433                         gl.enableVertexAttribArray( attribute );
434                         enabledAttributes[ attribute ] = 1;
435
436                 }
437
438                 if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
439
440                         var extension = extensions.get( 'ANGLE_instanced_arrays' );
441
442                         extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
443                         attributeDivisors[ attribute ] = meshPerAttribute;
444
445                 }
446
447         }
448
449         function disableUnusedAttributes() {
450
451                 for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
452
453                         if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
454
455                                 gl.disableVertexAttribArray( i );
456                                 enabledAttributes[ i ] = 0;
457
458                         }
459
460                 }
461
462         }
463
464         function enable( id ) {
465
466                 if ( capabilities[ id ] !== true ) {
467
468                         gl.enable( id );
469                         capabilities[ id ] = true;
470
471                 }
472
473         }
474
475         function disable( id ) {
476
477                 if ( capabilities[ id ] !== false ) {
478
479                         gl.disable( id );
480                         capabilities[ id ] = false;
481
482                 }
483
484         }
485
486         function getCompressedTextureFormats() {
487
488                 if ( compressedTextureFormats === null ) {
489
490                         compressedTextureFormats = [];
491
492                         if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
493                              extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
494                              extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
495
496                                 var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
497
498                                 for ( var i = 0; i < formats.length; i ++ ) {
499
500                                         compressedTextureFormats.push( formats[ i ] );
501
502                                 }
503
504                         }
505
506                 }
507
508                 return compressedTextureFormats;
509
510         }
511
512         function useProgram( program ) {
513
514                 if ( currentProgram !== program ) {
515
516                         gl.useProgram( program );
517
518                         currentProgram = program;
519
520                         return true;
521
522                 }
523
524                 return false;
525
526         }
527
528         function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
529
530                 if ( blending !== NoBlending ) {
531
532                         enable( gl.BLEND );
533
534                 } else {
535
536                         disable( gl.BLEND );
537
538                 }
539
540                 if ( blending !== CustomBlending ) {
541
542                         if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
543
544                                 switch ( blending ) {
545
546                                         case AdditiveBlending:
547
548                                                 if ( premultipliedAlpha ) {
549
550                                                         gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
551                                                         gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
552
553                                                 } else {
554
555                                                         gl.blendEquation( gl.FUNC_ADD );
556                                                         gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
557
558                                                 }
559                                                 break;
560
561                                         case SubtractiveBlending:
562
563                                                 if ( premultipliedAlpha ) {
564
565                                                         gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
566                                                         gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
567
568                                                 } else {
569
570                                                         gl.blendEquation( gl.FUNC_ADD );
571                                                         gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
572
573                                                 }
574                                                 break;
575
576                                         case MultiplyBlending:
577
578                                                 if ( premultipliedAlpha ) {
579
580                                                         gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
581                                                         gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
582
583                                                 } else {
584
585                                                         gl.blendEquation( gl.FUNC_ADD );
586                                                         gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
587
588                                                 }
589                                                 break;
590
591                                         default:
592
593                                                 if ( premultipliedAlpha ) {
594
595                                                         gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
596                                                         gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
597
598                                                 } else {
599
600                                                         gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
601                                                         gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
602
603                                                 }
604
605                                 }
606
607                         }
608
609                         currentBlendEquation = null;
610                         currentBlendSrc = null;
611                         currentBlendDst = null;
612                         currentBlendEquationAlpha = null;
613                         currentBlendSrcAlpha = null;
614                         currentBlendDstAlpha = null;
615
616                 } else {
617
618                         blendEquationAlpha = blendEquationAlpha || blendEquation;
619                         blendSrcAlpha = blendSrcAlpha || blendSrc;
620                         blendDstAlpha = blendDstAlpha || blendDst;
621
622                         if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
623
624                                 gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
625
626                                 currentBlendEquation = blendEquation;
627                                 currentBlendEquationAlpha = blendEquationAlpha;
628
629                         }
630
631                         if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
632
633                                 gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
634
635                                 currentBlendSrc = blendSrc;
636                                 currentBlendDst = blendDst;
637                                 currentBlendSrcAlpha = blendSrcAlpha;
638                                 currentBlendDstAlpha = blendDstAlpha;
639
640                         }
641
642                 }
643
644                 currentBlending = blending;
645                 currentPremultipledAlpha = premultipliedAlpha;
646
647         }
648
649         function setMaterial( material ) {
650
651                 material.side === DoubleSide
652                         ? disable( gl.CULL_FACE )
653                         : enable( gl.CULL_FACE );
654
655                 setFlipSided( material.side === BackSide );
656
657                 material.transparent === true
658                         ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
659                         : setBlending( NoBlending );
660
661                 depthBuffer.setFunc( material.depthFunc );
662                 depthBuffer.setTest( material.depthTest );
663                 depthBuffer.setMask( material.depthWrite );
664                 colorBuffer.setMask( material.colorWrite );
665
666                 setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
667
668         }
669
670         //
671
672         function setFlipSided( flipSided ) {
673
674                 if ( currentFlipSided !== flipSided ) {
675
676                         if ( flipSided ) {
677
678                                 gl.frontFace( gl.CW );
679
680                         } else {
681
682                                 gl.frontFace( gl.CCW );
683
684                         }
685
686                         currentFlipSided = flipSided;
687
688                 }
689
690         }
691
692         function setCullFace( cullFace ) {
693
694                 if ( cullFace !== CullFaceNone ) {
695
696                         enable( gl.CULL_FACE );
697
698                         if ( cullFace !== currentCullFace ) {
699
700                                 if ( cullFace === CullFaceBack ) {
701
702                                         gl.cullFace( gl.BACK );
703
704                                 } else if ( cullFace === CullFaceFront ) {
705
706                                         gl.cullFace( gl.FRONT );
707
708                                 } else {
709
710                                         gl.cullFace( gl.FRONT_AND_BACK );
711
712                                 }
713
714                         }
715
716                 } else {
717
718                         disable( gl.CULL_FACE );
719
720                 }
721
722                 currentCullFace = cullFace;
723
724         }
725
726         function setLineWidth( width ) {
727
728                 if ( width !== currentLineWidth ) {
729
730                         if ( lineWidthAvailable ) gl.lineWidth( width );
731
732                         currentLineWidth = width;
733
734                 }
735
736         }
737
738         function setPolygonOffset( polygonOffset, factor, units ) {
739
740                 if ( polygonOffset ) {
741
742                         enable( gl.POLYGON_OFFSET_FILL );
743
744                         if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
745
746                                 gl.polygonOffset( factor, units );
747
748                                 currentPolygonOffsetFactor = factor;
749                                 currentPolygonOffsetUnits = units;
750
751                         }
752
753                 } else {
754
755                         disable( gl.POLYGON_OFFSET_FILL );
756
757                 }
758
759         }
760
761         function setScissorTest( scissorTest ) {
762
763                 if ( scissorTest ) {
764
765                         enable( gl.SCISSOR_TEST );
766
767                 } else {
768
769                         disable( gl.SCISSOR_TEST );
770
771                 }
772
773         }
774
775         // texture
776
777         function activeTexture( webglSlot ) {
778
779                 if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
780
781                 if ( currentTextureSlot !== webglSlot ) {
782
783                         gl.activeTexture( webglSlot );
784                         currentTextureSlot = webglSlot;
785
786                 }
787
788         }
789
790         function bindTexture( webglType, webglTexture ) {
791
792                 if ( currentTextureSlot === null ) {
793
794                         activeTexture();
795
796                 }
797
798                 var boundTexture = currentBoundTextures[ currentTextureSlot ];
799
800                 if ( boundTexture === undefined ) {
801
802                         boundTexture = { type: undefined, texture: undefined };
803                         currentBoundTextures[ currentTextureSlot ] = boundTexture;
804
805                 }
806
807                 if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
808
809                         gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
810
811                         boundTexture.type = webglType;
812                         boundTexture.texture = webglTexture;
813
814                 }
815
816         }
817
818         function compressedTexImage2D() {
819
820                 try {
821
822                         gl.compressedTexImage2D.apply( gl, arguments );
823
824                 } catch ( error ) {
825
826                         console.error( 'THREE.WebGLState:', error );
827
828                 }
829
830         }
831
832         function texImage2D() {
833
834                 try {
835
836                         gl.texImage2D.apply( gl, arguments );
837
838                 } catch ( error ) {
839
840                         console.error( 'THREE.WebGLState:', error );
841
842                 }
843
844         }
845
846         //
847
848         function scissor( scissor ) {
849
850                 if ( currentScissor.equals( scissor ) === false ) {
851
852                         gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
853                         currentScissor.copy( scissor );
854
855                 }
856
857         }
858
859         function viewport( viewport ) {
860
861                 if ( currentViewport.equals( viewport ) === false ) {
862
863                         gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
864                         currentViewport.copy( viewport );
865
866                 }
867
868         }
869
870         //
871
872         function reset() {
873
874                 for ( var i = 0; i < enabledAttributes.length; i ++ ) {
875
876                         if ( enabledAttributes[ i ] === 1 ) {
877
878                                 gl.disableVertexAttribArray( i );
879                                 enabledAttributes[ i ] = 0;
880
881                         }
882
883                 }
884
885                 capabilities = {};
886
887                 compressedTextureFormats = null;
888
889                 currentTextureSlot = null;
890                 currentBoundTextures = {};
891
892                 currentProgram = null;
893
894                 currentBlending = null;
895
896                 currentFlipSided = null;
897                 currentCullFace = null;
898
899                 colorBuffer.reset();
900                 depthBuffer.reset();
901                 stencilBuffer.reset();
902
903         }
904
905         return {
906
907                 buffers: {
908                         color: colorBuffer,
909                         depth: depthBuffer,
910                         stencil: stencilBuffer
911                 },
912
913                 initAttributes: initAttributes,
914                 enableAttribute: enableAttribute,
915                 enableAttributeAndDivisor: enableAttributeAndDivisor,
916                 disableUnusedAttributes: disableUnusedAttributes,
917                 enable: enable,
918                 disable: disable,
919                 getCompressedTextureFormats: getCompressedTextureFormats,
920
921                 useProgram: useProgram,
922
923                 setBlending: setBlending,
924                 setMaterial: setMaterial,
925
926                 setFlipSided: setFlipSided,
927                 setCullFace: setCullFace,
928
929                 setLineWidth: setLineWidth,
930                 setPolygonOffset: setPolygonOffset,
931
932                 setScissorTest: setScissorTest,
933
934                 activeTexture: activeTexture,
935                 bindTexture: bindTexture,
936                 compressedTexImage2D: compressedTexImage2D,
937                 texImage2D: texImage2D,
938
939                 scissor: scissor,
940                 viewport: viewport,
941
942                 reset: reset
943
944         };
945
946 }
947
948
949 export { WebGLState };