Revision: 45751
          http://brlcad.svn.sourceforge.net/brlcad/?rev=45751&view=rev
Author:   kunigami
Date:     2011-08-02 01:50:12 +0000 (Tue, 02 Aug 2011)

Log Message:
-----------
added simple support for the multi-sample framebuffer. I'm currently using the 
scanline array to hold the partial averages, but this is not good since it is a 
char array and many values will be truncated when I compute the next average. I 
think we must use a dedicated buffer to hold these averages. To test this mode, 
compile with -DEXPERIMENTAL_MODE

Modified Paths:
--------------
    brlcad/trunk/src/rt/do.c
    brlcad/trunk/src/rt/ext.h
    brlcad/trunk/src/rt/opt.c
    brlcad/trunk/src/rt/view.c

Modified: brlcad/trunk/src/rt/do.c
===================================================================
--- brlcad/trunk/src/rt/do.c    2011-08-01 22:14:07 UTC (rev 45750)
+++ brlcad/trunk/src/rt/do.c    2011-08-02 01:50:12 UTC (rev 45751)
@@ -587,6 +587,13 @@
     vect_t work, temp;
     quat_t quat;
 
+    /* TODO: Read from command line */
+#ifdef EXPERIMENTAL_MODE
+    full_incr_mode = 1;
+    full_incr_nsamples = 10;
+#endif
+
+
     if (rt_verbosity & VERBOSE_FRAMENUMBER)
        bu_log("\n...................Frame %5d...................\n",
               framenumber);
@@ -825,17 +832,16 @@
            do_run(0, (1<<incr_level)*(1<<incr_level)-1);
        }
     } 
-#ifdef EXPERIMENTAL_MODE
-    else if (1){
-       int i;
+    else if (full_incr_mode){
        /* Multiple frame buffer mode */
-       for(i = 0; i < 10; i++){
-           if(i > 0)
+       for(full_incr_sample = 1; full_incr_sample <= full_incr_nsamples; 
+           full_incr_sample++){
+           fprintf(stderr, "sample: %d\n", full_incr_sample);
+           if(full_incr_sample > 1) /* first sample was already initialized */
                view_2init(&APP, framename);
            do_run(pix_start, pix_end);
        }
     }
-#endif
     else {
        do_run(pix_start, pix_end);
 

Modified: brlcad/trunk/src/rt/ext.h
===================================================================
--- brlcad/trunk/src/rt/ext.h   2011-08-01 22:14:07 UTC (rev 45750)
+++ brlcad/trunk/src/rt/ext.h   2011-08-02 01:50:12 UTC (rev 45751)
@@ -72,6 +72,7 @@
 extern int fullfloat_mode;
 extern int hypersample;                        /* number of extra rays to fire 
*/
 extern int incr_mode;                  /* !0 for incremental resolution */
+extern int full_incr_mode;              /* !0 for fully incremental resolution 
*/
 extern int npsw;                       /* number of worker PSWs to run */
 extern int reproj_cur;                 /* number of pixels reprojected this 
frame */
 extern int reproj_max;                 /* out of total number of pixels */
@@ -83,6 +84,8 @@
 extern size_t height;                  /* # of lines in Y */
 extern size_t incr_level;              /* current incremental level */
 extern size_t incr_nlevel;             /* number of levels */
+extern size_t full_incr_sample;         /* current fully incremental sample */
+extern size_t full_incr_nsamples;       /* number of fully incremental samples 
*/
 extern size_t width;                   /* # of pixels in X */
 extern struct floatpixel *curr_float_frame;    /* buffer of full frame */
 extern struct floatpixel *prev_float_frame;

Modified: brlcad/trunk/src/rt/opt.c
===================================================================
--- brlcad/trunk/src/rt/opt.c   2011-08-01 22:14:07 UTC (rev 45750)
+++ brlcad/trunk/src/rt/opt.c   2011-08-02 01:50:12 UTC (rev 45751)
@@ -87,8 +87,11 @@
                                 (fastf_t)0.0, (fastf_t)0.0, (fastf_t)0.0, 
(fastf_t)0.0};
 fastf_t                viewsize = (fastf_t)0.0;
 int            incr_mode = 0;          /* !0 for incremental resolution */
+int             full_incr_mode = 0;     /* !0 for fully incremental resolution 
*/
 size_t         incr_level = 0;         /* current incremental level */
 size_t         incr_nlevel = 0;        /* number of levels */
+size_t          full_incr_sample = 0;    /* current fully incremental sample */
+size_t          full_incr_nsamples = 0;  /* number of samples in the fully 
incremental mode */
 int            npsw = 1;               /* number of worker PSWs to run */
 struct resource        resource[MAX_PSW];      /* memory resources */
 int            transpose_grid = 0;     /* reverse the order of grid traversal 
*/

Modified: brlcad/trunk/src/rt/view.c
===================================================================
--- brlcad/trunk/src/rt/view.c  2011-08-01 22:14:07 UTC (rev 45750)
+++ brlcad/trunk/src/rt/view.c  2011-08-02 01:50:12 UTC (rev 45751)
@@ -123,6 +123,9 @@
 #define BUFMODE_RTSRV     4    /* output buffering into scanbuf */
 #define BUFMODE_FULLFLOAT 5    /* buffer entire frame as floats */
 #define BUFMODE_SCANLINE  6    /* Like _DYNAMIC, one scanline/cpu */
+#define BUFMODE_ACC       7     /* Cumulative buffer - The buffer
+                                  always have the average of the
+                                  colors sampled for each pixel */
 
 static struct scanline* scanline;
 
@@ -442,8 +445,55 @@
            }
            break;
 
-       default:
-           bu_exit(EXIT_FAILURE, "bad buf_mode");
+    case BUFMODE_ACC:
+    {
+       fastf_t tmp_value;
+       RGBpixel p;
+       int npix;
+
+       /* Unbuffered mode -- update the framebuffer at each pixel */
+       
+       /* Altough it's unbuffered, we need to keep the scanline
+        * structure to hold partial sums - 
+        TODO: there will be a lost of precision since we are storing averages 
in a char buffer */
+       bu_semaphore_acquire(RT_SEM_RESULTS);
+       slp = &scanline[ap->a_y];
+       if (slp->sl_buf == (unsigned char *)0) {
+           bu_log("Fatal error: this should not happen\n");
+       }
+       pixelp = slp->sl_buf+(ap->a_x*pwidth);
+
+       /* First run. Average equals the values */
+       if(full_incr_sample == 1){
+           *pixelp++ = p[0] = r;
+           *pixelp++ = p[1] = g;
+           *pixelp++ = p[2] = b;
+       }
+       /* Update the averages */
+       else { /* full_incr_sample > 1 */
+
+           /* TODO: move r,g,b and rpt_dist into a tmp array to
+              perform the following operations inside a loop? (clear
+              code, but little less efficient) */
+           /*fprintf(stderr, "prev_pixel: %d\n", *pixelp); */
+           tmp_value = *pixelp;
+           *pixelp++ = p[0] = (tmp_value * (full_incr_sample-1) + r) / 
full_incr_sample;
+
+           tmp_value = *pixelp;
+           *pixelp++ = p[1] = (tmp_value * (full_incr_sample-1) + g) / 
full_incr_sample;
+
+           tmp_value = *pixelp;
+           *pixelp++ = p[2] = (tmp_value * (full_incr_sample-1) + b) / 
full_incr_sample;
+       }
+       bu_semaphore_release(RT_SEM_RESULTS);
+       /* TODO: add rpt_dist */
+       if (--(slp->sl_left) <= 0)
+           do_eol = 1;
+    }              
+    break;
+    
+    default:
+       bu_exit(EXIT_FAILURE, "bad buf_mode: %d", buf_mode);
     }
 
 
@@ -482,6 +532,7 @@
            }
            break;
 
+        case BUFMODE_ACC:
        case BUFMODE_SCANLINE:
        case BUFMODE_DYNAMIC:
            if (fbp != FBIO_NULL) {
@@ -520,8 +571,12 @@
                if (count != width*pwidth)
                    bu_exit(EXIT_FAILURE, "view_pixel:  fwrite failure\n");
            }
-           bu_free(scanline[ap->a_y].sl_buf, "sl_buf scanline buffer");
-           scanline[ap->a_y].sl_buf = (unsigned char *)0;
+           /* Dont clear the buffer in the ACC BUFFER MODE */
+           if(buf_mode != BUFMODE_ACC){ 
+               bu_log("oops--------------------\n");
+               bu_free(scanline[ap->a_y].sl_buf, "sl_buf scanline buffer");
+               scanline[ap->a_y].sl_buf = (unsigned char *)0;
+           }
     }
 }
 
@@ -1428,11 +1483,23 @@
     /* Always allocate the scanline[] array (unless we already have
      * one in incremental mode)
      */
-    if ((!incr_mode || !scanline) && !fullfloat_mode) {
+    if ((!incr_mode || !scanline) && !fullfloat_mode && !full_incr_mode) {
         if (scanline)
             free_scanlines(height, scanline);
         scanline = alloc_scanlines(height);
     }
+    /* On fully incremental mode, allocate the scanline as the total
+       size of the image */
+    if(full_incr_mode && !scanline){
+       int y;
+        if (scanline)
+            free_scanlines(height, scanline);
+       scanline = alloc_scanlines(height);
+       for(y = 0; y < height; y++){
+           scanline[y].sl_buf = bu_calloc(width, pwidth, "sl_buf scanline 
buffer");
+           scanline[y].sl_left = width;
+       }
+    }
 
 #ifdef RTSRV
     buf_mode = BUFMODE_RTSRV;          /* multi-pixel buffering */
@@ -1441,7 +1508,11 @@
        buf_mode = BUFMODE_FULLFLOAT;
     } else if (incr_mode) {
        buf_mode = BUFMODE_INCR;
-    } else if (width <= 96) {
+    } else if (full_incr_mode){
+       buf_mode = BUFMODE_ACC;
+       /* buf_mode = BUFMODE_SCANLINE; */
+    }
+    else if (width <= 96) {
        buf_mode = BUFMODE_UNBUF;
     } else if ((size_t)npsw <= (size_t)height/4) {
        /* Have each CPU do a whole scanline.  Saves lots of semaphore
@@ -1450,7 +1521,8 @@
         */
        per_processor_chunk = width;
        buf_mode = BUFMODE_SCANLINE;
-    } else {
+    } 
+    else {
        buf_mode = BUFMODE_DYNAMIC;
     }
 #endif
@@ -1543,8 +1615,11 @@
            }
            
            break;
+        case BUFMODE_ACC:
+           bu_log("Multiple-sample, average buffering\n");
+           break;
        default:
-           bu_exit(EXIT_FAILURE, "bad buf_mode");
+           bu_exit(EXIT_FAILURE, "bad buf_mode: %d", buf_mode);
     }
 
     /* This is where we do Preperations for each Lighting Model if it


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts. 
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to