Two in one:
[blender.git] / source / blender / src / renderwin.c
index ced1f1bd6f53ee1322ce6f7ce6034da07aad133b..8ca96f89936090edb891d19bfb1e88366ce115ea 100644 (file)
@@ -63,6 +63,7 @@
 #include "BMF_Api.h"
 
 #include "DNA_image_types.h"
+#include "DNA_space_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_view3d_types.h"
@@ -88,6 +89,7 @@
 #include "BIF_toolbox.h"
 #include "BIF_writeimage.h"
 
+#include "BDR_sculptmode.h"
 #include "BDR_editobject.h"
 #include "BPY_extern.h" /* for BPY_do_all_scripts */
 
@@ -597,7 +599,7 @@ static void renderwin_handler(Window *win, void *user_data, short evt, short val
                                mainwindow_make_active();
                                rw->active= 0;
                                areawinset(find_biggest_area()->win);
-                               BIF_save_rendered_image_fs(0);
+                               BIF_save_rendered_image_fs();
                        }
                } 
                else if (evt==F11KEY) {
@@ -1055,9 +1057,11 @@ static void end_test_break_callback()
 
 static void do_render(int anim)
 {
+       Image *ima;
        Render *re= RE_NewRender(G.scene->id.name);
        unsigned int lay= G.scene->lay;
        int scemode= G.scene->r.scemode;
+       int sculptmode= G.f & G_SCULPTMODE;
        
        /* UGLY! we set this flag to prevent renderwindow queue to execute another render */
        /* is reset in RE_BlenderFrame */
@@ -1073,6 +1077,8 @@ static void do_render(int anim)
        if(G.obedit)
                exit_editmode(0);       /* 0 = no free data */
 
+       if(sculptmode) set_sculptmode();
+
        /* allow localview render for objects with lights in normal layers */
        if(curarea->spacetype==SPACE_VIEW3D) {
                if(G.vd->lay & 0xFF000000) {
@@ -1105,20 +1111,29 @@ static void do_render(int anim)
                
        scene_update_for_newframe(G.scene, G.scene->lay);       // no redraw needed, this restores to view as we left it
        
+       /* get a render result image, and make sure it is clean */
+       ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result");
+       BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
+       
+       if(sculptmode) set_sculptmode();
+       
        waitcursor(0);
 }
 
+/* called before render, store old render in spare buffer */
 static void renderwin_store_spare(void)
 {
        RenderResult rres;
        
        if(render_win==0 || render_win->storespare==0)
                return;
-
-       if(render_win->showspare) {
-               render_win->showspare= 0;
-               window_set_title(render_win->win, renderwin_get_title(1));
-       }
+       
+       /* only store when it does not show spare */
+       if(render_win->showspare==0)
+               return;
+       
+       render_win->showspare= 0;
+       window_set_title(render_win->win, renderwin_get_title(1));
        
        BLI_strncpy(render_win->render_text_spare, render_win->render_text, RW_MAXTEXT);
        
@@ -1190,6 +1205,14 @@ void BIF_end_render_callbacks(void)
        }
 }
 
+void BIF_store_spare(void)
+{
+       if(render_win)
+               renderwin_store_spare();
+       else
+               imagewin_store_spare();
+}
+
 /* set up display, render an image or scene */
 void BIF_do_render(int anim)
 {
@@ -1203,8 +1226,7 @@ void BIF_do_render(int anim)
                }
        }
        
-       if(render_win && render_win->showspare)
-               renderwin_store_spare();
+       BIF_store_spare();
 
        do_render(anim);
 
@@ -1320,12 +1342,7 @@ void BIF_redraw_render_rect(void)
                renderwin_queue_redraw(render_win);
        }
        else {
-               Image *ima = (Image *)find_id("IM", "Render Result");
-               if(ima && ima->ibuf) {
-                       IMB_freeImBuf(ima->ibuf);
-                       ima->ibuf= NULL;
-                       allqueue(REDRAWIMAGE, 0);
-               }
+               allqueue(REDRAWIMAGE, 0);
        }
 }      
 
@@ -1333,22 +1350,26 @@ void BIF_swap_render_rects(void)
 {
        RenderResult rres;
        
-       if (render_win==NULL) return;
-       
-       render_win->storespare= 1;
-       render_win->showspare ^= 1;
+       if(G.displaymode!=R_DISPLAYWIN) {
+               imagewindow_swap_render_rects();
+       }
+       else if(render_win) {
                
-       RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
+               render_win->storespare= 1;
+               render_win->showspare ^= 1;
+                       
+               RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
+                       
+               if(render_win->sparex!=rres.rectx || render_win->sparey!=rres.recty) {
+                       if(render_win->rectspare) MEM_freeN(render_win->rectspare);
+                       render_win->rectspare= NULL;
+                       if(render_win->rectsparef) MEM_freeN(render_win->rectsparef);
+                       render_win->rectsparef= NULL;
+               }
                
-       if(render_win->sparex!=rres.rectx || render_win->sparey!=rres.recty) {
-               if(render_win->rectspare) MEM_freeN(render_win->rectspare);
-               render_win->rectspare= NULL;
-               if(render_win->rectsparef) MEM_freeN(render_win->rectsparef);
-               render_win->rectsparef= NULL;
+               window_set_title(render_win->win, renderwin_get_title(1));
        }
        
-       window_set_title(render_win->win, renderwin_get_title(1));
-
        /* redraw */
        BIF_redraw_render_rect();