Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-07-16 05:16:10 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-07-16 19:01:44 +0300
commit5099cbeec9c481600e359e95a806a3393ba4ab0d (patch)
treeaa20597f4760b5f1b77356e30e90ce6a5c914874
parent436d38bb548d904200337d58720552b6f78555cb (diff)
Cleanup: GPU: Move depth/color masks functions to GPU_state
-rw-r--r--source/blender/draw/intern/draw_manager_exec.c11
-rw-r--r--source/blender/draw/intern/draw_view.c8
-rw-r--r--source/blender/editors/gpencil/annotate_draw.c10
-rw-r--r--source/blender/editors/gpencil/drawgpencil.c9
-rw-r--r--source/blender/editors/sculpt_paint/paint_cursor.c8
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c4
-rw-r--r--source/blender/gpu/GPU_state.h4
-rw-r--r--source/blender/gpu/intern/gpu_select_pick.c4
-rw-r--r--source/blender/gpu/intern/gpu_select_sample_query.c4
-rw-r--r--source/blender/gpu/intern/gpu_state.c22
-rw-r--r--source/blender/gpu/intern/gpu_viewport.c8
-rw-r--r--source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c4
12 files changed, 60 insertions, 36 deletions
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 59b4e9af14e..e0609533691 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -98,12 +98,7 @@ void drw_state_set(DRWState state)
{
int test;
if ((test = CHANGED_TO(DRW_STATE_WRITE_DEPTH))) {
- if (test == 1) {
- glDepthMask(GL_TRUE);
- }
- else {
- glDepthMask(GL_FALSE);
- }
+ GPU_depth_mask(test == 1);
}
}
@@ -142,10 +137,10 @@ void drw_state_set(DRWState state)
int test;
if ((test = CHANGED_TO(DRW_STATE_WRITE_COLOR))) {
if (test == 1) {
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ GPU_color_mask(true, true, true, true);
}
else {
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ GPU_color_mask(false, false, false, false);
}
}
}
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c
index 06026d51faf..3c470f802ec 100644
--- a/source/blender/draw/intern/draw_view.c
+++ b/source/blender/draw/intern/draw_view.c
@@ -103,9 +103,9 @@ void DRW_draw_cursor(void)
Scene *scene = draw_ctx->scene;
ViewLayer *view_layer = draw_ctx->view_layer;
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glDepthMask(GL_FALSE);
- glDisable(GL_DEPTH_TEST);
+ GPU_color_mask(true, true, true, true);
+ GPU_depth_mask(false);
+ GPU_depth_test(false);
if (is_cursor_visible(draw_ctx, scene, view_layer)) {
int co[2];
@@ -217,5 +217,5 @@ void DRW_draw_gizmo_2d(void)
WM_gizmomap_draw(region->gizmo_map, draw_ctx->evil_C, WM_GIZMOMAP_DRAWSTEP_2D);
- glDepthMask(GL_TRUE);
+ GPU_depth_mask(true);
}
diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c
index 20307e7f809..8c8e6da75c0 100644
--- a/source/blender/editors/gpencil/annotate_draw.c
+++ b/source/blender/editors/gpencil/annotate_draw.c
@@ -555,11 +555,8 @@ static void annotation_draw_strokes(const bGPDframe *gpf,
/* check which stroke-drawer to use */
if (dflag & GP_DRAWDATA_ONLY3D) {
const int no_xray = (dflag & GP_DRAWDATA_NO_XRAY);
- int mask_orig = 0;
if (no_xray) {
- glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig);
- glDepthMask(0);
GPU_depth_test(true);
/* first arg is normally rv3d->dist, but this isn't
@@ -578,7 +575,6 @@ static void annotation_draw_strokes(const bGPDframe *gpf,
}
if (no_xray) {
- glDepthMask(mask_orig);
GPU_depth_test(false);
bglPolygonOffset(0.0, 0.0);
@@ -743,12 +739,18 @@ static void annotation_draw_data(
GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
GPU_blend(true);
+ /* Do not write to depth (avoid self-occlusion). */
+ bool prev_depth_mask = GPU_depth_mask_get();
+ GPU_depth_mask(false);
+
/* draw! */
annotation_draw_data_layers(gpd, offsx, offsy, winx, winy, cfra, dflag);
/* turn off alpha blending, then smooth lines */
GPU_blend(false); // alpha blending
GPU_line_smooth(false); // smooth lines
+
+ GPU_depth_mask(prev_depth_mask);
}
/* if we have strokes for scenes (3d view)/clips (movie clip editor)
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 60fd52db707..4df071c84f8 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -306,6 +306,10 @@ static void gpencil_draw_strokes(tGPDdraw *tgpw)
GPU_program_point_size(true);
+ /* Do not write to depth (avoid self-occlusion). */
+ bool prev_depth_mask = GPU_depth_mask_get();
+ GPU_depth_mask(false);
+
bGPDstroke *gps_init = (tgpw->gps) ? tgpw->gps : tgpw->t_gpf->strokes.first;
for (bGPDstroke *gps = gps_init; gps; gps = gps->next) {
@@ -343,11 +347,8 @@ static void gpencil_draw_strokes(tGPDdraw *tgpw)
/* check which stroke-drawer to use */
if (tgpw->dflag & GP_DRAWDATA_ONLY3D) {
const int no_xray = (tgpw->dflag & GP_DRAWDATA_NO_XRAY);
- int mask_orig = 0;
if (no_xray) {
- glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig);
- glDepthMask(0);
GPU_depth_test(true);
/* first arg is normally rv3d->dist, but this isn't
@@ -393,7 +394,6 @@ static void gpencil_draw_strokes(tGPDdraw *tgpw)
}
}
if (no_xray) {
- glDepthMask(mask_orig);
GPU_depth_test(false);
bglPolygonOffset(0.0, 0.0);
@@ -405,6 +405,7 @@ static void gpencil_draw_strokes(tGPDdraw *tgpw)
}
}
+ GPU_depth_mask(prev_depth_mask);
GPU_program_point_size(false);
}
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index be7b824fc3e..527d73ca725 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -638,8 +638,8 @@ static bool paint_draw_tex_overlay(UnifiedPaintSettings *ups,
if (load_tex(brush, vc, zoom, col, primary)) {
GPU_blend(true);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glDepthMask(GL_FALSE);
+ GPU_color_mask(true, true, true, true);
+ GPU_depth_mask(false);
glDepthFunc(GL_ALWAYS);
if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
@@ -758,8 +758,8 @@ static bool paint_draw_cursor_overlay(
float center[2];
GPU_blend(true);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glDepthMask(GL_FALSE);
+ GPU_color_mask(true, true, true, true);
+ GPU_depth_mask(false);
glDepthFunc(GL_ALWAYS);
if (ups->draw_anchored) {
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index aa8fe1d63e5..82840f67699 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1085,7 +1085,7 @@ static void draw_rotation_guide(const RegionView3D *rv3d)
GPU_blend(true);
GPU_blend_set_func_separate(
GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
- glDepthMask(GL_FALSE); /* don't overwrite zbuf */
+ GPU_depth_mask(false); /* don't overwrite zbuf */
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
@@ -1175,7 +1175,7 @@ static void draw_rotation_guide(const RegionView3D *rv3d)
immUnbindProgram();
GPU_blend(false);
- glDepthMask(GL_TRUE);
+ GPU_depth_mask(true);
}
#endif /* WITH_INPUT_NDOF */
diff --git a/source/blender/gpu/GPU_state.h b/source/blender/gpu/GPU_state.h
index 6c0c4897fef..bdff3e66217 100644
--- a/source/blender/gpu/GPU_state.h
+++ b/source/blender/gpu/GPU_state.h
@@ -65,6 +65,10 @@ void GPU_scissor_get_f(float coords[4]);
void GPU_scissor_get_i(int coords[4]);
void GPU_viewport_size_get_f(float coords[4]);
void GPU_viewport_size_get_i(int coords[4]);
+void GPU_color_mask(bool r, bool g, bool b, bool a);
+void GPU_depth_mask(bool depth);
+bool GPU_depth_mask_get(void);
+void GPU_stencil_mask(uint stencil);
void GPU_flush(void);
void GPU_finish(void);
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 4b38cd333a1..3e5fc1ab19e 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -310,7 +310,7 @@ void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, c
gpuPushAttr(GPU_DEPTH_BUFFER_BIT | GPU_VIEWPORT_BIT);
/* disable writing to the framebuffer */
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ GPU_color_mask(false, false, false, false);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
@@ -539,7 +539,7 @@ uint gpu_select_pick_end(void)
gpu_select_pick_load_id(ps->gl.prev_id, true);
}
gpuPopAttr();
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ GPU_color_mask(true, true, true, true);
}
/* assign but never free directly since it may be in cache */
diff --git a/source/blender/gpu/intern/gpu_select_sample_query.c b/source/blender/gpu/intern/gpu_select_sample_query.c
index c82d1e17c66..b20b6cac36b 100644
--- a/source/blender/gpu/intern/gpu_select_sample_query.c
+++ b/source/blender/gpu/intern/gpu_select_sample_query.c
@@ -88,7 +88,7 @@ void gpu_select_query_begin(
gpuPushAttr(GPU_DEPTH_BUFFER_BIT | GPU_VIEWPORT_BIT | GPU_SCISSOR_BIT);
/* disable writing to the framebuffer */
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ GPU_color_mask(false, false, false, false);
/* In order to save some fill rate we minimize the viewport using rect.
* We need to get the region of the viewport so that our geometry doesn't
@@ -206,7 +206,7 @@ uint gpu_select_query_end(void)
MEM_freeN(g_query_state.queries);
MEM_freeN(g_query_state.id);
gpuPopAttr();
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ GPU_color_mask(true, true, true, true);
return hits;
}
diff --git a/source/blender/gpu/intern/gpu_state.c b/source/blender/gpu/intern/gpu_state.c
index 65acd5a7771..636a5e2c31d 100644
--- a/source/blender/gpu/intern/gpu_state.c
+++ b/source/blender/gpu/intern/gpu_state.c
@@ -192,6 +192,28 @@ void GPU_logic_op_xor_set(bool enable)
}
}
+void GPU_color_mask(bool r, bool g, bool b, bool a)
+{
+ glColorMask(r, g, b, a);
+}
+
+void GPU_depth_mask(bool depth)
+{
+ glDepthMask(depth);
+}
+
+bool GPU_depth_mask_get(void)
+{
+ GLint mask;
+ glGetIntegerv(GL_DEPTH_WRITEMASK, &mask);
+ return mask == GL_TRUE;
+}
+
+void GPU_stencil_mask(uint stencil)
+{
+ glStencilMask(stencil);
+}
+
/** \name GPU Push/Pop State
* \{ */
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
index 753da8544ea..4d31366f53f 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -630,13 +630,13 @@ void GPU_viewport_stereo_composite(GPUViewport *viewport, Stereo3dFormat *stereo
if (settings == S3D_DISPLAY_ANAGLYPH) {
switch (stereo_format->anaglyph_type) {
case S3D_ANAGLYPH_REDCYAN:
- glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
+ GPU_color_mask(false, true, true, true);
break;
case S3D_ANAGLYPH_GREENMAGENTA:
- glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
+ GPU_color_mask(true, false, true, true);
break;
case S3D_ANAGLYPH_YELLOWBLUE:
- glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE);
+ GPU_color_mask(false, false, true, true);
break;
}
}
@@ -666,7 +666,7 @@ void GPU_viewport_stereo_composite(GPUViewport *viewport, Stereo3dFormat *stereo
GPU_matrix_pop();
if (settings == S3D_DISPLAY_ANAGLYPH) {
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ GPU_color_mask(true, true, true, true);
}
GPU_framebuffer_restore();
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
index 6ed6c485e89..396b59ba6e2 100644
--- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
+++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
@@ -548,7 +548,7 @@ static void gizmo_draw_select_3d_loop(const bContext *C,
/* pass */
}
else {
- glDepthMask(!is_depth_skip);
+ GPU_depth_mask(!is_depth_skip);
is_depth_skip_prev = is_depth_skip;
}
@@ -565,7 +565,7 @@ static void gizmo_draw_select_3d_loop(const bContext *C,
GPU_depth_test(false);
}
if (is_depth_skip_prev) {
- glDepthMask(true);
+ GPU_depth_mask(true);
}
}