Add fallback option class (currently unused)

This commit is contained in:
Tamius Han 2024-12-22 23:20:07 +01:00
parent 9fc63e5cd3
commit 7be6fb9501
2 changed files with 35 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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);