[Bf-blender-cvs] [a131514d0f7] master: Edit Mesh: Fix some problem with new implementation

Clément Foucault noreply at git.blender.org
Tue Feb 5 15:38:20 CET 2019


Commit: a131514d0f79f7b82be526438c125e35beab9f8f
Author: Clément Foucault
Date:   Mon Feb 4 20:06:30 2019 +0100
Branches: master
https://developer.blender.org/rBa131514d0f79f7b82be526438c125e35beab9f8f

Edit Mesh: Fix some problem with new implementation

- Add manual depth offset to vertices and edges.
- Revert to plain edge decoration.
- Fix active edge coloring.
- Remove active face display if not in face selection mode.
- Add wide line support.

===================================================================

M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_manager_exec.c
M	source/blender/draw/modes/edit_mesh_mode.c
M	source/blender/draw/modes/shaders/edit_mesh_overlay_common_lib.glsl
M	source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl
M	source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl
M	source/blender/editors/include/BIF_glutil.h
M	source/blender/editors/screen/glutil.c

===================================================================

diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 4740879928c..87a1add4e81 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -289,7 +289,7 @@ typedef enum {
 	DRW_STATE_OFFSET_POSITIVE = (1 << 12),
 	/** Polygon offset. Does not work with lines and points. */
 	DRW_STATE_OFFSET_NEGATIVE = (1 << 13),
-	/* DRW_STATE_STIPPLE_4     = (1 << 14), */ /* Not used */
+	DRW_STATE_WIRE_WIDE     = (1 << 14),
 	DRW_STATE_BLEND         = (1 << 15),
 	DRW_STATE_ADDITIVE      = (1 << 16),
 	DRW_STATE_MULTIPLY      = (1 << 17),
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index ee91245fb1a..6481643a58e 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -120,7 +120,6 @@ struct GPUBatch *DRW_mesh_batch_cache_get_edit_lnors(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_facedots(struct Mesh *me);
 /* edit-mesh selection */
 struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_id(struct Mesh *me);
-struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_mask(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_facedots_with_select_id(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edges_with_select_id(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_verts_with_select_id(struct Mesh *me);
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 8147da90899..9bdd5d2ae93 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -183,15 +183,23 @@ void drw_state_set(DRWState state)
 
 	/* Wire Width */
 	{
-		if (CHANGED_ANY(DRW_STATE_WIRE | DRW_STATE_WIRE_SMOOTH)) {
-			if ((state & DRW_STATE_WIRE_SMOOTH) != 0) {
+		int test;
+		if (CHANGED_ANY_STORE_VAR(
+		        DRW_STATE_WIRE | DRW_STATE_WIRE_WIDE | DRW_STATE_WIRE_SMOOTH,
+		        test))
+		{
+			if (test & DRW_STATE_WIRE_WIDE) {
+				GPU_line_width(3.0f);
+			}
+			else if (test & DRW_STATE_WIRE_SMOOTH) {
 				GPU_line_width(2.0f);
 				GPU_line_smooth(true);
 			}
-			else if ((state & DRW_STATE_WIRE) != 0) {
+			else if (test & DRW_STATE_WIRE) {
 				GPU_line_width(1.0f);
 			}
 			else {
+				GPU_line_width(1.0f);
 				GPU_line_smooth(false);
 			}
 		}
diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c
index 01797e9e20c..d9c60115e14 100644
--- a/source/blender/draw/modes/edit_mesh_mode.c
+++ b/source/blender/draw/modes/edit_mesh_mode.c
@@ -38,6 +38,8 @@
 #include "BKE_editmesh.h"
 #include "BKE_object.h"
 
+#include "BIF_glutil.h"
+
 #include "BLI_dynstr.h"
 #include "BLI_string_utils.h"
 
@@ -102,6 +104,7 @@ typedef struct EDIT_MESH_Shaders {
 	GPUShader *overlay_vert;
 	GPUShader *overlay_edge;
 	GPUShader *overlay_edge_flat;
+	GPUShader *overlay_edge_deco;
 	GPUShader *overlay_face;
 	GPUShader *overlay_facedot;
 
@@ -134,6 +137,7 @@ typedef struct EDIT_MESH_PrivateData {
 
 	DRWShadingGroup *vert_shgrp;
 	DRWShadingGroup *edge_shgrp;
+	DRWShadingGroup *edge_deco_shgrp;
 	DRWShadingGroup *face_shgrp;
 	DRWShadingGroup *face_cage_shgrp;
 	DRWShadingGroup *facedot_shgrp;
@@ -200,9 +204,14 @@ static void EDIT_MESH_engine_init(void *vedata)
 		});
 		sh_data->overlay_edge_flat = DRW_shader_create_from_arrays({
 		        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
-		        .frag = (const char *[]){datatoc_edit_mesh_overlay_frag_glsl, NULL},
+		        .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
 		        .defs = (const char *[]){world_clip_def_or_empty, "#define EDGE\n", "#define FLAT\n", NULL},
 		});
+		sh_data->overlay_edge_deco = DRW_shader_create_from_arrays({
+		        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
+		        .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
+		        .defs = (const char *[]){world_clip_def_or_empty, "#define EDGE_DECORATION\n", "#define FLAT\n", NULL},
+		});
 		sh_data->overlay_vert = DRW_shader_create_from_arrays({
 		        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
 		        .frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL},
@@ -253,7 +262,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
         float *face_alpha, float *edge_width_scale, int *data_mask, bool do_edges, bool UNUSED(xray),
         DRWState statemod,
         DRWShadingGroup **r_face_shgrp, DRWShadingGroup **r_face_cage_shgrp, DRWShadingGroup **r_facedot_shgrp,
-        DRWShadingGroup **r_edge_shgrp, DRWShadingGroup **r_vert_shgrp)
+        DRWShadingGroup **r_edge_shgrp, DRWShadingGroup **r_edge_deco_shgrp, DRWShadingGroup **r_vert_shgrp)
 {
 	const DRWContextState *draw_ctx = DRW_context_state_get();
 	RegionView3D *rv3d = draw_ctx->rv3d;
@@ -262,6 +271,14 @@ static DRWPass *edit_mesh_create_overlay_pass(
 	EDIT_MESH_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
 	const bool select_vert = (tsettings->selectmode & SCE_SELECT_VERTEX) != 0;
 	const bool select_face = (tsettings->selectmode & SCE_SELECT_FACE) != 0;
+	float winmat[4][4];
+	float viewdist = rv3d->dist;
+	DRW_viewport_matrix_get(winmat, DRW_MAT_WIN);
+	/* special exception for ortho camera (viewdist isnt used for perspective cameras) */
+	if (rv3d->persp == RV3D_CAMOB && rv3d->is_persp == false) {
+		viewdist = 1.0f / max_ff(fabsf(rv3d->winmat[0][0]), fabsf(rv3d->winmat[1][1]));
+	}
+	const float depth_ofs = bglPolygonOffsetCalc((float *)winmat, viewdist, 1.0f);
 
 	DRWPass *pass = DRW_pass_create(
 	        "Edit Mesh Face Overlay Pass",
@@ -274,6 +291,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
 	GPUShader *edge_sh = (select_vert) ? sh_data->overlay_edge : sh_data->overlay_edge_flat;
 	GPUShader *face_sh = sh_data->overlay_face;
 	GPUShader *facedot_sh = sh_data->overlay_facedot;
+	GPUShader *edge_deco_sh = sh_data->overlay_edge_deco;
 	/* Faces */
 	if (select_face) {
 		grp = *r_facedot_shgrp = DRW_shgroup_create(facedot_sh, pass);
@@ -292,6 +310,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
 	DRW_shgroup_uniform_float(grp, "edgeScale", edge_width_scale, 1);
 	DRW_shgroup_uniform_ivec4(grp, "dataMask", data_mask, 1);
 	DRW_shgroup_uniform_bool_copy(grp, "doEdges", do_edges);
+	DRW_shgroup_uniform_float_copy(grp, "ofs", 0.0f);
 	if (rv3d->rflag & RV3D_CLIPPING) {
 		DRW_shgroup_world_clip_planes_from_rv3d(grp, rv3d);
 	}
@@ -301,12 +320,27 @@ static DRWPass *edit_mesh_create_overlay_pass(
 	DRW_shgroup_state_enable(grp, DRW_STATE_OFFSET_NEGATIVE);
 
 	/* Edges */
+	grp = *r_edge_deco_shgrp = DRW_shgroup_create(edge_deco_sh, pass);
+	DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
+	DRW_shgroup_uniform_ivec4(grp, "dataMask", data_mask, 1);
+	DRW_shgroup_uniform_bool_copy(grp, "doEdges", do_edges);
+	DRW_shgroup_uniform_float_copy(grp, "ofs", depth_ofs);
+	DRW_shgroup_state_enable(grp, DRW_STATE_OFFSET_NEGATIVE);
+	DRW_shgroup_state_enable(grp, DRW_STATE_BLEND);
+	DRW_shgroup_state_enable(grp, DRW_STATE_WIRE_WIDE);
+	/* To match blender loop structure. */
+	DRW_shgroup_state_enable(grp, DRW_STATE_FIRST_VERTEX_CONVENTION);
+	if (rv3d->rflag & RV3D_CLIPPING) {
+		DRW_shgroup_world_clip_planes_from_rv3d(grp, rv3d);
+	}
+
 	grp = *r_edge_shgrp = DRW_shgroup_create(edge_sh, pass);
 	DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
-	DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
 	DRW_shgroup_uniform_float(grp, "edgeScale", edge_width_scale, 1);
 	DRW_shgroup_uniform_ivec4(grp, "dataMask", data_mask, 1);
 	DRW_shgroup_uniform_bool_copy(grp, "doEdges", do_edges);
+	DRW_shgroup_uniform_float_copy(grp, "ofs", depth_ofs);
+	DRW_shgroup_state_enable(grp, DRW_STATE_WRITE_DEPTH);
 	DRW_shgroup_state_enable(grp, DRW_STATE_OFFSET_NEGATIVE);
 	/* To match blender loop structure. */
 	DRW_shgroup_state_enable(grp, DRW_STATE_FIRST_VERTEX_CONVENTION);
@@ -320,6 +354,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
 		DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
 		DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
 		DRW_shgroup_uniform_float(grp, "edgeScale", edge_width_scale, 1);
+		DRW_shgroup_uniform_float_copy(grp, "ofs", depth_ofs);
 		DRW_shgroup_state_enable(grp, DRW_STATE_OFFSET_NEGATIVE | DRW_STATE_WRITE_DEPTH);
 		DRW_shgroup_state_disable(grp, DRW_STATE_BLEND);
 		if (rv3d->rflag & RV3D_CLIPPING) {
@@ -375,6 +410,9 @@ static void EDIT_MESH_cache_init(void *vedata)
 				stl->g_data->data_mask[0] &= ~(VFLAG_FACE_SELECTED & VFLAG_FACE_FREESTYLE);
 				stl->g_data->do_faces = false;
 			}
+			if ((tsettings->selectmode & SCE_SELECT_FACE) == 0) {
+				stl->g_data->data_mask[0] &= ~VFLAG_FACE_ACTIVE;
+			}
 			if ((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_SEAMS) == 0) {
 				stl->g_data->data_mask[1] &= ~VFLAG_EDGE_SEAM;
 			}
@@ -473,6 +511,7 @@ static void EDIT_MESH_cache_init(void *vedata)
 		        &stl->g_data->face_cage_shgrp,
 		        &stl->g_data->facedot_shgrp,
 		        &stl->g_data->edge_shgrp,
+		        &stl->g_data->edge_deco_shgrp,
 		        &stl->g_data->vert_shgrp);
 	}
 	else {
@@ -484,6 +523,7 @@ static void EDIT_MESH_cache_init(void *vedata)
 		        &stl->g_data->face_cage_shgrp,
 		        &stl->g_data->facedot_shgrp,
 		        &stl->g_data->edge_shgrp,
+		        &stl->g_data->edge_deco_shgrp,
 		        &stl->g_data->vert_shgrp);
 
 		/* however we loose the front faces value (because we need the depth of occluded wires and
@@ -533,11 +573,13 @@ static void edit_mesh_add_ob_to_pass(
 	DRWShadingGroup *face_shgrp = (has_edit_mesh_cage) ? g_data->face_cage_shgrp : g_data->face_shgrp;
 	DRWShadingGroup *vert_shgrp = g_data->vert_shgrp;
 	DRWShadingGroup *edge_shgrp = g_data->edge_shgrp;
+	DRWShadingGroup *edge_deco_shgrp = g_data->edge_deco_shgrp;
 
 	geom_tris = DRW_mesh_batch_cache_get_edit_triangles(ob->data);
 	geom_edges = DRW_mesh_batch_cache_get_edit_edges(ob->data);
 	DRW_shgroup_call_add(face_shgrp, geom_tris, ob->obmat);
 	DRW_shgroup_call_a

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list