best method of updating alpha only of a framebuffer

so whats best method of updating alpha only of a framebuffer, ie not touching the RGB portion.
u can use glColorMask(0,0,0,1) but i believe ive read the graphics cards makers say this is a bad idea performance wise

is it my only option?

I think that’s your only option.

You might be able to do something with separate color/alpha functions, but that’s only available in the higher-end hardware.

Copy your framebuffer to a texture so you have the RGB values you want to preserve. Then use this texture when updating the alpha.

I’d have to go along with Cass. If you take Zed’s question literally, the only way to “not touch” the RGB portion is to mask it off. Not touching precludes copying/texturing and blending, doesn’t it?

Perhaps he had no intention of introducing such a stringent restriction, but IMHO that’s what he did :slight_smile:

P.S. Performance wise, how bad could masking be? Worse than blending or copying/texturing?

I can’t imagine that masking can be very expensive at all on modern hardware. It certainly must be cheaper than blending or copying.

You should really benchmark color masking yourself before dismissing it outright. Those features are there, because they are the right way to address this need.

There might be some special cases where it is significantly slower, but not generally. ie, some hardware likely implements things glClear as a 2D blit rather than a 3D op, and enabling masking might disable that optimization. But for general 3D drawing, I can’t imagine seeing a large difference.

I can’t imagine that masking can be very expensive at all on modern hardware. It certainly must be cheaper than blending or copying.
Well, hardware is designed for the most common operation. Which is writing one 32-bit color. Writing to individual bytes is actually much harder than shoving a 32-bit word across a bus; the latter requires a much simpler memory controller. So I could see masking actually being implemented as a specialized blend-style read/modify/write.

Zed, please tell us about the performance after you tried it :slight_smile:

my question was based on this from a ATI/NVIDIA performance pdf

nvidia specific FB operations

  • do not mask off only some color channels unless really necessary
    and since the pdf looks like a slide from a talk I thought perhaps they mentioned an alternative method of doing it,
    which appears not to be readily available.

though it seems to impley that ati doesnt have the performance degradation from part channel color masking

Originally posted by Zengar:
Zed, please tell us about the performance after you tried it :slight_smile:
sorry ive since switched to a different method for updating the alpha ( i usually try a few different methods before deciding on a final choice ), this was all for DOF, which does seem to be pretty sweet now (though wether it adds to gameplay is questionable, it certainly detracts from the framerate)
http://www.zedzeek.com/DOF1.jpg
http://www.zedzeek.com/DOF2.jpg
http://www.zedzeek.com/DOF3.jpg

next step HDR, cant say im looking forward to it :frowning:

Depending on the specific hardware, color mask can cost you just the bandwidth for updating alpha, or the bandwidth for updating RGB and A.

When it does cost you the full bandwidth, it usually also costs a full read-modify-write (like a blend) rather than a simple write.

There are also situations where leaving alpha in some unnecessarily “dirty” state could interfere with color compression.

It’s difficult to make general statements about what to avoid and what to use freely for best perf. Especially in a hardware neutral way…