]> zoso.dev Git - nano-pow.git/commitdiff
Create GL canvas as part of initialization call.
authorChris Duncan <chris@zoso.dev>
Sun, 9 Mar 2025 04:05:05 +0000 (20:05 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 9 Mar 2025 04:05:05 +0000 (20:05 -0800)
src/classes/gl.ts

index 520ab89364933676c7a01e10a9fa8eea303653d0..1dbc0568de8d9ebee5c457bcd46312189f07425e 100644 (file)
@@ -12,7 +12,7 @@ export class NanoPowGl {
        /** Used to set canvas size. */
        static #cores: number = Math.max(1, Math.floor(navigator.hardwareConcurrency))
        static #WORKLOAD: number = 256 * this.#cores
-       static #canvas: OffscreenCanvas = new OffscreenCanvas(this.#WORKLOAD, this.#WORKLOAD)
+       static #canvas: OffscreenCanvas
        static get size () { return this.#gl?.drawingBufferWidth }
 
        static #gl: WebGL2RenderingContext | null
@@ -43,6 +43,7 @@ export class NanoPowGl {
                this.#busy = true
 
                try {
+                       this.#canvas = new OffscreenCanvas(this.#WORKLOAD, this.#WORKLOAD)
                        this.#canvas.addEventListener('webglcontextlost', event => {
                                event.preventDefault()
                                console.warn('WebGL context lost. Waiting for it to be restored...')