-
Notifications
You must be signed in to change notification settings - Fork 680
Description
I'm probably just missing this somewhere but, I have some semi-generic WebGL code that needs to check if an object is WebGLTexture
or a WebGLRenderbuffer
. For the last several years I've had code like this
isTexture = object instanceOf WebGLTexture;
But now I'm trying to run this code in a worker and AFAICT WebGLTexture
does not exist inside a worker even though WebGL itself is running via OffscreenCanvas
.
- Is this a known issue?
- Will the WebGL types be exposed inside a worker?
- Are they exposed somewhere not the global object?
As it is a few workarounds which seem unclean (some wishy washy feeling I know but ...)
-
call
gl.isTexture
which requires aWebGLTexture
but throws if it's not. Seems pretty heavy to generate an exception just to check this stuff. In other wordsfunction isTexture(gl, obj) { let result = false; try { result = gl.isTexture(obj); } catch (e) { } return result; }
-
call
representative = gl.createTexture()
somewhere then useobjectInQuestion instanceOf representative.constructor
. ugh but it works and at least it's fast and doesn't generate garbage every check as 1 above does but it does generate a bogus object. -
???