🐛 offscreen canvas for webgl is weird..

This commit is contained in:
2019-01-28 22:23:31 +01:00
parent 912665885b
commit c9ce5846d1
2 changed files with 13 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ class CanvasPool {
} }
__createNewCanvas() { __createNewCanvas() {
console.log('create new canvas');
const canvas = (this.__ctx !== 'webgl') ? new OffscreenCanvas(1,1) : document.createElement('canvas'); const canvas = (this.__ctx !== 'webgl') ? new OffscreenCanvas(1,1) : document.createElement('canvas');
canvas.acquire = this.acquireCanvas.bind(this, canvas); canvas.acquire = this.acquireCanvas.bind(this, canvas);
canvas.release = this.releaseCanvas.bind(this, canvas); canvas.release = this.releaseCanvas.bind(this, canvas);

View File

@@ -1,6 +1,6 @@
import Node from '../Node'; import Node from '../Node';
import {createCanvas, mediaSize, paintToCanvas} from '../canvas'; import {createCanvas, mediaSize, paintToCanvas} from '../canvas';
import {canvasPoolWebGL} from '../../canvas/CanvasPool'; import {canvasPool2D} from '../../canvas/CanvasPool';
export default class WebGL extends Node { export default class WebGL extends Node {
@@ -139,7 +139,7 @@ export default class WebGL extends Node {
setup() { setup() {
if (!this.canvas) { if (!this.canvas) {
this.canvas = new OffscreenCanvas(1,1); this.canvas = document.createElement('canvas')
this.program = null; this.program = null;
} }
const gl = this.canvas.getContext('webgl'); const gl = this.canvas.getContext('webgl');
@@ -234,15 +234,22 @@ export default class WebGL extends Node {
// Draw the rectangle. // Draw the rectangle.
gl.drawArrays(gl.TRIANGLES, 0, 6); gl.drawArrays(gl.TRIANGLES, 0, 6);
const result = canvas.transferToImageBitmap(); const resultCanvas = canvasPool2D.createCanvas();
// this.canvas = null; resultCanvas.width = 1;
resultCanvas.height = 1;
resultCanvas.acquire();
resultCanvas.width = canvas.width;
resultCanvas.height = canvas.height;
const ctx = resultCanvas.getContext('2d');
ctx.drawImage(canvas, 0, 0);
if (image.release) { if (image.release) {
image.release(); image.release();
} }
if (this.out.image.value && this.out.image.value.release) { if (this.out.image.value && this.out.image.value.release) {
this.out.image.value.release(); this.out.image.value.release();
} }
this.out.image.value = result; this.out.image.value = resultCanvas;
if (this.out.width.value !== this.out.image.value.width) { if (this.out.width.value !== this.out.image.value.width) {
this.out.width.value = this.out.image.value.width; this.out.width.value = this.out.image.value.width;
} }