Just by curiosity, why we need to bind a dummy framebuffer and attach the texture to its color attachment before reading back the pixels? Can we just directly bind the texture instead?
let gl = this._gl;
if (!this._dummyFramebuffer) {
let dummy = gl.createFramebuffer();
if (!dummy) {
throw new Error("Unable to create dummy framebuffer");
}
this._dummyFramebuffer = dummy;
}
gl.bindFramebuffer(gl.FRAMEBUFFER, this._dummyFramebuffer);
if (faceIndex > -1) {
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, texture._webGLTexture, level);
} else {
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture._webGLTexture, level);
}
let readType = (texture.type !== undefined) ? this._getWebGLTextureType(texture.type) : gl.UNSIGNED_BYTE;
switch (readType) {
You can only read from framebuffer
I read the documentation from glReadPixels function - Windows applications | Microsoft Docs . Yes now understand better. Thank you.
No worries it is important to understand how it works