WebGLState.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  5. var _this = this;
  6. this.buffers = {
  7. color: new THREE.WebGLColorBuffer( gl, this ),
  8. depth: new THREE.WebGLDepthBuffer( gl, this ),
  9. stencil: new THREE.WebGLStencilBuffer( gl, this )
  10. };
  11. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  12. var newAttributes = new Uint8Array( maxVertexAttributes );
  13. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  14. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  15. var capabilities = {};
  16. var compressedTextureFormats = null;
  17. var currentBlending = null;
  18. var currentBlendEquation = null;
  19. var currentBlendSrc = null;
  20. var currentBlendDst = null;
  21. var currentBlendEquationAlpha = null;
  22. var currentBlendSrcAlpha = null;
  23. var currentBlendDstAlpha = null;
  24. var currentPremultipledAlpha = false;
  25. var currentFlipSided = null;
  26. var currentCullFace = null;
  27. var currentLineWidth = null;
  28. var currentPolygonOffsetFactor = null;
  29. var currentPolygonOffsetUnits = null;
  30. var currentScissorTest = null;
  31. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  32. var currentTextureSlot = null;
  33. var currentBoundTextures = {};
  34. var currentScissor = new THREE.Vector4();
  35. var currentViewport = new THREE.Vector4();
  36. function createTexture( type, target, count ) {
  37. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  38. var texture = gl.createTexture();
  39. gl.bindTexture( type, texture );
  40. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  41. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  42. for ( var i = 0; i < count; i ++ ) {
  43. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  44. }
  45. return texture;
  46. }
  47. var emptyTextures = {};
  48. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  49. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  50. //
  51. this.init = function () {
  52. this.clearColor( 0, 0, 0, 1 );
  53. this.clearDepth( 1 );
  54. this.clearStencil( 0 );
  55. this.enable( gl.DEPTH_TEST );
  56. this.setDepthFunc( THREE.LessEqualDepth );
  57. this.setFlipSided( false );
  58. this.setCullFace( THREE.CullFaceBack );
  59. this.enable( gl.CULL_FACE );
  60. this.enable( gl.BLEND );
  61. this.setBlending( THREE.NormalBlending );
  62. };
  63. this.initAttributes = function () {
  64. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  65. newAttributes[ i ] = 0;
  66. }
  67. };
  68. this.enableAttribute = function ( attribute ) {
  69. newAttributes[ attribute ] = 1;
  70. if ( enabledAttributes[ attribute ] === 0 ) {
  71. gl.enableVertexAttribArray( attribute );
  72. enabledAttributes[ attribute ] = 1;
  73. }
  74. if ( attributeDivisors[ attribute ] !== 0 ) {
  75. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  76. extension.vertexAttribDivisorANGLE( attribute, 0 );
  77. attributeDivisors[ attribute ] = 0;
  78. }
  79. };
  80. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  81. newAttributes[ attribute ] = 1;
  82. if ( enabledAttributes[ attribute ] === 0 ) {
  83. gl.enableVertexAttribArray( attribute );
  84. enabledAttributes[ attribute ] = 1;
  85. }
  86. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  87. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  88. attributeDivisors[ attribute ] = meshPerAttribute;
  89. }
  90. };
  91. this.disableUnusedAttributes = function () {
  92. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  93. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  94. gl.disableVertexAttribArray( i );
  95. enabledAttributes[ i ] = 0;
  96. }
  97. }
  98. };
  99. this.enable = function ( id ) {
  100. if ( capabilities[ id ] !== true ) {
  101. gl.enable( id );
  102. capabilities[ id ] = true;
  103. }
  104. };
  105. this.disable = function ( id ) {
  106. if ( capabilities[ id ] !== false ) {
  107. gl.disable( id );
  108. capabilities[ id ] = false;
  109. }
  110. };
  111. this.getCompressedTextureFormats = function () {
  112. if ( compressedTextureFormats === null ) {
  113. compressedTextureFormats = [];
  114. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  115. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  116. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  117. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  118. for ( var i = 0; i < formats.length; i ++ ) {
  119. compressedTextureFormats.push( formats[ i ] );
  120. }
  121. }
  122. }
  123. return compressedTextureFormats;
  124. };
  125. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  126. if ( blending !== THREE.NoBlending ) {
  127. this.enable( gl.BLEND );
  128. } else {
  129. this.disable( gl.BLEND );
  130. currentBlending = blending; // no blending, that is
  131. return;
  132. }
  133. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  134. if ( blending === THREE.AdditiveBlending ) {
  135. if ( premultipliedAlpha ) {
  136. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  137. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  138. } else {
  139. gl.blendEquation( gl.FUNC_ADD );
  140. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  141. }
  142. } else if ( blending === THREE.SubtractiveBlending ) {
  143. if ( premultipliedAlpha ) {
  144. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  145. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  146. } else {
  147. gl.blendEquation( gl.FUNC_ADD );
  148. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  149. }
  150. } else if ( blending === THREE.MultiplyBlending ) {
  151. if ( premultipliedAlpha ) {
  152. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  153. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  154. } else {
  155. gl.blendEquation( gl.FUNC_ADD );
  156. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  157. }
  158. } else {
  159. if ( premultipliedAlpha ) {
  160. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  161. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  162. } else {
  163. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  164. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  165. }
  166. }
  167. currentBlending = blending;
  168. currentPremultipledAlpha = premultipliedAlpha;
  169. }
  170. if ( blending === THREE.CustomBlending ) {
  171. blendEquationAlpha = blendEquationAlpha || blendEquation;
  172. blendSrcAlpha = blendSrcAlpha || blendSrc;
  173. blendDstAlpha = blendDstAlpha || blendDst;
  174. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  175. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  176. currentBlendEquation = blendEquation;
  177. currentBlendEquationAlpha = blendEquationAlpha;
  178. }
  179. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  180. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  181. currentBlendSrc = blendSrc;
  182. currentBlendDst = blendDst;
  183. currentBlendSrcAlpha = blendSrcAlpha;
  184. currentBlendDstAlpha = blendDstAlpha;
  185. }
  186. } else {
  187. currentBlendEquation = null;
  188. currentBlendSrc = null;
  189. currentBlendDst = null;
  190. currentBlendEquationAlpha = null;
  191. currentBlendSrcAlpha = null;
  192. currentBlendDstAlpha = null;
  193. }
  194. };
  195. // TODO Deprecate
  196. this.setColorWrite = function ( colorWrite ) {
  197. this.buffers.color.setMask( colorWrite );
  198. };
  199. this.setDepthTest = function ( depthTest ) {
  200. this.buffers.depth.setTest( depthTest );
  201. };
  202. this.setDepthWrite = function ( depthWrite ) {
  203. this.buffers.depth.setMask( depthWrite );
  204. };
  205. this.setDepthFunc = function ( depthFunc ) {
  206. this.buffers.depth.setFunc( depthFunc );
  207. };
  208. this.setStencilTest = function ( stencilTest ) {
  209. this.buffers.stencil.setTest( stencilTest );
  210. };
  211. this.setStencilWrite = function ( stencilWrite ) {
  212. this.buffers.stencil.setMask( stencilWrite );
  213. };
  214. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  215. this.buffers.stencil.setFunc( stencilFunc, stencilRef, stencilMask );
  216. };
  217. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  218. this.buffers.stencil.setOp( stencilFail, stencilZFail, stencilZPass );
  219. };
  220. //
  221. this.setFlipSided = function ( flipSided ) {
  222. if ( currentFlipSided !== flipSided ) {
  223. if ( flipSided ) {
  224. gl.frontFace( gl.CW );
  225. } else {
  226. gl.frontFace( gl.CCW );
  227. }
  228. currentFlipSided = flipSided;
  229. }
  230. };
  231. this.setCullFace = function ( cullFace ) {
  232. if ( cullFace !== THREE.CullFaceNone ) {
  233. this.enable( gl.CULL_FACE );
  234. if ( cullFace !== currentCullFace ) {
  235. if ( cullFace === THREE.CullFaceBack ) {
  236. gl.cullFace( gl.BACK );
  237. } else if ( cullFace === THREE.CullFaceFront ) {
  238. gl.cullFace( gl.FRONT );
  239. } else {
  240. gl.cullFace( gl.FRONT_AND_BACK );
  241. }
  242. }
  243. } else {
  244. this.disable( gl.CULL_FACE );
  245. }
  246. currentCullFace = cullFace;
  247. };
  248. this.setLineWidth = function ( width ) {
  249. if ( width !== currentLineWidth ) {
  250. gl.lineWidth( width );
  251. currentLineWidth = width;
  252. }
  253. };
  254. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  255. if ( polygonOffset ) {
  256. this.enable( gl.POLYGON_OFFSET_FILL );
  257. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  258. gl.polygonOffset( factor, units );
  259. currentPolygonOffsetFactor = factor;
  260. currentPolygonOffsetUnits = units;
  261. }
  262. } else {
  263. this.disable( gl.POLYGON_OFFSET_FILL );
  264. }
  265. };
  266. this.getScissorTest = function () {
  267. return currentScissorTest;
  268. };
  269. this.setScissorTest = function ( scissorTest ) {
  270. currentScissorTest = scissorTest;
  271. if ( scissorTest ) {
  272. this.enable( gl.SCISSOR_TEST );
  273. } else {
  274. this.disable( gl.SCISSOR_TEST );
  275. }
  276. };
  277. // texture
  278. this.activeTexture = function ( webglSlot ) {
  279. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  280. if ( currentTextureSlot !== webglSlot ) {
  281. gl.activeTexture( webglSlot );
  282. currentTextureSlot = webglSlot;
  283. }
  284. };
  285. this.bindTexture = function ( webglType, webglTexture ) {
  286. if ( currentTextureSlot === null ) {
  287. _this.activeTexture();
  288. }
  289. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  290. if ( boundTexture === undefined ) {
  291. boundTexture = { type: undefined, texture: undefined };
  292. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  293. }
  294. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  295. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  296. boundTexture.type = webglType;
  297. boundTexture.texture = webglTexture;
  298. }
  299. };
  300. this.compressedTexImage2D = function () {
  301. try {
  302. gl.compressedTexImage2D.apply( gl, arguments );
  303. } catch ( error ) {
  304. console.error( error );
  305. }
  306. };
  307. this.texImage2D = function () {
  308. try {
  309. gl.texImage2D.apply( gl, arguments );
  310. } catch ( error ) {
  311. console.error( error );
  312. }
  313. };
  314. // TODO Deprecate
  315. this.clearColor = function ( r, g, b, a ) {
  316. this.buffers.color.setClear( r, g, b, a );
  317. };
  318. this.clearDepth = function ( depth ) {
  319. this.buffers.depth.setClear( depth );
  320. };
  321. this.clearStencil = function ( stencil ) {
  322. this.buffers.stencil.setClear( stencil );
  323. };
  324. //
  325. this.scissor = function ( scissor ) {
  326. if ( currentScissor.equals( scissor ) === false ) {
  327. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  328. currentScissor.copy( scissor );
  329. }
  330. };
  331. this.viewport = function ( viewport ) {
  332. if ( currentViewport.equals( viewport ) === false ) {
  333. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  334. currentViewport.copy( viewport );
  335. }
  336. };
  337. //
  338. this.reset = function () {
  339. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  340. if ( enabledAttributes[ i ] === 1 ) {
  341. gl.disableVertexAttribArray( i );
  342. enabledAttributes[ i ] = 0;
  343. }
  344. }
  345. capabilities = {};
  346. compressedTextureFormats = null;
  347. currentTextureSlot = null;
  348. currentBoundTextures = {};
  349. currentBlending = null;
  350. currentFlipSided = null;
  351. currentCullFace = null;
  352. this.buffers.color.reset();
  353. this.buffers.depth.reset();
  354. this.buffers.stencil.reset();
  355. };
  356. };
  357. THREE.WebGLColorBuffer = function ( gl, state ) {
  358. var locked = false;
  359. var color = new THREE.Vector4();
  360. var currentColorMask = null;
  361. var currentColorClear = new THREE.Vector4();
  362. this.setMask = function ( colorMask ) {
  363. if ( currentColorMask !== colorMask && ! locked ) {
  364. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  365. currentColorMask = colorMask;
  366. }
  367. };
  368. this.setLocked = function ( lock ) {
  369. locked = lock;
  370. };
  371. this.setClear = function ( r, g, b, a ) {
  372. color.set( r, g, b, a );
  373. if ( currentColorClear.equals( color ) === false ) {
  374. gl.clearColor( r, g, b, a );
  375. currentColorClear.copy( color );
  376. }
  377. };
  378. this.reset = function () {
  379. locked = false;
  380. currentColorMask = null;
  381. currentColorClear = new THREE.Vector4();
  382. };
  383. };
  384. THREE.WebGLDepthBuffer = function( gl, state ) {
  385. var locked = false;
  386. var currentDepthMask = null;
  387. var currentDepthFunc = null;
  388. var currentDepthClear = null;
  389. this.setTest = function ( depthTest ) {
  390. if ( depthTest ) {
  391. state.enable( gl.DEPTH_TEST );
  392. } else {
  393. state.disable( gl.DEPTH_TEST );
  394. }
  395. };
  396. this.setMask = function( depthMask ){
  397. if ( currentDepthMask !== depthMask && ! locked ) {
  398. gl.depthMask( depthMask );
  399. currentDepthMask = depthMask;
  400. }
  401. };
  402. this.setFunc = function ( depthFunc ) {
  403. if ( currentDepthFunc !== depthFunc ) {
  404. if ( depthFunc ) {
  405. switch ( depthFunc ) {
  406. case THREE.NeverDepth:
  407. gl.depthFunc( gl.NEVER );
  408. break;
  409. case THREE.AlwaysDepth:
  410. gl.depthFunc( gl.ALWAYS );
  411. break;
  412. case THREE.LessDepth:
  413. gl.depthFunc( gl.LESS );
  414. break;
  415. case THREE.LessEqualDepth:
  416. gl.depthFunc( gl.LEQUAL );
  417. break;
  418. case THREE.EqualDepth:
  419. gl.depthFunc( gl.EQUAL );
  420. break;
  421. case THREE.GreaterEqualDepth:
  422. gl.depthFunc( gl.GEQUAL );
  423. break;
  424. case THREE.GreaterDepth:
  425. gl.depthFunc( gl.GREATER );
  426. break;
  427. case THREE.NotEqualDepth:
  428. gl.depthFunc( gl.NOTEQUAL );
  429. break;
  430. default:
  431. gl.depthFunc( gl.LEQUAL );
  432. }
  433. } else {
  434. gl.depthFunc( gl.LEQUAL );
  435. }
  436. currentDepthFunc = depthFunc;
  437. }
  438. };
  439. this.setLocked = function ( lock ) {
  440. locked = lock;
  441. };
  442. this.setClear = function ( depth ) {
  443. if ( currentDepthClear !== depth ) {
  444. gl.clearDepth( depth );
  445. currentDepthClear = depth;
  446. }
  447. };
  448. this.reset = function () {
  449. locked = false;
  450. currentDepthMask = null;
  451. currentDepthFunc = null;
  452. currentDepthClear = null;
  453. };
  454. };
  455. THREE.WebGLStencilBuffer = function ( gl, state ) {
  456. var locked = false;
  457. var currentStencilMask = null;
  458. var currentStencilFunc = null;
  459. var currentStencilRef = null;
  460. var currentStencilFuncMask = null;
  461. var currentStencilFail = null;
  462. var currentStencilZFail = null;
  463. var currentStencilZPass = null;
  464. var currentStencilClear = null;
  465. this.setTest = function ( stencilTest ) {
  466. if ( stencilTest ) {
  467. state.enable( gl.STENCIL_TEST );
  468. } else {
  469. state.disable( gl.STENCIL_TEST );
  470. }
  471. };
  472. this.setMask = function ( stencilMask ) {
  473. if ( currentStencilMask !== stencilMask && ! locked ) {
  474. gl.stencilMask( stencilMask );
  475. currentStencilMask = stencilMask;
  476. }
  477. };
  478. this.setFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  479. if ( currentStencilFunc !== stencilFunc ||
  480. currentStencilRef !== stencilRef ||
  481. currentStencilFuncMask !== stencilMask ) {
  482. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  483. currentStencilFunc = stencilFunc;
  484. currentStencilRef = stencilRef;
  485. currentStencilFuncMask = stencilMask;
  486. }
  487. };
  488. this.setOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  489. if ( currentStencilFail !== stencilFail ||
  490. currentStencilZFail !== stencilZFail ||
  491. currentStencilZPass !== stencilZPass ) {
  492. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  493. currentStencilFail = stencilFail;
  494. currentStencilZFail = stencilZFail;
  495. currentStencilZPass = stencilZPass;
  496. }
  497. };
  498. this.setLocked = function ( lock ) {
  499. locked = lock;
  500. };
  501. this.setClear = function ( stencil ) {
  502. if ( currentStencilClear !== stencil ) {
  503. gl.clearStencil( stencil );
  504. currentStencilClear = stencil;
  505. }
  506. };
  507. this.reset = function () {
  508. locked = false;
  509. currentStencilMask = null;
  510. currentStencilFunc = null;
  511. currentStencilRef = null;
  512. currentStencilFuncMask = null;
  513. currentStencilFail = null;
  514. currentStencilZFail = null;
  515. currentStencilZPass = null;
  516. currentStencilClear = null;
  517. };
  518. };