Skip to content

Fix readPixels PBO segfault & implement getBufferSubData for WebGL2#334

Open
Determinated738 wants to merge 1 commit into
stackgl:masterfrom
Determinated738:master
Open

Fix readPixels PBO segfault & implement getBufferSubData for WebGL2#334
Determinated738 wants to merge 1 commit into
stackgl:masterfrom
Determinated738:master

Conversation

@Determinated738

Copy link
Copy Markdown

This PR fixes a segfault that happens when using PBOs, as well as implementing getBufferSubData as it was missing.

Minimal code for recreating the segfault:

import createGL from "gl";

const width = 512;
const height = 512;
const size = width * height * 4;

const gl = createGL(width, height, { createWebGL2Context: true });

try {
    const pbo = gl.createBuffer();
    gl.bindBuffer(gl.PIXEL_PACK_BUFFER, pbo);
    gl.bufferData(gl.PIXEL_PACK_BUFFER, size, gl.STREAM_READ);
    gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);

    gl.clearColor(1, 0, 0, 1);
    gl.clear(gl.COLOR_BUFFER_BIT);

    gl.bindBuffer(gl.PIXEL_PACK_BUFFER, pbo);
    gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, 0);

    const pixels = new Uint8Array(size);
    gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, pixels);
    console.log(pixels);
} catch (e) {
    console.error("Caught JS Error:", e);
}

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