Jump to content

  • Log In with Google      Sign In   
  • Create Account

I need to copy datas from a buffer to texture object


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 FireInDark   Members   -  Reputation: 148

Like
0Likes
Like

Posted 07 August 2012 - 04:18 AM

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 ?

Sponsor:

#2 Ignifex   Members   -  Reputation: 507

Like
0Likes
Like

Posted 08 August 2012 - 04:40 AM

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?

#3 FireInDark   Members   -  Reputation: 148

Like
0Likes
Like

Posted 09 August 2012 - 02:26 AM

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 ..

#4 FireInDark   Members   -  Reputation: 148

Like
0Likes
Like

Posted 09 August 2012 - 02:40 AM

And that :if I can visit the datas from Frame Buffer there would be no problem..

But seems it's not possible..

#5 FireInDark   Members   -  Reputation: 148

Like
0Likes
Like

Posted 09 August 2012 - 02:43 AM

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?

#6 Ignifex   Members   -  Reputation: 507

Like
0Likes
Like

Posted 09 August 2012 - 05:51 AM

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.

#7 FireInDark   Members   -  Reputation: 148

Like
0Likes
Like

Posted 10 August 2012 - 03:37 AM

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.

#8 FireInDark   Members   -  Reputation: 148

Like
0Likes
Like

Posted 10 August 2012 - 03:44 AM

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 ?

#9 Olof Hedman   Crossbones+   -  Reputation: 2950

Like
0Likes
Like

Posted 10 August 2012 - 03:47 AM

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.

#10 Ignifex   Members   -  Reputation: 507

Like
0Likes
Like

Posted 10 August 2012 - 08:55 AM

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.

#11 FireInDark   Members   -  Reputation: 148

Like
0Likes
Like

Posted 12 August 2012 - 08:52 PM

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.


Maybe I understand now ,let me have a try.

Thank you very much.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS