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

Clément Foucault noreply at git.blender.org
Sat Mar 11 17:18:02 CET 2017


Commit: e29e63c0bab4b2beae40bc1faa9dd4f2bb12fc28
Author: Clément Foucault
Date:   Sat Mar 11 16:10:03 2017 +0100
Branches: blender2.8
https://developer.blender.org/rBe29e63c0bab4b2beae40bc1faa9dd4f2bb12fc28

OpenGL: Convert drawobject.c (cont)

Particle system (not edit mode)

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

M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_shader.h
M	source/blender/gpu/intern/gpu_shader.c
A	source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl

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

diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index c309c36ad18..e2d1852ea16 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -5589,16 +5589,62 @@ static bool drawDispList(Scene *scene, SceneLayer *sl, View3D *v3d, RegionView3D
 }
 
 /* *********** drawing for particles ************* */
-static void draw_particle_arrays(int draw_as, int totpoint, int ob_dt, int select)
+/* stride :   offset size in bytes
+ * col[4] :   the color to use when *color is NULL, can be also NULL */
+static void draw_vertex_array(int dt, const float *vert, const float *nor, const float *color, int stride, int vert_ct, float col[4])
+{
+	VertexFormat format = {0};
+	unsigned int pos_id, nor_id, col_id;
+	pos_id = add_attrib(&format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+	if (nor) nor_id = add_attrib(&format, "nor", GL_FLOAT, 3, KEEP_FLOAT);
+	if (color) col_id = add_attrib(&format, "color", GL_FLOAT, 3, KEEP_FLOAT);
+
+	VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+	VertexBuffer_allocate_data(vbo, vert_ct);
+
+	if (stride == 0) {
+		fillAttrib(vbo, pos_id, vert);
+		if (nor) fillAttrib(vbo, nor_id, nor);
+		if (color) fillAttrib(vbo, col_id, color);
+	}
+	else {
+		fillAttribStride(vbo, pos_id, stride, vert);
+		if (nor) fillAttribStride(vbo, nor_id, stride, nor);
+		if (color) fillAttribStride(vbo, col_id, stride, color);
+	}
+
+	Batch *batch = Batch_create(dt, vbo, NULL);
+	if (nor && color) {
+		Batch_set_builtin_program(batch, GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR);
+		Batch_Uniform3f(batch, "light", 0.0f, 0.0f, 1.0f);
+	}
+	else if (nor) {
+		Batch_set_builtin_program(batch, GPU_SHADER_SIMPLE_LIGHTING);
+		Batch_Uniform3f(batch, "light", 0.0f, 0.0f, 1.0f);
+		if (col) Batch_Uniform4fv(batch, "color", col);
+	}
+	else if (color) {
+		Batch_set_builtin_program(batch, GPU_SHADER_3D_SMOOTH_COLOR);
+	}
+	else {
+		Batch_set_builtin_program(batch, GPU_SHADER_3D_UNIFORM_COLOR);
+		if (col) Batch_Uniform4fv(batch, "color", col);
+	}
+	Batch_draw(batch);
+	Batch_discard_all(batch);
+}
+static void draw_particle_arrays_new(int draw_as, int ob_dt, int select,
+                                     const float *vert, const float *nor, const float *color,
+                                     int totpoint, float col[4])
 {
 	/* draw created data arrays */
 	switch (draw_as) {
 		case PART_DRAW_AXIS:
 		case PART_DRAW_CROSS:
-			glDrawArrays(GL_LINES, 0, 6 * totpoint);
+			draw_vertex_array(GL_LINES, vert, nor, color, 0, 6 * totpoint, col);
 			break;
 		case PART_DRAW_LINE:
-			glDrawArrays(GL_LINES, 0, 2 * totpoint);
+			draw_vertex_array(GL_LINES, vert, nor, color, 0, 2 * totpoint, col);
 			break;
 		case PART_DRAW_BB:
 			if (ob_dt <= OB_WIRE || select)
@@ -5606,10 +5652,10 @@ static void draw_particle_arrays(int draw_as, int totpoint, int ob_dt, int selec
 			else
 				glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
-			glDrawArrays(GL_QUADS, 0, 4 * totpoint);
+			draw_vertex_array(GL_QUADS, vert, nor, color, 0, 4 * totpoint, col);
 			break;
 		default:
-			glDrawArrays(GL_POINTS, 0, totpoint);
+			draw_vertex_array(GL_POINTS, vert, nor, color, 0, totpoint, col);
 			break;
 	}
 }
@@ -6234,26 +6280,11 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 /* 6. */
 
 	glGetIntegerv(GL_POLYGON_MODE, polygonmode);
-	glEnableClientState(GL_VERTEX_ARRAY);
 
 	if (draw_as == PART_DRAW_PATH) {
 		ParticleCacheKey **cache, *path;
 		float *cdata2 = NULL;
 
-		/* setup gl flags */
-		if (1) { //ob_dt > OB_WIRE) {
-			glEnableClientState(GL_NORMAL_ARRAY);
-
-			if ((dflag & DRAW_CONSTCOLOR) == 0) {
-				if (part->draw_col == PART_DRAW_COL_MAT)
-					glEnableClientState(GL_COLOR_ARRAY);
-			}
-
-			// XXX test
-			GPU_basic_shader_colors(NULL, NULL, 0.0f, 1.0f);
-			GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
-		}
-
 		if (totchild && (part->draw & PART_DRAW_PARENT) == 0)
 			totpart = 0;
 		else if (psys->pathcache == NULL)
@@ -6264,41 +6295,27 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 		for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
 			path = cache[a];
 			if (path->segments > 0) {
-				glVertexPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->co);
-
-				if (1) { //ob_dt > OB_WIRE) {
-					glNormalPointer(GL_FLOAT, sizeof(ParticleCacheKey), path->vel);
-					if ((dflag & DRAW_CONSTCOLOR) == 0) {
-						if (part->draw_col == PART_DRAW_COL_MAT) {
-							glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
-						}
-					}
+				if (((dflag & DRAW_CONSTCOLOR) == 0) && (part->draw_col == PART_DRAW_COL_MAT)) {
+					draw_vertex_array(GL_LINE_STRIP, path->co, path->vel, path->col, sizeof(ParticleCacheKey), path->segments + 1, NULL);
+				}
+				else {
+					float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+					draw_vertex_array(GL_LINE_STRIP, path->co, path->vel, NULL, sizeof(ParticleCacheKey), path->segments + 1, color);
 				}
-
-				glDrawArrays(GL_LINE_STRIP, 0, path->segments + 1);
 			}
 		}
 
 		if (part->type ==  PART_HAIR) {
 			if (part->draw & PART_DRAW_GUIDE_HAIRS) {
 				DerivedMesh *hair_dm = psys->hair_out_dm;
-				
-				glDisableClientState(GL_NORMAL_ARRAY);
-				glDisableClientState(GL_COLOR_ARRAY);
-				
+
 				for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
 					if (pa->totkey > 1) {
 						HairKey *hkey = pa->hair;
 						
-						glVertexPointer(3, GL_FLOAT, sizeof(HairKey), hkey->world_co);
-
-#if 0 /* XXX use proper theme color here */
-						UI_ThemeColor(TH_NORMAL);
-#else
-						glColor3f(0.58f, 0.67f, 1.0f);
-#endif
-
-						glDrawArrays(GL_LINE_STRIP, 0, pa->totkey);
+						/* XXX use proper theme color here */
+						float color[4] = {0.58f, 0.67f, 1.0f, 1.0f};
+						draw_vertex_array(GL_LINE_STRIP, hkey->world_co, NULL, NULL, sizeof(HairKey), pa->totkey, color);
 					}
 				}
 				
@@ -6306,30 +6323,36 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 					MVert *mvert = hair_dm->getVertArray(hair_dm);
 					int i;
 					
-					glColor3f(0.9f, 0.4f, 0.4f);
-					
-					glBegin(GL_LINES);
+					unsigned int pos_id = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+					immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+					immUniformColor3f(0.9f, 0.4f, 0.4f);
+
+					unsigned int count = 0;
 					for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
-						for (i = 1; i < pa->totkey; ++i) {
-							float v1[3], v2[3];
-							
-							copy_v3_v3(v1, mvert[pa->hair_index + i - 1].co);
-							copy_v3_v3(v2, mvert[pa->hair_index + i].co);
-							
-							mul_m4_v3(ob->obmat, v1);
-							mul_m4_v3(ob->obmat, v2);
-							
-							glVertex3fv(v1);
-							glVertex3fv(v2);
+						count += MAX2(pa->totkey - 1, 0);
+					}
+
+					if (count > 0) {
+						immBegin(GL_LINES, count * 2);
+						for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
+							for (i = 1; i < pa->totkey; ++i) {
+								float v1[3], v2[3];
+
+								copy_v3_v3(v1, mvert[pa->hair_index + i - 1].co);
+								copy_v3_v3(v2, mvert[pa->hair_index + i].co);
+
+								mul_m4_v3(ob->obmat, v1);
+								mul_m4_v3(ob->obmat, v2);
+
+								immVertex3fv(pos_id, v1);
+								immVertex3fv(pos_id, v2);
+							}
 						}
+						immEnd();
 					}
-					glEnd();
+
+					immUnbindProgram();
 				}
-				
-				glEnableClientState(GL_NORMAL_ARRAY);
-				if ((dflag & DRAW_CONSTCOLOR) == 0)
-					if (part->draw_col == PART_DRAW_COL_MAT)
-						glEnableClientState(GL_COLOR_ARRAY);
 			}
 			
 			if (part->draw & PART_DRAW_HAIR_GRID) {
@@ -6340,64 +6363,69 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 					int *res = clmd->hair_grid_res;
 					int i;
 					
-					glDisableClientState(GL_NORMAL_ARRAY);
-					glDisableClientState(GL_COLOR_ARRAY);
-					
+					unsigned int pos_id = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+					immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
 					if (select)
-						UI_ThemeColor(TH_ACTIVE);
+						immUniformThemeColor(TH_ACTIVE);
 					else
-						UI_ThemeColor(TH_WIRE);
-					glBegin(GL_LINES);
-					glVertex3f(gmin[0], gmin[1], gmin[2]); glVertex3f(gmax[0], gmin[1], gmin[2]);
-					glVertex3f(gmax[0], gmin[1], gmin[2]); glVertex3f(gmax[0], gmax[1], gmin[2]);
-					glVertex3f(gmax[0], gmax[1], gmin[2]); glVertex3f(gmin[0], gmax[1], gmin[2]);
-					glVertex3f(gmin[0], gmax[1], gmin[2]); glVertex3f(gmin[0], gmin[1], gmin[2]);
+						immUniformThemeColor(TH_WIRE);
+
+					immBegin(GL_LINES, 24);
+					immVertex3f(pos_id, gmin[0], gmin[1], gmin[2]); immVertex3f(pos_id, gmax[0], gmin[1], gmin[2]);
+					immVertex3f(pos_id, gmax[0], gmin[1], gmin[2]); immVertex3f(pos_id, gmax[0], gmax[1], gmin[2]);
+					immVertex3f(pos_id, gmax[0], gmax[1], gmin[2]); immVertex3f(pos_id, gmin[0], gmax[1], gmin[2]);
+					immVertex3f(pos_id, gmin[0], gmax[1], gmin[2]); immVertex3f(pos_id, gmin[0], gmin[1], gmin[2]);
 					
-					glVertex3f(gmin[0], gmin[1], gmax[2]); glVertex3f(gmax[0], gmin[1], gmax[2]);
-					glVertex3f(gmax[0], gmin[1], gmax[2]); glVertex3f(gmax[0], gmax[1], gmax[2]);
-					glVertex3f(gmax[0], gmax[1], gmax[2]); glVertex3f(gmin[0], gmax[1], gmax[2]);
-					glVertex3f(gmin[0], gmax[1], gmax[2]); glVertex3f(gmin[0], gmin[1], gmax[2]);
+					immVertex3f(pos_id, gmin[0], gmin[1], gmax[2]); immVertex3f(pos_id, gmax[0], gmin[1], gmax[2]);
+					immVertex3f(pos_id, gmax[0], gmin[1], gmax[2]); immVertex3f(pos_id, gmax[0], gmax[1], gmax[2]);
+					immVertex3f(pos_id, gmax[0], gmax[1], gmax[2]); immVertex3f(pos_id, gmin[0], gmax[1], gmax[2]);
+					immVertex3f(pos_id, gmin[0], gmax[1], gmax[2]); immVertex3f(pos_id, gmin[0], gmin[1], gmax[2]);
 					
-					glVertex3f(gmin[0], gmin[1], gmin[2]); glVertex3f(gmin[0], gmin[1], gmax[2]);
-					glVertex3f(gmax[0], gmin[1], gmin[2]); glVertex3f(gmax[0], gmin[1], gmax[2]);
-					glVertex3f(gmin[0], gmax[1], gmin[2]); glVertex3f(gmin[0], gmax[1], gmax[2]);
-					glVertex3f(gmax[0], gmax[1], gmin[2]); glVertex3f(gmax[0], gmax[1], gmax[2]);
-					glEnd();
+					immVertex3f(pos_id, gmin[0], gmin[1], gmin[2]); immVertex3f(pos_id, gmin[0], gm

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list