ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rxpiece.cpp
(Generate patch)

Comparing ray/src/rt/rxpiece.cpp (file contents):
Revision 2.2 by greg, Tue Sep 17 00:05:11 2024 UTC vs.
Revision 2.6 by greg, Thu Oct 31 19:22:36 2024 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
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] */
# Line 55 | Line 57 | static RenderDataType rpiece(char *pout, RenderDataTyp
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  
# Line 315 | Line 323 | main(int  argc, char  *argv[])
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]);
# Line 332 | Line 340 | wputs(                         /* warning output function */
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;
# Line 598 | Line 608 | rpiece(char *pout, RenderDataType dt, char *zout)
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);
# Line 608 | Line 621 | rpiece(char *pout, RenderDataType dt, char *zout)
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);
613 <                        error(USER, errmsg);
614 <                }
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
# Line 635 | Line 646 | rpiece(char *pout, RenderDataType dt, char *zout)
646                  if (dt == RDTnone)
647                          quit(1);
648                  fprtresolu(hresolu, vresolu, pdfp[0]);
649 <        }
650 <        if (RDTdepthT(dt) == RDTdshort) {
640 <                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)
# Line 653 | Line 665 | rpiece(char *pout, RenderDataType dt, char *zout)
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);
# Line 666 | Line 678 | rpiece(char *pout, RenderDataType dt, char *zout)
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);
# Line 714 | Line 726 | rpiece(char *pout, RenderDataType dt, char *zout)
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");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines