14 |
|
|
15 |
|
#include "platform.h" |
16 |
|
#include "RpictSimulManager.h" |
17 |
+ |
#include "ambient.h" |
18 |
+ |
#include "pmapray.h" |
19 |
|
#include "random.h" |
20 |
|
|
21 |
|
extern char *progname; /* argv[0] */ |
57 |
|
"OutputCS=RGB,XYZ,prims,spec\n" |
58 |
|
|
59 |
|
|
60 |
+ |
// We could call myRPmanager.Cleanup() but why waste time |
61 |
+ |
// unwinding data structures when the whole frame is going away? |
62 |
|
void |
63 |
|
quit(int code) /* quit program */ |
64 |
|
{ |
65 |
+ |
ambsync(); // flush ambient cache |
66 |
+ |
|
67 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
68 |
+ |
|
69 |
|
exit(code); |
70 |
|
} |
71 |
|
|
323 |
|
// render tiles |
324 |
|
dtype = rpiece(outfile, dtype, zfile); |
325 |
|
|
326 |
< |
quit(dtype==RDTnone); // clean up and exit |
326 |
> |
quit(dtype==RDTnone); // status is 1 on failure |
327 |
|
|
328 |
|
badopt: |
329 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
606 |
|
|
607 |
|
const bool newOutput = (access(pout, F_OK) < 0); |
608 |
|
FILE *pdfp[2]; |
609 |
< |
if (!newOutput) { // output exists? |
609 |
> |
if (newOutput) { // new output file? |
610 |
> |
CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1), |
611 |
> |
USER, "bad tiling specification"); |
612 |
> |
} else { |
613 |
|
dt = myRPmanager.ReopenOutput(pdfp, pout, zout); |
614 |
|
if (dt == RDTnone) |
615 |
|
quit(1); |
619 |
|
myRPmanager.NewHeader(pout); // get prev. header info |
620 |
|
const char * tval = myRPmanager.GetHeadStr("TILED="); |
621 |
|
if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]); |
622 |
< |
if (!myRPmanager.GetView()) { |
623 |
< |
sprintf(errmsg, "missing view in picture file '%s'", pout); |
613 |
< |
error(USER, errmsg); |
614 |
< |
} |
622 |
> |
CHECK(myRPmanager.GetView()==NULL, |
623 |
> |
USER, "missing view in picture file"); |
624 |
|
ourview = *myRPmanager.GetView(); |
625 |
|
} |
626 |
|
int hvdim[2] = {hresolu, vresolu}; // set up tiled frame |
644 |
|
if (dt == RDTnone) |
645 |
|
quit(1); |
646 |
|
fprtresolu(hresolu, vresolu, pdfp[0]); |
647 |
< |
} |
648 |
< |
if (RDTdepthT(dt) == RDTdshort) { |
640 |
< |
if (newOutput) |
647 |
> |
fflush(pdfp[0]); |
648 |
> |
if (RDTdepthT(dt) == RDTdshort) { |
649 |
|
fprtresolu(hresolu, vresolu, pdfp[1]); |
650 |
< |
else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || |
651 |
< |
(hvdim[0] != hresolu) | (hvdim[1] != vresolu)) |
652 |
< |
error(USER, "mismatched depth file resolution"); |
653 |
< |
} |
650 |
> |
fflush(pdfp[1]); |
651 |
> |
} |
652 |
> |
} else if (RDTdepthT(dt) == RDTdshort && |
653 |
> |
(!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || |
654 |
> |
(hvdim[0] != hresolu) | (hvdim[1] != vresolu))) |
655 |
> |
error(USER, "mismatched depth file resolution"); |
656 |
|
// prepare (flat) pixel buffer |
657 |
|
const long pdata_beg = ftell(pdfp[0]); |
658 |
|
const size_t pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR) |
663 |
|
if (pmlen&7) pmlen += 8 - (pmlen&7); // 8-byte alignment to be safe |
664 |
|
pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1]; |
665 |
|
// map picture file to memory |
666 |
< |
if (ftruncate(fileno(pdfp[0]), pmlen) < 0) |
666 |
> |
if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0) |
667 |
|
error(SYSTEM, "cannot extend picture buffer"); |
668 |
|
uby8 * pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE, |
669 |
|
MAP_SHARED, fileno(pdfp[0]), 0); |
676 |
|
const size_t zmlen = zdata_beg + zdpSiz*hresolu*vresolu; |
677 |
|
uby8 * zdMap = NULL; |
678 |
|
if (RDTdepthT(dt)) { |
679 |
< |
if (ftruncate(fileno(pdfp[1]), zmlen) < 0) |
679 |
> |
if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0) |
680 |
|
error(SYSTEM, "cannot extend depth buffer"); |
681 |
|
zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE, |
682 |
|
MAP_SHARED, fileno(pdfp[1]), 0); |
724 |
|
error(USER, errmsg); |
725 |
|
} |
726 |
|
tile_p(ti)->status = 1; // mark tile completed |
727 |
+ |
ndone++; |
728 |
|
} |
729 |
|
if (!ndone) |
730 |
|
error(WARNING, "no tiles need rendering, exit"); |