Merged changes in the trunk up to revision 42116.
[blender.git] / source / blender / blenkernel / intern / scene.c
index 14dfe015894c5d5f8b18b3cc58347e989d1cc926..33fb15faa56c1bda15e5505519284745e0abbadc 100644 (file)
@@ -44,6 +44,7 @@
 
 #include "DNA_anim_types.h"
 #include "DNA_group_types.h"
+#include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
@@ -77,6 +78,8 @@
 //XXX #include "BIF_previewrender.h"
 //XXX #include "BIF_editseq.h"
 
+#include "FRS_freestyle_config.h"
+
 //XXX #include "nla.h"
 
 #ifdef WIN32
@@ -241,7 +244,8 @@ Scene *copy_scene(Scene *sce, int type)
 void free_scene(Scene *sce)
 {
        Base *base;
-
+       SceneRenderLayer *srl;
+       
        base= sce->base.first;
        while(base) {
                base->object->id.us--;
@@ -281,6 +285,10 @@ void free_scene(Scene *sce)
                sce->r.ffcodecdata.properties = NULL;
        }
        
+       for(srl= sce->r.layers.first; srl; srl= srl->next) {
+               FRS_free_freestyle_config(srl);
+       }
+       
        BLI_freelistN(&sce->markers);
        BLI_freelistN(&sce->transform_spaces);
        BLI_freelistN(&sce->r.layers);
@@ -346,9 +354,11 @@ Scene *add_scene(const char *name)
        sce->r.mblur_samples= 1;
        sce->r.filtertype= R_FILTER_MITCH;
        sce->r.size= 50;
-       sce->r.planes= 24;
-       sce->r.imtype= R_PNG;
-       sce->r.quality= 90;
+
+       sce->r.im_format.planes= R_IMF_PLANES_RGB;
+       sce->r.im_format.imtype= R_IMF_IMTYPE_PNG;
+       sce->r.im_format.quality= 90;
+
        sce->r.displaymode= R_OUTPUT_AREA;
        sce->r.framapto= 100;
        sce->r.images= 100;
@@ -483,7 +493,7 @@ Scene *add_scene(const char *name)
        sce->r.osa= 8;
 
        /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
-       scene_add_render_layer(sce);
+       scene_add_render_layer(sce, NULL);
        
        /* game data */
        sce->gm.stereoflag = STEREO_NOSTEREO;
@@ -1086,13 +1096,15 @@ void scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay)
 }
 
 /* return default layer, also used to patch old files */
-void scene_add_render_layer(Scene *sce)
+SceneRenderLayer *scene_add_render_layer(Scene *sce, const char *name)
 {
        SceneRenderLayer *srl;
-//     int tot= 1 + BLI_countlist(&sce->r.layers);
-       
+
+       if(!name)
+               name= "RenderLayer";
+
        srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
-       strcpy(srl->name, "RenderLayer");
+       BLI_strncpy(srl->name, name, sizeof(srl->name));
        BLI_uniquename(&sce->r.layers, srl, "RenderLayer", '.', offsetof(SceneRenderLayer, name), sizeof(srl->name));
        BLI_addtail(&sce->r.layers, srl);
 
@@ -1100,6 +1112,46 @@ void scene_add_render_layer(Scene *sce)
        srl->lay= (1<<20) -1;
        srl->layflag= 0x7FFF;   /* solid ztra halo edge strand */
        srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
+       FRS_add_freestyle_config( srl );
+
+       return srl;
+}
+
+int scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl)
+{
+       const int act= BLI_findindex(&scene->r.layers, srl);
+       Scene *sce;
+
+       if (act == -1) {
+               return 0;
+       }
+       else if ( (scene->r.layers.first == scene->r.layers.last) &&
+                 (scene->r.layers.first == srl))
+       {
+               /* ensure 1 layer is kept */
+               return 0;
+       }
+
+       BLI_remlink(&scene->r.layers, srl);
+       MEM_freeN(srl);
+
+       scene->r.actlay= 0;
+
+       for(sce = bmain->scene.first; sce; sce = sce->id.next) {
+               if(sce->nodetree) {
+                       bNode *node;
+                       for(node = sce->nodetree->nodes.first; node; node = node->next) {
+                               if(node->type==CMP_NODE_R_LAYERS && (Scene*)node->id==scene) {
+                                       if(node->custom1==act)
+                                               node->custom1= 0;
+                                       else if(node->custom1>act)
+                                               node->custom1--;
+                               }
+                       }
+               }
+       }
+
+       return 1;
 }
 
 /* render simplification */
@@ -1163,6 +1215,6 @@ Base *_setlooper_base_step(Scene **sce_iter, Base *base)
 int scene_use_new_shading_nodes(Scene *scene)
 {
        RenderEngineType *type= RE_engines_find(scene->r.engine);
-       return (type->flag & RE_USE_SHADING_NODES);
+       return (type && type->flag & RE_USE_SHADING_NODES);
 }