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
path: root/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-07-18 00:00:55 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-07-18 04:43:52 +0300
commit4c28b1c74ec2a96055fcc393920f3967666dd735 (patch)
treeb85643f0b470eb092c0c3706cb10f56dddc2cade /source
parent59975b0adf42cfbc51a90c02caaed49085abafa2 (diff)
Cleanup: GPU: Encapsulate clipDistances
This also remove some non functionnal state changes that were left from legacy code.
Diffstat (limited to 'source')
-rw-r--r--source/blender/draw/intern/draw_manager.c12
-rw-r--r--source/blender/draw/intern/draw_manager_exec.c8
-rw-r--r--source/blender/draw/intern/draw_manager_text.c6
-rw-r--r--source/blender/editors/include/ED_view3d.h3
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c34
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c8
-rw-r--r--source/blender/gpu/GPU_state.h1
-rw-r--r--source/blender/gpu/intern/gpu_state.c12
8 files changed, 22 insertions, 62 deletions
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index fcedc6bf0c7..08fb80c11d2 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2469,12 +2469,6 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons
#endif
}
-/** See #DRW_shgroup_world_clip_planes_from_rv3d. */
-static void draw_world_clip_planes_from_rv3d(GPUBatch *batch, const float world_clip_planes[6][4])
-{
- GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, world_clip_planes[0]);
-}
-
/**
* Clears the Depth Buffer and draws only the specified object.
*/
@@ -2497,7 +2491,7 @@ void DRW_draw_depth_object(
const float(*world_clip_planes)[4] = NULL;
if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
- ED_view3d_clipping_set(rv3d);
+ GPU_clip_distances(6);
ED_view3d_clipping_local(rv3d, object->obmat);
world_clip_planes = rv3d->clip_local;
}
@@ -2525,7 +2519,7 @@ void DRW_draw_depth_object(
GPU_SHADER_CFG_DEFAULT;
GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_DEPTH_ONLY, sh_cfg);
if (world_clip_planes != NULL) {
- draw_world_clip_planes_from_rv3d(batch, world_clip_planes);
+ GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, world_clip_planes[0]);
}
GPU_batch_draw(batch);
@@ -2536,7 +2530,7 @@ void DRW_draw_depth_object(
}
if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
- ED_view3d_clipping_disable();
+ GPU_clip_distances(0);
}
GPU_matrix_set(rv3d->viewmat);
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index e0609533691..b6f51ada5a1 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -350,14 +350,10 @@ void drw_state_set(DRWState state)
int test;
if ((test = CHANGED_TO(DRW_STATE_CLIP_PLANES))) {
if (test == 1) {
- for (int i = 0; i < DST.view_active->clip_planes_len; i++) {
- glEnable(GL_CLIP_DISTANCE0 + i);
- }
+ GPU_clip_distances(DST.view_active->clip_planes_len);
}
else {
- for (int i = 0; i < MAX_CLIP_PLANES; i++) {
- glDisable(GL_CLIP_DISTANCE0 + i);
- }
+ GPU_clip_distances(0);
}
}
}
diff --git a/source/blender/draw/intern/draw_manager_text.c b/source/blender/draw/intern/draw_manager_text.c
index f4601fe4f48..b3c4c97715e 100644
--- a/source/blender/draw/intern/draw_manager_text.c
+++ b/source/blender/draw/intern/draw_manager_text.c
@@ -38,6 +38,7 @@
#include "DNA_view3d_types.h"
#include "GPU_matrix.h"
+#include "GPU_state.h"
#include "ED_screen.h"
#include "ED_view3d.h"
@@ -149,8 +150,9 @@ void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, struct View3D *v3d)
if (tot) {
int col_pack_prev = 0;
+ /* Disable clipping for text */
if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
- ED_view3d_clipping_disable();
+ GPU_clip_distances(0);
}
float original_proj[4][4];
@@ -188,7 +190,7 @@ void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, struct View3D *v3d)
GPU_matrix_projection_set(original_proj);
if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
- ED_view3d_clipping_enable();
+ GPU_clip_distances(6);
}
}
}
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index f8a4884c594..f44b099f42e 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -464,9 +464,6 @@ void ED_view3d_clipping_local(struct RegionView3D *rv3d, float mat[4][4]);
bool ED_view3d_clipping_test(const struct RegionView3D *rv3d,
const float co[3],
const bool is_local);
-void ED_view3d_clipping_set(struct RegionView3D *rv3d);
-void ED_view3d_clipping_enable(void);
-void ED_view3d_clipping_disable(void);
float ED_view3d_radius_to_dist_persp(const float angle, const float radius);
float ED_view3d_radius_to_dist_ortho(const float lens, const float radius);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index c97be078b60..b4098f17212 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -844,16 +844,9 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *region, View3D *v3d, bo
ED_view3d_draw_setup_view(
G_MAIN->wm.first, NULL, depsgraph, scene, region, v3d, NULL, NULL, NULL);
- GPU_clear(GPU_DEPTH_BIT);
-
- if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
- ED_view3d_clipping_set(rv3d);
- }
/* get surface depth without bias */
rv3d->rflag |= RV3D_ZOFFSET_DISABLED;
- GPU_depth_test(true);
-
/* Needed in cases the view-port isn't already setup. */
WM_draw_region_viewport_ensure(region, SPACE_VIEW3D);
WM_draw_region_viewport_bind(region);
@@ -867,14 +860,8 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *region, View3D *v3d, bo
WM_draw_region_viewport_unbind(region);
- if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
- ED_view3d_clipping_disable();
- }
rv3d->rflag &= ~RV3D_ZOFFSET_DISABLED;
- /* Reset default for UI */
- GPU_depth_test(false);
-
U.glalphaclip = glalphaclip;
v3d->flag = flag;
@@ -2114,27 +2101,6 @@ bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const
return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
}
-void ED_view3d_clipping_set(RegionView3D *UNUSED(rv3d))
-{
- for (uint a = 0; a < 6; a++) {
- glEnable(GL_CLIP_DISTANCE0 + a);
- }
-}
-
-/* Use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set. */
-void ED_view3d_clipping_disable(void)
-{
- for (uint a = 0; a < 6; a++) {
- glDisable(GL_CLIP_DISTANCE0 + a);
- }
-}
-void ED_view3d_clipping_enable(void)
-{
- for (uint a = 0; a < 6; a++) {
- glEnable(GL_CLIP_DISTANCE0 + a);
- }
-}
-
/* *********************** backdraw for selection *************** */
/**
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 53c87d2b7e4..66efa5b5de3 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -1104,10 +1104,6 @@ int view3d_opengl_select(ViewContext *vc,
GPU_depth_test(true);
}
- if (RV3D_CLIPPING_ENABLED(vc->v3d, vc->rv3d)) {
- ED_view3d_clipping_set(vc->rv3d);
- }
-
/* If in xray mode, we select the wires in priority. */
if (XRAY_ACTIVE(v3d) && use_nearest) {
/* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
@@ -1173,10 +1169,6 @@ int view3d_opengl_select(ViewContext *vc,
GPU_depth_test(false);
}
- if (RV3D_CLIPPING_ENABLED(v3d, vc->rv3d)) {
- ED_view3d_clipping_disable();
- }
-
DRW_opengl_context_disable();
finally:
diff --git a/source/blender/gpu/GPU_state.h b/source/blender/gpu/GPU_state.h
index 0f0a8a5dd6e..8d50330ac93 100644
--- a/source/blender/gpu/GPU_state.h
+++ b/source/blender/gpu/GPU_state.h
@@ -86,6 +86,7 @@ void GPU_depth_mask(bool depth);
bool GPU_depth_mask_get(void);
void GPU_stencil_mask(uint stencil);
void GPU_unpack_row_length_set(uint len);
+void GPU_clip_distances(int enabled_len);
void GPU_flush(void);
void GPU_finish(void);
diff --git a/source/blender/gpu/intern/gpu_state.c b/source/blender/gpu/intern/gpu_state.c
index f1b842403f9..bd7aff9772b 100644
--- a/source/blender/gpu/intern/gpu_state.c
+++ b/source/blender/gpu/intern/gpu_state.c
@@ -256,6 +256,18 @@ void GPU_stencil_mask(uint stencil)
glStencilMask(stencil);
}
+void GPU_clip_distances(int distances_new)
+{
+ static int distances_enabled = 0;
+ for (int i = 0; i < distances_new; i++) {
+ glEnable(GL_CLIP_DISTANCE0 + i);
+ }
+ for (int i = distances_new; i < distances_enabled; i++) {
+ glDisable(GL_CLIP_DISTANCE0 + i);
+ }
+ distances_enabled = distances_new;
+}
+
/** \name GPU Push/Pop State
* \{ */