-
Notifications
You must be signed in to change notification settings - Fork 2
/
state.js
87 lines (82 loc) · 3.12 KB
/
state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// The code that follows was originally sourced from:
// https://www.khronos.org/registry/webgl/sdk/debug/webgl-debug.js
//
module.exports = stateReset
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
function stateReset(gl) {
var numAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS)
var tmp = gl.createBuffer()
gl.bindBuffer(gl.ARRAY_BUFFER, tmp)
for (var ii = 0; ii < numAttribs; ++ii) {
gl.disableVertexAttribArray(ii)
gl.vertexAttribPointer(ii, 4, gl.FLOAT, false, 0, 0)
gl.vertexAttrib1f(ii, 0)
}
gl.deleteBuffer(tmp)
var numTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS)
for (var ii = 0; ii < numTextureUnits; ++ii) {
gl.activeTexture(gl.TEXTURE0 + ii)
gl.bindTexture(gl.TEXTURE_CUBE_MAP, null)
gl.bindTexture(gl.TEXTURE_2D, null)
}
gl.activeTexture(gl.TEXTURE0)
gl.useProgram(null)
gl.bindBuffer(gl.ARRAY_BUFFER, null)
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null)
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
gl.bindRenderbuffer(gl.RENDERBUFFER, null)
gl.disable(gl.BLEND)
gl.disable(gl.CULL_FACE)
gl.disable(gl.DEPTH_TEST)
gl.disable(gl.DITHER)
gl.disable(gl.SCISSOR_TEST)
gl.blendColor(0, 0, 0, 0)
gl.blendEquation(gl.FUNC_ADD)
gl.blendFunc(gl.ONE, gl.ZERO)
gl.clearColor(0, 0, 0, 0)
gl.clearDepth(1)
gl.clearStencil(-1)
gl.colorMask(true, true, true, true)
gl.cullFace(gl.BACK)
gl.depthFunc(gl.LESS)
gl.depthMask(true)
gl.depthRange(0, 1)
gl.frontFace(gl.CCW)
gl.hint(gl.GENERATE_MIPMAP_HINT, gl.DONT_CARE)
gl.lineWidth(1)
gl.pixelStorei(gl.PACK_ALIGNMENT, 4)
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4)
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false)
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false)
gl.polygonOffset(0, 0)
gl.sampleCoverage(1, false)
gl.scissor(0, 0, gl.canvas.width, gl.canvas.height)
gl.stencilFunc(gl.ALWAYS, 0, 0xFFFFFFFF)
gl.stencilMask(0xFFFFFFFF)
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP)
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height)
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
return gl
}