[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24007] trunk/blender/source/blender: Smoke:

Daniel Genrich daniel.genrich at gmx.net
Tue Oct 20 17:51:31 CEST 2009


Revision: 24007
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24007
Author:   genscher
Date:     2009-10-20 17:51:25 +0200 (Tue, 20 Oct 2009)

Log Message:
-----------
Smoke:
* Use GL_QUADS and GL_TRIANGLES instead of GL_POLYGON for faster drawing
* Use variable count of slices 

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_view3d/drawvolume.c
    trunk/blender/source/blender/gpu/intern/gpu_extensions.c

Modified: trunk/blender/source/blender/editors/space_view3d/drawvolume.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawvolume.c	2009-10-20 15:51:18 UTC (rev 24006)
+++ trunk/blender/source/blender/editors/space_view3d/drawvolume.c	2009-10-20 15:51:25 UTC (rev 24007)
@@ -119,6 +119,51 @@
 
 #include "view3d_intern.h"	// own include
 
+
+#ifdef _WIN32
+#include <time.h>
+#include <stdio.h>
+#include <conio.h>
+#include <windows.h>
+
+static LARGE_INTEGER liFrequency;
+static LARGE_INTEGER liStartTime;
+static LARGE_INTEGER liCurrentTime;
+
+static void tstart ( void )
+{
+	QueryPerformanceFrequency ( &liFrequency );
+	QueryPerformanceCounter ( &liStartTime );
+}
+static void tend ( void )
+{
+	QueryPerformanceCounter ( &liCurrentTime );
+}
+static double tval()
+{
+	return ((double)( (liCurrentTime.QuadPart - liStartTime.QuadPart)* (double)1000.0/(double)liFrequency.QuadPart ));
+}
+#else
+#include <sys/time.h>
+static struct timeval _tstart, _tend;
+static struct timezone tz;
+static void tstart ( void )
+{
+	gettimeofday ( &_tstart, &tz );
+}
+static void tend ( void )
+{
+	gettimeofday ( &_tend,&tz );
+}
+static double tval()
+{
+	double t1, t2;
+	t1 = ( double ) _tstart.tv_sec*1000 + ( double ) _tstart.tv_usec/ ( 1000 );
+	t2 = ( double ) _tend.tv_sec*1000 + ( double ) _tend.tv_usec/ ( 1000 );
+	return t2-t1;
+}
+#endif
+
 struct GPUTexture;
 
 int intersect_edges(float *points, float a, float b, float c, float d, float edges[12][2][3])
@@ -227,6 +272,8 @@
 	
 	float size[3];
 
+	tstart();
+
 	VECSUB(size, max, min);
 
 	// maxx, maxy, maxz
@@ -370,7 +417,7 @@
 	// inserting previously found vertex into the plane equation
 	d0 = (viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]);
 	ds = (ABS(viewnormal[0])*size[0] + ABS(viewnormal[1])*size[1] + ABS(viewnormal[2])*size[2]);
-	dd = ds/128.0f;
+	dd = 0.03; // ds/512.0f;
 	n = 0;
 	good_index = i;
 
@@ -386,7 +433,7 @@
 			break;
 
 		VECCOPY(tmp_point, viewnormal);
-		VecMulf(tmp_point, -dd*(128.0f-(float)n));
+		VecMulf(tmp_point, -dd*((ds/dd)-(float)n));
 		VECADD(tmp_point2, cv[good_index], tmp_point);
 		d = INPR(tmp_point2, viewnormal);
 
@@ -406,27 +453,74 @@
 			{
 				for(j = i + 1; j < numpoints; j++)
 				{
-					if(convex(p0, viewnormal, &points[j * 3], &points[i * 3]))
+					if(!convex(p0, viewnormal, &points[j * 3], &points[i * 3]))
 					{
 						float tmp2[3];
-						VECCOPY(tmp2, &points[i * 3]);
-						VECCOPY(&points[i * 3], &points[j * 3]);
-						VECCOPY(&points[j * 3], tmp2);
+						VECCOPY(tmp2, &points[j * 3]);
+						VECCOPY(&points[j * 3], &points[i * 3]);
+						VECCOPY(&points[i * 3], tmp2);
 					}
 				}
 			}
 
-			glBegin(GL_POLYGON);
-			for (i = 0; i < numpoints; i++) {
+			if(numpoints==3)
+			{
+				glBegin(GL_TRIANGLES);
 				glColor3f(1.0, 1.0, 1.0);
+				for (i = 0; i < numpoints; i++) {
+					glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
+					glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
+				}
+				glEnd();
+			}
+			else if(numpoints == 4)
+			{
+				glBegin(GL_QUADS);
+				glColor3f(1.0, 1.0, 1.0);
+				for (i = 0; i < numpoints; i++) {
+					glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
+					glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
+				}
+				glEnd();
+			}
+			else if(numpoints == 5)
+			{
+				glBegin(GL_TRIANGLES);
+				glColor3f(1.0, 1.0, 1.0);
+				for (i = 0; i < 3; i++) {
+					glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
+					glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
+				}
+				glEnd();
+				glBegin(GL_QUADS);
+				glColor3f(1.0, 1.0, 1.0);
+				for (i = 2; i < numpoints; i++) {
+					glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
+					glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
+				}
+				i = 0;
 				glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
-				glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
+					glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
+				glEnd();
 			}
-			glEnd();
+			else
+			{
+				// printf("numpoints: %d\n", numpoints);
+				glBegin(GL_POLYGON);
+				glColor3f(1.0, 1.0, 1.0);
+				for (i = 0; i < numpoints; i++) {
+					glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
+					glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
+				}
+				glEnd();
+			}
 		}
 		n++;
 	}
 
+	tend();
+	printf ( "Draw Time: %f\n",( float ) tval() );
+
 	if(tex_shadow)
 		GPU_texture_unbind(tex_shadow);
 	GPU_texture_unbind(tex);

Modified: trunk/blender/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_extensions.c	2009-10-20 15:51:18 UTC (rev 24006)
+++ trunk/blender/source/blender/gpu/intern/gpu_extensions.c	2009-10-20 15:51:25 UTC (rev 24007)
@@ -382,9 +382,9 @@
 	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	GPU_print_error("3D GL_LINEAR");
-	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
-	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
-	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
+	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
 	GPU_print_error("3D GL_CLAMP_TO_BORDER");
 
 	if (pixels)





More information about the Bf-blender-cvs mailing list