Merged changes in the trunk up to revision 41225.
[blender-staging.git] / source / blender / render / intern / source / pipeline.c
index 08e9278ce46acede1725abf909ad9cac6515b27a..0fcf01e235a33d84796be70a31eeff87b456a9f7 100644 (file)
@@ -74,6 +74,7 @@
 
 #include "intern/openexr/openexr_multi.h"
 
+#include "RE_engine.h"
 #include "RE_pipeline.h"
 
 #include "FRS_freestyle.h"
@@ -219,7 +220,7 @@ void RE_FreeRenderResult(RenderResult *res)
 }
 
 /* version that's compatible with fullsample buffers */
-static void free_render_result(ListBase *lb, RenderResult *rr)
+void free_render_result(ListBase *lb, RenderResult *rr)
 {
        RenderResult *rrnext;
        
@@ -482,7 +483,7 @@ static void scene_unique_exr_name(Scene *scene, char *str, int sample)
        else
                BLI_snprintf(name, sizeof(name), "%s_%s%d.exr", fi, scene->id.name+2, sample);
 
-       BLI_make_file_string("/", str, btempdir, name);
+       BLI_make_file_string("/", str, BLI_temporary_dir(), name);
 }
 
 static void render_unique_exr_name(Render *re, char *str, int sample)
@@ -549,12 +550,11 @@ RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name)
        return NULL;
 }
 
-#define RR_USEMEM      0
 /* called by main render as well for parts */
 /* will read info from Render *re to define layers */
 /* called in threads */
 /* re->winx,winy is coordinate space of entire image, partrct the part within */
-static RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int savebuffers)
+RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int savebuffers)
 {
        RenderResult *rr;
        RenderLayer *rl;
@@ -734,7 +734,7 @@ static void do_merge_tile(RenderResult *rr, RenderResult *rrpart, float *target,
 /* used when rendering to a full buffer, or when reading the exr part-layer-pass file */
 /* no test happens here if it fits... we also assume layers are in sync */
 /* is used within threads */
-static void merge_render_result(RenderResult *rr, RenderResult *rrpart)
+void merge_render_result(RenderResult *rr, RenderResult *rrpart)
 {
        RenderLayer *rl, *rlp;
        RenderPass *rpass, *rpassp;
@@ -1003,7 +1003,7 @@ static int read_render_result_from_file(const char *filename, RenderResult *rr)
                IMB_exr_read_channels(exrhandle);
                renderresult_add_names(rr);
        }
-       
+
        IMB_exr_close(exrhandle);
 
        return 1;
@@ -1816,13 +1816,12 @@ void RE_TileProcessor(Render *re)
 
 /* ************  This part uses API, for rendering Blender scenes ********** */
 
-static int external_render_3d(Render *re, int do_all);
 static void add_freestyle(Render *re);
 
 static void do_render_3d(Render *re)
 {
        /* try external */
-       if(external_render_3d(re, 0))
+       if(RE_engine_render(re, 0))
                return;
 
        /* internal */
@@ -2272,7 +2271,7 @@ static void ntree_render_scenes(Render *re)
                                        restore_scene= (scene != re->scene);
                                        node->id->flag &= ~LIB_DOIT;
                                        
-                                       NodeTagChanged(re->scene->nodetree, node);
+                                       nodeUpdate(re->scene->nodetree, node);
                                }
                        }
                }
@@ -2541,7 +2540,7 @@ static void do_render_composite_fields_blur_3d(Render *re)
                        ntreeCompositTagAnimated(ntree);
                }
                
-               if(ntree && re->r.scemode & R_DOCOMP) {
+               if(ntree && re->scene->use_nodes && re->r.scemode & R_DOCOMP) {
                        /* checks if there are render-result nodes that need scene */
                        if((re->r.scemode & R_SINGLE_LAYER)==0)
                                ntree_render_scenes(re);
@@ -2723,7 +2722,7 @@ static void do_render_all_options(Render *re)
        /* ensure no images are in memory from previous animated sequences */
        BKE_image_all_free_anim_ibufs(re->r.cfra);
 
-       if(external_render_3d(re, 1)) {
+       if(RE_engine_render(re, 1)) {
                /* in this case external render overrides all */
        }
        else if(seq_render_active(re)) {
@@ -2828,7 +2827,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r
                
                scene_unique_exr_name(scene, str, 0);
                
-               if (BLI_is_writable(str)==0) {
+               if (BLI_file_is_writable(str)==0) {
                        BKE_report(reports, RPT_ERROR, "Can not save render buffers, check the temp default path");
                        return 0;
                }
@@ -3230,13 +3229,13 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
                                if(scene->r.mode & (R_NO_OVERWRITE | R_TOUCH))
                                        BKE_makepicstring(name, scene->r.pic, scene->r.cfra, scene->r.imtype, scene->r.scemode & R_EXTENSION, TRUE);
 
-                               if(scene->r.mode & R_NO_OVERWRITE && BLI_exist(name)) {
+                               if(scene->r.mode & R_NO_OVERWRITE && BLI_exists(name)) {
                                        printf("skipping existing frame \"%s\"\n", name);
                                        continue;
                                }
-                               if(scene->r.mode & R_TOUCH && !BLI_exist(name)) {
+                               if(scene->r.mode & R_TOUCH && !BLI_exists(name)) {
                                        BLI_make_existing_file(name); /* makes the dir if its not there */
-                                       BLI_touch(name);
+                                       BLI_file_touch(name);
                                }
                        }
 
@@ -3259,7 +3258,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
                        if(G.afbreek==1) {
                                /* remove touched file */
                                if(BKE_imtype_is_movie(scene->r.imtype) == 0) {
-                                       if (scene->r.mode & R_TOUCH && BLI_exist(name) && BLI_filepathsize(name) == 0) {
+                                       if (scene->r.mode & R_TOUCH && BLI_exists(name) && BLI_file_size(name) == 0) {
                                                BLI_delete(name, 0, 0);
                                        }
                                }
@@ -3363,106 +3362,6 @@ void RE_init_threadcount(Render *re)
        }
 }
 
-/************************** External Engines ***************************/
-
-RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h)
-{
-       Render *re= engine->re;
-       RenderResult *result;
-       rcti disprect;
-
-       /* ensure the coordinates are within the right limits */
-       CLAMP(x, 0, re->result->rectx);
-       CLAMP(y, 0, re->result->recty);
-       CLAMP(w, 0, re->result->rectx);
-       CLAMP(h, 0, re->result->recty);
-
-       if(x + w > re->result->rectx)
-               w= re->result->rectx - x;
-       if(y + h > re->result->recty)
-               h= re->result->recty - y;
-
-       /* allocate a render result */
-       disprect.xmin= x;
-       disprect.xmax= x+w;
-       disprect.ymin= y;
-       disprect.ymax= y+h;
-
-       if(0) { // XXX (re->r.scemode & R_FULL_SAMPLE)) {
-               result= new_full_sample_buffers(re, &engine->fullresult, &disprect, 0);
-       }
-       else {
-               result= new_render_result(re, &disprect, 0, RR_USEMEM);
-               BLI_addtail(&engine->fullresult, result);
-       }
-
-       return result;
-}
-
-void RE_engine_update_result(RenderEngine *engine, RenderResult *result)
-{
-       Render *re= engine->re;
-
-       if(result && render_display_draw_enabled(re)) {
-               result->renlay= result->layers.first; // weak
-               re->display_draw(re->ddh, result, NULL);
-       }
-}
-
-void RE_engine_end_result(RenderEngine *engine, RenderResult *result)
-{
-       Render *re= engine->re;
-
-       if(!result)
-               return;
-
-       /* merge */
-       if(re->result->exrhandle) {
-               RenderResult *rr, *rrpart;
-               
-               // XXX crashes, exr expects very particular part sizes
-               for(rr= re->result, rrpart= result; rr && rrpart; rr= rr->next, rrpart= rrpart->next)
-                       save_render_result_tile(rr, rrpart);
-       }
-       else if(render_display_draw_enabled(re)) {
-               /* on break, don't merge in result for preview renders, looks nicer */
-               if(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS));
-               else merge_render_result(re->result, result);
-       }
-
-       /* draw */
-       if(!re->test_break(re->tbh) && render_display_draw_enabled(re)) {
-               result->renlay= result->layers.first; // weak
-               re->display_draw(re->ddh, result, NULL);
-       }
-
-       /* free */
-       free_render_result(&engine->fullresult, result);
-}
-
-int RE_engine_test_break(RenderEngine *engine)
-{
-       Render *re= engine->re;
-
-       return re->test_break(re->tbh);
-}
-
-void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info)
-{
-       Render *re= engine->re;
-
-       re->i.statstr= stats;
-       re->i.infostr= info;
-       re->stats_draw(re->sdh, &re->i);
-       re->i.infostr= NULL;
-       re->i.statstr= NULL;
-}
-
-void RE_engine_report(RenderEngine *engine, int type, const char *msg)
-{
-       BKE_report(engine->re->reports, type, msg);
-}
-
 /* 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_load_from_file(RenderLayer *layer, ReportList *reports, const char *filename, int x, int y)
@@ -3513,64 +3412,6 @@ void RE_result_load_from_file(RenderResult *result, ReportList *reports, const c
        }
 }
 
-static int external_render_3d(Render *re, int do_all)
-{
-       RenderEngineType *type= BLI_findstring(&R_engines, re->r.engine, offsetof(RenderEngineType, idname));
-       RenderEngine engine;
-
-       if(!(type && type->render))
-               return 0;
-       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW))
-               return 0;
-       if(do_all && !(type->flag & RE_DO_ALL))
-               return 0;
-       if(!do_all && (type->flag & RE_DO_ALL))
-               return 0;
-
-       BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-       if(re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
-               RE_FreeRenderResult(re->result);
-       
-               if(0) // XXX re->r.scemode & R_FULL_SAMPLE)
-                       re->result= new_full_sample_buffers_exr(re);
-               else
-                       re->result= new_render_result(re, &re->disprect, 0, 0); // XXX re->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE));
-       }
-       BLI_rw_mutex_unlock(&re->resultmutex);
-       
-       if(re->result==NULL)
-               return 1;
-
-       /* external */
-       memset(&engine, 0, sizeof(engine));
-       engine.type= type;
-       engine.re= re;
-
-       type->render(&engine, re->scene);
-
-       free_render_result(&engine.fullresult, engine.fullresult.first);
-
-       BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-       if(re->result->exrhandle) {
-               RenderResult *rr;
-
-               save_empty_result_tiles(re);
-               
-               for(rr= re->result; rr; rr= rr->next) {
-                       IMB_exr_close(rr->exrhandle);
-                       rr->exrhandle= NULL;
-               }
-               
-               free_render_result(&re->fullresult, re->result);
-               re->result= NULL;
-               
-               read_render_result(re, 0);
-       }
-       BLI_rw_mutex_unlock(&re->resultmutex);
-
-       return 1;
-}
-
 const float default_envmap_layout[] = { 0,0, 1,0, 2,0, 0,1, 1,1, 2,1 };
 
 int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env, const char *relpath, int imtype, float layout[12])
@@ -3628,3 +3469,4 @@ int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env,
                return FALSE;
        }
 }
+