Skip to content

Commit 148d755

Browse files
committed
WebGLState: Implement true reset.
1 parent dc2b340 commit 148d755

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/renderers/webgl/WebGLState.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function WebGLState( gl, extensions, capabilities ) {
318318

319319
let currentProgram = null;
320320

321-
let currentBlendingEnabled = null;
321+
let currentBlendingEnabled = false;
322322
let currentBlending = null;
323323
let currentBlendEquation = null;
324324
let currentBlendSrc = null;
@@ -480,7 +480,7 @@ function WebGLState( gl, extensions, capabilities ) {
480480

481481
if ( blending === NoBlending ) {
482482

483-
if ( currentBlendingEnabled ) {
483+
if ( currentBlendingEnabled === true ) {
484484

485485
disable( gl.BLEND );
486486
currentBlendingEnabled = false;
@@ -491,7 +491,7 @@ function WebGLState( gl, extensions, capabilities ) {
491491

492492
}
493493

494-
if ( ! currentBlendingEnabled ) {
494+
if ( currentBlendingEnabled === false ) {
495495

496496
enable( gl.BLEND );
497497
currentBlendingEnabled = true;
@@ -877,14 +877,46 @@ function WebGLState( gl, extensions, capabilities ) {
877877

878878
function reset() {
879879

880+
// reset state
881+
882+
gl.disable( gl.BLEND );
883+
gl.disable( gl.CULL_FACE );
884+
gl.disable( gl.DEPTH_TEST );
885+
gl.disable( gl.POLYGON_OFFSET_FILL );
886+
gl.disable( gl.SCISSOR_TEST );
887+
gl.disable( gl.STENCIL_TEST );
888+
889+
gl.blendEquation( gl.FUNC_ADD );
890+
gl.blendFunc( gl.ONE, gl.ZERO );
891+
gl.blendFuncSeparate( gl.ONE, gl.ZERO, gl.ONE, gl.ZERO );
892+
893+
gl.colorMask( true, true, true, true );
894+
gl.clearColor( 0, 0, 0, 0 );
895+
896+
gl.depthMask( true );
897+
gl.depthFunc( gl.LESS );
898+
gl.clearDepth( 1 );
899+
900+
gl.stencilMask( 0xffffffff );
901+
gl.stencilFunc( gl.ALWAYS, 0, 1 );
902+
gl.stencilOp( gl.KEEP, gl.KEEP, gl.KEEP );
903+
gl.clearStencil( 0 );
904+
905+
gl.cullFace( gl.BACK );
906+
gl.frontFace( gl.CCW );
907+
908+
gl.polygonOffset( 0, 0 );
909+
910+
// reset internals
911+
880912
enabledCapabilities = {};
881913

882914
currentTextureSlot = null;
883915
currentBoundTextures = {};
884916

885917
currentProgram = null;
886918

887-
currentBlendingEnabled = null;
919+
currentBlendingEnabled = false;
888920
currentBlending = null;
889921
currentBlendEquation = null;
890922
currentBlendSrc = null;

0 commit comments

Comments
 (0)