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.1 by greg, Mon Sep 16 23:49:13 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 482 | Line 492 | children_finished()
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);
# Line 600 | 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);
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
# Line 636 | 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) {
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)
# Line 654 | 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 667 | 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 682 | Line 693 | rpiece(char *pout, RenderDataType dt, char *zout)
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() +
# 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");
733          /*
734          munmap(pixMap, pmlen);                  // technically unnecessary...
735          if (zdMap) munmap(zdMap, zmlen);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines