[Bf-blender-cvs] [9d101153748] temp-gpu-clip-fix: Fill in dummy values when clipping to a box (4)
Campbell Barton
noreply at git.blender.org
Mon Jan 21 13:48:23 CET 2019
Commit: 9d101153748c4a10567c0ce8f7b65124dbc1d049
Author: Campbell Barton
Date: Mon Jan 21 23:44:06 2019 +1100
Branches: temp-gpu-clip-fix
https://developer.blender.org/rB9d101153748c4a10567c0ce8f7b65124dbc1d049
Fill in dummy values when clipping to a box (4)
===================================================================
M source/blender/draw/engines/workbench/workbench_data.c
M source/blender/draw/engines/workbench/workbench_materials.c
M source/blender/draw/engines/workbench/workbench_private.h
M source/blender/draw/intern/DRW_render.h
M source/blender/draw/intern/draw_manager_exec.c
M source/blender/draw/modes/edit_mesh_mode.c
M source/blender/draw/modes/overlay_mode.c
M source/blender/draw/modes/shaders/common_world_clip_lib.glsl
===================================================================
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c
index 60bcae3eee3..38787210036 100644
--- a/source/blender/draw/engines/workbench/workbench_data.c
+++ b/source/blender/draw/engines/workbench/workbench_data.c
@@ -91,12 +91,11 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
{
RegionView3D *rv3d = draw_ctx->rv3d;
if (rv3d->rflag & RV3D_CLIPPING) {
- wpd->world_clip_planes_len = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
- memcpy(wpd->world_clip_planes, rv3d->clip, sizeof(float[4]) * wpd->world_clip_planes_len);
- DRW_state_clip_planes_len_set(wpd->world_clip_planes_len);
+ wpd->world_clip_planes = rv3d->clip;
+ DRW_state_clip_planes_set_from_rv3d(rv3d);
}
else {
- wpd->world_clip_planes_len = 0;
+ wpd->world_clip_planes = NULL;
}
}
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c
index 6658877ef7d..d19f9293af9 100644
--- a/source/blender/draw/engines/workbench/workbench_materials.c
+++ b/source/blender/draw/engines/workbench/workbench_materials.c
@@ -110,7 +110,7 @@ char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, bool use_text
if (is_hair) {
BLI_dynstr_appendf(ds, "#define HAIR_SHADER\n");
}
- if (wpd->world_clip_planes_len) {
+ if (wpd->world_clip_planes != NULL) {
BLI_dynstr_appendf(ds, "#define USE_WORLD_CLIP_PLANES\n");
}
@@ -171,7 +171,7 @@ int workbench_material_get_prepass_shader_index(
SET_FLAG_FROM_TEST(index, NORMAL_VIEWPORT_PASS_ENABLED(wpd), 1 << 3);
SET_FLAG_FROM_TEST(index, MATCAP_ENABLED(wpd), 1 << 4);
SET_FLAG_FROM_TEST(index, use_textures, 1 << 5);
- SET_FLAG_FROM_TEST(index, wpd->world_clip_planes_len != 0, 1 << 6);
+ SET_FLAG_FROM_TEST(index, wpd->world_clip_planes != NULL, 1 << 6);
return index;
}
@@ -241,8 +241,8 @@ void workbench_material_shgroup_uniform(
DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1);
}
- if (wpd->world_clip_planes_len) {
- DRW_shgroup_uniform_vec4(grp, "WorldClipPlanes", wpd->world_clip_planes[0], wpd->world_clip_planes_len);
+ if (wpd->world_clip_planes != NULL) {
+ DRW_shgroup_uniform_vec4(grp, "WorldClipPlanes", wpd->world_clip_planes[0], 6);
DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES);
}
}
diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h
index a4cfd297516..82d84fef67a 100644
--- a/source/blender/draw/engines/workbench/workbench_private.h
+++ b/source/blender/draw/engines/workbench/workbench_private.h
@@ -200,8 +200,7 @@ typedef struct WORKBENCH_PrivateData {
bool shadow_changed;
bool is_playback;
- float world_clip_planes[6][4];
- int world_clip_planes_len;
+ float (*world_clip_planes)[4];
/* Volumes */
bool volumes_do;
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 96525a47c77..cb5b8074f4b 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -533,6 +533,7 @@ void DRW_state_invert_facing(void);
void DRW_state_clip_planes_len_set(uint plane_len);
void DRW_state_clip_planes_reset(void);
+void DRW_state_clip_planes_set_from_rv3d(struct RegionView3D *rv3d);
/* Culling, return true if object is inside view frustum. */
bool DRW_culling_sphere_test(BoundSphere *bsphere);
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index e5654ab2a64..21647d54eea 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -447,6 +447,19 @@ void DRW_state_clip_planes_reset(void)
DST.clip_planes_len = 0;
}
+void DRW_state_clip_planes_set_from_rv3d(RegionView3D *rv3d)
+{
+ int max_len = 6;
+ int real_len = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : max_len;
+ while (real_len < max_len) {
+ /* Fill in dummy values that wont change results (6 is hard coded in shaders). */
+ copy_v4_v4(rv3d->clip[real_len], rv3d->clip[3]);
+ real_len++;
+ }
+
+ DRW_state_clip_planes_len_set(max_len);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c
index a5dea9b2db0..59aa4ea5ff0 100644
--- a/source/blender/draw/modes/edit_mesh_mode.c
+++ b/source/blender/draw/modes/edit_mesh_mode.c
@@ -299,7 +299,7 @@ static void EDIT_MESH_engine_init(void *vedata)
});
if (is_clip) {
- DRW_state_clip_planes_len_set((draw_ctx->rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6);
+ DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
}
if (!sh_data->weight_face) {
diff --git a/source/blender/draw/modes/overlay_mode.c b/source/blender/draw/modes/overlay_mode.c
index bdae377e166..16e008d349d 100644
--- a/source/blender/draw/modes/overlay_mode.c
+++ b/source/blender/draw/modes/overlay_mode.c
@@ -114,7 +114,7 @@ static void overlay_engine_init(void *vedata)
const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
if (is_clip) {
- DRW_state_clip_planes_len_set((draw_ctx->rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6);
+ DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
}
if (!stl->g_data) {
diff --git a/source/blender/draw/modes/shaders/common_world_clip_lib.glsl b/source/blender/draw/modes/shaders/common_world_clip_lib.glsl
index e211def8eff..b889780751e 100644
--- a/source/blender/draw/modes/shaders/common_world_clip_lib.glsl
+++ b/source/blender/draw/modes/shaders/common_world_clip_lib.glsl
@@ -10,8 +10,9 @@ void world_clip_planes_calc_clip_distance(vec3 wpos)
gl_ClipDistance[4] = dot(WorldClipPlanes[4].xyz, wpos) + WorldClipPlanes[4].w;
gl_ClipDistance[5] = dot(WorldClipPlanes[5].xyz, wpos) + WorldClipPlanes[5].w;
}
+#endif
-#define world_clip_planes_set_clip_distance(c)
+#define world_clip_planes_set_clip_distance(c) \
{ \
gl_ClipDistance[0] = (c)[0]; \
gl_ClipDistance[1] = (c)[1]; \
@@ -22,4 +23,3 @@ void world_clip_planes_calc_clip_distance(vec3 wpos)
}
#endif
-#endif
More information about the Bf-blender-cvs
mailing list