Skip to content

Commit

Permalink
Fix webgl2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
raub committed Oct 22, 2023
1 parent 81f7c85 commit df23b7d
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 601 deletions.
46 changes: 29 additions & 17 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,35 @@ declare module "webgl-raub" {
name: string;
}

export class WebGLRenderingContext extends TGLObject {}
export class WebGLProgram extends TGLObject {}
export class WebGLQuery extends TGLObject {}
export class WebGLShader extends TGLObject {}
export class WebGLVertexArrayObject extends TGLObject {}
export class WebGLBuffer extends TGLObject {}
export class WebGLVertexArray extends TGLObject {}
export class WebGLFramebuffer extends TGLObject {}
export class WebGLRenderbuffer extends TGLObject {}
export class WebGLTexture extends TGLObject {}
export class WebGLUniformLocation extends TGLObject {}
export class WebGLActiveInfo extends TGLActiveInfo {}
export class WebGLTransformFeedback extends TGLObject {}
export class WebGLSampler extends TGLObject {}
export class WebGLSync extends TGLObject {}
const WebGLRenderingContext = class WebGLRenderingContext extends TGLObject {};
const WebGLProgram = class WebGLProgram extends TGLObject {};
const WebGLQuery = class WebGLQuery extends TGLObject {};
const WebGLShader = class WebGLShader extends TGLObject {};
const WebGLVertexArrayObject = class WebGLVertexArrayObject extends TGLObject {};
const WebGLBuffer = class WebGLBuffer extends TGLObject {};
const WebGLVertexArray = class WebGLVertexArray extends TGLObject {};
const WebGLFramebuffer = class WebGLFramebuffer extends TGLObject {};
const WebGLRenderbuffer = class WebGLRenderbuffer extends TGLObject {};
const WebGLTexture = class WebGLTexture extends TGLObject {};
const WebGLUniformLocation = class WebGLUniformLocation extends TGLObject {};
const WebGLActiveInfo = class WebGLActiveInfo extends TGLActiveInfo {};
const WebGLTransformFeedback = class WebGLTransformFeedback extends TGLObject {};
const WebGLSampler = class WebGLSampler extends TGLObject {};
const WebGLSync = class WebGLSync extends TGLObject {};
const WebGL2RenderingContext = class WebGL2RenderingContext extends TGLObject {};

/**
* Add `WebGL2RenderingContext` to global, and set the GL object prototype.
*
* `typeof WebGL2RenderingContext !== 'undefined' && gl.constructor.name === 'WebGL2RenderingContext';`
* The condition above becomes true, after using this method - this is how
* frameworks usually look for WebGL2 compatibility.
*/
const useWebGL2: ()=> void;

/**
* Init GLEW.
*/
const init: ()=> void;

const contextAttributes: TContextAttributes;
Expand Down Expand Up @@ -571,7 +584,7 @@ declare module "webgl-raub" {

const drawingBufferWidth: number;
const drawingBufferHeight: number;

const DEPTH_BUFFER_BIT: number;
const STENCIL_BUFFER_BIT: number;
const COLOR_BUFFER_BIT: number;
Expand Down Expand Up @@ -965,7 +978,6 @@ declare module "webgl-raub" {
const PIXEL_UNPACK_BUFFER: number;
const PIXEL_PACK_BUFFER_BINDING: number;
const PIXEL_UNPACK_BUFFER_BINDING: number;

const READ_BUFFER: number;
const PACK_ROW_LENGTH: number;
const PACK_SKIP_ROWS: number;
Expand Down
2 changes: 1 addition & 1 deletion install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ const { install } = require('addon-tools-raub');


const prefix = 'https://github.com/node-3d/webgl-raub/releases/download';
const tag = '4.0.0';
const tag = '4.1.0';

install(`${prefix}/${tag}`);
6 changes: 6 additions & 0 deletions js/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if (!gl.__isInited) {
this.name = _.name;
};
gl.WebGLTransformFeedback = function WebGLTransformFeedback(_) { this._ = _; };
gl.WebGL2RenderingContext = function WebGL2RenderingContext(_) { this._ = _; };

// Global scope constructors for browser-style libs
global.WebGLRenderingContext = gl.WebGLRenderingContext;
Expand All @@ -53,6 +54,11 @@ if (!gl.__isInited) {
global.WebGLActiveInfo = gl.WebGLActiveInfo;
global.WebGLTransformFeedback = gl.WebGLTransformFeedback;

gl.useWebGL2 = () => {
global.WebGL2RenderingContext = gl.WebGL2RenderingContext;
Object.setPrototypeOf(gl, gl.WebGL2RenderingContext.prototype);
};

gl.contextAttributes = {
alpha: true,
antialias: true,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Luis Blanco <[email protected]>",
"name": "webgl-raub",
"version": "4.0.3",
"version": "4.1.0",
"description": "WebGL for Node.js",
"license": "MIT",
"main": "index.js",
Expand Down
Loading

0 comments on commit df23b7d

Please sign in to comment.