Skip to content

Fix: Support all WebGL2 TypedArray types in convertPixels#335

Open
Determinated738 wants to merge 1 commit into
stackgl:masterfrom
Determinated738:fix-webgl2-tex-conversion
Open

Fix: Support all WebGL2 TypedArray types in convertPixels#335
Determinated738 wants to merge 1 commit into
stackgl:masterfrom
Determinated738:fix-webgl2-tex-conversion

Conversation

@Determinated738

Copy link
Copy Markdown

This PR fixes an issue where when you pass a TypedArray such as Uint32Array to gl.texImage2D, the convertPixels fails and returns null, resulting in the cpp side getting null and defaulting to all 0s.

Minimal code to recreate the bug:

const gl = createGL(64, 64, { createWebGL2Context: true });
const tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
const inputData = new Uint32Array([10, 20, 30, 40]);
// This should succeed in WebGL2, but the headless driver rejects it.
gl.texImage2D(
    gl.TEXTURE_2D,
    0,
    gl.RGBA32UI,
    1,
    1,
    0,
    gl.RGBA_INTEGER,
    gl.UNSIGNED_INT,
    inputData,
);

const fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferTexture2D(
    gl.FRAMEBUFFER,
    gl.COLOR_ATTACHMENT0,
    gl.TEXTURE_2D,
    tex,
    0,
);
const readback = new Uint32Array(4);
gl.readPixels(0, 0, 1, 1, gl.RGBA_INTEGER, gl.UNSIGNED_INT, readback);
console.log("Expected output:", inputData);
console.log("Actual readback:", readback);

Changes:

Updated src/javascript/utils.js to use the isTypedArray helper function in convertPixels. To support all the standard TypedArray types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant