fix(image-pipeline): correct webgl source binding and context init

This commit is contained in:
Matthias
2026-04-04 22:09:14 +02:00
parent 80f12739f9
commit 195a812ba2
2 changed files with 86 additions and 3 deletions

View File

@@ -42,12 +42,14 @@ function assertSupportedStep(step: PipelineStep): void {
function createGlContext(): WebGLRenderingContext {
if (typeof document !== "undefined") {
const canvas = document.createElement("canvas");
const context = canvas.getContext("webgl", {
const contextOptions: WebGLContextAttributes = {
alpha: true,
antialias: false,
premultipliedAlpha: false,
preserveDrawingBuffer: true,
});
};
const context =
canvas.getContext("webgl2", contextOptions) ?? canvas.getContext("webgl", contextOptions);
if (context) {
return context;
}
@@ -55,7 +57,7 @@ function createGlContext(): WebGLRenderingContext {
if (typeof OffscreenCanvas !== "undefined") {
const canvas = new OffscreenCanvas(1, 1);
const context = canvas.getContext("webgl");
const context = canvas.getContext("webgl2") ?? canvas.getContext("webgl");
if (context) {
return context;
}
@@ -229,6 +231,9 @@ function runStepOnGpu(context: WebglBackendContext, request: BackendStepRequest)
throw new Error("WebGL framebuffer is incomplete.");
}
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, sourceTexture);
const sourceLocation = gl.getUniformLocation(shaderProgram, "uSource");
if (sourceLocation) {
gl.uniform1i(sourceLocation, 0);