Freestyle was changed from a tile-based process to a post-processing effect. This...
authorMaxime Curioni <maxime.curioni@gmail.com>
Sun, 22 Mar 2009 16:25:14 +0000 (16:25 +0000)
committerMaxime Curioni <maxime.curioni@gmail.com>
Sun, 22 Mar 2009 16:25:14 +0000 (16:25 +0000)
Corrected crash when Freestyle is rendered in "Single" render layer mode (for example, in the compositor)

source/blender/freestyle/FRS_freestyle.h
source/blender/freestyle/intern/app_blender/FRS_freestyle.cpp
source/blender/freestyle/intern/stroke/BlenderStrokeRenderer.cpp
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/pipeline.c

index aa66ce999bc78e744003e80bd3c45c4bce72b3c3..3bc6e092f028529fb90ae4d92804ee7c88b3792a 100644 (file)
@@ -22,7 +22,9 @@ extern "C" {
        void FRS_initialize();
        void FRS_prepare(Render* re);
        void FRS_render_Blender(Render* re);
-
+       void FRS_composite_result(Render* re, SceneRenderLayer* srl);
+       void FRS_add_Freestyle(Render* re);
+       
 #ifdef __cplusplus
 }
 #endif
index 233fe26a38d5c1f7e79a9dca0d1c5164e155288d..af9210205bd0f7751261462834fe714ddedd9c72 100644 (file)
@@ -16,6 +16,7 @@ extern "C" {
 
 #include "render_types.h"
 #include "renderpipeline.h"
+#include "pixelblending.h"
 
 #include "BLI_blenlib.h"
 #include "BIF_renderwin.h"
@@ -161,7 +162,57 @@ extern "C" {
                        cout << "Freestyle cannot be used because the view map is not available" << endl;
                }
                cout << "\n###################################################################" << endl;
-       }       
+       }
+       
+       void FRS_composite_result(Render* re, SceneRenderLayer* srl)
+       {
+
+               RenderLayer *rl;
+           float *src, *dest, *pixSrc, *pixDest;
+               int x, y, rectx, recty;
+               
+               if( re->freestyle_render == NULL || re->freestyle_render->result == NULL )
+                       return;
+
+               rl = render_get_active_layer( re->freestyle_render, re->freestyle_render->result );
+           if( !rl || rl->rectf == NULL) { cout << "Cannot find Freestyle result image" << endl; return; }
+               src  = rl->rectf;
+               
+               rl = RE_GetRenderLayer(re->result, srl->name);
+           if( !rl || rl->rectf == NULL) { cout << "No layer to composite to" << endl; return; }
+               dest  = rl->rectf;
+               
+               rectx = re->rectx;
+               recty = re->recty;
+
+           for( y = 0; y < recty; y++) {
+               for( x = 0; x < rectx; x++) {
+
+                   pixSrc = src + 4 * (rectx * y + x);
+                   if( pixSrc[3] > 0.0) {
+                                       pixDest = dest + 4 * (rectx * y + x);
+                                       addAlphaOverFloat(pixDest, pixSrc);
+                    }
+                }
+           }
+               
+       }
+       
+       void FRS_add_Freestyle(Render* re) {
+               
+               SceneRenderLayer *srl, *freestyle_srl = NULL;
+               for(srl= (SceneRenderLayer *)re->scene->r.layers.first; srl && (freestyle_srl == NULL); srl= srl->next) {
+                       if(srl->layflag & SCE_LAY_FRS) {
+                               if (!freestyle_srl) freestyle_srl = srl;
+                       }
+               }
+               
+               if( freestyle_srl ) {
+                       FRS_prepare(re);
+                       FRS_render_Blender(re);
+                       FRS_composite_result(re, freestyle_srl);
+               }
+       }
        
 #ifdef __cplusplus
 }
index a175620c8d7dd49246ffb19518648e0b981e4445..286d23c619bb06ef9d99b6d57b70f4b3ba46daa1 100644 (file)
@@ -230,10 +230,12 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
 
 void BlenderStrokeRenderer::RenderScene( Render *re ) {
        scene->r.mode &= ~( R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR );
+       scene->r.scemode &= ~( R_SINGLE_LAYER );
        scene->r.planes = R_PLANES32;
        scene->r.imtype = R_PNG;
        
        re->freestyle_render = RE_NewRender(scene->id.name);
+       
        RE_BlenderFrame( re->freestyle_render, scene, 1);
 
        // char filepath[255];
index 2f0455a6716dd2b744d00b36a838c3949ec3d23d..8313019024d65ee46c7253b37c6ce54b5389f32e 100644 (file)
@@ -4879,13 +4879,7 @@ void RE_Database_FromScene(Render *re, Scene *scene, int use_camera_view)
                if((re->r.mode & R_SSS) && !re->test_break())
                        if(re->r.renderer==R_INTERN)
                                make_sss_tree(re);
-                               
-               /* Freestyle */
-               if((re->r.mode & R_EDGE_FRS ) && !re->test_break())
-                       if(re->r.renderer==R_INTERN) {  
-                               FRS_prepare(re);
-                               FRS_render_Blender(re);
-               }
+
        }
        
        if(re->test_break())
index 673bea87d6c497339d163e77dbd52b4f42c45818..12dcd812a04c9473288f481856568017472ac1ee 100644 (file)
@@ -1637,6 +1637,10 @@ static void do_render_3d(Render *re)
                if(!re->test_break())
                        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);
 }