Skip to content

Accessing WebGL types in a worker? #2571

@greggman

Description

@greggman

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 ...)

  1. call gl.isTexture which requires a WebGLTexture but throws if it's not. Seems pretty heavy to generate an exception just to check this stuff. In other words

     function isTexture(gl, obj) {
       let result = false;
       try {
         result = gl.isTexture(obj);
       } catch (e) {
       }
       return result;
     }
    
  2. call representative = gl.createTexture() somewhere then use objectInQuestion 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.

  3. ???

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions