[Bf-blender-cvs] [bbf3298] blender2.8: OpenGL: draw speaker with new immediate mode

Mike Erwin noreply at git.blender.org
Thu Sep 29 20:50:29 CEST 2016


Commit: bbf32980b09fbe5151457bdb78217d37ee8a065e
Author: Mike Erwin
Date:   Thu Sep 29 14:47:38 2016 -0400
Branches: blender2.8
https://developer.blender.org/rBbbf32980b09fbe5151457bdb78217d37ee8a065e

OpenGL: draw speaker with new immediate mode

patch P388 by @lichtwerk, I tweaked a few things.

Since speaker theme color is opaque we leave blend mode alone.

Part of T49043

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

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 8ff6886..63db6c4 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -89,6 +89,7 @@
 #include "GPU_select.h"
 #include "GPU_basic_shader.h"
 #include "GPU_shader.h"
+#include "GPU_immediate.h"
 
 #include "ED_mesh.h"
 #include "ED_screen.h"
@@ -2185,43 +2186,48 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
 }
 
 /* flag similar to draw_object() */
-static void drawspeaker(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D *UNUSED(rv3d),
-                        Object *UNUSED(ob), int UNUSED(flag))
-{
-	float vec[3];
+static void drawspeaker(const unsigned char ob_wire_col[3]) {
+	VertexFormat *format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+	if (ob_wire_col)
+		immUniformColor3ubv(ob_wire_col);
 
-	glEnable(GL_BLEND);
 	glLineWidth(1);
 
+	const int segments = 16;
+
 	for (int j = 0; j < 3; j++) {
-		vec[2] = 0.25f * j - 0.125f;
+		float z = 0.25f * j - 0.125f;
 
-		glBegin(GL_LINE_LOOP);
-		for (int i = 0; i < 16; i++) {
-			vec[0] = cosf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
-			vec[1] = sinf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
-			glVertex3fv(vec);
+		immBegin(GL_LINE_LOOP, segments);
+		for (int i = 0; i < segments; i++) {
+			float x = cosf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
+			float y = sinf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
+			immVertex3f(pos, x, y, z);
 		}
-		glEnd();
+		immEnd();
 	}
 
 	for (int j = 0; j < 4; j++) {
-		vec[0] = (((j + 1) % 2) * (j - 1)) * 0.5f;
-		vec[1] = ((j % 2) * (j - 2)) * 0.5f;
-		glBegin(GL_LINE_STRIP);
+		float x = (((j + 1) % 2) * (j - 1)) * 0.5f;
+		float y = ((j % 2) * (j - 2)) * 0.5f;
+		immBegin(GL_LINE_STRIP, 3);
 		for (int i = 0; i < 3; i++) {
 			if (i == 1) {
-				vec[0] *= 0.5f;
-				vec[1] *= 0.5f;
+				x *= 0.5f;
+				y *= 0.5f;
 			}
 
-			vec[2] = 0.25f * i - 0.125f;
-			glVertex3fv(vec);
+			float z = 0.25f * i - 0.125f;
+			immVertex3f(pos, x, y, z);
 		}
-		glEnd();
+		immEnd();
 	}
 
-	glDisable(GL_BLEND);
+	immUnbindProgram();
 }
 
 static void lattice_draw_verts(Lattice *lt, DispList *dl, BPoint *actbp, short sel)
@@ -6596,7 +6602,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
 				break;
 			case OB_SPEAKER:
 				if (!render_override)
-					drawspeaker(scene, v3d, rv3d, ob, dflag);
+					drawspeaker(ob_wire_col);
 				break;
 			case OB_LATTICE:
 				if (!render_override) {




More information about the Bf-blender-cvs mailing list