[Bf-blender-cvs] [2a62ec8003c] blender2.8: OpenGL: drawobject.c (cont)

Clément Foucault noreply at git.blender.org
Thu Mar 9 03:23:55 CET 2017


Commit: 2a62ec8003c3a3c54559d243b06e4e82fd968f44
Author: Clément Foucault
Date:   Thu Mar 9 03:21:42 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB2a62ec8003c3a3c54559d243b06e4e82fd968f44

OpenGL: drawobject.c (cont)

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

M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/gpu/intern/gpu_batch.c

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

diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 5669921b0a9..bd90f5c79a4 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -206,6 +206,7 @@ typedef struct drawMVertOffset_userData {
 typedef struct drawDMLayer_userData {
 	BMesh *bm;
 	int cd_layer_offset;
+	unsigned int pos, col;
 } drawDMLayer_userData;
 
 typedef struct drawBMOffset_userData {
@@ -1666,14 +1667,6 @@ bool view3d_camera_border_hack_test = false;
 
 /* ****************** draw clip data *************** */
 
-static void draw_bundle_sphere(void)
-{
-	GLUquadricObj *qobj = gluNewQuadric();
-	gluQuadricDrawStyle(qobj, GLU_FILL);
-	gluSphere(qobj, 0.05, 8, 8);
-	gluDeleteQuadric(qobj);
-}
-
 static void draw_viewport_object_reconstruction(
         Scene *scene, BaseLegacy *base, const View3D *v3d, const RegionView3D *rv3d,
         MovieClip *clip, MovieTrackingObject *tracking_object,
@@ -1756,26 +1749,46 @@ static void draw_viewport_object_reconstruction(
 		}
 		else if (v3d_drawtype > OB_WIRE) {
 			if (v3d->bundle_drawtype == OB_EMPTY_SPHERE) {
+				Batch *batch;
+
+				glScalef(0.05f, 0.05f, 0.05f);
+
 				/* selection outline */
 				if (selected) {
+					batch = Batch_get_sphere_wire(1);
+
 					if ((dflag & DRAW_CONSTCOLOR) == 0) {
-						glColor3ubv(ob_wire_col);
+						Batch_set_builtin_program(batch, GPU_SHADER_3D_UNIFORM_COLOR);
+						Batch_Uniform4f(batch, "color",
+						                ob_wire_col[0]/255.f,
+						                ob_wire_col[1]/255.f,
+						                ob_wire_col[2]/255.f, 1.0f);
+					}
+					else {
+						Batch_set_builtin_program(batch, GPU_SHADER_3D_DEPTH_ONLY);
 					}
-
 					glLineWidth(2.0f);
-					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
-					draw_bundle_sphere();
-
-					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+					Batch_draw(batch);
 				}
 
+				batch = Batch_get_sphere(0);
+
 				if ((dflag & DRAW_CONSTCOLOR) == 0) {
-					if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
-					else UI_ThemeColor(TH_BUNDLE_SOLID);
+					const float light[3] = {0.0f, 0.0f, 1.0f};
+					float col[3];
+					Batch_set_builtin_program(batch, GPU_SHADER_SIMPLE_LIGHTING);
+					Batch_Uniform3fv(batch, "light", light);
+
+					if (track->flag & TRACK_CUSTOMCOLOR) copy_v3_v3(col, track->color);
+					else UI_GetThemeColor3fv(TH_BUNDLE_SOLID, col);
+					Batch_Uniform4f(batch, "color", col[0], col[1], col[2], 1.0f);
+				}
+				else {
+					Batch_set_builtin_program(batch, GPU_SHADER_3D_DEPTH_ONLY);
 				}
 
-				draw_bundle_sphere();
+				Batch_draw(batch);
 			}
 			else {
 				unsigned char color[4];
@@ -3307,8 +3320,10 @@ static void draw_dm_bweights__mapFunc(void *userData, int index, const float co[
 	if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
 		const float bweight = BM_ELEM_CD_GET_FLOAT(eve, data->cd_layer_offset);
 		if (bweight != 0.0f) {
-			UI_ThemeColorBlend(TH_VERTEX, TH_VERTEX_BEVEL, bweight);
-			glVertex3fv(co);
+			unsigned char col[3];
+			UI_GetThemeColorBlend3ubv(TH_VERTEX, TH_VERTEX_BEVEL, bweight, col);
+			immAttrib3ubv(data->col, col);
+			immVertex3fv(data->pos, co);
 		}
 	}
 }
@@ -3322,11 +3337,21 @@ static void draw_dm_bweights(BMEditMesh *em, Scene *scene, DerivedMesh *dm)
 		data.bm = em->bm;
 		data.cd_layer_offset = CustomData_get_offset(&em->bm->vdata, CD_BWEIGHT);
 
+		/* is that ever true? */
 		if (data.cd_layer_offset != -1) {
+			VertexFormat *format = immVertexFormat();
+			data.pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+			data.col = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT);
+
+			immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR);
+
 			glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE) + 2.0f);
-			glBegin(GL_POINTS);
+
+			immBeginAtMost(GL_POINTS, dm->getNumVerts(dm));
 			dm->foreachMappedVert(dm, draw_dm_bweights__mapFunc, &data, DM_FOREACH_NOP);
-			glEnd();
+			immEnd();
+
+			immUnbindProgram();
 		}
 	}
 	else {
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index d4cf3583de9..19229cde7f0 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -41,6 +41,7 @@ static Batch *sphere_high = NULL;
 static Batch *sphere_med = NULL;
 static Batch *sphere_low = NULL;
 static Batch *sphere_wire_low = NULL;
+static Batch *sphere_wire_med = NULL;
 
 static VertexBuffer *vbo;
 static VertexFormat format = {0};
@@ -139,9 +140,14 @@ Batch *Batch_get_sphere(int lod)
 		return sphere_high;
 }
 
-Batch *Batch_get_sphere_wire(int UNUSED(lod))
+Batch *Batch_get_sphere_wire(int lod)
 {
-	return sphere_wire_low;
+	BLI_assert(lod >= 0 && lod <= 1);
+
+	if (lod == 0)
+		return sphere_wire_low;
+	else
+		return sphere_wire_med;
 }
 
 void gpu_batch_init(void)
@@ -152,6 +158,7 @@ void gpu_batch_init(void)
 	sphere_high = batch_sphere(32, 24);
 
 	sphere_wire_low = batch_sphere_wire(6, 8);
+	sphere_wire_med = batch_sphere_wire(8, 16);
 }
 
 void gpu_batch_exit(void)
@@ -159,4 +166,6 @@ void gpu_batch_exit(void)
 	Batch_discard_all(sphere_low);
 	Batch_discard_all(sphere_med);
 	Batch_discard_all(sphere_high);
+	Batch_discard_all(sphere_wire_low);
+	Batch_discard_all(sphere_wire_med);
 }




More information about the Bf-blender-cvs mailing list