forked from stackgl/headless-gl
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
33 lines (28 loc) · 922 Bytes
/
index.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
"use strict"
var GL = module.exports = require("./webgl.js");
var WebGLRenderingContext = GL.WebGLRenderingContext;
//Interoperate with node-canvas when available
(function() {
var pGetContext;
function getContextGLShim(contextid) {
if (contextid === "webgl" ||
contextid === "experimental-webgl") {
if (this._gl_context) {
return this._gl_context;
}
this._gl_context = new WebGLRenderingContext();
return this._gl_context;
}
return pGetContext.call(this, contextid);
}
try {
var Canvas = require("canvas");
if (Canvas) {
pGetContext = Canvas.prototype.getContext;
Canvas.prototype.getContext = getContextGLShim;
}
} catch (e) {}
})();
module.exports.createContext = function(width, height) {
return new WebGLRenderingContext(width, height);
};