soc-2008-mxcurioni: merged changes to revision 23516
[blender.git] / source / blender / render / intern / source / pipeline.c
index 9e0d0e9efa741ac42bba064851598df2a9338f61..b6c81e1ea6082e8bbe5afabc0c5db1901198439d 100644 (file)
@@ -66,6 +66,9 @@
 
 #include "RE_pipeline.h"
 
+#include "FRS_freestyle.h"
+#include "FRS_freestyle_config.h"
+
 /* internal */
 #include "render_types.h"
 #include "renderpipeline.h"
@@ -406,7 +409,7 @@ static int passtype_from_name(char *str)
 
 static void render_unique_exr_name(Render *re, char *str, int sample)
 {
-       char di[FILE_MAX], name[FILE_MAXFILE], fi[FILE_MAXFILE];
+       char di[FILE_MAX], name[FILE_MAXFILE+MAX_ID_NAME+100], fi[FILE_MAXFILE];
        
        BLI_strncpy(di, G.sce, FILE_MAX);
        BLI_splitdirstring(di, fi);
@@ -596,6 +599,7 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int
                rl->lay= (1<<20) -1;
                rl->layflag= 0x7FFF;    /* solid ztra halo strand */
                rl->passflag= SCE_PASS_COMBINED;
+               FRS_add_freestyle_config( srl );
                
                re->r.actlay= 0;
        }
@@ -868,33 +872,26 @@ static void renderresult_add_names(RenderResult *rr)
                        strcpy(rpass->name, get_pass_name(rpass->passtype, -1));
 }
 
-
-/* only for temp buffer files, makes exact copy of render result */
-static void read_render_result(Render *re, int sample)
+/* called for reading temp files, and for external engines */
+static int read_render_result_from_file(char *filename, RenderResult *rr)
 {
        RenderLayer *rl;
        RenderPass *rpass;
        void *exrhandle= IMB_exr_get_handle();
        int rectx, recty;
-       char str[FILE_MAX];
-       
-       RE_FreeRenderResult(re->result);
-       re->result= new_render_result(re, &re->disprect, 0, RR_USEMEM);
 
-       render_unique_exr_name(re, str, sample);
-       if(IMB_exr_begin_read(exrhandle, str, &rectx, &recty)==0) {
+       if(IMB_exr_begin_read(exrhandle, filename, &rectx, &recty)==0) {
                IMB_exr_close(exrhandle);
-               printf("cannot read: %s\n", str);
-               return;
+               return 0;
        }
        
-       printf("read exr tmp file: %s\n", str);
-       
-       if(re->result == NULL || rectx!=re->result->rectx || recty!=re->result->recty) {
+       if(rr == NULL || rectx!=rr->rectx || recty!=rr->recty) {
                printf("error in reading render result\n");
+               IMB_exr_close(exrhandle);
+               return 0;
        }
        else {
-               for(rl= re->result->layers.first; rl; rl= rl->next) {
+               for(rl= rr->layers.first; rl; rl= rl->next) {
                        
                        /* combined */
                        if(rl->rectf) {
@@ -914,10 +911,27 @@ static void read_render_result(Render *re, int sample)
                        
                }
                IMB_exr_read_channels(exrhandle);
-               renderresult_add_names(re->result);
+               renderresult_add_names(rr);
        }
        
        IMB_exr_close(exrhandle);
+
+       return 1;
+}
+
+/* only for temp buffer files, makes exact copy of render result */
+static void read_render_result(Render *re, int sample)
+{
+       char str[FILE_MAX];
+
+       RE_FreeRenderResult(re->result);
+       re->result= new_render_result(re, &re->disprect, 0, RR_USEMEM);
+
+       render_unique_exr_name(re, str, sample);
+       printf("read exr tmp file: %s\n", str);
+
+       if(!read_render_result_from_file(str, re->result))
+               printf("cannot read: %s\n", str);
 }
 
 /* *************************************************** */
@@ -1516,7 +1530,7 @@ static void threaded_tile_processor(Render *re)
        if(re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
                RE_FreeRenderResult(re->result);
        
-               if(re->sss_points)
+               if(re->sss_points && render_display_draw_enabled(re))
                        re->result= new_render_result(re, &re->disprect, 0, 0);
                else if(re->r.scemode & R_FULL_SAMPLE)
                        re->result= new_full_sample_buffers_exr(re);
@@ -1699,6 +1713,10 @@ static void do_render_3d(Render *re)
                if(!re->test_break(re->tbh))
                        add_halo_flare(re);
        
+       /* Freestyle  */
+       if( re->r.mode & R_EDGE_FRS && re->r.renderer==R_INTERN)
+               FRS_add_Freestyle(re);
+               
        /* free all render verts etc */
        RE_Database_Free(re);
 }
@@ -2560,16 +2578,15 @@ static int render_initialize_from_scene(Render *re, Scene *scene, int anim, int
        /* check all scenes involved */
        tag_scenes_for_render(re);
 
-#ifdef 0
        /*
         * Disabled completely for now,
         * can be later set as render profile option
         * and default for background render.
        */
-
-       /* make sure dynamics are up to date */
-       update_physics_cache(re, scene, anim_init);
-#endif
+       if(0) {
+               /* make sure dynamics are up to date */
+               update_physics_cache(re, scene, anim_init);
+       }
        
        if(scene->r.scemode & R_SINGLE_LAYER)
                push_render_result(re);
@@ -2945,7 +2962,7 @@ void RE_engine_update_stats(RenderEngine *engine, char *stats, char *info)
 
 /* loads in image into a result, size must match
  * x/y offsets are only used on a partial copy when dimensions dont match */
-void RE_layer_rect_from_file(RenderLayer *layer, ReportList *reports, char *filename, int x, int y)
+void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, char *filename)
 {
        ImBuf *ibuf = IMB_loadiffname(filename, IB_rect);
 
@@ -2956,7 +2973,7 @@ void RE_layer_rect_from_file(RenderLayer *layer, ReportList *reports, char *file
 
                        memcpy(layer->rectf, ibuf->rect_float, sizeof(float)*4*layer->rectx*layer->recty);
                } else {
-                       if ((ibuf->x - x >= layer->rectx) && (ibuf->y - y >= layer->recty)) {
+                       if ((ibuf->x >= layer->rectx) && (ibuf->y >= layer->recty)) {
                                ImBuf *ibuf_clip;
 
                                if(ibuf->rect_float==NULL)
@@ -2964,7 +2981,7 @@ void RE_layer_rect_from_file(RenderLayer *layer, ReportList *reports, char *file
 
                                ibuf_clip = IMB_allocImBuf(layer->rectx, layer->recty, 32, IB_rectfloat, 0);
                                if(ibuf_clip) {
-                                       IMB_rectcpy(ibuf_clip, ibuf, 0,0, x,y, layer->rectx, layer->recty);
+                                       IMB_rectcpy(ibuf_clip, ibuf, 0,0, 0,0, layer->rectx, layer->recty);
 
                                        memcpy(layer->rectf, ibuf_clip->rect_float, sizeof(float)*4*layer->rectx*layer->recty);
                                        IMB_freeImBuf(ibuf_clip);
@@ -2984,6 +3001,15 @@ void RE_layer_rect_from_file(RenderLayer *layer, ReportList *reports, char *file
                BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
        }
 }
+
+void RE_result_load_from_file(RenderResult *result, ReportList *reports, char *filename)
+{
+       if(!read_render_result_from_file(filename, result)) {
+               BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
+               return;
+       }
+}
+
 static void external_render_3d(Render *re, RenderEngineType *type)
 {
        RenderEngine engine;