[Bf-blender-cvs] [18c4fcb9a34] greasepencil-refactor: DRW: Add subtract blend logic
Clément Foucault
noreply at git.blender.org
Fri Dec 13 19:45:02 CET 2019
Commit: 18c4fcb9a34b05da4854b34509b3641b793eda6b
Author: Clément Foucault
Date: Fri Dec 13 19:31:02 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB18c4fcb9a34b05da4854b34509b3641b793eda6b
DRW: Add subtract blend logic
This is to support subtract blending with Multiple Render Targets
===================================================================
M source/blender/draw/intern/DRW_render.h
M source/blender/draw/intern/draw_manager_exec.c
===================================================================
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index f00bf61cbb7..d84a8a66810 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -305,8 +305,9 @@ typedef enum {
DRW_STATE_BLEND_ALPHA_UNDER_PREMUL = (1 << 20),
DRW_STATE_BLEND_OIT = (1 << 21),
DRW_STATE_BLEND_MUL = (1 << 22),
+ DRW_STATE_BLEND_SUB = (1 << 23),
/** Use dual source blending. WARNING: Only one color buffer allowed. */
- DRW_STATE_BLEND_CUSTOM = (1 << 23),
+ DRW_STATE_BLEND_CUSTOM = (1 << 24),
DRW_STATE_IN_FRONT_SELECT = (1 << 25),
DRW_STATE_LOGIC_INVERT = (1 << 26),
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 977bec92cba..bd378d78780 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -233,11 +233,11 @@ void drw_state_set(DRWState state)
/* Blending (all buffer) */
{
int test;
- if (CHANGED_ANY_STORE_VAR(DRW_STATE_BLEND_ALPHA | DRW_STATE_BLEND_ALPHA_PREMUL |
- DRW_STATE_BLEND_ADD | DRW_STATE_BLEND_MUL |
- DRW_STATE_BLEND_ADD_FULL | DRW_STATE_BLEND_OIT |
- DRW_STATE_BLEND_ALPHA_UNDER_PREMUL | DRW_STATE_BLEND_CUSTOM,
- test)) {
+ if (CHANGED_ANY_STORE_VAR(
+ DRW_STATE_BLEND_ALPHA | DRW_STATE_BLEND_ALPHA_PREMUL | DRW_STATE_BLEND_ADD |
+ DRW_STATE_BLEND_MUL | DRW_STATE_BLEND_ADD_FULL | DRW_STATE_BLEND_OIT |
+ DRW_STATE_BLEND_ALPHA_UNDER_PREMUL | DRW_STATE_BLEND_CUSTOM | DRW_STATE_BLEND_SUB,
+ test)) {
if (test) {
glEnable(GL_BLEND);
@@ -273,6 +273,9 @@ void drw_state_set(DRWState state)
/* Let alpha accumulate. */
glBlendFunc(GL_ONE, GL_ONE);
}
+ else if ((state & DRW_STATE_BLEND_SUB) != 0) {
+ glBlendFunc(GL_ONE, GL_ONE);
+ }
else if ((state & DRW_STATE_BLEND_CUSTOM) != 0) {
/* Custom blend parameters using dual source blending.
* Can only be used with one Draw Buffer. */
@@ -281,6 +284,13 @@ void drw_state_set(DRWState state)
else {
BLI_assert(0);
}
+
+ if ((state & DRW_STATE_BLEND_SUB) != 0) {
+ glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
+ }
+ else {
+ glBlendEquation(GL_FUNC_ADD);
+ }
}
else {
glDisable(GL_BLEND);
More information about the Bf-blender-cvs
mailing list