[Bf-blender-cvs] [5f3fdee53a3] master: UVEdit: Port batches to batch request

Clément Foucault noreply at git.blender.org
Fri Jan 11 16:00:53 CET 2019


Commit: 5f3fdee53a3e2716013147029e6da9e90e2c8ba8
Author: Clément Foucault
Date:   Wed Jan 9 22:56:27 2019 +0100
Branches: master
https://developer.blender.org/rB5f3fdee53a3e2716013147029e6da9e90e2c8ba8

UVEdit: Port batches to batch request

This is in order to allow more spaces to have their batches created at the
same time and sharing the batches.

This is part of the effort fo making the drawing code more optimized. This
commit however should not introduce any difference.

This commit bypass the aspect ratio correction for angle stretch display
but this should be fixed in the next commit.

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

M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/editors/include/ED_uvedit.h
M	source/blender/editors/uvedit/uvedit_draw.c
M	source/blender/editors/uvedit/uvedit_intern.h

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

diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index dfdbd7f47e7..9f4162195bf 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -132,24 +132,18 @@ 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);
 /* Object mode Wireframe overlays */
 struct GPUBatch *DRW_mesh_batch_cache_get_wireframes_face(struct Mesh *me);
+/* edit-mesh UV editor */
+struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_strech_area(struct Mesh *me);
+struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_strech_angle(struct Mesh *me);
+struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces(struct Mesh *me);
+struct GPUBatch *DRW_mesh_batch_cache_get_edituv_edges(struct Mesh *me);
+struct GPUBatch *DRW_mesh_batch_cache_get_edituv_verts(struct Mesh *me);
+struct GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(struct Mesh *me);
 
 void DRW_mesh_cache_sculpt_coords_ensure(struct Mesh *me);
 
-enum {
-	UVEDIT_EDGES          = (1 << 0),
-	UVEDIT_DATA           = (1 << 1),
-	UVEDIT_FACEDOTS       = (1 << 2),
-	UVEDIT_FACES          = (1 << 3),
-	UVEDIT_STRETCH_ANGLE  = (1 << 4),
-	UVEDIT_STRETCH_AREA   = (1 << 5),
-	UVEDIT_SYNC_SEL       = (1 << 6),
-};
-
 /* For Image UV editor. */
 struct GPUBatch *DRW_mesh_batch_cache_get_texpaint_loop_wire(struct Mesh *me);
-void DRW_mesh_cache_uvedit(
-        struct Object *me, struct SpaceImage *sima, struct Scene *scene, uchar state,
-        struct GPUBatch **faces, struct GPUBatch **edges, struct GPUBatch **verts, struct GPUBatch **facedots);
 
 /* Edit mesh bitflags (is this the right place?) */
 
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index a0da6fb2919..524e802e80d 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -2036,6 +2036,17 @@ typedef struct MeshBatchCache {
 		GPUVertBuf *facedots_idx;
 	} edit;
 
+	/* Edit UVs:
+	 * We need different flags and vertex count form edit mesh. */
+	struct {
+		GPUVertBuf *loop_stretch_angle;
+		GPUVertBuf *loop_stretch_area;
+		GPUVertBuf *loop_uv;
+		GPUVertBuf *loop_data;
+		GPUVertBuf *facedots_uv;
+		GPUVertBuf *facedots_data;
+	} edituv;
+
 	/* Index Buffers:
 	 * Only need to be updated when topology changes. */
 	struct {
@@ -2054,6 +2065,8 @@ typedef struct MeshBatchCache {
 		GPUIndexBuf *edit_loops_points; /* verts */
 		GPUIndexBuf *edit_loops_lines; /* edges */
 		GPUIndexBuf *edit_loops_tris; /* faces */
+		/* Edit UVs */
+		GPUIndexBuf *edituv_loops_lines; /* edges & faces */
 	} ibo;
 
 	struct {
@@ -2069,6 +2082,13 @@ typedef struct MeshBatchCache {
 		GPUBatch *edit_triangles_lnor;
 		GPUBatch *edit_loose_edges_nor;
 		GPUBatch *edit_facedots;
+		/* Edit UVs */
+		GPUBatch *edituv_faces_strech_area;
+		GPUBatch *edituv_faces_strech_angle;
+		GPUBatch *edituv_faces;
+		GPUBatch *edituv_edges;
+		GPUBatch *edituv_verts;
+		GPUBatch *edituv_facedots;
 		/* Edit selection */
 		GPUBatch *edit_selection_verts;
 		GPUBatch *edit_selection_edges;
@@ -2087,27 +2107,8 @@ typedef struct MeshBatchCache {
 	GPUBatch **surf_per_mat;
 
 	/* OLD BATCH METHOD, thoses needs to be ported and added in the structs above. */
-
-	/* 2D/UV edit */
-	GPUVertBuf *edituv_pos;
-	GPUVertBuf *edituv_area;
-	GPUVertBuf *edituv_angle;
-	GPUVertBuf *edituv_data;
-
-	GPUIndexBuf *edituv_visible_faces;
-	GPUIndexBuf *edituv_visible_edges;
-
 	GPUBatch *texpaint_uv_loops;
 
-	GPUBatch *edituv_faces_strech_area;
-	GPUBatch *edituv_faces_strech_angle;
-	GPUBatch *edituv_faces;
-	GPUBatch *edituv_edges;
-	GPUBatch *edituv_verts;
-	GPUBatch *edituv_facedots;
-
-	char edituv_state;
-
 	/* arrays of bool uniform names (and value) that will be use to
 	 * set srgb conversion for auto attribs.*/
 	char *auto_layer_names;
@@ -2123,6 +2124,7 @@ typedef struct MeshBatchCache {
 	int vert_len;
 	int mat_len;
 	bool is_editmode;
+	bool is_uvsyncsel;
 
 	struct DRW_MeshWeightState weight_state;
 
@@ -2204,12 +2206,6 @@ static void mesh_batch_cache_init(Mesh *me)
 	cache->surf_per_mat_tris = MEM_callocN(sizeof(*cache->surf_per_mat_tris) * cache->mat_len, __func__);
 	cache->surf_per_mat = MEM_callocN(sizeof(*cache->surf_per_mat) * cache->mat_len, __func__);
 
-	/* TODO Might be wiser to alloc in one chunck. */
-	for (int i = 0; i < cache->mat_len; ++i) {
-		cache->surf_per_mat_tris[i] = MEM_callocN(sizeof(GPUIndexBuf), "GPUIndexBuf");
-		cache->surf_per_mat[i] = MEM_callocN(sizeof(GPUBatch), "GPUBatch");
-	}
-
 	cache->is_maybe_dirty = false;
 	cache->is_dirty = false;
 
@@ -2264,45 +2260,22 @@ static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache)
 
 static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache)
 {
-	GPU_VERTBUF_DISCARD_SAFE(cache->edituv_pos);
-	GPU_VERTBUF_DISCARD_SAFE(cache->edituv_area);
-	GPU_VERTBUF_DISCARD_SAFE(cache->edituv_angle);
-	GPU_VERTBUF_DISCARD_SAFE(cache->edituv_data);
-
-	GPU_INDEXBUF_DISCARD_SAFE(cache->edituv_visible_faces);
-	GPU_INDEXBUF_DISCARD_SAFE(cache->edituv_visible_edges);
-
-	if (cache->edituv_faces_strech_area) {
-		gpu_batch_presets_unregister(cache->edituv_faces_strech_area);
-	}
-	if (cache->edituv_faces_strech_angle) {
-		gpu_batch_presets_unregister(cache->edituv_faces_strech_angle);
-	}
-	if (cache->edituv_faces) {
-		gpu_batch_presets_unregister(cache->edituv_faces);
-	}
-	if (cache->edituv_edges) {
-		gpu_batch_presets_unregister(cache->edituv_edges);
-	}
-	if (cache->edituv_verts) {
-		gpu_batch_presets_unregister(cache->edituv_verts);
-	}
-	if (cache->edituv_facedots) {
-		gpu_batch_presets_unregister(cache->edituv_facedots);
+	for (int i = 0; i < sizeof(cache->edituv) / sizeof(void *); ++i) {
+		GPUVertBuf **vbo = (GPUVertBuf **)&cache->edituv;
+		GPU_VERTBUF_DISCARD_SAFE(vbo[i]);
 	}
 
-	GPU_BATCH_DISCARD_SAFE(cache->edituv_faces_strech_area);
-	GPU_BATCH_DISCARD_SAFE(cache->edituv_faces_strech_angle);
-	GPU_BATCH_DISCARD_SAFE(cache->edituv_faces);
-	GPU_BATCH_DISCARD_SAFE(cache->edituv_edges);
-	GPU_BATCH_DISCARD_SAFE(cache->edituv_verts);
-	GPU_BATCH_DISCARD_SAFE(cache->edituv_facedots);
+	GPU_INDEXBUF_DISCARD_SAFE(cache->ibo.edituv_loops_lines);
+	GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_strech_area);
+	GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_strech_angle);
+	GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces);
+	GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_edges);
+	GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_verts);
+	GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_facedots);
 
 	gpu_batch_presets_unregister(cache->texpaint_uv_loops);
 
 	GPU_BATCH_DISCARD_SAFE(cache->texpaint_uv_loops);
-
-	cache->edituv_state = 0;
 }
 
 void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode)
@@ -4658,6 +4631,42 @@ GPUBatch *DRW_mesh_batch_cache_get_verts_with_select_id(Mesh *me)
 /** \name UV Image editor API
  * \{ */
 
+GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_strech_area(Mesh *me)
+{
+	MeshBatchCache *cache = mesh_batch_cache_get(me);
+	return DRW_batch_request(&cache->batch.edituv_faces_strech_area);
+}
+
+GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_strech_angle(Mesh *me)
+{
+	MeshBatchCache *cache = mesh_batch_cache_get(me);
+	return DRW_batch_request(&cache->batch.edituv_faces_strech_angle);
+}
+
+GPUBatch *DRW_mesh_batch_cache_get_edituv_faces(Mesh *me)
+{
+	MeshBatchCache *cache = mesh_batch_cache_get(me);
+	return DRW_batch_request(&cache->batch.edituv_faces);
+}
+
+GPUBatch *DRW_mesh_batch_cache_get_edituv_edges(Mesh *me)
+{
+	MeshBatchCache *cache = mesh_batch_cache_get(me);
+	return DRW_batch_request(&cache->batch.edituv_edges);
+}
+
+GPUBatch *DRW_mesh_batch_cache_get_edituv_verts(Mesh *me)
+{
+	MeshBatchCache *cache = mesh_batch_cache_get(me);
+	return DRW_batch_request(&cache->batch.edituv_verts);
+}
+
+GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(Mesh *me)
+{
+	MeshBatchCache *cache = mesh_batch_cache_get(me);
+	return DRW_batch_request(&cache->batch.edituv_facedots);
+}
+
 /* TODO port to batch request. Is basically batch.wire_loops. */
 GPUBatch *DRW_mesh_batch_cache_get_texpaint_loop_wire(Mesh *me)
 {
@@ -4735,31 +4744,13 @@ void DRW_mesh_cache_sculpt_coords_ensure(Mesh *UNUSED(me))
 #endif
 }
 
-static uchar mesh_batch_cache_validate_edituvs(MeshBatchCache *cache, uchar state)
-{
-	if ((cache->edituv_state & UVEDIT_SYNC_SEL) != (state & UVEDIT_SYNC_SEL)) {
-		mesh_batch_cache_discard_uvedit(cache);
-		return state;
-	}
-	else {
-		return ((cache->edituv_state & state) ^ state);
-	}
-}
-
 /* Compute 3D & 2D areas and their sum. */
 BLI_INLINE void edit_uv_preprocess_stretch_area(
-        float (*tf_uv)[2], BMFace *efa, const float asp[2], const int cd_loop_uv_offset, uint fidx,
+        BMFace *efa, const int cd_loop_uv_offset, uint fidx,
         float *totarea, float *totuvarea, float (*faces_areas)[2])
 {
-	BMLoop *l;
-	BMIter liter;
-	int i;
-	BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) {
-		MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-		mul_v2_v2v2(tf_uv[i], luv->uv, asp);
-	}
 	faces_areas[fidx][0] = BM_face_calc_area(efa);
-	faces_areas[fidx][1] = area_poly_v2(tf_uv, efa->len);
+	faces_areas[fidx][1] = BM_face_calc_area_uv(efa, cd_loop_uv_offset);
 
 	*totarea += faces_areas[fidx][0];
 	*totuvarea += faces_areas[fidx][1];
@@ -4836,10 +4827,11 @@ static struct EditUVFormatIndex {
 } uv_attr_id = {0};
 
 static void uvedit_fill_buffer_data(
-        Object *ob, struct SpaceImage *sima, Scene *scene, uchar state, MeshBatchCache *cache,
-        GPUIndexBufBuilder *elb_faces, GPUIndexBufBuilder *elb_edges, GPUVertBuf **facedots_vbo)
+        Mesh *me, const ToolSettings *ts,
+        GPUVertBuf *vbo_pos, GPUVertBuf *vbo_data, GPUVertBuf *vbo_area, GPUVertBuf *vbo_angle,
+        GPUVertBuf *vbo_fdots_pos, GPUVertBuf *vbo_fdots_data,
+        GPUIndexBufBuilder *elb)
 {
-	Mesh *me = ob->data;
 	BMEditMesh *embm = me->edit_btmesh;
 	BMesh *bm = embm->bm;
 	BMIter iter, liter;
@@ -4848,20 +4840,16 @@ static void uvedit_fill_buffer_data(
 	MLoopUV *luv;
 	uint vidx, fidx, i;
 	float (*faces_areas)[2] = NULL;
-	fl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list