0

I have an existing framebuffer (with color and depth information) that I need to composite with the canvas' backbuffer (drawing buffer). How can I draw the contents from one framebuffer into the backbuffer?

Alternatively, if there is a way to directly manipulate the drawing buffer, I could put my information directly into it without creating a second framebuffer. Write now I am writing a texture into the framebuffer using:

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

But that will not work on the drawing buffer because it throws an error when gl.FRAMEBUFFER is not bound (and I don't know a way to bind it to the drawing buffer).

Eric
  • 1,414
  • 3
  • 16
  • 35
  • I'm not sure I follow your question. A framebuffer is just a combination of attachments. Those attachments can be renderbuffers and textures. Any textures can easily be rendered with. That means your question becomes basically 'how can I render a texture' which I'm guessing you already know. – gman Nov 06 '13 at 01:18
  • Heh, heh ... quite right that my question is a little more complicated than that. ;o) I'm wondering how I can take a texture that already exists and set it as the color_attachment of the drawing buffer (so, I'm not drawing polygons that I'm applying this texture to, I'm actually using the texture as the entire rendered scene). I will then do the same with the depth attachment and then render another set of geometry in the drawing buffer to create a composite scene ... does that make more sense? – Eric Nov 06 '13 at 14:59
  • 1
    I'm still not following. If you're just going to draw some polygons to a texture, then make that texture the drawing buffer, then draw my polygons on top, why not just draw all to the drawing buffer in the first place? Otherwise, draw the texture as a quad onto the drawing buffer and then draw your stuff over it. There's no way in WebGL to make your texture the color attachment of the drawing buffer. The drawing buffer(s) are managed by WebGL exclusively (at least in version 1 of WebGL) – gman Nov 07 '13 at 01:28
  • The first render is actually not done on my machine. It is served up by a render server. But you bring up a good point. I can put that in a framebuffer, then draw my triangles to that same framebuffer, then I can draw the resulting texture onto a rectangle in the drawing buffer. Thanks! -- If you want to write that as an answer, I'll accept it. :o) – Eric Nov 08 '13 at 17:45

1 Answers1

0

To get data out of the primary screen buffer you need to copyTexImage2D its data to another texture.

Also note the issues around whether you have constructed your WebGL context using 'preserveDrawingBuffer' set to true or not. The default for context creation is false, and that means that after you return control to the browser after drawing, you cannot count on the contents of the main drawing buffer still being there.

And it's generally a good idea to have preserveDrawingBuffer=false, because it can have a significant impact on performance.

Baxissimo
  • 2,629
  • 2
  • 25
  • 23
  • I'm actually trying to go the other direction ... cramming a texture into the primary screen buffer, rather than reading it out. Any idea how to do that? – Eric Nov 06 '13 at 14:58