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]); |
340 |
|
const char *s |
341 |
|
) |
342 |
|
{ |
343 |
+ |
if (!erract[WARNING].pf) |
344 |
+ |
return; // warnings were disabled! |
345 |
|
int lasterrno = errno; |
346 |
|
eputs(s); |
347 |
|
errno = lasterrno; |
492 |
|
for (ti[1] = 0; ti[1] < tileGrid[1]; ti[1]++) |
493 |
|
for (ti[0] = 0; ti[0] < tileGrid[0]; ti[0]++) |
494 |
|
cnt += renderable_tile(tile_p(ti)); |
495 |
< |
if (!cnt) { // nothing left to do? |
496 |
< |
error(WARNING, "output appears to be complete, nothing added"); |
487 |
< |
return true; |
488 |
< |
} |
495 |
> |
if (!cnt) |
496 |
> |
return false; // parent can do nothing |
497 |
|
if (cnt < nproc) { |
498 |
|
sprintf(errmsg, "only %d renderable tiles, reducing process count", cnt); |
499 |
|
error(WARNING, errmsg); |
608 |
|
|
609 |
|
const bool newOutput = (access(pout, F_OK) < 0); |
610 |
|
FILE *pdfp[2]; |
611 |
< |
if (!newOutput) { // output exists? |
611 |
> |
if (newOutput) { // new output file? |
612 |
> |
CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1), |
613 |
> |
USER, "bad tiling specification"); |
614 |
> |
} else { |
615 |
|
dt = myRPmanager.ReopenOutput(pdfp, pout, zout); |
616 |
|
if (dt == RDTnone) |
617 |
|
quit(1); |
618 |
|
if (!fscnresolu(&hresolu, &vresolu, pdfp[0])) |
619 |
|
error(USER, "missing picture resolution"); |
620 |
+ |
pixaspect = .0; // need to leave this as is |
621 |
|
myRPmanager.NewHeader(pout); // get prev. header info |
622 |
|
const char * tval = myRPmanager.GetHeadStr("TILED="); |
623 |
|
if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]); |
624 |
< |
if (!myRPmanager.GetView()) { |
625 |
< |
sprintf(errmsg, "missing view in picture file '%s'", pout); |
614 |
< |
error(USER, errmsg); |
615 |
< |
} |
624 |
> |
CHECK(myRPmanager.GetView()==NULL, |
625 |
> |
USER, "missing view in picture file"); |
626 |
|
ourview = *myRPmanager.GetView(); |
627 |
|
} |
628 |
|
int hvdim[2] = {hresolu, vresolu}; // set up tiled frame |
646 |
|
if (dt == RDTnone) |
647 |
|
quit(1); |
648 |
|
fprtresolu(hresolu, vresolu, pdfp[0]); |
649 |
< |
} |
650 |
< |
if (RDTdepthT(dt) == RDTdshort) { |
641 |
< |
if (newOutput) |
649 |
> |
fflush(pdfp[0]); |
650 |
> |
if (RDTdepthT(dt) == RDTdshort) { |
651 |
|
fprtresolu(hresolu, vresolu, pdfp[1]); |
652 |
< |
else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || |
653 |
< |
(hvdim[0] != hresolu) | (hvdim[1] != vresolu)) |
654 |
< |
error(USER, "mismatched depth file resolution"); |
655 |
< |
} |
652 |
> |
fflush(pdfp[1]); |
653 |
> |
} |
654 |
> |
} else if (RDTdepthT(dt) == RDTdshort && |
655 |
> |
(!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || |
656 |
> |
(hvdim[0] != hresolu) | (hvdim[1] != vresolu))) |
657 |
> |
error(USER, "mismatched depth file resolution"); |
658 |
|
// prepare (flat) pixel buffer |
659 |
|
const long pdata_beg = ftell(pdfp[0]); |
660 |
|
const size_t pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR) |
665 |
|
if (pmlen&7) pmlen += 8 - (pmlen&7); // 8-byte alignment to be safe |
666 |
|
pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1]; |
667 |
|
// map picture file to memory |
668 |
< |
if (ftruncate(fileno(pdfp[0]), pmlen) < 0) |
668 |
> |
if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0) |
669 |
|
error(SYSTEM, "cannot extend picture buffer"); |
670 |
|
uby8 * pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE, |
671 |
|
MAP_SHARED, fileno(pdfp[0]), 0); |
678 |
|
const size_t zmlen = zdata_beg + zdpSiz*hresolu*vresolu; |
679 |
|
uby8 * zdMap = NULL; |
680 |
|
if (RDTdepthT(dt)) { |
681 |
< |
if (ftruncate(fileno(pdfp[1]), zmlen) < 0) |
681 |
> |
if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0) |
682 |
|
error(SYSTEM, "cannot extend depth buffer"); |
683 |
|
zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE, |
684 |
|
MAP_SHARED, fileno(pdfp[1]), 0); |
693 |
|
if (children_finished()) // work done in children? |
694 |
|
return dt; |
695 |
|
|
696 |
< |
int ti[2]; // else render tiles |
696 |
> |
int ndone = 0; // else render tiles |
697 |
> |
int ti[2]; |
698 |
|
while (nexttile(ti)) { |
699 |
|
const int offset = (tileGrid[1]-1-ti[1])*myRPmanager.GetWidth()*myRPmanager.THeight() + |
700 |
|
(myRPmanager.THeight()-1)*myRPmanager.GetWidth() + |
726 |
|
error(USER, errmsg); |
727 |
|
} |
728 |
|
tile_p(ti)->status = 1; // mark tile completed |
729 |
+ |
ndone++; |
730 |
|
} |
731 |
+ |
if (!ndone) |
732 |
+ |
error(WARNING, "no tiles need rendering, exit"); |
733 |
|
/* |
734 |
|
munmap(pixMap, pmlen); // technically unnecessary... |
735 |
|
if (zdMap) munmap(zdMap, zmlen); |