DRW: Add DRW_STATE_BLEND_PREMUL blend mode.
authorClément Foucault <foucault.clem@gmail.com>
Mon, 23 Apr 2018 20:58:47 +0000 (22:58 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 2 May 2018 18:49:38 +0000 (20:49 +0200)
source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_manager_exec.c

index a9c14762a041bc442404699a24c67961966ee9e1..31046377b19e2871b4832e95128b3464896f889f 100644 (file)
@@ -268,6 +268,7 @@ typedef enum {
        DRW_STATE_TRANSMISSION  = (1 << 17),
        DRW_STATE_CLIP_PLANES   = (1 << 18),
        DRW_STATE_ADDITIVE_FULL = (1 << 19), /* Same as DRW_STATE_ADDITIVE but let alpha accumulate without premult. */
+       DRW_STATE_BLEND_PREMUL  = (1 << 20), /* Use that if color is already premult by alpha. */
 
        DRW_STATE_WRITE_STENCIL    = (1 << 27),
        DRW_STATE_STENCIL_EQUAL    = (1 << 28),
index 9aa5efc837d79f662ed2c3ff4d6563d82665daeb..a70d80257e6302ca349be614bd648df6499eb313 100644 (file)
@@ -190,8 +190,8 @@ void drw_state_set(DRWState state)
        {
                int test;
                if (CHANGED_ANY_STORE_VAR(
-                       DRW_STATE_BLEND | DRW_STATE_ADDITIVE | DRW_STATE_MULTIPLY | DRW_STATE_TRANSMISSION |
-                       DRW_STATE_ADDITIVE_FULL,
+                       DRW_STATE_BLEND | DRW_STATE_BLEND_PREMUL | DRW_STATE_ADDITIVE |
+                       DRW_STATE_MULTIPLY | DRW_STATE_TRANSMISSION | DRW_STATE_ADDITIVE_FULL,
                        test))
                {
                        if (test) {
@@ -201,6 +201,9 @@ void drw_state_set(DRWState state)
                                        glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, /* RGB */
                                                            GL_ONE, GL_ONE_MINUS_SRC_ALPHA); /* Alpha */
                                }
+                               else if ((state & DRW_STATE_BLEND_PREMUL) != 0) {
+                                       glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+                               }
                                else if ((state & DRW_STATE_MULTIPLY) != 0) {
                                        glBlendFunc(GL_DST_COLOR, GL_ZERO);
                                }