[SOLVED] Can't read from a texture locked with TEXTURELOCK_READ, it doesn't seem to do anything

Hi @heretique,

Yes, correct, you should be using readPixels, not aware of any other way. Here is how I do this:

const readPixelsFromTexture = function (texture) {

    const app = this.app;

    // make a framebuffer
    const gl = app.graphicsDevice.gl;
    const fb = gl.createFramebuffer();

    // make this the current frame buffer
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);

    // attach the texture to the framebuffer.
    gl.framebufferTexture2D(
        gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
        gl.TEXTURE_2D, texture._glTexture, 0);

    // read the pixels
    const pixels = new Uint8Array(texture.width * texture.height * 4);
    gl.readPixels(0, 0, texture.width, texture.height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

    // Unbind the framebuffer
    gl.bindFramebuffer(gl.FRAMEBUFFER, null);

    return pixels;
};
3 Likes