fix canvas initialization, add add methods to attach canvas to main body for ez debug

This commit is contained in:
Tamius Han 2024-11-07 00:18:13 +01:00
parent 903f356252
commit c235b52e3b
2 changed files with 27 additions and 5 deletions

View File

@ -290,9 +290,10 @@ class Aard {
*/ */
private init() { private init() {
this.canvasStore = { this.canvasStore = {
main: new GlCanvas(new GlCanvas(this.settings.active.arDetect.canvasDimensions.sampleCanvas)), main: new GlCanvas(new GlCanvas({...this.settings.active.arDetect.canvasDimensions.sampleCanvas, id: 'main-gl'})),
}; };
this.canvasSamples = { this.canvasSamples = {
top: generateSampleArray( top: generateSampleArray(
this.settings.active.arDetect.sampling.staticCols, this.settings.active.arDetect.sampling.staticCols,

View File

@ -4,6 +4,7 @@ import { GlCanvasBuffers, initBuffers } from './gl-init';
export interface GlCanvasOptions { export interface GlCanvasOptions {
width: number; width: number;
height: number; height: number;
id?: string;
} }
// Vertex shader program // Vertex shader program
@ -91,17 +92,19 @@ export class GlCanvas {
constructor(options: GlCanvasOptions) { constructor(options: GlCanvasOptions) {
this.canvas = document.createElement('canvas'); this.canvas = document.createElement('canvas');
this.canvas.setAttribute('width', `${options.width}`);
this.canvas.setAttribute('height', `${options.height}`);
this.gl = this.canvas.getContext('webgl'); this.gl = this.canvas.getContext('webgl');
if (!this.gl) { if (!this.gl) {
throw new Error('WebGL not supported'); throw new Error('WebGL not supported');
} }
if(options.id) {
this.canvas.width = options.width; this.canvas.setAttribute('id', options.id);
this.canvas.height = options.height; }
this.frameBufferSize = options.width * options.height * 4; this.frameBufferSize = options.width * options.height * 4;
this.initWebgl(); this.initWebgl();
} }
@ -123,6 +126,24 @@ export class GlCanvas {
return this.frameBuffer; return this.frameBuffer;
} }
showCanvas() {
this.canvas.style.display = 'block';
this.canvas.style.position = 'fixed';
this.canvas.style.left = '0px';
this.canvas.style.top = '0px';
this.canvas.style.border = '1px dotted red';
this.canvas.style.zIndex = '1000000';
document.body.appendChild(this.canvas);
}
hideCanvas() {
this.canvas.style.display = '';
this.canvas.style.position = '';
this.canvas.style.left = '';
this.canvas.style.top = '';
this.canvas.remove();
}
/** /**
* Cleans up after itself * Cleans up after itself
*/ */