diff --git a/src/ext/lib/aard/gl/FallbackCanvas.ts b/src/ext/lib/aard/gl/FallbackCanvas.ts new file mode 100644 index 0000000..fd3c8fe --- /dev/null +++ b/src/ext/lib/aard/gl/FallbackCanvas.ts @@ -0,0 +1,32 @@ +import { GlCanvas, GlCanvasOptions } from './GlCanvas'; + + +export class FallbackCanvas extends GlCanvas { + + context: CanvasRenderingContext2D; + + constructor(options: GlCanvasOptions) { + super(options); + this.context = this.canvas.getContext('2d'); + } + + /** + * We need to override the following methods in order to avoid default behaviour, + * since these methods in GlCanvas touch some webGL properties that we cannot really + * touch in this class. + */ + + destroy() { } + + protected initWebgl() { } + + drawVideoFrame(video: HTMLVideoElement) { + this.context.drawImage(video, this.context.canvas.width, this.context.canvas.height); + } + + getImageData() { + this.frameBuffer = this.context.getImageData(0,0,this.context.canvas.width,this.context.canvas.height).data as any as Uint8Array; + return this.frameBuffer; + } + +} diff --git a/src/ext/lib/aard/gl/GlCanvas.ts b/src/ext/lib/aard/gl/GlCanvas.ts index 836cb4c..88ef93f 100644 --- a/src/ext/lib/aard/gl/GlCanvas.ts +++ b/src/ext/lib/aard/gl/GlCanvas.ts @@ -71,7 +71,7 @@ export class GlCanvas { private frameBufferSize: number; private _frameBuffer: Uint8Array; - private set frameBuffer(x: Uint8Array) { + protected set frameBuffer(x: Uint8Array) { this._frameBuffer = x; } public get frameBuffer(): Uint8Array { @@ -118,7 +118,7 @@ export class GlCanvas { } /** - * Reads pixels from the canvas + * Reads pixels from the canvas into framebuffer, and returns pointer to the framebuffer * @returns */ getImageData(): Uint8Array { @@ -156,7 +156,7 @@ export class GlCanvas { this.gl.deleteTexture(this.texture); } - private initWebgl() { + protected initWebgl() { // Initialize the GL context this.gl.clearColor(0.0, 0.0, 0.0, 1.0); this.gl.clear(this.gl.COLOR_BUFFER_BIT);