Skip to content
Snippets Groups Projects
Commit e68221c1 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

Update gl2ps with new occlusion culling improvements from Shahzad.
parent 3a9fe4fe
Branches
Tags
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* GL2PS, an OpenGL to PostScript Printing Library * GL2PS, an OpenGL to PostScript Printing Library
* Copyright (C) 1999-2003 Christophe Geuzaine * Copyright (C) 1999-2003 Christophe Geuzaine
* *
* $Id: gl2ps.cpp,v 1.66 2003-06-12 17:39:33 geuzaine Exp $ * $Id: gl2ps.cpp,v 1.67 2003-07-03 18:59:52 geuzaine Exp $
* *
* E-mail: geuz@geuz.org * E-mail: geuz@geuz.org
* URL: http://www.geuz.org/gl2ps/ * URL: http://www.geuz.org/gl2ps/
...@@ -645,7 +645,7 @@ void gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives){ ...@@ -645,7 +645,7 @@ void gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives){
void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon, void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon,
GLboolean (*compare)(GLfloat f1, GLfloat f2), GLboolean (*compare)(GLfloat f1, GLfloat f2),
void (*action)(void *data, void *dummy)){ void (*action)(void *data, void *dummy), int inverse){
GLfloat result; GLfloat result;
if(!tree) return; if(!tree) return;
...@@ -653,18 +653,28 @@ void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon, ...@@ -653,18 +653,28 @@ void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon,
result = gl2psComparePointPlane(eye, tree->plane); result = gl2psComparePointPlane(eye, tree->plane);
if(compare(result, epsilon)){ if(compare(result, epsilon)){
gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action); gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action, inverse);
gl2psListAction(tree->primitives, action); if(inverse){
gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action); gl2psListActionInverse(tree->primitives, action);
}
else{
gl2psListAction(tree->primitives, action);
}
gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action, inverse);
} }
else if(compare(-epsilon, result)){ else if(compare(-epsilon, result)){
gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action); gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action, inverse);
gl2psListAction(tree->primitives, action); if(inverse){
gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action); gl2psListActionInverse(tree->primitives, action);
}
else{
gl2psListAction(tree->primitives, action);
}
gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action, inverse);
} }
else{ else{
gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action); gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action, inverse);
gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action); gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action, inverse);
} }
} }
...@@ -943,7 +953,9 @@ GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree){ ...@@ -943,7 +953,9 @@ GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree){
} }
if(*tree == NULL){ if(*tree == NULL){
gl2psAddPlanesInBspTreeImage(prim, tree); if(!gl2ps->zerosurfacearea){
gl2psAddPlanesInBspTreeImage(gl2ps->primitivetoadd, tree);
}
return 1; return 1;
} }
else{ else{
...@@ -966,8 +978,19 @@ GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree){ ...@@ -966,8 +978,19 @@ GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree){
gl2psFree(backprim); gl2psFree(backprim);
return ret; return ret;
case GL2PS_COINCIDENT: case GL2PS_COINCIDENT:
if(prim->numverts < 3) return 1; if((*tree)->back != NULL){
else return 0; gl2ps->zerosurfacearea = 1;
ret = gl2psAddInBspImageTree(prim, &(*tree)->back);
gl2ps->zerosurfacearea = 0;
if(ret) return ret;
}
if((*tree)->front != NULL){
gl2ps->zerosurfacearea = 1;
ret = gl2psAddInBspImageTree(prim, &(*tree)->front);
gl2ps->zerosurfacearea = 0;
if(ret) return ret;
}
return 0;
} }
} }
return 0; return 0;
...@@ -975,7 +998,7 @@ GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree){ ...@@ -975,7 +998,7 @@ GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree){
void gl2psAddInImageTree(void *a, void *b){ void gl2psAddInImageTree(void *a, void *b){
GL2PSprimitive *prim = *(GL2PSprimitive **)a; GL2PSprimitive *prim = *(GL2PSprimitive **)a;
gl2ps->primitivetoadd = prim;
if(!gl2psAddInBspImageTree(prim, &gl2ps->imagetree)){ if(!gl2psAddInBspImageTree(prim, &gl2ps->imagetree)){
prim->culled = 1; prim->culled = 1;
} }
...@@ -1937,11 +1960,11 @@ GLint gl2psPrintPrimitives(void){ ...@@ -1937,11 +1960,11 @@ GLint gl2psPrintPrimitives(void){
if(gl2ps->boundary) gl2psBuildPolygonBoundary(root); if(gl2ps->boundary) gl2psBuildPolygonBoundary(root);
if(gl2ps->options & GL2PS_OCCLUSION_CULL){ if(gl2ps->options & GL2PS_OCCLUSION_CULL){
gl2psTraverseBspTree(root, eye, -(float)GL2PS_EPSILON, gl2psLess, gl2psTraverseBspTree(root, eye, -(float)GL2PS_EPSILON, gl2psLess,
gl2psAddInImageTree); gl2psAddInImageTree, 1);
gl2psFreeBspImageTree(&gl2ps->imagetree); gl2psFreeBspImageTree(&gl2ps->imagetree);
} }
gl2psTraverseBspTree(root, eye, (float)GL2PS_EPSILON, gl2psGreater, gl2psTraverseBspTree(root, eye, (float)GL2PS_EPSILON, gl2psGreater,
pprim); pprim, 0);
gl2psFreeBspTree(&root); gl2psFreeBspTree(&root);
/* reallocate the primitive list (it's been deleted by /* reallocate the primitive list (it's been deleted by
gl2psBuildBspTree) in case there is another viewport */ gl2psBuildBspTree) in case there is another viewport */
...@@ -1975,8 +1998,14 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, ...@@ -1975,8 +1998,14 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer,
gl2ps->filename = filename; gl2ps->filename = filename;
gl2ps->sort = sort; gl2ps->sort = sort;
gl2ps->options = options; gl2ps->options = options;
for(i = 0; i < 4; i++){
gl2ps->viewport[i] = viewport[i]; if(gl2ps->options & GL2PS_USE_CURRENT_VIEWPORT){
glGetIntegerv(GL_VIEWPORT, viewport);
}
else{
for(i = 0; i < 4; i++){
gl2ps->viewport[i] = viewport[i];
}
} }
gl2ps->threshold[0] = nr ? 1./(GLfloat)nr : 0.032; gl2ps->threshold[0] = nr ? 1./(GLfloat)nr : 0.032;
gl2ps->threshold[1] = ng ? 1./(GLfloat)ng : 0.017; gl2ps->threshold[1] = ng ? 1./(GLfloat)ng : 0.017;
...@@ -1988,6 +2017,8 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, ...@@ -1988,6 +2017,8 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer,
} }
gl2ps->lastlinewidth = -1.; gl2ps->lastlinewidth = -1.;
gl2ps->imagetree = NULL; gl2ps->imagetree = NULL;
gl2ps->primitivetoadd = NULL;
gl2ps->zerosurfacearea = 0;
if(gl2ps->colormode == GL_RGBA){ if(gl2ps->colormode == GL_RGBA){
gl2ps->colorsize = 0; gl2ps->colorsize = 0;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* GL2PS, an OpenGL to PostScript Printing Library * GL2PS, an OpenGL to PostScript Printing Library
* Copyright (C) 1999-2003 Christophe Geuzaine * Copyright (C) 1999-2003 Christophe Geuzaine
* *
* $Id: gl2ps.h,v 1.40 2003-06-12 17:39:33 geuzaine Exp $ * $Id: gl2ps.h,v 1.41 2003-07-03 18:59:52 geuzaine Exp $
* *
* E-mail: geuz@geuz.org * E-mail: geuz@geuz.org
* URL: http://www.geuz.org/gl2ps/ * URL: http://www.geuz.org/gl2ps/
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
#define GL2PS_MAJOR_VERSION 0 #define GL2PS_MAJOR_VERSION 0
#define GL2PS_MINOR_VERSION 9 #define GL2PS_MINOR_VERSION 9
#define GL2PS_PATCH_VERSION 1 #define GL2PS_PATCH_VERSION 2
#define GL2PS_VERSION (GL2PS_MAJOR_VERSION + \ #define GL2PS_VERSION (GL2PS_MAJOR_VERSION + \
0.01 * GL2PS_MINOR_VERSION + \ 0.01 * GL2PS_MINOR_VERSION + \
...@@ -77,16 +77,17 @@ ...@@ -77,16 +77,17 @@
/* Options for gl2psBeginPage */ /* Options for gl2psBeginPage */
#define GL2PS_NONE 0 #define GL2PS_NONE 0
#define GL2PS_DRAW_BACKGROUND (1<<0) #define GL2PS_DRAW_BACKGROUND (1<<0)
#define GL2PS_SIMPLE_LINE_OFFSET (1<<1) #define GL2PS_SIMPLE_LINE_OFFSET (1<<1)
#define GL2PS_SILENT (1<<2) #define GL2PS_SILENT (1<<2)
#define GL2PS_BEST_ROOT (1<<3) #define GL2PS_BEST_ROOT (1<<3)
#define GL2PS_OCCLUSION_CULL (1<<4) #define GL2PS_OCCLUSION_CULL (1<<4)
#define GL2PS_NO_TEXT (1<<5) #define GL2PS_NO_TEXT (1<<5)
#define GL2PS_LANDSCAPE (1<<6) #define GL2PS_LANDSCAPE (1<<6)
#define GL2PS_NO_PS3_SHADING (1<<7) #define GL2PS_NO_PS3_SHADING (1<<7)
#define GL2PS_NO_PIXMAP (1<<8) #define GL2PS_NO_PIXMAP (1<<8)
#define GL2PS_USE_CURRENT_VIEWPORT (1<<9)
/* Arguments for gl2psEnable/gl2psDisable */ /* Arguments for gl2psEnable/gl2psDisable */
...@@ -197,7 +198,7 @@ typedef struct { ...@@ -197,7 +198,7 @@ typedef struct {
typedef struct { typedef struct {
GLint format, sort, options, colorsize, colormode, buffersize, maxbestroot; GLint format, sort, options, colorsize, colormode, buffersize, maxbestroot;
const char *title, *producer, *filename; const char *title, *producer, *filename;
GLboolean boundary; GLboolean boundary, zerosurfacearea;
GLfloat *feedback, offset[2]; GLfloat *feedback, offset[2];
GLint viewport[4]; GLint viewport[4];
GL2PSrgba *colormap, lastrgba, threshold; GL2PSrgba *colormap, lastrgba, threshold;
...@@ -205,6 +206,7 @@ typedef struct { ...@@ -205,6 +206,7 @@ typedef struct {
GL2PSlist *primitives; GL2PSlist *primitives;
GL2PSbsptree2d *imagetree; GL2PSbsptree2d *imagetree;
FILE *stream; FILE *stream;
GL2PSprimitive *primitivetoadd;
} GL2PScontext; } GL2PScontext;
/* public functions */ /* public functions */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment