Compare commits
10 Commits
689e75d3d8
...
0e4b75746d
Author | SHA1 | Date | |
---|---|---|---|
0e4b75746d | |||
41db18e1ed | |||
836bf6240e | |||
831e6b8541 | |||
81195e7b48 | |||
40e1effa2d | |||
56456bddda | |||
b1257a4c51 | |||
fb7d7735be | |||
b296552e35 |
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@ -8,10 +8,16 @@
|
|||||||
"name": "Launch addon",
|
"name": "Launch addon",
|
||||||
"type": "firefox",
|
"type": "firefox",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"port":6000,
|
"port": 6000,
|
||||||
"reAttach": true,
|
"reAttach": true,
|
||||||
"addonType": "webExtension",
|
"addonType": "webExtension",
|
||||||
"addonPath": "${workspaceFolder}/dist-ff",
|
"addonPath": "${workspaceFolder}/dist-ff",
|
||||||
|
"pathMappings": [
|
||||||
|
{
|
||||||
|
"url": "webpack:///",
|
||||||
|
"path": "${workspaceFolder}/src/"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"firefox": {
|
"firefox": {
|
||||||
|
4033
package-lock.json
generated
4033
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -330,7 +330,7 @@ class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canLogFile(component) {
|
canLogFile(component) {
|
||||||
if (!this.conf.fileOptions.enabled || this.temp_disable) {
|
if (!(this.conf.fileOptions?.enabled) || this.temp_disable) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Array.isArray(component) && component.length ) {
|
if (Array.isArray(component) && component.length ) {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import Debug from '../../conf/Debug';
|
import Debug from '../../conf/Debug';
|
||||||
import EdgeDetect from './edge-detect/EdgeDetect';
|
import EdgeDetect from './edge-detect/EdgeDetect';
|
||||||
import EdgeStatus from './edge-detect/enums/EdgeStatusEnum';
|
import EdgeStatus from './edge-detect/enums/EdgeStatusEnum';
|
||||||
@ -44,6 +43,16 @@ class AardGl {
|
|||||||
|
|
||||||
this.canDoFallbackMode = false;
|
this.canDoFallbackMode = false;
|
||||||
this.logger.log('info', 'init', `[AardGl::ctor] creating new AardGl. arid: ${this.arid}`);
|
this.logger.log('info', 'init', `[AardGl::ctor] creating new AardGl. arid: ${this.arid}`);
|
||||||
|
|
||||||
|
this.glData = {
|
||||||
|
positionBuffer: null,
|
||||||
|
textureCoordsBuffer: null,
|
||||||
|
textureCoordsLocation: null
|
||||||
|
};
|
||||||
|
|
||||||
|
// delete this:
|
||||||
|
this.count = 0;
|
||||||
|
this.greenC = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,11 +207,34 @@ class AardGl {
|
|||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
//#region WebGL helpers
|
//#region WebGL helpers
|
||||||
|
glInitBuffers(width, height) {
|
||||||
|
// create buffers and bind them
|
||||||
|
this.glData.positionBuffer = this.gl.createBuffer();
|
||||||
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.glData.positionBuffer);
|
||||||
|
|
||||||
|
// create rectangle for drawing
|
||||||
|
this.glSetRectangle(this.gl, width, height);
|
||||||
|
|
||||||
|
// create texture coordinate buffer
|
||||||
|
this.glData.textureCoordsBuffer = this.gl.createBuffer();
|
||||||
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.glData.textureCoordsBuffer);
|
||||||
|
|
||||||
|
// create index buffer
|
||||||
|
this.glData.indexBuffer = this.gl.createBuffer();
|
||||||
|
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.glData.indexBuffer);
|
||||||
|
|
||||||
|
// This array defines each face as two triangles, using the
|
||||||
|
// indices into the vertex array to specify each triangle's
|
||||||
|
// position.
|
||||||
|
const indices = [0, 1, 2, 3, 4, 5];
|
||||||
|
this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), this.gl.STATIC_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
glSetRectangle(glContext, width, height) {
|
glSetRectangle(glContext, width, height) {
|
||||||
glContext.bufferData(glContext.ARRAY_BUFFER, new Float32Array([
|
glContext.bufferData(glContext.ARRAY_BUFFER, new Float32Array([
|
||||||
0, 0,
|
0, 0, //
|
||||||
width, 0,
|
width, 0, // this line are swapped over for experiment
|
||||||
0, height,
|
0, height, // this triangle is flipped. This and
|
||||||
0, height,
|
0, height,
|
||||||
width, 0,
|
width, 0,
|
||||||
width, height
|
width, height
|
||||||
@ -224,8 +256,8 @@ class AardGl {
|
|||||||
|
|
||||||
// check if shader was compiled successfully
|
// check if shader was compiled successfully
|
||||||
if (! glContext.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {
|
if (! glContext.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {
|
||||||
|
this.logger.log('error', ['init', 'debug', 'arDetect'], `%c[AardGl::setupShader] <@${this.arid}> Failed to setup shader. Error given:`, _ard_console_stop, this.gl.getShaderInfoLog(shader));
|
||||||
glContext.deleteShader(shader);
|
glContext.deleteShader(shader);
|
||||||
this.logger.log('error', ['init', 'debug', 'arDetect'], `%c[AardGl::setupShader] <@${this.arid}> Failed to setup shader.`, _ard_console_stop);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,16 +273,25 @@ class AardGl {
|
|||||||
console.log(glContext, shaders);
|
console.log(glContext, shaders);
|
||||||
const program = glContext.createProgram();
|
const program = glContext.createProgram();
|
||||||
for (const shader of shaders) {
|
for (const shader of shaders) {
|
||||||
|
console.log("shader", shader);
|
||||||
glContext.attachShader(program, shader);
|
glContext.attachShader(program, shader);
|
||||||
}
|
}
|
||||||
glContext.linkProgram(program);
|
glContext.linkProgram(program);
|
||||||
if (! glContext.getProgramParameter(program, glContext.LINK_STATUS)) {
|
if (! glContext.getProgramParameter(program, glContext.LINK_STATUS)) {
|
||||||
glContext.deleteShader(shader);
|
this.logger.log('error', ['init', 'debug', 'arDetect'], `%c[AardGl::setupProgram] <@${this.arid}> Failed to setup program.`, glContext.getProgramInfoLog(program), _ard_console_stop);
|
||||||
this.logger.log('error', ['init', 'debug', 'arDetect'], `%c[AardGl::setupProgram] <@${this.arid}> Failed to setup program.`, _ard_console_stop);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return program;
|
return {
|
||||||
|
program,
|
||||||
|
attribLocations: {
|
||||||
|
vertexPosition: this.gl.getAttribLocation(program, 'aVertexPosition'),
|
||||||
|
textureCoord: this.gl.getAttribLocation(program, 'aTextureCoord'),
|
||||||
|
},
|
||||||
|
uniformLocations: {
|
||||||
|
u_frame: this.gl.getUniformLocation(program, 'u_frame'),
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
@ -271,7 +312,7 @@ class AardGl {
|
|||||||
throw "Settings prevent autoar from starting"
|
throw "Settings prevent autoar from starting"
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.log('error', 'init', `%c[AardGl::init] <@${this.arid}> Initialization failed.`, _ard_console_stop, e);
|
this.logger.log('error', ['init', 'debug', 'aard'], `%c[AardGl::init] <@${this.arid}> Initialization failed.`, _ard_console_stop, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,6 +367,17 @@ class AardGl {
|
|||||||
this.blackframeCanvas.width = this.settings.active.aard.canvasDimensions.blackframeCanvas.width;
|
this.blackframeCanvas.width = this.settings.active.aard.canvasDimensions.blackframeCanvas.width;
|
||||||
this.blackframeCanvas.height = this.settings.active.aard.canvasDimensions.blackframeCanvas.height;
|
this.blackframeCanvas.height = this.settings.active.aard.canvasDimensions.blackframeCanvas.height;
|
||||||
|
|
||||||
|
// FOR DEBUG PURPOSES ONLY — REMOVE!
|
||||||
|
var body = document.getElementsByTagName('body')[0];
|
||||||
|
|
||||||
|
this.canvas.style.position = "fixed";
|
||||||
|
this.canvas.style.left = `50px`;
|
||||||
|
this.canvas.style.top = `64px`;
|
||||||
|
this.canvas.style.zIndex = 10002;
|
||||||
|
|
||||||
|
body.appendChild(this.canvas);
|
||||||
|
// END FOR DEBUG PURPOSES ONLY
|
||||||
|
|
||||||
// this.context = this.canvas.getContext("2d");
|
// this.context = this.canvas.getContext("2d");
|
||||||
|
|
||||||
this.pixelBuffer = new Uint8Array(cwidth * cheight * 4);
|
this.pixelBuffer = new Uint8Array(cwidth * cheight * 4);
|
||||||
@ -333,8 +385,67 @@ class AardGl {
|
|||||||
//
|
//
|
||||||
// [2] SETUP WEBGL STUFF —————————————————————————————————————————————————————————————————————————————————
|
// [2] SETUP WEBGL STUFF —————————————————————————————————————————————————————————————————————————————————
|
||||||
//#region webgl setup
|
//#region webgl setup
|
||||||
|
|
||||||
|
this.glSetup(cwidth, cheight);
|
||||||
|
|
||||||
|
console.log("glsetup complete")
|
||||||
|
|
||||||
|
// do setup once
|
||||||
|
// tho we could do it for every frame
|
||||||
|
this.canvasScaleFactor = cheight / this.video.videoHeight;
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// [5] do other things setup needs to do
|
||||||
|
//
|
||||||
|
|
||||||
|
// this.detectionTimeoutEventCount = 0;
|
||||||
|
// this.resetBlackLevel();
|
||||||
|
|
||||||
|
// // if we're restarting AardGl, we need to do this in order to force-recalculate aspect ratio
|
||||||
|
// this.conf.resizer.setLastAr({type: AspectRatio.Automatic, ratio: this.getDefaultAr()});
|
||||||
|
|
||||||
|
// this.canvasImageDataRowLength = cwidth << 2;
|
||||||
|
// this.noLetterboxCanvasReset = false;
|
||||||
|
|
||||||
|
// if (this.settings.canStartAutoAr() ) {
|
||||||
|
// this.start();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if(Debug.debugCanvas.enabled){
|
||||||
|
// // this.debugCanvas.init({width: cwidth, height: cheight});
|
||||||
|
// // DebugCanvas.draw("test marker","test","rect", {x:5, y:5}, {width: 5, height: 5});
|
||||||
|
// }
|
||||||
|
|
||||||
|
this.conf.arSetupComplete = true;
|
||||||
|
console.log("DRAWING BUFFER SIZE:", this.gl.drawingBufferWidth, '×', this.gl.drawingBufferHeight);
|
||||||
|
|
||||||
|
// start autodetection after setup is complete
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
glSetup(cwidth, cheight) {
|
||||||
this.gl = this.canvas.getContext("webgl");
|
this.gl = this.canvas.getContext("webgl");
|
||||||
|
|
||||||
|
if (this.gl === null) {
|
||||||
|
throw new Error('Unable to initialize WebGL. WebGL may not be supported by machine.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// set color to half-transparent blue initially, for testing purposes
|
||||||
|
if (process.env.CHANNEL === 'dev') {
|
||||||
|
try {
|
||||||
|
this.gl.clearColor(0, 0, 1.0, 0.5);
|
||||||
|
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("failing to clear channel!", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.gl.clearColor(0, 0, 0.0, 0.0);
|
||||||
|
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
// load shaders and stuff. PixelSize for horizontalAdder should be 1/sample canvas width
|
// load shaders and stuff. PixelSize for horizontalAdder should be 1/sample canvas width
|
||||||
const vertexShaderSrc = getBasicVertexShader();
|
const vertexShaderSrc = getBasicVertexShader();
|
||||||
const horizontalAdderShaderSrc = generateHorizontalAdder(10, 1 / cwidth); // todo: unhardcode 10 as radius
|
const horizontalAdderShaderSrc = generateHorizontalAdder(10, 1 / cwidth); // todo: unhardcode 10 as radius
|
||||||
@ -344,86 +455,88 @@ class AardGl {
|
|||||||
const horizontalAdderShader = this.compileShader(this.gl, horizontalAdderShaderSrc, this.gl.FRAGMENT_SHADER);
|
const horizontalAdderShader = this.compileShader(this.gl, horizontalAdderShaderSrc, this.gl.FRAGMENT_SHADER);
|
||||||
|
|
||||||
// link shaders to program
|
// link shaders to program
|
||||||
const glProgram = this.compileProgram(this.gl, [vertexShader, horizontalAdderShader]);
|
const programInfo = this.compileProgram(this.gl, [vertexShader, horizontalAdderShader]);
|
||||||
|
this.glProgram = programInfo.program;
|
||||||
|
this.glData.attribLocations = programInfo.attribLocations;
|
||||||
|
this.glData.uniformLocations = programInfo.uniformLocations;
|
||||||
|
|
||||||
// look up where the vertex data needs to go
|
// look up where the vertex data needs to go
|
||||||
// const positionLocation = this.gl.getAttributeLocation(glProgram, 'a_position');
|
// const positionLocation = this.gl.getAttributeLocation(glProgram, 'a_position');
|
||||||
// const textureCoordsLocation = this.gl.getAttributeLocation(glProgram, 'a_textureCoords');
|
// const textureCoordsLocation = this.gl.getAttributeLocation(glProgram, 'a_textureCoords');
|
||||||
|
|
||||||
// create buffers and bind them
|
console.log("program compiled. init buffers");
|
||||||
const positionBuffer = this.gl.createBuffer();
|
|
||||||
const textureCoordsBuffer = this.gl.createBuffer();
|
this.glInitBuffers(this.settings.active.aardGl.sampleCols, cheight);
|
||||||
this.gl.bindBuffer(this.gl, positionBuffer);
|
|
||||||
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, textureCoordsBuffer);
|
console.log("program compiled. buffer init complete");
|
||||||
|
|
||||||
// create a texture
|
|
||||||
this.texture = this.gl.createTexture();
|
this.texture = this.gl.createTexture();
|
||||||
this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
|
this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
|
||||||
|
|
||||||
|
// texture is half-transparent blue by default. Helps with debugging.
|
||||||
|
// this.gl.texImage2D(
|
||||||
|
// this.gl.TEXTURE_2D, // target
|
||||||
|
// 0, // level
|
||||||
|
// this.gl.RGBA, // internal format
|
||||||
|
// 1, 1, 0, // width, height, border
|
||||||
|
// this.gl.RGBA, // format of content
|
||||||
|
// this.gl.UNSIGNED_BYTE, // type
|
||||||
|
// new ArrayBufferView([0, 0, 255, 128])
|
||||||
|
// );
|
||||||
|
|
||||||
// set some parameters
|
// set some parameters
|
||||||
// btw we don't need to set gl.TEXTURE_WRAP_[S|T], because it's set to repeat by default — which is what we want
|
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST);
|
||||||
this.gl.texParameteri(this.gl, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST);
|
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST);
|
||||||
this.gl.texParameteri(this.gl, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST);
|
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
|
||||||
|
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
|
||||||
|
|
||||||
// we need a rectangle. This is output data, not texture. This means that the size of the rectangle should be
|
// we need a rectangle. This is output data, not texture. This means that the size of the rectangle should be
|
||||||
// [sample count] x height of the sample, as shader can sample frame at a different resolution than what gets
|
// [sample count] x height of the sample, as shader can sample frame at a different resolution than what gets
|
||||||
// rendered here. We don't need all horizontal pixels on our output. We do need all vertical pixels, though)
|
// rendered here. We don't need all horizontal pixels on our output. We do need all vertical pixels, though)
|
||||||
this.glSetRectangle(this.gl, this.settings.active.aard.sampleCols, cheight);
|
this.glSetRectangle(this.gl, this.settings.active.aard.sampleCols, cheight);
|
||||||
|
|
||||||
// do setup once
|
console.log("gl setup complete");
|
||||||
// tho we could do it for every frame
|
|
||||||
this.canvasScaleFactor = cheight / this.video.videoHeight;
|
|
||||||
|
|
||||||
//#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
// [3] detect if we're in the fallback mode and reset guardline
|
|
||||||
//
|
|
||||||
|
|
||||||
if (this.fallbackMode) {
|
|
||||||
this.logger.log('warn', 'debug', `[AardGl::setup] <@${this.arid}> WARNING: CANVAS RESET DETECTED/we're in fallback mode - recalculating guardLine`, "background: #000; color: #ff2");
|
|
||||||
// blackbar, imagebar
|
|
||||||
this.guardLine.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// [4] see if browser supports "fallback mode" by drawing a small portion of our window
|
|
||||||
//
|
|
||||||
|
|
||||||
try {
|
drawScene() {
|
||||||
this.blackframeContext.drawWindow(window,0, 0, this.blackframeCanvas.width, this.blackframeCanvas.height, "rgba(0,0,128,1)");
|
if (this.count++ % 10 === 0) {
|
||||||
this.canDoFallbackMode = true;
|
this.greenC = !this.greenC;
|
||||||
} catch (e) {
|
}
|
||||||
this.canDoFallbackMode = false;
|
// clear canvas
|
||||||
|
this.gl.clearColor(0, this.greenC ? 0.5 : 0, 0.75, 0.5);
|
||||||
|
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
this.gl.useProgram(this.glProgram);
|
||||||
|
|
||||||
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.glData.positionBuffer);
|
||||||
|
this.gl.vertexAttribPointer(this.glData.attribLocations.vertexPosition, 3, this.gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.glData.textureCoordsBuffer);
|
||||||
|
this.gl.vertexAttribPointer(this.glData.attribLocations.textureCoord, size, type, normalized, stride, offset)
|
||||||
|
|
||||||
|
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.glData.indexBuffer);
|
||||||
|
|
||||||
|
// run our program
|
||||||
|
this.gl.useProgram(this.glProgram);
|
||||||
|
|
||||||
|
// Tell WebGL we want to affect texture unit 0
|
||||||
|
gl.activeTexture(gl.TEXTURE0);
|
||||||
|
|
||||||
|
// Bind the texture to texture unit 0
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
|
|
||||||
|
// Tell the shader we bound the texture to texture unit 0
|
||||||
|
gl.uniform1i(this.glData.uniformLocations.u_frame, 0);
|
||||||
|
|
||||||
|
// this.gl.drawElements(this.gl.TRIANGLES, 2, this.gl.UNSIGNED_BYTE, 0);
|
||||||
|
this.gl.drawArrays(this.gl.TRIANGLES, 0, 2)
|
||||||
|
|
||||||
|
// get the pixels back out:
|
||||||
|
this.gl.readPixels(0, 0, width, height, this.gl.RGBA, this.gl.UNSIGNED_BYTE, this.pixelBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
updateTexture() {
|
||||||
// [5] do other things setup needs to do
|
|
||||||
//
|
|
||||||
|
|
||||||
this.detectionTimeoutEventCount = 0;
|
|
||||||
this.resetBlackLevel();
|
|
||||||
|
|
||||||
// if we're restarting AardGl, we need to do this in order to force-recalculate aspect ratio
|
|
||||||
this.conf.resizer.setLastAr({type: AspectRatio.Automatic, ratio: this.getDefaultAr()});
|
|
||||||
|
|
||||||
this.canvasImageDataRowLength = cwidth << 2;
|
|
||||||
this.noLetterboxCanvasReset = false;
|
|
||||||
|
|
||||||
if (this.settings.canStartAutoAr() ) {
|
|
||||||
this.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Debug.debugCanvas.enabled){
|
|
||||||
// this.debugCanvas.init({width: cwidth, height: cheight});
|
|
||||||
// DebugCanvas.draw("test marker","test","rect", {x:5, y:5}, {width: 5, height: 5});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.conf.arSetupComplete = true;
|
|
||||||
console.log("DRAWING BUFFER SIZE:", this.gl.drawingBufferWidth, '×', this.gl.drawingBufferHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
drawFrame() {
|
|
||||||
const level = 0;
|
const level = 0;
|
||||||
const internalFormat = this.gl.RGBA;
|
const internalFormat = this.gl.RGBA;
|
||||||
const sourceFormat = this.gl.RGBA;
|
const sourceFormat = this.gl.RGBA;
|
||||||
@ -435,25 +548,31 @@ class AardGl {
|
|||||||
// TODO: check if 'width' and 'height' mean the input gets resized
|
// TODO: check if 'width' and 'height' mean the input gets resized
|
||||||
// this.gl.texImage2D(gl.TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels)
|
// this.gl.texImage2D(gl.TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels)
|
||||||
// } else {
|
// } else {
|
||||||
this.gl.texImage2D(gl.TEXTURE_2D, level, internalformat, sourceFormat, sourceType, this.video);
|
console.log(this.video)
|
||||||
|
this.gl.texImage2D(this.gl.TEXTURE_2D, level, internalFormat, sourceFormat, sourceType, this.video);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// get the pixels back out:
|
|
||||||
this.gl.readPixels(0, 0, width, height, format, type, pixels)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async main() {
|
async main() {
|
||||||
|
this.logger.log('info', 'debug', `"%c[AardGl::main] <@${this.arid}> Entering main function.`, _ard_console_start);
|
||||||
if (this._paused) {
|
if (this._paused) {
|
||||||
// unpause if paused
|
// unpause if paused
|
||||||
this._paused = false;
|
this._paused = false;
|
||||||
return; // main loop still keeps executing. Return is needed to avoid a million instances of autodetection
|
return; // main loop still keeps executing. Return is needed to avoid a million instances of autodetection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("we werent paused");
|
||||||
|
|
||||||
if (!this._halted) {
|
if (!this._halted) {
|
||||||
// we are already running, don't run twice
|
// we are already running, don't run twice
|
||||||
// this would have handled the 'paused' from before, actually.
|
// this would have handled the 'paused' from before, actually.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("we werent halted");
|
||||||
|
|
||||||
let exitedRetries = 10;
|
let exitedRetries = 10;
|
||||||
|
|
||||||
while (!this._exited && exitedRetries --> 0) {
|
while (!this._exited && exitedRetries --> 0) {
|
||||||
@ -465,7 +584,9 @@ class AardGl {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log('info', 'debug', `%c[AardGl::main] <@${this.arid}> Previous instance didn't exit in time. Not starting a new one.`);
|
console.log("no other instances")
|
||||||
|
|
||||||
|
this.logger.log('info', 'debug', `%c[AardGl::main] <@${this.arid}> Starting a new instance.`);
|
||||||
|
|
||||||
// we need to unhalt:
|
// we need to unhalt:
|
||||||
this._halted = false;
|
this._halted = false;
|
||||||
@ -478,6 +599,9 @@ class AardGl {
|
|||||||
let frameCheckBufferIndex = 0;
|
let frameCheckBufferIndex = 0;
|
||||||
let fcstart, fctime;
|
let fcstart, fctime;
|
||||||
|
|
||||||
|
this.logger.log('info', 'debug', `"%c[AardGl::start] <@${this.arid}> Starting aardGL loop!`, _ard_console_start);
|
||||||
|
|
||||||
|
try {
|
||||||
while (this && !this._halted) {
|
while (this && !this._halted) {
|
||||||
// NOTE: we separated tickrate and inter-check timeouts so that when video switches
|
// NOTE: we separated tickrate and inter-check timeouts so that when video switches
|
||||||
// state from 'paused' to 'playing', we don't need to wait for the rest of the longer
|
// state from 'paused' to 'playing', we don't need to wait for the rest of the longer
|
||||||
@ -505,21 +629,27 @@ class AardGl {
|
|||||||
|
|
||||||
await this.nextFrame();
|
await this.nextFrame();
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.log('error', 'debug', `%c[AardGl::main] <@${this.arid}> Main autodetection loop crashed. Reason?`, e, _ard_console_stop);
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.log('info', 'debug', `%c[AardGl::main] <@${this.arid}> Main autodetection loop exited. Halted? ${this._halted}`, _ard_console_stop);
|
this.logger.log('info', 'debug', `%c[AardGl::main] <@${this.arid}> Main autodetection loop exited. Halted? ${this._halted}`, _ard_console_stop);
|
||||||
this._exited = true;
|
this._exited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
frameCheck(){
|
frameCheck(){
|
||||||
|
try {
|
||||||
if(! this.video){
|
if(! this.video){
|
||||||
this.logger.log('error', 'debug', `%c[AardGl::frameCheck] <@${this.arid}> Video went missing. Destroying current instance of videoData.`);
|
this.logger.log('error', 'debug', `%c[AardGl::frameCheck] <@${this.arid}> Video went missing. Destroying current instance of videoData.`);
|
||||||
this.conf.destroy();
|
this.conf.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.blackframeContext) {
|
|
||||||
this.init();
|
// we dont have blackframe canvas atm
|
||||||
}
|
// if (!this.blackframeContext) {
|
||||||
|
// this.init();
|
||||||
|
// }
|
||||||
|
|
||||||
var startTime = performance.now();
|
var startTime = performance.now();
|
||||||
|
|
||||||
@ -529,7 +659,7 @@ class AardGl {
|
|||||||
let imageData;
|
let imageData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.drawFrame();
|
// this.drawFrame();
|
||||||
|
|
||||||
|
|
||||||
this.fallbackMode = false;
|
this.fallbackMode = false;
|
||||||
@ -537,12 +667,22 @@ class AardGl {
|
|||||||
this.logger.log('error', 'arDetect', `%c[AardGl::frameCheck] <@${this.arid}> %c[AardGl::frameCheck] can't draw image on canvas. ${this.canDoFallbackMode ? 'Trying canvas.drawWindow instead' : 'Doing nothing as browser doesn\'t support fallback mode.'}`, "color:#000; backgroud:#f51;", e);
|
this.logger.log('error', 'arDetect', `%c[AardGl::frameCheck] <@${this.arid}> %c[AardGl::frameCheck] can't draw image on canvas. ${this.canDoFallbackMode ? 'Trying canvas.drawWindow instead' : 'Doing nothing as browser doesn\'t support fallback mode.'}`, "color:#000; backgroud:#f51;", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [1]
|
// [1] update frame
|
||||||
|
try {
|
||||||
|
this.updateTexture();
|
||||||
|
this.drawScene();
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.log('error', 'aardGl', `%c[AardGl::frameCheck] <@${this.arid}> Something went wrong while trying to update/draw video frame with gl!`, "color:#000; backgroud:#f51;", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("TEXTURE DRAWN!", this.pixelBuffer)
|
||||||
|
|
||||||
|
// [N] clear data
|
||||||
|
|
||||||
this.clearImageData(imageData);
|
this.clearImageData(imageData);
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.log('error', 'debug', `%c[AardGl::frameCheck] <@${this.arid}> Error during framecheck.`, "background: #000; color: #fa2", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,7 +179,8 @@ class VideoData {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(! this.arSetupComplete){
|
if(! this.arSetupComplete){
|
||||||
this.arDetector = new ArDetector(this);
|
// this.arDetector = new ArDetector(this);
|
||||||
|
this.arDetector = new AardGl(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +193,8 @@ class VideoData {
|
|||||||
this.arDetector.init();
|
this.arDetector.init();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
this.arDetector = new ArDetector(this);
|
// this.arDetector = new ArDetector(this);
|
||||||
|
this.arDetector = new AardGl(this);
|
||||||
this.arDetector.init();
|
this.arDetector.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user