src/Common/Misc/WebGl/index.js
function bindTextureToFramebuffer(gl, fbo, texture) {
  gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
  gl.bindTexture(gl.TEXTURE_2D, texture);

  gl.texImage2D(
    gl.TEXTURE_2D,
    0,
    gl.RGBA,
    fbo.width,
    fbo.height,
    0,
    gl.RGBA,
    gl.UNSIGNED_BYTE,
    null
  );

  gl.framebufferTexture2D(
    gl.FRAMEBUFFER,
    gl.COLOR_ATTACHMENT0,
    gl.TEXTURE_2D,
    texture,
    0
  );

  // Check fbo status
  const fbs = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
  if (fbs !== gl.FRAMEBUFFER_COMPLETE) {
    console.log('ERROR: There is a problem with the framebuffer:', fbs);
  }

  // Clear the bindings we created in this function.
  gl.bindTexture(gl.TEXTURE_2D, null);
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
function bindTextureToFramebuffer(gl, fbo, texture) {
  gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
  gl.bindTexture(gl.TEXTURE_2D, texture);

  gl.texImage2D(
    gl.TEXTURE_2D,
    0,
    gl.RGBA,
    fbo.width,
    fbo.height,
    0,
    gl.RGBA,
    gl.UNSIGNED_BYTE,
    null
  );

  gl.framebufferTexture2D(
    gl.FRAMEBUFFER,
    gl.COLOR_ATTACHMENT0,
    gl.TEXTURE_2D,
    texture,
    0
  );

  // Check fbo status
  const fbs = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
  if (fbs !== gl.FRAMEBUFFER_COMPLETE) {
    console.log('ERROR: There is a problem with the framebuffer:', fbs);
  }

  // Clear the bindings we created in this function.
  gl.bindTexture(gl.TEXTURE_2D, null);
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
function bindTextureToFramebuffer ( gl , fbo , texture ) { gl . bindFramebuffer ( gl . FRAMEBUFFER , fbo ) ; gl . bindTexture ( gl . TEXTURE_2D , texture ) ; gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , fbo . width , fbo . height , 0 , gl . RGBA , gl . UNSIGNED_BYTE , null ) ; gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , texture , 0 ) ; // Check fbo status const fbs = gl . checkFramebufferStatus ( gl . FRAMEBUFFER ) ; if ( fbs !== gl . FRAMEBUFFER_COMPLETE ) { console . log ( 'ERROR: There is a problem with the framebuffer:' , fbs ) ; } // Clear the bindings we created in this function. gl . bindTexture ( gl . TEXTURE_2D , null ) ; gl . bindFramebuffer ( gl . FRAMEBUFFER , null ) ; }
Bind texture to Framebuffer
Bind texture to Framebuffer