From 6ac66ea9c306b86dbecc870931fc37dc278d230d Mon Sep 17 00:00:00 2001 From: Michael Herrmann Date: Tue, 13 Sep 2022 18:33:36 -0700 Subject: [PATCH] export WebGLRenderingContext and add gl consts --- index.js | 1 + src/javascript/webgl-rendering-context.js | 8 ++++++++ test/webgl-rendering-context.js | 12 ++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/webgl-rendering-context.js diff --git a/index.js b/index.js index 7b11a039..0eef94e9 100644 --- a/index.js +++ b/index.js @@ -3,3 +3,4 @@ if (typeof WebGLRenderingContext !== 'undefined') { } else { module.exports = require('./src/javascript/node-index') } +module.exports.WebGLRenderingContext = require('./src/javascript/webgl-rendering-context').WebGLRenderingContext diff --git a/src/javascript/webgl-rendering-context.js b/src/javascript/webgl-rendering-context.js index df2b4202..0319be5e 100644 --- a/src/javascript/webgl-rendering-context.js +++ b/src/javascript/webgl-rendering-context.js @@ -3861,4 +3861,12 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext { } } +// Make the gl consts available as static properties +for (const [key, value] of Object.entries(gl)) { + if (typeof value !== 'number') { + continue + } + Object.assign(WebGLRenderingContext, { [key]: value }) +} + module.exports = { WebGLRenderingContext, wrapContext } diff --git a/test/webgl-rendering-context.js b/test/webgl-rendering-context.js new file mode 100644 index 00000000..eb77d9bf --- /dev/null +++ b/test/webgl-rendering-context.js @@ -0,0 +1,12 @@ +'use strict' + +const tape = require('tape') +const WebGLRenderingContext = require('../index').WebGLRenderingContext + +tape('use WebGLRenderingContext', function (t) { + t.equals(!!WebGLRenderingContext, true) + t.equals(!!WebGLRenderingContext.STATIC_DRAW, true) + t.equals(!!WebGLRenderingContext.STENCIL_TEST, true) + t.equals(!!WebGLRenderingContext.FRAMEBUFFER, true) + t.end() +})