|
@@ -7,13 +7,304 @@ import { Vector4 } from '../../math/Vector4';
|
|
|
|
|
|
function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
- var _this = this;
|
|
|
+ function ColorBuffer() {
|
|
|
|
|
|
- this.buffers = {
|
|
|
- color: new WebGLColorBuffer( gl, this ),
|
|
|
- depth: new WebGLDepthBuffer( gl, this ),
|
|
|
- stencil: new WebGLStencilBuffer( gl, this )
|
|
|
- };
|
|
|
+ var locked = false;
|
|
|
+
|
|
|
+ var color = new Vector4();
|
|
|
+ var currentColorMask = null;
|
|
|
+ var currentColorClear = new Vector4();
|
|
|
+
|
|
|
+ return {
|
|
|
+
|
|
|
+ setMask: function ( colorMask ) {
|
|
|
+
|
|
|
+ if ( currentColorMask !== colorMask && ! locked ) {
|
|
|
+
|
|
|
+ gl.colorMask( colorMask, colorMask, colorMask, colorMask );
|
|
|
+ currentColorMask = colorMask;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setLocked: function ( lock ) {
|
|
|
+
|
|
|
+ locked = lock;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setClear: function ( r, g, b, a ) {
|
|
|
+
|
|
|
+ color.set( r, g, b, a );
|
|
|
+
|
|
|
+ if ( currentColorClear.equals( color ) === false ) {
|
|
|
+
|
|
|
+ gl.clearColor( r, g, b, a );
|
|
|
+ currentColorClear.copy( color );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ reset: function () {
|
|
|
+
|
|
|
+ locked = false;
|
|
|
+
|
|
|
+ currentColorMask = null;
|
|
|
+ currentColorClear.set( 0, 0, 0, 1 );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function DepthBuffer() {
|
|
|
+
|
|
|
+ var locked = false;
|
|
|
+
|
|
|
+ var currentDepthMask = null;
|
|
|
+ var currentDepthFunc = null;
|
|
|
+ var currentDepthClear = null;
|
|
|
+
|
|
|
+ return {
|
|
|
+
|
|
|
+ setTest: function ( depthTest ) {
|
|
|
+
|
|
|
+ if ( depthTest ) {
|
|
|
+
|
|
|
+ enable( gl.DEPTH_TEST );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ disable( gl.DEPTH_TEST );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setMask: function ( depthMask ) {
|
|
|
+
|
|
|
+ if ( currentDepthMask !== depthMask && ! locked ) {
|
|
|
+
|
|
|
+ gl.depthMask( depthMask );
|
|
|
+ currentDepthMask = depthMask;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setFunc: function ( depthFunc ) {
|
|
|
+
|
|
|
+ if ( currentDepthFunc !== depthFunc ) {
|
|
|
+
|
|
|
+ if ( depthFunc ) {
|
|
|
+
|
|
|
+ switch ( depthFunc ) {
|
|
|
+
|
|
|
+ case NeverDepth:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.NEVER );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case AlwaysDepth:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.ALWAYS );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case LessDepth:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.LESS );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case LessEqualDepth:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.LEQUAL );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case EqualDepth:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.EQUAL );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case GreaterEqualDepth:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.GEQUAL );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case GreaterDepth:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.GREATER );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case NotEqualDepth:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.NOTEQUAL );
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+
|
|
|
+ gl.depthFunc( gl.LEQUAL );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ gl.depthFunc( gl.LEQUAL );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ currentDepthFunc = depthFunc;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setLocked: function ( lock ) {
|
|
|
+
|
|
|
+ locked = lock;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setClear: function ( depth ) {
|
|
|
+
|
|
|
+ if ( currentDepthClear !== depth ) {
|
|
|
+
|
|
|
+ gl.clearDepth( depth );
|
|
|
+ currentDepthClear = depth;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ reset: function () {
|
|
|
+
|
|
|
+ locked = false;
|
|
|
+
|
|
|
+ currentDepthMask = null;
|
|
|
+ currentDepthFunc = null;
|
|
|
+ currentDepthClear = null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function StencilBuffer() {
|
|
|
+
|
|
|
+ var locked = false;
|
|
|
+
|
|
|
+ var currentStencilMask = null;
|
|
|
+ var currentStencilFunc = null;
|
|
|
+ var currentStencilRef = null;
|
|
|
+ var currentStencilFuncMask = null;
|
|
|
+ var currentStencilFail = null;
|
|
|
+ var currentStencilZFail = null;
|
|
|
+ var currentStencilZPass = null;
|
|
|
+ var currentStencilClear = null;
|
|
|
+
|
|
|
+ return {
|
|
|
+
|
|
|
+ setTest: function ( stencilTest ) {
|
|
|
+
|
|
|
+ if ( stencilTest ) {
|
|
|
+
|
|
|
+ enable( gl.STENCIL_TEST );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ disable( gl.STENCIL_TEST );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setMask: function ( stencilMask ) {
|
|
|
+
|
|
|
+ if ( currentStencilMask !== stencilMask && ! locked ) {
|
|
|
+
|
|
|
+ gl.stencilMask( stencilMask );
|
|
|
+ currentStencilMask = stencilMask;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
|
|
|
+
|
|
|
+ if ( currentStencilFunc !== stencilFunc ||
|
|
|
+ currentStencilRef !== stencilRef ||
|
|
|
+ currentStencilFuncMask !== stencilMask ) {
|
|
|
+
|
|
|
+ gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
|
|
|
+
|
|
|
+ currentStencilFunc = stencilFunc;
|
|
|
+ currentStencilRef = stencilRef;
|
|
|
+ currentStencilFuncMask = stencilMask;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
|
|
|
+
|
|
|
+ if ( currentStencilFail !== stencilFail ||
|
|
|
+ currentStencilZFail !== stencilZFail ||
|
|
|
+ currentStencilZPass !== stencilZPass ) {
|
|
|
+
|
|
|
+ gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
|
|
|
+
|
|
|
+ currentStencilFail = stencilFail;
|
|
|
+ currentStencilZFail = stencilZFail;
|
|
|
+ currentStencilZPass = stencilZPass;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setLocked: function ( lock ) {
|
|
|
+
|
|
|
+ locked = lock;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setClear: function ( stencil ) {
|
|
|
+
|
|
|
+ if ( currentStencilClear !== stencil ) {
|
|
|
+
|
|
|
+ gl.clearStencil( stencil );
|
|
|
+ currentStencilClear = stencil;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ reset: function () {
|
|
|
+
|
|
|
+ locked = false;
|
|
|
+
|
|
|
+ currentStencilMask = null;
|
|
|
+ currentStencilFunc = null;
|
|
|
+ currentStencilRef = null;
|
|
|
+ currentStencilFuncMask = null;
|
|
|
+ currentStencilFail = null;
|
|
|
+ currentStencilZFail = null;
|
|
|
+ currentStencilZPass = null;
|
|
|
+ currentStencilClear = null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ var colorBuffer = new ColorBuffer();
|
|
|
+ var depthBuffer = new DepthBuffer();
|
|
|
+ var stencilBuffer = new StencilBuffer();
|
|
|
|
|
|
var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
|
|
|
var newAttributes = new Uint8Array( maxVertexAttributes );
|
|
@@ -76,25 +367,25 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
//
|
|
|
|
|
|
- this.init = function () {
|
|
|
+ function init() {
|
|
|
|
|
|
- this.clearColor( 0, 0, 0, 1 );
|
|
|
- this.clearDepth( 1 );
|
|
|
- this.clearStencil( 0 );
|
|
|
+ clearColor( 0, 0, 0, 1 );
|
|
|
+ clearDepth( 1 );
|
|
|
+ clearStencil( 0 );
|
|
|
|
|
|
- this.enable( gl.DEPTH_TEST );
|
|
|
- this.setDepthFunc( LessEqualDepth );
|
|
|
+ enable( gl.DEPTH_TEST );
|
|
|
+ setDepthFunc( LessEqualDepth );
|
|
|
|
|
|
- this.setFlipSided( false );
|
|
|
- this.setCullFace( CullFaceBack );
|
|
|
- this.enable( gl.CULL_FACE );
|
|
|
+ setFlipSided( false );
|
|
|
+ setCullFace( CullFaceBack );
|
|
|
+ enable( gl.CULL_FACE );
|
|
|
|
|
|
- this.enable( gl.BLEND );
|
|
|
- this.setBlending( NormalBlending );
|
|
|
+ enable( gl.BLEND );
|
|
|
+ setBlending( NormalBlending );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.initAttributes = function () {
|
|
|
+ function initAttributes() {
|
|
|
|
|
|
for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
|
|
|
|
|
@@ -102,9 +393,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.enableAttribute = function ( attribute ) {
|
|
|
+ function enableAttribute( attribute ) {
|
|
|
|
|
|
newAttributes[ attribute ] = 1;
|
|
|
|
|
@@ -124,9 +415,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
|
|
|
+ function enableAttributeAndDivisor( attribute, meshPerAttribute, extension ) {
|
|
|
|
|
|
newAttributes[ attribute ] = 1;
|
|
|
|
|
@@ -144,9 +435,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.disableUnusedAttributes = function () {
|
|
|
+ function disableUnusedAttributes() {
|
|
|
|
|
|
for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
|
|
|
|
|
@@ -159,9 +450,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.enable = function ( id ) {
|
|
|
+ function enable( id ) {
|
|
|
|
|
|
if ( capabilities[ id ] !== true ) {
|
|
|
|
|
@@ -170,9 +461,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.disable = function ( id ) {
|
|
|
+ function disable( id ) {
|
|
|
|
|
|
if ( capabilities[ id ] !== false ) {
|
|
|
|
|
@@ -181,9 +472,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.getCompressedTextureFormats = function () {
|
|
|
+ function getCompressedTextureFormats() {
|
|
|
|
|
|
if ( compressedTextureFormats === null ) {
|
|
|
|
|
@@ -207,17 +498,17 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
return compressedTextureFormats;
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
|
|
|
+ function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
|
|
|
|
|
|
if ( blending !== NoBlending ) {
|
|
|
|
|
|
- this.enable( gl.BLEND );
|
|
|
+ enable( gl.BLEND );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- this.disable( gl.BLEND );
|
|
|
+ disable( gl.BLEND );
|
|
|
currentBlending = blending; // no blending, that is
|
|
|
return;
|
|
|
|
|
@@ -325,61 +616,61 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
// TODO Deprecate
|
|
|
|
|
|
- this.setColorWrite = function ( colorWrite ) {
|
|
|
+ function setColorWrite( colorWrite ) {
|
|
|
|
|
|
- this.buffers.color.setMask( colorWrite );
|
|
|
+ colorBuffer.setMask( colorWrite );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setDepthTest = function ( depthTest ) {
|
|
|
+ function setDepthTest( depthTest ) {
|
|
|
|
|
|
- this.buffers.depth.setTest( depthTest );
|
|
|
+ depthBuffer.setTest( depthTest );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setDepthWrite = function ( depthWrite ) {
|
|
|
+ function setDepthWrite( depthWrite ) {
|
|
|
|
|
|
- this.buffers.depth.setMask( depthWrite );
|
|
|
+ depthBuffer.setMask( depthWrite );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setDepthFunc = function ( depthFunc ) {
|
|
|
+ function setDepthFunc( depthFunc ) {
|
|
|
|
|
|
- this.buffers.depth.setFunc( depthFunc );
|
|
|
+ depthBuffer.setFunc( depthFunc );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setStencilTest = function ( stencilTest ) {
|
|
|
+ function setStencilTest( stencilTest ) {
|
|
|
|
|
|
- this.buffers.stencil.setTest( stencilTest );
|
|
|
+ stencilBuffer.setTest( stencilTest );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setStencilWrite = function ( stencilWrite ) {
|
|
|
+ function setStencilWrite( stencilWrite ) {
|
|
|
|
|
|
- this.buffers.stencil.setMask( stencilWrite );
|
|
|
+ stencilBuffer.setMask( stencilWrite );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
|
|
|
+ function setStencilFunc( stencilFunc, stencilRef, stencilMask ) {
|
|
|
|
|
|
- this.buffers.stencil.setFunc( stencilFunc, stencilRef, stencilMask );
|
|
|
+ stencilBuffer.setFunc( stencilFunc, stencilRef, stencilMask );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
|
|
|
+ function setStencilOp( stencilFail, stencilZFail, stencilZPass ) {
|
|
|
|
|
|
- this.buffers.stencil.setOp( stencilFail, stencilZFail, stencilZPass );
|
|
|
+ stencilBuffer.setOp( stencilFail, stencilZFail, stencilZPass );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
//
|
|
|
|
|
|
- this.setFlipSided = function ( flipSided ) {
|
|
|
+ function setFlipSided( flipSided ) {
|
|
|
|
|
|
if ( currentFlipSided !== flipSided ) {
|
|
|
|
|
@@ -397,13 +688,13 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setCullFace = function ( cullFace ) {
|
|
|
+ function setCullFace( cullFace ) {
|
|
|
|
|
|
if ( cullFace !== CullFaceNone ) {
|
|
|
|
|
|
- this.enable( gl.CULL_FACE );
|
|
|
+ enable( gl.CULL_FACE );
|
|
|
|
|
|
if ( cullFace !== currentCullFace ) {
|
|
|
|
|
@@ -425,15 +716,15 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- this.disable( gl.CULL_FACE );
|
|
|
+ disable( gl.CULL_FACE );
|
|
|
|
|
|
}
|
|
|
|
|
|
currentCullFace = cullFace;
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setLineWidth = function ( width ) {
|
|
|
+ function setLineWidth( width ) {
|
|
|
|
|
|
if ( width !== currentLineWidth ) {
|
|
|
|
|
@@ -443,13 +734,13 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setPolygonOffset = function ( polygonOffset, factor, units ) {
|
|
|
+ function setPolygonOffset( polygonOffset, factor, units ) {
|
|
|
|
|
|
if ( polygonOffset ) {
|
|
|
|
|
|
- this.enable( gl.POLYGON_OFFSET_FILL );
|
|
|
+ enable( gl.POLYGON_OFFSET_FILL );
|
|
|
|
|
|
if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
|
|
|
|
|
@@ -462,37 +753,37 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- this.disable( gl.POLYGON_OFFSET_FILL );
|
|
|
+ disable( gl.POLYGON_OFFSET_FILL );
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.getScissorTest = function () {
|
|
|
+ function getScissorTest() {
|
|
|
|
|
|
return currentScissorTest;
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setScissorTest = function ( scissorTest ) {
|
|
|
+ function setScissorTest( scissorTest ) {
|
|
|
|
|
|
currentScissorTest = scissorTest;
|
|
|
|
|
|
if ( scissorTest ) {
|
|
|
|
|
|
- this.enable( gl.SCISSOR_TEST );
|
|
|
+ enable( gl.SCISSOR_TEST );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- this.disable( gl.SCISSOR_TEST );
|
|
|
+ disable( gl.SCISSOR_TEST );
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
// texture
|
|
|
|
|
|
- this.activeTexture = function ( webglSlot ) {
|
|
|
+ function activeTexture( webglSlot ) {
|
|
|
|
|
|
if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
|
|
|
|
|
@@ -503,13 +794,13 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.bindTexture = function ( webglType, webglTexture ) {
|
|
|
+ function bindTexture( webglType, webglTexture ) {
|
|
|
|
|
|
if ( currentTextureSlot === null ) {
|
|
|
|
|
|
- _this.activeTexture();
|
|
|
+ activeTexture();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -531,9 +822,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.compressedTexImage2D = function () {
|
|
|
+ function compressedTexImage2D() {
|
|
|
|
|
|
try {
|
|
|
|
|
@@ -545,9 +836,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.texImage2D = function () {
|
|
|
+ function texImage2D() {
|
|
|
|
|
|
try {
|
|
|
|
|
@@ -559,31 +850,31 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
// TODO Deprecate
|
|
|
|
|
|
- this.clearColor = function ( r, g, b, a ) {
|
|
|
+ function clearColor( r, g, b, a ) {
|
|
|
|
|
|
- this.buffers.color.setClear( r, g, b, a );
|
|
|
+ colorBuffer.setClear( r, g, b, a );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.clearDepth = function ( depth ) {
|
|
|
+ function clearDepth( depth ) {
|
|
|
|
|
|
- this.buffers.depth.setClear( depth );
|
|
|
+ depthBuffer.setClear( depth );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.clearStencil = function ( stencil ) {
|
|
|
+ function clearStencil( stencil ) {
|
|
|
|
|
|
- this.buffers.stencil.setClear( stencil );
|
|
|
+ stencilBuffer.setClear( stencil );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
//
|
|
|
|
|
|
- this.scissor = function ( scissor ) {
|
|
|
+ function scissor( scissor ) {
|
|
|
|
|
|
if ( currentScissor.equals( scissor ) === false ) {
|
|
|
|
|
@@ -592,9 +883,9 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.viewport = function ( viewport ) {
|
|
|
+ function viewport( viewport ) {
|
|
|
|
|
|
if ( currentViewport.equals( viewport ) === false ) {
|
|
|
|
|
@@ -603,11 +894,11 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
//
|
|
|
|
|
|
- this.reset = function () {
|
|
|
+ function reset() {
|
|
|
|
|
|
for ( var i = 0; i < enabledAttributes.length; i ++ ) {
|
|
|
|
|
@@ -632,294 +923,66 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
currentFlipSided = null;
|
|
|
currentCullFace = null;
|
|
|
|
|
|
- this.buffers.color.reset();
|
|
|
- this.buffers.depth.reset();
|
|
|
- this.buffers.stencil.reset();
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
-};
|
|
|
-
|
|
|
-function WebGLColorBuffer( gl, state ) {
|
|
|
-
|
|
|
- var locked = false;
|
|
|
-
|
|
|
- var color = new Vector4();
|
|
|
- var currentColorMask = null;
|
|
|
- var currentColorClear = new Vector4();
|
|
|
-
|
|
|
- this.setMask = function ( colorMask ) {
|
|
|
-
|
|
|
- if ( currentColorMask !== colorMask && ! locked ) {
|
|
|
-
|
|
|
- gl.colorMask( colorMask, colorMask, colorMask, colorMask );
|
|
|
- currentColorMask = colorMask;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setLocked = function ( lock ) {
|
|
|
-
|
|
|
- locked = lock;
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setClear = function ( r, g, b, a ) {
|
|
|
-
|
|
|
- color.set( r, g, b, a );
|
|
|
-
|
|
|
- if ( currentColorClear.equals( color ) === false ) {
|
|
|
-
|
|
|
- gl.clearColor( r, g, b, a );
|
|
|
- currentColorClear.copy( color );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.reset = function () {
|
|
|
-
|
|
|
- locked = false;
|
|
|
-
|
|
|
- currentColorMask = null;
|
|
|
- currentColorClear.set( 0, 0, 0, 1 );
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-function WebGLDepthBuffer( gl, state ) {
|
|
|
-
|
|
|
- var locked = false;
|
|
|
-
|
|
|
- var currentDepthMask = null;
|
|
|
- var currentDepthFunc = null;
|
|
|
- var currentDepthClear = null;
|
|
|
-
|
|
|
- this.setTest = function ( depthTest ) {
|
|
|
-
|
|
|
- if ( depthTest ) {
|
|
|
-
|
|
|
- state.enable( gl.DEPTH_TEST );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- state.disable( gl.DEPTH_TEST );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setMask = function( depthMask ){
|
|
|
-
|
|
|
- if ( currentDepthMask !== depthMask && ! locked ) {
|
|
|
-
|
|
|
- gl.depthMask( depthMask );
|
|
|
- currentDepthMask = depthMask;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setFunc = function ( depthFunc ) {
|
|
|
-
|
|
|
- if ( currentDepthFunc !== depthFunc ) {
|
|
|
-
|
|
|
- if ( depthFunc ) {
|
|
|
+ colorBuffer.reset();
|
|
|
+ depthBuffer.reset();
|
|
|
+ stencilBuffer.reset();
|
|
|
|
|
|
- switch ( depthFunc ) {
|
|
|
-
|
|
|
- case NeverDepth:
|
|
|
-
|
|
|
- gl.depthFunc( gl.NEVER );
|
|
|
- break;
|
|
|
-
|
|
|
- case AlwaysDepth:
|
|
|
-
|
|
|
- gl.depthFunc( gl.ALWAYS );
|
|
|
- break;
|
|
|
-
|
|
|
- case LessDepth:
|
|
|
-
|
|
|
- gl.depthFunc( gl.LESS );
|
|
|
- break;
|
|
|
-
|
|
|
- case LessEqualDepth:
|
|
|
-
|
|
|
- gl.depthFunc( gl.LEQUAL );
|
|
|
- break;
|
|
|
-
|
|
|
- case EqualDepth:
|
|
|
-
|
|
|
- gl.depthFunc( gl.EQUAL );
|
|
|
- break;
|
|
|
-
|
|
|
- case GreaterEqualDepth:
|
|
|
-
|
|
|
- gl.depthFunc( gl.GEQUAL );
|
|
|
- break;
|
|
|
-
|
|
|
- case GreaterDepth:
|
|
|
-
|
|
|
- gl.depthFunc( gl.GREATER );
|
|
|
- break;
|
|
|
-
|
|
|
- case NotEqualDepth:
|
|
|
-
|
|
|
- gl.depthFunc( gl.NOTEQUAL );
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
-
|
|
|
- gl.depthFunc( gl.LEQUAL );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- gl.depthFunc( gl.LEQUAL );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- currentDepthFunc = depthFunc;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setLocked = function ( lock ) {
|
|
|
-
|
|
|
- locked = lock;
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setClear = function ( depth ) {
|
|
|
-
|
|
|
- if ( currentDepthClear !== depth ) {
|
|
|
-
|
|
|
- gl.clearDepth( depth );
|
|
|
- currentDepthClear = depth;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.reset = function () {
|
|
|
-
|
|
|
- locked = false;
|
|
|
-
|
|
|
- currentDepthMask = null;
|
|
|
- currentDepthFunc = null;
|
|
|
- currentDepthClear = null;
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
-};
|
|
|
-
|
|
|
-function WebGLStencilBuffer( gl, state ) {
|
|
|
-
|
|
|
- var locked = false;
|
|
|
-
|
|
|
- var currentStencilMask = null;
|
|
|
- var currentStencilFunc = null;
|
|
|
- var currentStencilRef = null;
|
|
|
- var currentStencilFuncMask = null;
|
|
|
- var currentStencilFail = null;
|
|
|
- var currentStencilZFail = null;
|
|
|
- var currentStencilZPass = null;
|
|
|
- var currentStencilClear = null;
|
|
|
-
|
|
|
- this.setTest = function ( stencilTest ) {
|
|
|
-
|
|
|
- if ( stencilTest ) {
|
|
|
-
|
|
|
- state.enable( gl.STENCIL_TEST );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- state.disable( gl.STENCIL_TEST );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setMask = function ( stencilMask ) {
|
|
|
-
|
|
|
- if ( currentStencilMask !== stencilMask && ! locked ) {
|
|
|
-
|
|
|
- gl.stencilMask( stencilMask );
|
|
|
- currentStencilMask = stencilMask;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setFunc = function ( stencilFunc, stencilRef, stencilMask ) {
|
|
|
-
|
|
|
- if ( currentStencilFunc !== stencilFunc ||
|
|
|
- currentStencilRef !== stencilRef ||
|
|
|
- currentStencilFuncMask !== stencilMask ) {
|
|
|
-
|
|
|
- gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
|
|
|
-
|
|
|
- currentStencilFunc = stencilFunc;
|
|
|
- currentStencilRef = stencilRef;
|
|
|
- currentStencilFuncMask = stencilMask;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setOp = function ( stencilFail, stencilZFail, stencilZPass ) {
|
|
|
-
|
|
|
- if ( currentStencilFail !== stencilFail ||
|
|
|
- currentStencilZFail !== stencilZFail ||
|
|
|
- currentStencilZPass !== stencilZPass ) {
|
|
|
-
|
|
|
- gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
|
|
|
-
|
|
|
- currentStencilFail = stencilFail;
|
|
|
- currentStencilZFail = stencilZFail;
|
|
|
- currentStencilZPass = stencilZPass;
|
|
|
-
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- };
|
|
|
+ return {
|
|
|
|
|
|
- this.setLocked = function ( lock ) {
|
|
|
+ buffers: {
|
|
|
+ color: colorBuffer,
|
|
|
+ depth: depthBuffer,
|
|
|
+ stencil: stencilBuffer
|
|
|
+ },
|
|
|
|
|
|
- locked = lock;
|
|
|
+ init: init,
|
|
|
+ initAttributes: initAttributes,
|
|
|
+ enableAttribute: enableAttribute,
|
|
|
+ enableAttributeAndDivisor: enableAttributeAndDivisor,
|
|
|
+ disableUnusedAttributes: disableUnusedAttributes,
|
|
|
+ enable: enable,
|
|
|
+ disable: disable,
|
|
|
+ getCompressedTextureFormats: getCompressedTextureFormats,
|
|
|
|
|
|
- };
|
|
|
+ setBlending: setBlending,
|
|
|
|
|
|
- this.setClear = function ( stencil ) {
|
|
|
+ setColorWrite: setColorWrite,
|
|
|
+ setDepthTest: setDepthTest,
|
|
|
+ setDepthWrite: setDepthWrite,
|
|
|
+ setDepthFunc: setDepthFunc,
|
|
|
+ setStencilTest: setStencilTest,
|
|
|
+ setStencilWrite: setStencilWrite,
|
|
|
+ setStencilFunc: setStencilFunc,
|
|
|
+ setStencilOp: setStencilOp,
|
|
|
|
|
|
- if ( currentStencilClear !== stencil ) {
|
|
|
+ setFlipSided: setFlipSided,
|
|
|
+ setCullFace: setCullFace,
|
|
|
|
|
|
- gl.clearStencil( stencil );
|
|
|
- currentStencilClear = stencil;
|
|
|
+ setLineWidth: setLineWidth,
|
|
|
+ setPolygonOffset: setPolygonOffset,
|
|
|
|
|
|
- }
|
|
|
+ getScissorTest: getScissorTest,
|
|
|
+ setScissorTest: setScissorTest,
|
|
|
|
|
|
- };
|
|
|
+ activeTexture: activeTexture,
|
|
|
+ bindTexture: bindTexture,
|
|
|
+ compressedTexImage2D: compressedTexImage2D,
|
|
|
+ texImage2D: texImage2D,
|
|
|
|
|
|
- this.reset = function () {
|
|
|
+ clearColor: clearColor,
|
|
|
+ clearDepth: clearDepth,
|
|
|
+ clearStencil: clearStencil,
|
|
|
|
|
|
- locked = false;
|
|
|
+ scissor: scissor,
|
|
|
+ viewport: viewport,
|
|
|
|
|
|
- currentStencilMask = null;
|
|
|
- currentStencilFunc = null;
|
|
|
- currentStencilRef = null;
|
|
|
- currentStencilFuncMask = null;
|
|
|
- currentStencilFail = null;
|
|
|
- currentStencilZFail = null;
|
|
|
- currentStencilZPass = null;
|
|
|
- currentStencilClear = null;
|
|
|
+ reset: reset
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
-export { WebGLStencilBuffer, WebGLDepthBuffer, WebGLColorBuffer, WebGLState };
|
|
|
+export { WebGLState };
|