Browse Source

Add stencil parameter and constants

Garrett Johnson 6 years ago
parent
commit
4ef4b6d878
3 changed files with 32 additions and 0 deletions
  1. 20 0
      src/constants.js
  2. 2 0
      src/materials/Material.js
  3. 10 0
      src/renderers/webgl/WebGLState.js

+ 20 - 0
src/constants.js

@@ -142,3 +142,23 @@ export var BasicDepthPacking = 3200;
 export var RGBADepthPacking = 3201;
 export var TangentSpaceNormalMap = 0;
 export var ObjectSpaceNormalMap = 1;
+
+// StencilOp
+export var ZERO = 0;
+export var KEEP = 7680;
+export var REPLACE = 7681;
+export var INCR = 7682;
+export var DECR = 7683;
+export var INCR_WRAP = 34055;
+export var DECR_WRAP = 34056;
+export var INVERT = 5386;
+
+// StencilFunc
+export var NEVER = 512;
+export var LESS = 513;
+export var EQUAL = 514;
+export var LEQUAL = 515;
+export var GREATER = 516;
+export var NOTEQUAL = 517;
+export var GEQUAL = 518;
+export var ALWAYS = 519;

+ 2 - 0
src/materials/Material.js

@@ -40,6 +40,8 @@ function Material() {
 	this.depthTest = true;
 	this.depthWrite = true;
 
+	this.stencil = null;
+
 	this.clippingPlanes = null;
 	this.clipIntersection = false;
 	this.clipShadows = false;

+ 10 - 0
src/renderers/webgl/WebGLState.js

@@ -677,6 +677,16 @@ function WebGLState( gl, extensions, utils, capabilities ) {
 		depthBuffer.setMask( material.depthWrite );
 		colorBuffer.setMask( material.colorWrite );
 
+		var stencil = material.stencil;
+		var useStencil = stencil !== null;
+		stencilBuffer.setTest( useStencil );
+		if ( useStencil ) {
+
+			stencilBuffer.setFunc( stencil.func, stencil.ref, stencil.mask );
+			stencilBuffer.setOp( stencil.fail, stencil.zfail, stencil.zpass );
+
+		}
+
 		setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
 
 	}