[Bf-blender-cvs] [3d78e028373] greasepencil-refactor: DRW: Add DRW_shgroup_stencil_set to set all stencil test values
Clément Foucault
noreply at git.blender.org
Sun Dec 15 03:43:17 CET 2019
Commit: 3d78e028373d367e0fd2898bb6029a0f4f3dd49c
Author: Clément Foucault
Date: Sun Dec 15 03:14:19 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB3d78e028373d367e0fd2898bb6029a0f4f3dd49c
DRW: Add DRW_shgroup_stencil_set to set all stencil test values
This is to allow more fine tuning. The other function is
deprecated and need to be replace.
===================================================================
M source/blender/draw/intern/DRW_render.h
M source/blender/draw/intern/draw_manager.h
M source/blender/draw/intern/draw_manager_data.c
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 d84a8a66810..df2fc1d7edf 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -432,6 +432,17 @@ void DRW_buffer_add_entry_array(DRWCallBuffer *buffer, const void *attr[], uint
void DRW_shgroup_state_enable(DRWShadingGroup *shgroup, DRWState state);
void DRW_shgroup_state_disable(DRWShadingGroup *shgroup, DRWState state);
+
+/* Reminders:
+ * - (compare_mask & reference) is what is tested against (compare_mask & stencil_value)
+ * stencil_value being the value stored in the stencil buffer.
+ * - (writemask & reference) is what gets written if the test condition is fullfiled.
+ **/
+void DRW_shgroup_stencil_set(DRWShadingGroup *shgroup,
+ uint write_mask,
+ uint reference,
+ uint comp_mask);
+/* TODO remove this function. Obsolete version. mask is actually reference value. */
void DRW_shgroup_stencil_mask(DRWShadingGroup *shgroup, uint mask);
/* Issue a clear command. */
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index f3683bdaf51..1d56690a752 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -231,7 +231,9 @@ typedef struct DRWCommandSetMutableState {
} DRWCommandSetMutableState;
typedef struct DRWCommandSetStencil {
- uint mask;
+ uint write_mask;
+ uint comp_mask;
+ uint ref;
} DRWCommandSetStencil;
typedef struct DRWCommandSetSelectID {
@@ -475,7 +477,6 @@ typedef struct DRWManager {
/* Managed by `DRW_state_set`, `DRW_state_reset` */
DRWState state;
DRWState state_lock;
- uint stencil_mask;
/* Per viewport */
GPUViewport *viewport;
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index ee72081825d..e7f3211ffab 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -691,11 +691,18 @@ static void drw_command_set_select_id(DRWShadingGroup *shgroup, GPUVertBuf *buf,
cmd->select_id = select_id;
}
-static void drw_command_set_stencil_mask(DRWShadingGroup *shgroup, uint mask)
-{
- BLI_assert(mask <= 0xFF);
+static void drw_command_set_stencil_mask(DRWShadingGroup *shgroup,
+ uint write_mask,
+ uint reference,
+ uint comp_mask)
+{
+ BLI_assert(write_mask <= 0xFF);
+ BLI_assert(reference <= 0xFF);
+ BLI_assert(comp_mask <= 0xFF);
DRWCommandSetStencil *cmd = drw_command_create(shgroup, DRW_CMD_STENCIL);
- cmd->mask = mask;
+ cmd->write_mask = write_mask;
+ cmd->comp_mask = comp_mask;
+ cmd->ref = reference;
}
static void drw_command_clear(DRWShadingGroup *shgroup,
@@ -1329,9 +1336,18 @@ void DRW_shgroup_state_disable(DRWShadingGroup *shgroup, DRWState state)
drw_command_set_mutable_state(shgroup, 0x0, state);
}
+void DRW_shgroup_stencil_set(DRWShadingGroup *shgroup,
+ uint write_mask,
+ uint reference,
+ uint comp_mask)
+{
+ drw_command_set_stencil_mask(shgroup, write_mask, reference, comp_mask);
+}
+
+/* TODO remove this function. */
void DRW_shgroup_stencil_mask(DRWShadingGroup *shgroup, uint mask)
{
- drw_command_set_stencil_mask(shgroup, mask);
+ drw_command_set_stencil_mask(shgroup, 0xFF, mask, 0xFF);
}
void DRW_shgroup_clear_framebuffer(DRWShadingGroup *shgroup,
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index bd378d78780..2583a5e07e8 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -220,7 +220,6 @@ void drw_state_set(DRWState state)
{
int test;
if (CHANGED_ANY_STORE_VAR(DRW_STATE_STENCIL_TEST_ENABLED, test)) {
- DST.stencil_mask = STENCIL_UNDEFINED;
if (test) {
glEnable(GL_STENCIL_TEST);
}
@@ -398,19 +397,23 @@ void drw_state_set(DRWState state)
DST.state = state;
}
-static void drw_stencil_set(uint mask)
+static void drw_stencil_state_set(uint write_mask, uint reference, uint compare_mask)
{
- if (DST.stencil_mask != mask) {
- DST.stencil_mask = mask;
- if ((DST.state & DRW_STATE_STENCIL_ALWAYS) != 0) {
- glStencilFunc(GL_ALWAYS, mask, 0xFF);
- }
- else if ((DST.state & DRW_STATE_STENCIL_EQUAL) != 0) {
- glStencilFunc(GL_EQUAL, mask, 0xFF);
- }
- else if ((DST.state & DRW_STATE_STENCIL_NEQUAL) != 0) {
- glStencilFunc(GL_NOTEQUAL, mask, 0xFF);
- }
+ /* Reminders:
+ * - (compare_mask & reference) is what is tested against (compare_mask & stencil_value)
+ * stencil_value being the value stored in the stencil buffer.
+ * - (writemask & reference) is what gets written if the test condition is fullfiled.
+ **/
+ glStencilMask(write_mask);
+
+ if ((DST.state & DRW_STATE_STENCIL_ALWAYS) != 0) {
+ glStencilFunc(GL_ALWAYS, reference, compare_mask);
+ }
+ else if ((DST.state & DRW_STATE_STENCIL_EQUAL) != 0) {
+ glStencilFunc(GL_EQUAL, reference, compare_mask);
+ }
+ else if ((DST.state & DRW_STATE_STENCIL_NEQUAL) != 0) {
+ glStencilFunc(GL_NOTEQUAL, reference, compare_mask);
}
}
@@ -1316,7 +1319,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
drw_state_set((pass_state & ~state.drw_state_disabled) | state.drw_state_enabled);
break;
case DRW_CMD_STENCIL:
- drw_stencil_set(cmd->stencil.mask);
+ drw_stencil_state_set(cmd->stencil.write_mask, cmd->stencil.ref, cmd->stencil.comp_mask);
break;
case DRW_CMD_SELECTID:
state.select_id = cmd->select_id.select_id;
More information about the Bf-blender-cvs
mailing list