created ShadeMyCanvas (smc)

This commit is contained in:
do butterflies cry? 2026-02-02 01:12:53 +10:00
parent 935cc44f66
commit 1d06470ccd
12 changed files with 539 additions and 24 deletions

37
www/js/smc/smc.js.bak Normal file
View file

@ -0,0 +1,37 @@
import { SmcErr } from "./errors.js";
import { SmcBuilder } from "./builder.js";
export { SmcErr };
// XXX: TODO: merge SmcBuilder into smc
class smc {
#canvas;
#builderDelegate = _ => { };
constructor(canvas) {
this.#canvas = canvas;
}
build(delegate) {
this.#builderDelegate = delegate;
return this;
}
onError(delegate) {
this.#errorDelegate = delegate;
return this;
}
run() {
this.#canvas = canvas;
const gl = this.#canvas.getContext("webgl");
if (gl == null) {
this.#raiseError(
SmcErr.UNSUPPORTED,
Error("Unable to initialize WebGL. Your browser or machine may not support it."),
);
}
const builder = this.#builderDelegate(new SmcBuilder(gl, this.#raiseError))
builder.render()
}
}