Blit from multisample textures to non multisample - opengl

I've one MS FBO with 3 attached MS textures and nonMS FBO also with 3 attacheed nonMS textures. Is there a way how to blit that? If i blit FBO's entirely, MS FBO combines it in a one texture, and that's not working. How to make that separately?
Thank you.

Framebuffer blitting can only read from a single color attachment (specified by glReadBuffer) at one time. It can blit to multiple output attachments (specified by glDrawBuffers), but that's just copying the same rectangle to multiple destinations.
If you want to read from each image and write to the corresponding image, you need to use 3 separate blitting function calls.

Related

Rendering layers of bitmaps with alpha to FBO

I need to draw several "layers" of bitmaps that are semi-transparent to a FBO (for later readback).
My current approach is to create a FBO, attach a texture to it and use glTexSubImage2D to "draw" the bitmaps to the FBO, this however, doesn't work as glTexSubImage2D doesn't draw/blend the pixels, but just overwrite the pixels currently in the texture.
What's the best way to do this?
You create a FBO with a clean texture R attached to hold the final result.
For each of your bitmaps you:
Upload the bitmap to a texture T (T and and R are different textures).
Render a quad textured with T into the FBO with GL_BLEND enabled and properly set up.
The final result is that R holds your blended bitmaps. You can now read it back or use in other texturing operations.

Render to window framebuffer and FBO to save full scale texture image

I would like to save the output of my image processing OpenGL shader program to an image file and also display the result on the screen. I know how to save the window framebuffer using glReadPixels(). However, the resolution of the screen is smaller than the dimensions of the image.
If I render to an FBO, do I need to call glDrawArrays() again after saving and unbinding the FBO to see the results on the screen? Or is it possible to tell the window framebuffer to render from the FBO without having to run the shader program a second time?
To save the rendered image in the RBO, you can read the pixels directly by setting which buffer OpenGL will read the pixels from by calling glReadBuffer. In your particular case, setting the read buffer to GL_COLOR_ATTACHMENT<i> should do the trick. See the glDrawBuffer man page for details.
In order to display the image in the FBO: yes, you will need to make an additional rendering pass to copy the FBO's image into the default frame buffer. You an either bind the FBO as a texture, and render geometry, as you suggest, to get the image on the screen, or, you may be able to use glBlitFramebuffer to simplify the copying and image filtering.
If I render to an FBO, do I need to call glDrawArrays() again after saving and unbinding the FBO to see the results on the screen?
You should use glBlitFramebuffer (...), the purpose of this function is to copy one framebuffer (read buffer) to another (draw buffer). Provided you are not doing something unusual like drawing into an integer texture attachment then your FBO's draw buffer should be compatible with your default framebuffer (window).
There are some additional caveats related to the filter method and the type of image you are copying (e.g. depth buffers cannot use linearly interpolation), but since you are discussing "full scale" here, I imagine you are interested in GL_NEAREST anyway.

Can a texture be bound to more than one fbo?

Can the same texture be bound to more than one framebuffer object?
I need to write on some texture in a multi target rendering pass with a certain fbo, and later to add some blending to just one of those texture, so I need a second framebuffer object with that texture bound to.
I have no idea why you would think that you can't attach a texture to multiple FBOs. So yes, you can.
However, you shouldn't need to for your purposes. You don't have to write to all of the images attached to an FBO. You control what images get written to with glDrawBuffers. You can even selectively enable and disable blending to certain draw buffers, if you need to write to multiple buffers but only blend with certain ones.
So yes you can, but you shouldn't bother. Just switch your draw buffers, unless you need a new depth buffer or something.

What is faster? Framebuffer color attachment or full screen texture quad?

I want to draw fullscreen frames of a sequence, and switch between them fast. I saw that I could attach multiply color attachments to a framebuffer.
I'm wondering if it could be far cheaper to use renderbuffer attachments instead of the current textured quads method.
How can I switch between attachments by the way? Is there a maximum number of attachments?
I want to draw fullscreen frames of a sequence, and switch between them fast.
Drawing images always means uploading the data to a texture and drawing a quad using that texture. Look into Pixel Buffer Objects to implement asynchronous data upload and glTexStorage (OpenGL-4.2 feature) for how to bolt the memory layout down.
I saw that I could attach multiply color attachments to a framebuffer.
The framebuffers this applies to are off-screen framebuffer objects, and not the on screen framebuffer. I.e. this won't help you in any way.

How to render Framebuffer Objects on multi-sampled textures?

I currently have a rendering engine using multiple passes in which various parts of the image are rendered on textures, and then combined using shaders. It works, and now I would like to activate multi-sampling.
I read here ( http://www.opengl.org/wiki/Framebuffer_Object_Examples#MSAA ) that, with OpenGL, you can't attach a GL_TEXTURE2D_MULTISAMPLE to a framebuffer object.
It seems one way to use multi-sampling and still have access to the result as texture is to use a multi-sampled render buffer, and then copy the result into a multisample texture.
My question is: what would be the best way to go forward?
Is it possible to render in a render buffer and use the output in my shader, without copying into a texture?
Should I indeed copy the content of the buffer into a texture, and then use it?
Is there another, better, solution?
Thanks.
I read here ( http://www.opengl.org/wiki/Framebuffer_Object_Examples#MSAA ) that, with OpenGL, you can't attach a GL_TEXTURE2D_MULTISAMPLE to a framebuffer object.
Read it again. It says nothing about GL_TEXTURE_2D_MULTISAMPLE textures. Actually, I take that back: don't read that page again. If you want good FBO info, read the page on Framebuffer Objects that explains 3.x behavior. The page you linked to is old.
Back in the EXT days, all you had were multisampled renderbuffers, because multisample textures didn't exist. You could create multisampled buffers, but you couldn't texture with them. You could only blit them.
In 3.3 OpenGL, you can create multisampled textures. And you can attach them just like any other texture to an FBO.