Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Blend mode copying DESTINATION alpha?

This thread is locked; no one can reply to it. rss feed Print
Blend mode copying DESTINATION alpha?
Winfield
Member #15,244
July 2013
avatar

Like the title says, I've got to blend two bitmaps together and I need to retain the destination alpha. I've kludged around the problem for now by re-drawing the original bitmap with this blender mode:

ALLEGRO_ADD, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ALPHA

...which is an absolutely awful solution, so I need to either figure out a one-pass draw blender which retains the destination alpha, or implement the whole pipeline in a shader.

As a bonus question, how do shaders compare to blender options in terms of performance?

SiegeLord
Member #7,827
October 2006
avatar

al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE).

Winfield said:

As a bonus question, how do shaders compare to blender options in terms of performance?

They do different things, so comparing them is somewhat tenuous. Blenders blend source and destination pixels. Shaders modify source pixels only (with an option to combine several bitmaps together in the process).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Kris Asick
Member #1,424
July 2001

Blenders inherently work on all colour channels at once, so in order to achieve different results on different channels in a single pass, you're gonna have to use shaders. :P

Siege made note that you can only operate on source pixels though, so what you'll likely need to do is have a destination bitmap that's separate from the two bitmaps you want to blend together. The plus side though is that shaders are lightning fast and for what you want to do there shouldn't be a performance hit at all, even on low-end hardware. :)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Winfield
Member #15,244
July 2013
avatar

SiegeLord's blender did the trick. Brill, can't believe I missed the al_set_separate_blender function in the manual. :)

Kris Asick
Member #1,424
July 2001

*facepalm* I totally forgot about that function too, and I've even read about it before! ::)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Go to: