|
| 1 | +var tape = require('tape') |
| 2 | +var { WebGLRenderingContext } = require('../../src/javascript/webgl-rendering-context') |
| 3 | +var createContext = require('../../src/javascript/node-index') |
| 4 | + |
| 5 | +tape('stencil check cache - gl.stencilFunc()', function (t) { |
| 6 | + var gl = new WebGLRenderingContext() |
| 7 | + t.equals(gl._checkStencil, undefined, 'gl._checkStencil starts undefined') |
| 8 | + gl.destroy() |
| 9 | + t.end() |
| 10 | +}) |
| 11 | + |
| 12 | +tape('stencil check cache - gl.stencilFunc()', function (t) { |
| 13 | + var gl = new WebGLRenderingContext() |
| 14 | + gl.stencilFunc() |
| 15 | + t.equals(gl._checkStencil, true, 'gl.stencilFunc() calls set gl._checkStencil to true') |
| 16 | + gl.destroy() |
| 17 | + t.end() |
| 18 | +}) |
| 19 | + |
| 20 | +tape('stencil check cache - gl.stencilFuncSeparate()', function (t) { |
| 21 | + var gl = new WebGLRenderingContext() |
| 22 | + gl.stencilFuncSeparate() |
| 23 | + t.equals(gl._checkStencil, true, 'gl.stencilFuncSeparate() calls set gl._checkStencil to true') |
| 24 | + gl.destroy() |
| 25 | + t.end() |
| 26 | +}) |
| 27 | + |
| 28 | +tape('stencil check cache - gl.stencilMask()', function (t) { |
| 29 | + var gl = new WebGLRenderingContext() |
| 30 | + gl.stencilMask() |
| 31 | + t.equals(gl._checkStencil, true, 'gl.stencilMask() calls set gl._checkStencil to true') |
| 32 | + gl.destroy() |
| 33 | + t.end() |
| 34 | +}) |
| 35 | + |
| 36 | +tape('stencil check cache - gl.stencilMaskSeparate()', function (t) { |
| 37 | + var gl = new WebGLRenderingContext() |
| 38 | + gl.stencilMaskSeparate() |
| 39 | + t.equals(gl._checkStencil, true, 'gl.stencilMaskSeparate() calls set gl._checkStencil to true') |
| 40 | + gl.destroy() |
| 41 | + t.end() |
| 42 | +}) |
| 43 | + |
| 44 | +tape('stencil check cache - gl.stencilOp()', function (t) { |
| 45 | + var gl = new WebGLRenderingContext() |
| 46 | + gl.stencilOp() |
| 47 | + t.equals(gl._checkStencil, true, 'gl.stencilOp() calls set gl._checkStencil to true') |
| 48 | + gl.destroy() |
| 49 | + t.end() |
| 50 | +}) |
| 51 | + |
| 52 | +tape('stencil check cache - gl.stencilOpSeparate()', function (t) { |
| 53 | + var gl = new WebGLRenderingContext() |
| 54 | + gl.stencilOpSeparate() |
| 55 | + t.equals(gl._checkStencil, true, 'gl.stencilOpSeparate() calls set gl._checkStencil to true') |
| 56 | + gl.destroy() |
| 57 | + t.end() |
| 58 | +}) |
| 59 | + |
| 60 | +tape('stencil check cache - gl.clearStencil()', function (t) { |
| 61 | + var gl = new WebGLRenderingContext() |
| 62 | + gl.clearStencil() |
| 63 | + t.equals(gl._checkStencil, false, 'gl.clearStencil() calls set gl._checkStencil to false') |
| 64 | + gl.destroy() |
| 65 | + t.end() |
| 66 | +}) |
| 67 | + |
| 68 | +tape('stencil check cache - gl._checkStencilState() without errors', function (t) { |
| 69 | + var gl = new WebGLRenderingContext() |
| 70 | + gl._checkStencil = true |
| 71 | + t.equals(gl._checkStencilState(), true, 'gl._checkStencilState() value is cached and returned') |
| 72 | + t.equals(gl._checkStencil, false, 'gl._checkStencilState() calls set gl._checkStencil to false') |
| 73 | + t.equals(gl._stencilState, true, 'gl._checkStencilState() calls set gl._stencilState to true') |
| 74 | + gl._stencilState = 'test value' |
| 75 | + gl.getParameter = function () { |
| 76 | + throw new Error('should not be called!') |
| 77 | + } |
| 78 | + t.equals(gl._checkStencilState(), 'test value', 'subsequent gl._checkStencilState() calls use the cached state stored in gl._stencilState') |
| 79 | + gl.destroy() |
| 80 | + t.end() |
| 81 | +}) |
| 82 | + |
| 83 | +tape('stencil check cache - gl._checkStencilState() with errors', function (t) { |
| 84 | + var gl = new WebGLRenderingContext() |
| 85 | + gl._checkStencil = true |
| 86 | + gl.getParameter = function (stencil) { |
| 87 | + if (stencil === gl.STENCIL_WRITEMASK) return 1 |
| 88 | + } |
| 89 | + t.equals(gl._checkStencilState(), false, 'gl._checkStencilState() value is cached and returned') |
| 90 | + t.equals(gl._checkStencil, false, 'gl._checkStencilState() calls set gl._checkStencil to false') |
| 91 | + t.equals(gl._stencilState, false, 'gl._checkStencilState() calls set gl._stencilState to true') |
| 92 | + gl._stencilState = 'test value' |
| 93 | + gl.getParameter = function () { |
| 94 | + throw new Error('should not be called!') |
| 95 | + } |
| 96 | + t.equals(gl._checkStencilState(), 'test value', 'subsequent gl._checkStencilState() calls use the cached state stored in gl._stencilState') |
| 97 | + gl.destroy() |
| 98 | + t.end() |
| 99 | +}) |
| 100 | + |
| 101 | +tape('stencil check cache - createContext initial state', function (t) { |
| 102 | + var gl = createContext(1, 1) |
| 103 | + gl.getParameter = function () { |
| 104 | + throw new Error('should not be called!') |
| 105 | + } |
| 106 | + gl._stencilState = 'test value' |
| 107 | + t.equals(gl._checkStencilState(), true, 'initial call to createContext()._checkStencilState() return gl._stencilState and not call gl.getParameter()') |
| 108 | + gl.destroy() |
| 109 | + t.end() |
| 110 | +}) |
0 commit comments