fix canvas initialization, add add methods to attach canvas to main body for ez debug
This commit is contained in:
parent
903f356252
commit
c235b52e3b
@ -290,9 +290,10 @@ class Aard {
|
||||
*/
|
||||
private init() {
|
||||
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 = {
|
||||
top: generateSampleArray(
|
||||
this.settings.active.arDetect.sampling.staticCols,
|
||||
|
@ -4,6 +4,7 @@ import { GlCanvasBuffers, initBuffers } from './gl-init';
|
||||
export interface GlCanvasOptions {
|
||||
width: number;
|
||||
height: number;
|
||||
id?: string;
|
||||
}
|
||||
|
||||
// Vertex shader program
|
||||
@ -91,17 +92,19 @@ export class GlCanvas {
|
||||
|
||||
constructor(options: GlCanvasOptions) {
|
||||
this.canvas = document.createElement('canvas');
|
||||
this.canvas.setAttribute('width', `${options.width}`);
|
||||
this.canvas.setAttribute('height', `${options.height}`);
|
||||
|
||||
this.gl = this.canvas.getContext('webgl');
|
||||
|
||||
if (!this.gl) {
|
||||
throw new Error('WebGL not supported');
|
||||
}
|
||||
|
||||
this.canvas.width = options.width;
|
||||
this.canvas.height = options.height;
|
||||
if(options.id) {
|
||||
this.canvas.setAttribute('id', options.id);
|
||||
}
|
||||
|
||||
this.frameBufferSize = options.width * options.height * 4;
|
||||
|
||||
this.initWebgl();
|
||||
}
|
||||
|
||||
@ -123,6 +126,24 @@ export class GlCanvas {
|
||||
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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user