forked from stackgl/headless-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrap.js
52 lines (45 loc) · 1.48 KB
/
wrap.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
var webgl = require('./webgl')
var privateMethods = [
'resize',
'destroy'
]
module.exports = function wrapContext (gl) {
var props = Object.keys(gl).concat(Object.keys(gl.constructor.prototype))
var wrapper = new WebGLRenderingContext()
props.forEach(function (prop) {
if (prop[0] === '_' ||
prop[0] === '0' ||
prop[0] === '1') {
return
}
var value = gl[prop]
if (typeof value === 'function') {
if (privateMethods.indexOf(value) < 0) {
wrapper[prop] = value.bind(gl)
}
} else {
wrapper[prop] = value
}
})
Object.defineProperties(wrapper, {
drawingBufferWidth: {
get: function () { return gl.drawingBufferWidth }
},
drawingBufferHeight: {
get: function () { return gl.drawingBufferHeight }
}
})
return wrapper
}
function WebGLRenderingContext () {}
module.exports.WebGLRenderingContext = WebGLRenderingContext
// FIXME: Wrap all these objects to prevent headless-gl stuff from leaking
module.exports.WebGLProgram = webgl.WebGLProgram
module.exports.WebGLShader = webgl.WebGLShader
module.exports.WebGLBuffer = webgl.WebGLBuffer
module.exports.WebGLFramebuffer = webgl.WebGLFramebuffer
module.exports.WebGLRenderbuffer = webgl.WebGLRenderbuffer
module.exports.WebGLTexture = webgl.WebGLTexture
module.exports.WebGLUniformLocation = webgl.WebGLUniformLocation
module.exports.WebGLActiveInfo = webgl.WebGLActiveInfo
module.exports.WebGLShaderPrecisionFormat = webgl.WebGLShaderPrecisionFormat