I need to copy datas from a buffer to texture object
#2 Members - Reputation: 431
Posted 08 August 2012 - 04:40 AM
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 Members - Reputation: 148
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 ..
#6 Members - Reputation: 431
Posted 09 August 2012 - 05:51 AM
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 Members - Reputation: 148
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 Members - Reputation: 148
Posted 10 August 2012 - 03:44 AM
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 ?
#10 Members - Reputation: 431
Posted 10 August 2012 - 08:55 AM
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 Members - Reputation: 148
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.






