greggman / twgl.js

A Tiny WebGL helper Library
http://twgljs.org
MIT License
2.61k stars 258 forks source link

resizeCanvasToDisplaySize in a web worker sets the width and height to 0 #206

Closed adarah closed 1 year ago

adarah commented 1 year ago

I was porting some code which ran in the main thread to a Web Worker via the OffscreenCanvas API, and I noticed that calling resizeCanvasToDisplaySize was making my scene disappear. Is this intended behavior? If so, do you have any recommendations on how to work around this limitation so that I can still have the canvas resizing functionality in the Web Worker?

greggman commented 1 year ago

It makes no sense to call resizeCanvasToDisplaySize in a worker as there is no display size in a worker. Any display size you want would have to be passed from your main page into the worker and of course twgl would no idea how you're going to do that.

As for ideas, this article shows one way to make a proxy to send this info to your worker.

https://threejs.org/manual/#en/offscreencanvas

adarah commented 1 year ago

I see, I'll study that article then, thanks for responding so quickly!