WIP aardgl work, before switching back to master
This commit is contained in:
parent
b296552e35
commit
fb7d7735be
@ -325,6 +325,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 = "absolute";
|
||||||
|
this.canvas.style.left = `50px`;
|
||||||
|
this.canvas.style.top = `50px`;
|
||||||
|
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);
|
||||||
@ -343,17 +354,17 @@ 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]);
|
this.glProgram = this.compileProgram(this.gl, [vertexShader, horizontalAdderShader]);
|
||||||
|
|
||||||
// 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
|
// create buffers and bind them
|
||||||
const positionBuffer = this.gl.createBuffer();
|
this.positionBuffer = this.gl.createBuffer();
|
||||||
const textureCoordsBuffer = this.gl.createBuffer();
|
this.textureCoordsBuffer = this.gl.createBuffer();
|
||||||
this.gl.bindBuffer(this.gl, positionBuffer);
|
this.gl.bindBuffer(this.gl, this.positionBuffer);
|
||||||
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, textureCoordsBuffer);
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.textureCoordsBuffer);
|
||||||
|
|
||||||
// create a texture
|
// create a texture
|
||||||
this.texture = this.gl.createTexture();
|
this.texture = this.gl.createTexture();
|
||||||
@ -422,7 +433,23 @@ class AardGl {
|
|||||||
console.log("DRAWING BUFFER SIZE:", this.gl.drawingBufferWidth, '×', this.gl.drawingBufferHeight);
|
console.log("DRAWING BUFFER SIZE:", this.gl.drawingBufferWidth, '×', this.gl.drawingBufferHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawFrame() {
|
drawScene() {
|
||||||
|
// clear canvas
|
||||||
|
this.gl.clearColor(0.0, 0.0, 1.0, 0.5);
|
||||||
|
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
this.gl.useProgram(this.glProgram);
|
||||||
|
|
||||||
|
this.gl.bindBuffer(this.gl, this.positionBuffer);
|
||||||
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.textureCoordsBuffer);
|
||||||
|
|
||||||
|
// this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, framebuffer)
|
||||||
|
|
||||||
|
// get the pixels back out:
|
||||||
|
// this.gl.readPixels(0, 0, width, height, format, type, pixels)
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTexture() {
|
||||||
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;
|
||||||
@ -437,22 +464,27 @@ class AardGl {
|
|||||||
this.gl.texImage2D(gl.TEXTURE_2D, level, internalformat, sourceFormat, sourceType, this.video);
|
this.gl.texImage2D(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) {
|
||||||
@ -464,7 +496,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;
|
||||||
@ -477,6 +511,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
|
||||||
@ -504,6 +541,9 @@ 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;
|
||||||
@ -516,9 +556,12 @@ class AardGl {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.blackframeContext) {
|
console.info("frame check into happenings")
|
||||||
this.init();
|
|
||||||
}
|
// we dont have blackframe canvas atm
|
||||||
|
// if (!this.blackframeContext) {
|
||||||
|
// this.init();
|
||||||
|
// }
|
||||||
|
|
||||||
var startTime = performance.now();
|
var startTime = performance.now();
|
||||||
|
|
||||||
@ -528,7 +571,7 @@ class AardGl {
|
|||||||
let imageData;
|
let imageData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.drawFrame();
|
// this.drawFrame();
|
||||||
|
|
||||||
|
|
||||||
this.fallbackMode = false;
|
this.fallbackMode = false;
|
||||||
@ -536,10 +579,15 @@ 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.clearImageData(imageData);
|
this.clearImageData(imageData);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user