forked from bartvdbraak/blender
Smoke:
* Use GL_QUADS and GL_TRIANGLES instead of GL_POLYGON for faster drawing * Use variable count of slices
This commit is contained in:
parent
0e5a6a21e8
commit
b2d771a438
@ -119,6 +119,51 @@
|
|||||||
|
|
||||||
#include "view3d_intern.h" // own include
|
#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;
|
struct GPUTexture;
|
||||||
|
|
||||||
int intersect_edges(float *points, float a, float b, float c, float d, float edges[12][2][3])
|
int intersect_edges(float *points, float a, float b, float c, float d, float edges[12][2][3])
|
||||||
@ -227,6 +272,8 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
|
|||||||
|
|
||||||
float size[3];
|
float size[3];
|
||||||
|
|
||||||
|
tstart();
|
||||||
|
|
||||||
VECSUB(size, max, min);
|
VECSUB(size, max, min);
|
||||||
|
|
||||||
// maxx, maxy, maxz
|
// maxx, maxy, maxz
|
||||||
@ -370,7 +417,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
|
|||||||
// inserting previously found vertex into the plane equation
|
// inserting previously found vertex into the plane equation
|
||||||
d0 = (viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]);
|
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]);
|
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;
|
n = 0;
|
||||||
good_index = i;
|
good_index = i;
|
||||||
|
|
||||||
@ -386,7 +433,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
VECCOPY(tmp_point, viewnormal);
|
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);
|
VECADD(tmp_point2, cv[good_index], tmp_point);
|
||||||
d = INPR(tmp_point2, viewnormal);
|
d = INPR(tmp_point2, viewnormal);
|
||||||
|
|
||||||
@ -406,27 +453,74 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
|
|||||||
{
|
{
|
||||||
for(j = i + 1; j < numpoints; j++)
|
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];
|
float tmp2[3];
|
||||||
VECCOPY(tmp2, &points[i * 3]);
|
VECCOPY(tmp2, &points[j * 3]);
|
||||||
VECCOPY(&points[i * 3], &points[j * 3]);
|
VECCOPY(&points[j * 3], &points[i * 3]);
|
||||||
VECCOPY(&points[j * 3], tmp2);
|
VECCOPY(&points[i * 3], tmp2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glBegin(GL_POLYGON);
|
if(numpoints==3)
|
||||||
for (i = 0; i < numpoints; i++) {
|
{
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glColor3f(1.0, 1.0, 1.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]);
|
for (i = 0; i < numpoints; i++) {
|
||||||
glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
|
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]);
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tend();
|
||||||
|
printf ( "Draw Time: %f\n",( float ) tval() );
|
||||||
|
|
||||||
if(tex_shadow)
|
if(tex_shadow)
|
||||||
GPU_texture_unbind(tex_shadow);
|
GPU_texture_unbind(tex_shadow);
|
||||||
GPU_texture_unbind(tex);
|
GPU_texture_unbind(tex);
|
||||||
|
@ -382,9 +382,9 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
|
|||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
GPU_print_error("3D 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_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||||
GPU_print_error("3D GL_CLAMP_TO_BORDER");
|
GPU_print_error("3D GL_CLAMP_TO_BORDER");
|
||||||
|
|
||||||
if (pixels)
|
if (pixels)
|
||||||
|
Loading…
Reference in New Issue
Block a user