Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing WebGL types in a worker? #2571

Closed
greggman opened this issue Jan 2, 2018 · 3 comments
Closed

Accessing WebGL types in a worker? #2571

greggman opened this issue Jan 2, 2018 · 3 comments

Comments

@greggman
Copy link
Contributor

greggman commented Jan 2, 2018

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

@kainino0x
Copy link
Contributor

This sounds like an oversight to me, but I haven't worked on OffscreenCanvas myself. In Chrome, it looks like it's just a matter of adding Exposed(Worker ExperimentalCanvasFeatures) to WebGLTexture and the rest of the WebGL interface objects (we already have it for WebGL(2)RenderingContext).

cc @junov

@foolip
Copy link

foolip commented Jul 19, 2018

This will have to be fixed in the specs as well. As of whatwg/webidl#423 [Exposed] is mandatory, relevant change deep in https://heycam.github.io/webidl/#idl-interfaces: "Non-callback interfaces which are not annotated with a [NoInterfaceObject] extended attribute, and callback interfaces which declare constants must be annotated with an [Exposed] extended attribute."

kenrussell added a commit to kenrussell/WebGL that referenced this issue Jul 19, 2018
This extended attribute has been required by Web IDL since
whatwg/webidl#423 . In order for WebGL to be accessible by web workers
using OffscreenCanvas, the attribute being added to all WebGL
interfaces is:
[Exposed=(Window,Worker)]

Fixes KhronosGroup#2571 .
@kenrussell
Copy link
Member

Chromium's implementation has been fixed to expose these interfaces on workers as of https://chromium-review.googlesource.com/1142292 .

aarongable pushed a commit to chromium/chromium that referenced this issue Jul 19, 2018
Addresses KhronosGroup/WebGL#2571 .

Bug: none
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I2e84b89bb2d9b46e5c7094419681d38a377dcbb1
Reviewed-on: https://chromium-review.googlesource.com/1142292
Reviewed-by: Philip Jägenstedt <[email protected]>
Commit-Queue: Kenneth Russell <[email protected]>
Cr-Commit-Position: refs/heads/master@{#576627}
kenrussell added a commit to kenrussell/WebGL that referenced this issue Jul 26, 2018
This extended attribute has been required by Web IDL since
whatwg/webidl#423 . In order for WebGL to be accessible by web workers
using OffscreenCanvas, the attribute being added to all WebGL
interfaces is:
[Exposed=(Window,Worker)]

Fixes KhronosGroup#2571 .
kenrussell added a commit that referenced this issue Jul 26, 2018
* Add [Exposed] Web IDL attribute to all WebGL interfaces.

This extended attribute has been required by Web IDL since
whatwg/webidl#423 . In order for WebGL to be accessible by web workers
using OffscreenCanvas, the attribute being added to all WebGL
interfaces is:
[Exposed=(Window,Worker)]

Fixes #2571 .

* Address review feedback from jgilbert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants