[Bf-blender-cvs] [224d70c] temp-blender2.8: OpenGL: draw lamp objects with new imm mode

Mike Erwin noreply at git.blender.org
Thu Oct 20 22:56:17 CEST 2016


Commit: 224d70c978859bf17c5294c7e0a50b50111141f8
Author: Mike Erwin
Date:   Thu Oct 20 16:55:40 2016 -0400
Branches: temp-blender2.8
https://developer.blender.org/rB224d70c978859bf17c5294c7e0a50b50111141f8

OpenGL: draw lamp objects with new imm mode

Previous commit in blender2.8 branch had some... unintended
consequences. This one should be better.

Part of T49043. Also uses new matrix API (T49450)

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

M	source/blender/editors/space_view3d/drawobject.c

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

diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 1400ae1..88f1222 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -1033,7 +1033,7 @@ static void drawcube_size(float size, unsigned pos)
 #endif
 }
 
-static void drawshadbuflimits(Lamp *la, float mat[4][4])
+static void drawshadbuflimits(const Lamp *la, const float mat[4][4], unsigned pos)
 {
 	float sta[3], end[3], lavec[3];
 
@@ -1043,16 +1043,16 @@ static void drawshadbuflimits(Lamp *la, float mat[4][4])
 	madd_v3_v3v3fl(sta, mat[3], lavec, la->clipsta);
 	madd_v3_v3v3fl(end, mat[3], lavec, la->clipend);
 
-	glBegin(GL_LINES);
-	glVertex3fv(sta);
-	glVertex3fv(end);
-	glEnd();
+	immBegin(GL_LINES, 2);
+	immVertex3fv(pos, sta);
+	immVertex3fv(pos, end);
+	immEnd();
 
 	glPointSize(3.0);
-	glBegin(GL_POINTS);
-	glVertex3fv(sta);
-	glVertex3fv(end);
-	glEnd();
+	immBegin(GL_POINTS, 2);
+	immVertex3fv(pos, sta);
+	immVertex3fv(pos, end);
+	immEnd();
 }
 
 static void spotvolume(float lvec[3], float vvec[3], const float inp)
@@ -1118,31 +1118,33 @@ static void spotvolume(float lvec[3], float vvec[3], const float inp)
 	mul_m3_v3(mat2, vvec);
 }
 
-static void draw_spot_cone(Lamp *la, float x, float z)
+static void draw_spot_cone(Lamp *la, float x, float z, unsigned pos)
 {
 	z = fabsf(z);
 
-	glBegin(GL_TRIANGLE_FAN);
-	glVertex3f(0.0f, 0.0f, -x);
+	const bool square = (la->mode & LA_SQUARE);
+
+	immBegin(GL_TRIANGLE_FAN, square ? 6 : 34);
+	immVertex3f(pos, 0.0f, 0.0f, -x);
 
-	if (la->mode & LA_SQUARE) {
-		glVertex3f(z, z, 0);
-		glVertex3f(-z, z, 0);
-		glVertex3f(-z, -z, 0);
-		glVertex3f(z, -z, 0);
-		glVertex3f(z, z, 0);
+	if (square) {
+		immVertex3f(pos, z, z, 0);
+		immVertex3f(pos, -z, z, 0);
+		immVertex3f(pos, -z, -z, 0);
+		immVertex3f(pos, z, -z, 0);
+		immVertex3f(pos, z, z, 0);
 	}
 	else {
 		for (int a = 0; a < 33; a++) {
 			float angle = a * M_PI * 2 / (33 - 1);
-			glVertex3f(z * cosf(angle), z * sinf(angle), 0);
+			immVertex3f(pos, z * cosf(angle), z * sinf(angle), 0.0f);
 		}
 	}
 
-	glEnd();
+	immEnd();
 }
 
-static void draw_transp_spot_volume(Lamp *la, float x, float z)
+static void draw_transp_spot_volume(Lamp *la, float x, float z, unsigned pos)
 {
 	glEnable(GL_CULL_FACE);
 	glEnable(GL_BLEND);
@@ -1152,17 +1154,17 @@ static void draw_transp_spot_volume(Lamp *la, float x, float z)
 	glCullFace(GL_FRONT);
 
 	glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
-	glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+	immUniformColor4f(0.0f, 0.0f, 0.0f, 0.4f);
 
-	draw_spot_cone(la, x, z);
+	draw_spot_cone(la, x, z, pos);
 
 	/* draw front side lighting */
 	glCullFace(GL_BACK);
 
 	glBlendFunc(GL_ONE, GL_ONE);
-	glColor4f(0.2f, 0.2f, 0.2f, 1.0f);
+	immUniformColor4f(0.2f, 0.2f, 0.2f, 1.0f);
 
-	draw_spot_cone(la, x, z);
+	draw_spot_cone(la, x, z, pos);
 
 	/* restore state */
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -1173,7 +1175,7 @@ static void draw_transp_spot_volume(Lamp *la, float x, float z)
 }
 
 #ifdef WITH_GAMEENGINE
-static void draw_transp_sun_volume(Lamp *la)
+static void draw_transp_sun_volume(Lamp *la, unsigned pos)
 {
 	float box[8][3];
 
@@ -1186,7 +1188,7 @@ static void draw_transp_sun_volume(Lamp *la)
 	box[1][2] = box[2][2] = box[5][2] = box[6][2] = -la->clipsta;
 
 	/* draw edges */
-	draw_box(box, false);
+	imm_draw_box(box, false, pos);
 
 	/* draw faces */
 	glEnable(GL_CULL_FACE);
@@ -1197,17 +1199,17 @@ static void draw_transp_sun_volume(Lamp *la)
 	glCullFace(GL_FRONT);
 
 	glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
-	glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+	immUniformColor4f(0.0f, 0.0f, 0.0f, 0.4f);
 
-	draw_box(box, true);
+	imm_draw_box(box, true, pos);
 
 	/* draw front side lighting */
 	glCullFace(GL_BACK);
 
 	glBlendFunc(GL_ONE, GL_ONE);
-	glColor4f(0.2f, 0.2f, 0.2f, 1.0f);
+	immUniformColor4f(0.2f, 0.2f, 0.2f, 1.0f);
 
-	draw_box(box, true);
+	imm_draw_box(box, true, pos);
 
 	/* restore state */
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -1225,11 +1227,8 @@ void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
 	const float pixsize = ED_view3d_pixel_size(rv3d, ob->obmat[3]);
 	Lamp *la = ob->data;
 	float vec[3], lvec[3], vvec[3], circrad;
-	float lampsize;
 	float imat[4][4];
 
-	unsigned char curcol[4];
-	unsigned char col[4];
 	/* cone can't be drawn for duplicated lamps, because duplilist would be freed */
 	/* the moment of view3d_draw_transp() call */
 	const bool is_view = (rv3d->persp == RV3D_CAMOB && v3d->camera == base->object);
@@ -1260,115 +1259,155 @@ void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
 		ED_view3d_after_add(&v3d->afterdraw_transp, base, dflag);
 		return;
 	}
-	
+
 	/* we first draw only the screen aligned & fixed scale stuff */
-	glPushMatrix();
-	glLoadMatrixf(rv3d->viewmat);
+	gpuMatrixBegin3D_legacy();
+	gpuPushMatrix();
+	gpuLoadMatrix3D(rv3d->viewmat);
 
 	/* lets calculate the scale: */
-	lampsize = pixsize * ((float)U.obcenter_dia * 0.5f);
+	const float lampsize_px = U.obcenter_dia;
+	const float lampsize = pixsize * lampsize_px * 0.5f;
 
 	/* and view aligned matrix: */
 	copy_m4_m4(imat, rv3d->viewinv);
 	normalize_v3(imat[0]);
 	normalize_v3(imat[1]);
 
+	const unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
 	/* lamp center */
 	copy_v3_v3(vec, ob->obmat[3]);
 
+	float curcol[4];
 	if ((dflag & DRAW_CONSTCOLOR) == 0) {
 		/* for AA effects */
-		curcol[0] = ob_wire_col[0];
-		curcol[1] = ob_wire_col[1];
-		curcol[2] = ob_wire_col[2];
-		curcol[3] = 154;
-		glColor4ubv(curcol);
+		rgb_uchar_to_float(curcol, ob_wire_col);
+		curcol[3] = 0.6f;
+		/* TODO: pay attention to GL_BLEND */
 	}
 
 	glLineWidth(1);
+	setlinestyle(3);
 
 	if (lampsize > 0.0f) {
+		const float outlineWidth = 1.5f * U.pixelsize;
+		const float lampdot_size = lampsize_px * U.pixelsize + outlineWidth;
 
+		/* Inner Circle */
 		if ((dflag & DRAW_CONSTCOLOR) == 0) {
+			const float *color = curcol;
 			if (ob->id.us > 1) {
 				if (is_obact || (ob->flag & SELECT)) {
-					glColor4ub(0x88, 0xFF, 0xFF, 155);
+					static const float active_color[4] = {0.533f, 1.0f, 1.0f, 1.0f};
+					color = active_color;
 				}
 				else {
-					glColor4ub(0x77, 0xCC, 0xCC, 155);
+					static const float inactive_color[4] = {0.467f, 0.8f, 0.8f, 1.0f};
+					color = inactive_color;
 				}
 			}
+
+			GPU_enable_program_point_size();
+			glEnable(GL_BLEND);
+			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+			immBindBuiltinProgram(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_SMOOTH);
+			immUniform1f("size", lampdot_size);
+			immUniform1f("outlineWidth", outlineWidth);
+			immUniformColor3fvAlpha(color, 0.3f);
+			immUniform4fv("outlineColor", color);
+
+			immBegin(GL_POINTS, 1);
+			immVertex3fv(pos, vec);
+			immEnd();
+
+			immUnbindProgram();
+
+			glDisable(GL_BLEND);
+			GPU_disable_program_point_size();
 		}
-		
-		/* Inner Circle */
-		glEnable(GL_BLEND);
-		drawcircball(GL_LINE_LOOP, vec, lampsize, imat);
-		glDisable(GL_BLEND);
-		drawcircball(GL_POLYGON, vec, lampsize, imat);
-		
+		else {
+			/* CONSTCOLOR in effect */
+			/* TODO: separate picking from drawing */
+			immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR);
+			/* color doesn't matter, so don't set */
+			glPointSize(lampdot_size);
+
+			immBegin(GL_POINTS, 1);
+			immVertex3fv(pos, vec);
+			immEnd();
+
+			immUnbindProgram();
+		}
+
+		immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+		/* TODO(merwin): short term, use DEPTH_ONLY for picking
+		 *               long term, separate picking from drawing
+		 */
+
 		/* restore */
 		if ((dflag & DRAW_CONSTCOLOR) == 0) {
-			if (ob->id.us > 1)
-				glColor4ubv(curcol);
+			immUniformColor4fv(curcol);
 		}
 
 		/* Outer circle */
 		circrad = 3.0f * lampsize;
-		setlinestyle(3);
 
-		drawcircball(GL_LINE_LOOP, vec, circrad, imat);
+		imm_drawcircball(vec, circrad, imat, pos);
 
 		/* draw dashed outer circle if shadow is on. remember some lamps can't have certain shadows! */
 		if (la->type != LA_HEMI) {
 			if ((la->mode & LA_SHAD_RAY) || ((la->mode & LA_SHAD_BUF) && (la->type == LA_SPOT))) {
-				drawcircball(GL_LINE_LOOP, vec, circrad + 3.0f * pixsize, imat);
+				imm_drawcircball(vec, circrad + 3.0f * pixsize, imat, pos);
 			}
 		}
 	}
 	else {
-		setlinestyle(3);
+		immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+		immUniformColor4fv(curcol);
 		circrad = 0.0f;
 	}
-	
+
 	/* draw the pretty sun rays */
 	if (la->type == LA_SUN) {
 		float v1[3], v2[3], mat[3][3];
 		short axis;
-		
+
 		/* setup a 45 degree rotation matrix */
 		axis_angle_normalized_to_mat3_ex(mat, imat[2], M_SQRT1_2, M_SQRT1_2);
 
 		/* vectors */
 		mul_v3_v3fl(v1, imat[0], circrad * 1.2f);
 		mul_v3_v3fl(v2, imat[0], circrad * 2.5f);
-		
+
 		/* center */
-		glTranslate3fv(vec);
-		
+		gpuPushMatrix();
+		gpuTranslate3fv(vec);
+
 		setlinestyle(3);
-		
-		glBegin(GL_LINES);
+
+		immBegin(GL_LINES, 16);
 		for (axis = 0; axis < 8; axis++) {
-			glVertex3fv(v1);
-			glVertex3fv(v2);
+			immVertex3fv(pos, v1);
+			immVertex3fv(pos, v2);
 			mul_m3_v3(mat, v1);
 			mul_m3_v3(mat, v2);
 		}
-		glEnd();
-		
-		glTranslatef(-vec[0], -vec[1], -vec[2]);
+		immEnd();
 
+		gpuPopMatrix();
 	}
-	
+
 	if (la->type == LA_LOCAL) {
 		if (la->mode & LA_SPHERE) {
-			drawcircball(GL_LINE_LOOP, vec, la->dist, imat);
+			imm_drawcircball(vec, la->dist, imat, pos);
 		}
 	}
-	
-	glPopMatrix();  /* back in object space */
+
+	gpuPopMatrix();  /* back in object space */
 	zero_v3(vec);
-	
+
 	if (is_view) {
 		/* skip drawing extra info */
 	}
@@ -1400,24 +1439,18 @@ void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
 			    {z_abs, -z_abs, x},
 			    {-z_abs, z_abs, x},
 			};
-			const unsigned char indices[] = {
-			    0, 1, 3,
-			    0, 3, 2,
-			    0, 2, 4,
-			    0, 1, 4,
-			};
 
-			/* Draw call:
-			 * activate and specify pointer to vertex array */
-			glEnableClientState(GL_VERTEX_ARRAY);
-			glVertexPointer(3, GL_FLOAT, 0, vertices);
-			/* draw the pyramid */
-			glDrawElements(GL_LINE_STRIP, 12, GL_UNSIGNED_BYTE, indices);
-
-			/* deactivate vertex arrays after drawing */
-			glDisableClientState(GL_VERTEX_ARRAY);
+			immBegin(GL_LI

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list