14 |
|
|
15 |
|
#include "platform.h" |
16 |
|
#include "RpictSimulManager.h" |
17 |
+ |
#include "func.h" |
18 |
+ |
#include "ambient.h" |
19 |
+ |
#include "pmapray.h" |
20 |
|
#include "random.h" |
21 |
|
|
19 |
– |
extern char *progname; /* argv[0] */ |
22 |
|
const char *sigerr[NSIG]; /* signal error messages */ |
23 |
|
|
24 |
|
VIEW ourview = STDVIEW; /* global view parameters */ |
37 |
|
|
38 |
|
double dblur = 0.; /* depth-of-field blur parameter */ |
39 |
|
|
40 |
< |
int nproc = 1; /* number of processes to run */ |
40 |
> |
int nproc = 1; /* number of processes to run (-1 in child) */ |
41 |
|
|
42 |
|
RpictSimulManager myRPmanager; // global simulation manager |
43 |
|
|
56 |
|
"AdaptiveShadowTesting\nOutputs=v,l\n" \ |
57 |
|
"OutputCS=RGB,XYZ,prims,spec\n" |
58 |
|
|
59 |
< |
|
59 |
> |
// Exit program |
60 |
|
void |
61 |
|
quit(int code) /* quit program */ |
62 |
|
{ |
63 |
< |
exit(code); |
63 |
> |
exit(code); // don't bother to free data structs |
64 |
|
} |
65 |
|
|
66 |
+ |
/* Set default options */ |
67 |
+ |
static void |
68 |
+ |
default_options(void) |
69 |
+ |
{ |
70 |
+ |
shadthresh = .05; |
71 |
+ |
shadcert = .5; |
72 |
+ |
srcsizerat = .25; |
73 |
+ |
directrelay = 1; |
74 |
+ |
ambacc = 0.2; |
75 |
+ |
ambres = 64; |
76 |
+ |
ambdiv = 512; |
77 |
+ |
ambssamp = 128; |
78 |
+ |
maxdepth = 7; |
79 |
+ |
} |
80 |
|
|
81 |
|
int |
82 |
|
main(int argc, char *argv[]) |
98 |
|
int outfmt = 'c'; |
99 |
|
int rval; |
100 |
|
int i; |
101 |
< |
/* global program name */ |
102 |
< |
progname = argv[0]; |
101 |
> |
/* set global program name */ |
102 |
> |
fixargv0(argv[0]); |
103 |
|
/* feature check only? */ |
104 |
|
strcat(RFeatureList, RXPIECE_FEATURES); |
105 |
|
if (argc > 1 && !strcmp(argv[1], "-features")) |
106 |
|
return feature_status(argc-2, argv+2); |
107 |
+ |
/* initialize calcomp routines */ |
108 |
+ |
initfunc(); |
109 |
+ |
/* set defaults */ |
110 |
+ |
default_options(); |
111 |
|
/* option city */ |
112 |
|
for (i = 1; i < argc; i++) { |
113 |
|
/* expand arguments */ |
335 |
|
// render tiles |
336 |
|
dtype = rpiece(outfile, dtype, zfile); |
337 |
|
|
338 |
< |
quit(dtype==RDTnone); // clean up and exit |
338 |
> |
ambsync(); // flush ambient cache |
339 |
|
|
340 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
341 |
+ |
|
342 |
+ |
quit(dtype==RDTnone); // status is 1 on failure |
343 |
+ |
|
344 |
|
badopt: |
345 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
346 |
|
error(USER, errmsg); |
356 |
|
const char *s |
357 |
|
) |
358 |
|
{ |
359 |
+ |
if (!erract[WARNING].pf) |
360 |
+ |
return; // warnings were disabled! |
361 |
|
int lasterrno = errno; |
362 |
|
eputs(s); |
363 |
|
errno = lasterrno; |
525 |
|
|
526 |
|
if (cpid == 0) { // children render tiles |
527 |
|
sleep(nproc - cnt); // avoid race conditions |
528 |
+ |
nproc = -1; // flag as child |
529 |
|
return false; |
530 |
|
} |
531 |
|
cow_doneshare(); // parent frees memory and waits |
625 |
|
|
626 |
|
const bool newOutput = (access(pout, F_OK) < 0); |
627 |
|
FILE *pdfp[2]; |
628 |
< |
if (!newOutput) { // output exists? |
628 |
> |
if (newOutput) { // new output file? |
629 |
> |
CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1), |
630 |
> |
USER, "bad tiling specification"); |
631 |
> |
} else { |
632 |
|
dt = myRPmanager.ReopenOutput(pdfp, pout, zout); |
633 |
|
if (dt == RDTnone) |
634 |
< |
quit(1); |
634 |
> |
return RDTnone; |
635 |
|
if (!fscnresolu(&hresolu, &vresolu, pdfp[0])) |
636 |
|
error(USER, "missing picture resolution"); |
637 |
|
pixaspect = .0; // need to leave this as is |
638 |
|
myRPmanager.NewHeader(pout); // get prev. header info |
639 |
|
const char * tval = myRPmanager.GetHeadStr("TILED="); |
640 |
< |
if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]); |
641 |
< |
if (!myRPmanager.GetView()) { |
642 |
< |
sprintf(errmsg, "missing view in picture file '%s'", pout); |
643 |
< |
error(USER, errmsg); |
614 |
< |
} |
640 |
> |
if (!tval || sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]) != 2) |
641 |
> |
error(USER, "existing picture must be tiled"); |
642 |
> |
CHECK(myRPmanager.GetView()==NULL, |
643 |
> |
USER, "missing view in picture file"); |
644 |
|
ourview = *myRPmanager.GetView(); |
645 |
|
} |
646 |
|
int hvdim[2] = {hresolu, vresolu}; // set up tiled frame |
662 |
|
myRPmanager.AddHeader(buf); |
663 |
|
dt = myRPmanager.NewOutput(pdfp, pout, dt, zout); |
664 |
|
if (dt == RDTnone) |
665 |
< |
quit(1); |
665 |
> |
return RDTnone; |
666 |
|
fprtresolu(hresolu, vresolu, pdfp[0]); |
667 |
< |
} |
668 |
< |
if (RDTdepthT(dt) == RDTdshort) { |
640 |
< |
if (newOutput) |
667 |
> |
fflush(pdfp[0]); |
668 |
> |
if (RDTdepthT(dt) == RDTdshort) { |
669 |
|
fprtresolu(hresolu, vresolu, pdfp[1]); |
670 |
< |
else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || |
671 |
< |
(hvdim[0] != hresolu) | (hvdim[1] != vresolu)) |
672 |
< |
error(USER, "mismatched depth file resolution"); |
673 |
< |
} |
670 |
> |
fflush(pdfp[1]); |
671 |
> |
} |
672 |
> |
} else if (RDTdepthT(dt) == RDTdshort && |
673 |
> |
(!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || |
674 |
> |
(hvdim[0] != hresolu) | (hvdim[1] != vresolu))) |
675 |
> |
error(USER, "mismatched depth file resolution"); |
676 |
|
// prepare (flat) pixel buffer |
677 |
|
const long pdata_beg = ftell(pdfp[0]); |
678 |
|
const size_t pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR) |
683 |
|
if (pmlen&7) pmlen += 8 - (pmlen&7); // 8-byte alignment to be safe |
684 |
|
pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1]; |
685 |
|
// map picture file to memory |
686 |
< |
if (ftruncate(fileno(pdfp[0]), pmlen) < 0) |
686 |
> |
if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0) |
687 |
|
error(SYSTEM, "cannot extend picture buffer"); |
688 |
|
uby8 * pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE, |
689 |
|
MAP_SHARED, fileno(pdfp[0]), 0); |
696 |
|
const size_t zmlen = zdata_beg + zdpSiz*hresolu*vresolu; |
697 |
|
uby8 * zdMap = NULL; |
698 |
|
if (RDTdepthT(dt)) { |
699 |
< |
if (ftruncate(fileno(pdfp[1]), zmlen) < 0) |
699 |
> |
if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0) |
700 |
|
error(SYSTEM, "cannot extend depth buffer"); |
701 |
|
zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE, |
702 |
|
MAP_SHARED, fileno(pdfp[1]), 0); |
744 |
|
error(USER, errmsg); |
745 |
|
} |
746 |
|
tile_p(ti)->status = 1; // mark tile completed |
747 |
+ |
ndone++; |
748 |
|
} |
749 |
|
if (!ndone) |
750 |
< |
error(WARNING, "no tiles need rendering, exit"); |
750 |
> |
error(WARNING, "no tiles to render, exiting"); |
751 |
|
/* |
752 |
|
munmap(pixMap, pmlen); // technically unnecessary... |
753 |
|
if (zdMap) munmap(zdMap, zmlen); |