I need to copy datas from a buffer to texture object

Started by
9 comments, last by FireInDark 11 years, 8 months ago
A FBO connect with a RenderTexture ,depth buffer,and other buffers..

Now I create a new Texture ,I want to copy the data from depth buffer to this texture.
Any way ?
Advertisement
The most obvious answer would be a call to glCopyTexImage2D, or something similar, after "unbinding" your FBO.
If this is not what you are looking for, could you tell us a little more on this new texture? What format is it? Is it also used with an FBO?

Is it also used with an FBO?


No ,it's just a common texture.

To be honest ,What I want to do is blending all the objects rendered by it's depth ,stencil ,alpha and some thing else. my self.

I got a way to do what I want to do ,But there are extra works to do ,not so directly ..
And that :if I can visit the datas from Frame Buffer there would be no problem..

But seems it's not possible..
Think about that :
If copy the datas to a texture with glCopyTexImage2D every time an element rendered ,wouldn't it'll take a long time?
What do you mean by visiting the data of the Frame Buffer? Do you wish to use the data on the CPU?
If that is the case, then I'm afraid it won't be fast. The best you can do is glGetTexImage, which returns the image's pixels to memory.

Simply copying data from one texture to another should, and I am only 90% sure, dependent on the internal texture formats, be done entirely on the GPU and should not take up too much time.

If you are looking for advice on the fastest way to do something, you will need to be a little more specific on what you have and what you want to do with it.

What do you mean by visiting the data of the Frame Buffer? Do you wish to use the data on the CPU?


No I don't use the datas in CPU but GPU -GLSL

I need control if the right pixel of an element such as a triangle will be draw to the frame buffer.
It is this:

There are two elemets A and B .
1.We render A to the Frame Buffer - yes then the Frame Buffer contains pixel of A , some pixels's alpha are zero and some are not..
2.We render B to the Frame Buffer - and how ever - if the alpha in Frame Buffer is zero ,the pixels at the same position(2D) of B will be draw to the FrameBuffer else not.

May be we can use stencil values but there are some reason I don't want to do like this.

Any way ?
With an FBO, you can bind textures as color and depth attachements, and get the pixels in the texture(s) "automatically", without doing an explicit copy.

With modern hardware, this should be very efficient.
If you only need information from your alpha channel, after your first render of A, then it might be sufficient to use some properly set up alpha blending. Try using the destination alpha to blend with in glBlendFunc.

If that is not sufficient, I see several other options. The problem is mainly that you cannot read from and write to the same FBO. Several workarounds:
- As you mentioned, copy the data to another texture and use this texture during the render of B. Not really fast imo.
- Use 2 FBO's. You use a separate renderpass where you render A's "alpha" as a greyvalue to the second FBO. Then you can use this data while rendering A and B to the first FBO.
- Use one FBO with two color targets. This works, is probably the fastest if simple blending is not sufficient, but is a bit difficult to set up properly.

Apart from these, I don't see a fast way to get what you want. However, I believe you should be able to achieve what you want using alpha blending.

This topic is closed to new replies.

Advertisement