[Bf-blender-cvs] [8add4cc900] blender2.8: OpenGL immediate mode: uvedit_draw.c

Luca Rood noreply at git.blender.org
Sat Feb 11 00:47:14 CET 2017


Commit: 8add4cc900b4d6c8fe66d09b1563bc48b3b7be32
Author: Luca Rood
Date:   Thu Feb 2 18:47:33 2017 -0200
Branches: blender2.8
https://developer.blender.org/rB8add4cc900b4d6c8fe66d09b1563bc48b3b7be32

OpenGL immediate mode: uvedit_draw.c

Still has one `UI_ThemeColor` call, because drawing is happening in a DM
drawing callback which hasn't been converted yet.

Also has some old gl calls that are #ifdef'ed out.

This also changes active face drawing in UVs from stippled to a solid
color, which makes active faces much more visible, and also looks nicer.
The same should probably be done for active face drawing in the 3d view.
(has been discussed with merwin on IRC)

Part of T49043

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

M	source/blender/editors/uvedit/uvedit_draw.c

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

diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c
index 93cf88e62c..3510e1e708 100644
--- a/source/blender/editors/uvedit/uvedit_draw.c
+++ b/source/blender/editors/uvedit/uvedit_draw.c
@@ -55,6 +55,8 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "GPU_immediate.h"
+
 #include "ED_image.h"
 #include "ED_mesh.h"
 #include "ED_uvedit.h"
@@ -70,7 +72,7 @@
 /* use editmesh tessface */
 #define USE_EDBM_LOOPTRIS
 
-static void draw_uvs_lineloop_bmface(BMFace *efa, const int cd_loop_uv_offset);
+static void draw_uvs_lineloop_bmface(BMFace *efa, const int cd_loop_uv_offset, unsigned int pos);
 
 void ED_image_draw_cursor(ARegion *ar, const float cursor[2])
 {
@@ -81,35 +83,67 @@ void ED_image_draw_cursor(ARegion *ar, const float cursor[2])
 	mul_v2_fl(zoom, 256.0f * UI_DPI_FAC);
 	x_fac = zoom[0];
 	y_fac = zoom[1];
-	
-	cpack(0xFFFFFF);
+
 	glTranslate2fv(cursor);
-	fdrawline(-0.05f * x_fac, 0, 0, 0.05f * y_fac);
-	fdrawline(0, 0.05f * y_fac, 0.05f * x_fac, 0.0f);
-	fdrawline(0.05f * x_fac, 0.0f, 0.0f, -0.05f * y_fac);
-	fdrawline(0.0f, -0.05f * y_fac, -0.05f * x_fac, 0.0f);
 
-	setlinestyle(4);
-	cpack(0xFF);
-	fdrawline(-0.05f * x_fac, 0.0f, 0.0f, 0.05f * y_fac);
-	fdrawline(0.0f, 0.05f * y_fac, 0.05f * x_fac, 0.0f);
-	fdrawline(0.05f * x_fac, 0.0f, 0.0f, -0.05f * y_fac);
-	fdrawline(0.0f, -0.05f * y_fac, -0.05f * x_fac, 0.0f);
+	unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
 
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 
-	setlinestyle(0.0f);
-	cpack(0x0);
-	fdrawline(-0.020f * x_fac, 0.0f, -0.1f * x_fac, 0.0f);
-	fdrawline(0.1f * x_fac, 0.0f, 0.020f * x_fac, 0.0f);
-	fdrawline(0.0f, -0.020f * y_fac, 0.0f, -0.1f * y_fac);
-	fdrawline(0.0f, 0.1f * y_fac, 0.0f, 0.020f * y_fac);
+	imm_cpack(0xFFFFFF);
+
+	immBegin(GL_LINE_LOOP, 4);
+	immVertex2f(pos, -0.05f * x_fac, 0.0f);
+	immVertex2f(pos, 0.0f, 0.05f * y_fac);
+	immVertex2f(pos, 0.05f * x_fac, 0.0f);
+	immVertex2f(pos, 0.0f, -0.05f * y_fac);
+	immEnd();
+
+	setlinestyle(4);
+	imm_cpack(0xFF);
+
+	/* drawing individual segments, because the stipple pattern
+	 * gets messed up when drawing a continuous loop */
+	immBegin(GL_LINES, 8);
+	immVertex2f(pos, -0.05f * x_fac, 0.0f);
+	immVertex2f(pos, 0.0f, 0.05f * y_fac);
+	immVertex2f(pos, 0.0f, 0.05f * y_fac);
+	immVertex2f(pos, 0.05f * x_fac, 0.0f);
+	immVertex2f(pos, 0.05f * x_fac, 0.0f);
+	immVertex2f(pos, 0.0f, -0.05f * y_fac);
+	immVertex2f(pos, 0.0f, -0.05f * y_fac);
+	immVertex2f(pos, -0.05f * x_fac, 0.0f);
+	immEnd();
+
+	setlinestyle(0);
+	imm_cpack(0x0);
+
+	immBegin(GL_LINES, 8);
+	immVertex2f(pos, -0.020f * x_fac, 0.0f);
+	immVertex2f(pos, -0.1f * x_fac, 0.0f);
+	immVertex2f(pos, 0.1f * x_fac, 0.0f);
+	immVertex2f(pos, 0.020f * x_fac, 0.0f);
+	immVertex2f(pos, 0.0f, -0.020f * y_fac);
+	immVertex2f(pos, 0.0f, -0.1f * y_fac);
+	immVertex2f(pos, 0.0f, 0.1f * y_fac);
+	immVertex2f(pos, 0.0f, 0.020f * y_fac);
+	immEnd();
 
 	setlinestyle(1);
-	cpack(0xFFFFFF);
-	fdrawline(-0.020f * x_fac, 0.0f, -0.1f * x_fac, 0.0f);
-	fdrawline(0.1f * x_fac, 0.0f, 0.020f * x_fac, 0.0f);
-	fdrawline(0.0f, -0.020f * y_fac, 0.0f, -0.1f * y_fac);
-	fdrawline(0.0f, 0.1f * y_fac, 0.0f, 0.020f * y_fac);
+	imm_cpack(0xFFFFFF);
+
+	immBegin(GL_LINES, 8);
+	immVertex2f(pos, -0.020f * x_fac, 0.0f);
+	immVertex2f(pos, -0.1f * x_fac, 0.0f);
+	immVertex2f(pos, 0.1f * x_fac, 0.0f);
+	immVertex2f(pos, 0.020f * x_fac, 0.0f);
+	immVertex2f(pos, 0.0f, -0.020f * y_fac);
+	immVertex2f(pos, 0.0f, -0.1f * y_fac);
+	immVertex2f(pos, 0.0f, 0.1f * y_fac);
+	immVertex2f(pos, 0.0f, 0.020f * y_fac);
+	immEnd();
+
+	immUnbindProgram();
 
 	glTranslatef(-cursor[0], -cursor[1], 0.0);
 	setlinestyle(0);
@@ -141,12 +175,18 @@ static void draw_uvs_shadow(Object *obedit)
 
 	const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
 
+	unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
 	/* draws the mesh when painting */
-	UI_ThemeColor(TH_UV_SHADOW);
+	immUniformThemeColor(TH_UV_SHADOW);
 
 	BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
-		draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset);
+		draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos);
 	}
+
+	immUnbindProgram();
 }
 
 static int draw_uvs_dm_shadow(DerivedMesh *dm)
@@ -212,19 +252,27 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
 					BM_elem_flag_disable(efa, BM_ELEM_TAG);
 				}
 			}
-			
+
+			unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+			immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
 			if (totarea < FLT_EPSILON || totuvarea < FLT_EPSILON) {
 				col[0] = 1.0;
 				col[1] = col[2] = 0.0;
-				glColor3fv(col);
+
+				immUniformColor3fv(col);
+
 				BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 					if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
-						glBegin(GL_POLYGON);
+						immBegin(GL_TRIANGLE_FAN, efa->len);
+
 						BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 							luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-							glVertex2fv(luv->uv);
+							immVertex2fv(pos, luv->uv);
 						}
-						glEnd();
+
+						immEnd();
 					}
 				}
 			}
@@ -254,18 +302,23 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
 							areadiff = 1.0f - (area / uvarea);
 						
 						weight_to_rgb(col, areadiff);
-						glColor3fv(col);
+						immUniformColor3fv(col);
 						
 						/* TODO: USE_EDBM_LOOPTRIS */
-						glBegin(GL_POLYGON);
+						immBegin(GL_TRIANGLE_FAN, efa->len);
+
 						BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 							luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-							glVertex2fv(luv->uv);
+							immVertex2fv(pos, luv->uv);
 						}
-						glEnd();
+
+						immEnd();
 					}
 				}
 			}
+
+			immUnbindProgram();
+
 			break;
 		}
 		case SI_UVDT_STRETCH_ANGLE:
@@ -278,7 +331,13 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
 			BLI_buffer_declare_static(vec2f, auv_buf, BLI_BUFFER_NOP, BM_DEFAULT_NGON_STACK_SIZE);
 
 			col[3] = 0.5f; /* hard coded alpha, not that nice */
-			
+
+			VertexFormat* format = immVertexFormat();
+			unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+			unsigned int color = add_attrib(format, "color", GL_FLOAT, 3, KEEP_FLOAT);
+
+			immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+
 			BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 				tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
 				
@@ -320,15 +379,15 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
 					}
 
 					/* TODO: USE_EDBM_LOOPTRIS */
-					glBegin(GL_POLYGON);
+					immBegin(GL_TRIANGLE_FAN, efa->len);
 					BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
 						luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 						a = fabsf(uvang[i] - ang[i]) / (float)M_PI;
 						weight_to_rgb(col, 1.0f - pow2f(1.0f - a));
-						glColor3fv(col);
-						glVertex2fv(luv->uv);
+						immAttrib3fv(color, col);
+						immVertex2fv(pos, luv->uv);
 					}
-					glEnd();
+					immEnd();
 				}
 				else {
 					if (tf == activetf)
@@ -337,6 +396,8 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
 				}
 			}
 
+			immUnbindProgram();
+
 			BLI_buffer_free(&uvang_buf);
 			BLI_buffer_free(&ang_buf);
 			BLI_buffer_free(&av_buf);
@@ -350,34 +411,38 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
 	BLI_buffer_free(&tf_uvorig_buf);
 }
 
-static void draw_uvs_lineloop_bmface(BMFace *efa, const int cd_loop_uv_offset)
+static void draw_uvs_lineloop_bmface(BMFace *efa, const int cd_loop_uv_offset, unsigned int pos)
 {
 	BMIter liter;
 	BMLoop *l;
 	MLoopUV *luv;
 
-	glBegin(GL_LINE_LOOP);
+	immBegin(GL_LINE_LOOP, efa->len);
+
 	BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 		luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-		glVertex2fv(luv->uv);
+		immVertex2fv(pos, luv->uv);
 	}
-	glEnd();
+
+	immEnd();
 }
 
-static void draw_uvs_lineloop_mpoly(Mesh *me, MPoly *mpoly)
+static void draw_uvs_lineloop_mpoly(Mesh *me, MPoly *mpoly, unsigned int pos)
 {
 	MLoopUV *mloopuv;
 	int i;
 
-	glBegin(GL_LINE_LOOP);
+	immBegin(GL_LINE_LOOP, mpoly->totloop);
+
 	mloopuv = &me->mloopuv[mpoly->loopstart];
 	for (i = mpoly->totloop; i != 0; i--, mloopuv++) {
-		glVertex2fv(mloopuv->uv);
+		immVertex2fv(pos, mloopuv->uv);
 	}
-	glEnd();
+
+	immEnd();
 }
 
-static void draw_uvs_other_mesh_texface(Object *ob, const Image *curimage, const int other_uv_filter)
+static void draw_uvs_other_mesh_texface(Object *ob, const Image *curimage, const int other_uv_filter, unsigned int pos)
 {
 	Mesh *me = ob->data;
 	MPoly *mpoly = me->mpoly;
@@ -398,10 +463,10 @@ static void draw_uvs_other_mesh_texface(Object *ob, const Image *curimage, const
 			}
 		}
 
-		draw_uvs_lineloop_mpoly(me, mpoly);
+		draw_uvs_lineloop_mpoly(me, mpoly, pos);
 	}
 }
-static void draw_uvs_other_mesh_new_shading(Object *ob, const Image *curimage, const int other_uv_filter)
+static void draw_uvs_other_mesh_new_shading(Object *ob, const Image *curimage, const int other_uv_filter, unsigned int pos)
 {
 	Mesh *me = ob->data;
 	MPoly *mpoly = me->mpoly;
@@ -453,17 +518,17 @@ static void draw_uvs_other_mesh_new_shading(Object *ob, const Image *curimage, c
 			}
 		}
 
-		draw_uvs_lineloop_mpoly(me, mpoly);
+		draw_uvs_lineloop_mpoly(me, mpoly, pos);
 	}
 }
 static void draw_uvs_other_mesh(Object *ob, const Image *curimage, const bool new_shading_nodes,
-                                const int other_uv_filter)
+                                const int other_uv_filter, unsigned int pos)
 {
 	if (new_shading_nodes) {
-		draw_uvs_other_mesh_new_shading(ob, curimage, other_uv_filter);
+		draw_uvs_other_mesh_new_shading(ob, curimage, other_uv_filter, pos);
 	}
 	else {
-		draw_uvs_other_mesh_texface(ob, curimage, other_uv_filter);
+		draw_uvs_other_mesh_texface(ob, curimage, other_uv_filter, pos);
 	}
 }
 
@@ -472,7 +537,11 @@ static void draw_uvs_other(Scene *scene, Object *obedit, const Image *curimage,
 {
 	BaseLegacy *base;
 
-	UI_ThemeColor(TH_UV_OTH

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list