Cycles:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 22 Aug 2011 13:17:43 +0000 (13:17 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 22 Aug 2011 13:17:43 +0000 (13:17 +0000)
* Update progress bar during render (patch by Thomas)
* Show status/pass/time during render in 3d view

intern/cycles/blender/addon/engine.py
intern/cycles/blender/blender_session.cpp
intern/cycles/blender/blender_session.h
intern/cycles/blender/blender_util.h
source/blender/editors/space_view3d/view3d_draw.c
source/blender/render/extern/include/RE_engine.h
source/blender/render/intern/pipeline/engine.c

index 6879efcb24eb2016137454128f24bcdc0e6a8c06..d25eb21eeb9e50c623dca8bc1afbebfea7e222fa 100644 (file)
@@ -58,41 +58,7 @@ def draw(engine, region, v3d, rv3d):
        rv3d = rv3d.as_pointer()
 
        # draw render image
-       status, substatus = lib.draw(engine.session, v3d, rv3d)
-
-       # draw text over image
-       if status != "":
-               import blf
-               import bgl
-
-               fontid = 0 # todo, find out how to set this
-               dim = blf.dimensions(fontid, status)
-               dim_sub = blf.dimensions(fontid, substatus)
-
-               padding = 5
-
-               x = (region.width - max(dim[0], dim_sub[0]))*0.5 - padding
-               y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5 - padding
-
-               bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
-               bgl.glEnable(bgl.GL_BLEND)
-               bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
-               bgl.glRectf(x, y, x+max(dim[0], dim_sub[0])+padding+padding, y+dim[1]+dim_sub[1]+padding+padding+2)
-               bgl.glDisable(bgl.GL_BLEND)
-
-               x = (region.width - dim[0])*0.5
-               y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5 + dim_sub[1] + padding
-
-               bgl.glColor3f(0.8, 0.8, 0.8)
-               blf.position(fontid, x, y, 0)
-               blf.draw(fontid, status)
-
-               x = (region.width - dim_sub[0])*0.5
-               y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5
-
-               bgl.glColor3f(0.6, 0.6, 0.6)
-               blf.position(fontid, x, y, 0)
-               blf.draw(fontid, substatus)
+       lib.draw(engine.session, v3d, rv3d)
 
 def available_devices():
        import libcycles_blender as lib
index f69ebff533823061ce637f00e6b719f82426bb23..045efef0ef066ca4a192615dec7d31a780d134ea 100644 (file)
@@ -243,6 +243,15 @@ void BlenderSession::get_status(string& status, string& substatus)
        session->progress.get_status(status, substatus);
 }
 
+void BlenderSession::get_progress(float& progress, double& total_time)
+{
+       double pass_time;
+       int pass;
+
+       session->progress.get_pass(pass, total_time, pass_time);
+       progress = ((float)pass/(float)session->params.passes);
+}
+
 void BlenderSession::tag_update()
 {
        /* tell blender that we want to get another update callback */
@@ -251,16 +260,28 @@ void BlenderSession::tag_update()
 
 void BlenderSession::tag_redraw()
 {
-       if(background) {
-               /* offline render, set stats and redraw if timeout passed */
-               string status, substatus;
-               get_status(status, substatus);
+       string status, substatus;
+       float progress;
+       double total_time;
+       char time_str[128];
+
+       /* update stats and progress */
+       get_status(status, substatus);
+       get_progress(progress, total_time);
+
+       if(!background) {
+               BLI_timestr(total_time, time_str);
+               status = "Time: " + string(time_str) + " | " + status;
+       }
 
-               if(substatus.size() > 0)
-                       status += " | " + substatus;
+       if(substatus.size() > 0)
+               status += " | " + substatus;
 
-               RE_engine_update_stats((RenderEngine*)b_engine.ptr.data, "", status.c_str());
+       RE_engine_update_stats((RenderEngine*)b_engine.ptr.data, "", status.c_str());
+       RE_engine_update_progress((RenderEngine*)b_engine.ptr.data, progress);
 
+       if(background) {
+               /* offline render, redraw if timeout passed */
                if(time_dt() - last_redraw_time > 1.0f) {
                        write_render_result();
                        engine_tag_redraw((RenderEngine*)b_engine.ptr.data);
index 8bc5d3dfab9ea7ac28814a266953347ed95d4509..ea3e005a884ba2068794852e1dc6ebb64e197b0c 100644 (file)
@@ -55,6 +55,7 @@ public:
        void tag_redraw();
        void tag_update();
        void get_status(string& status, string& substatus);
+       void get_progress(float& progress, double& total_time);
        void test_cancel();
 
        bool background;
index 354a195758ffe2fd3194b015888bc81da1c6069e..fe9a611e2f87f4dfcb1c5b6d796a8b5ebe7da48b 100644 (file)
@@ -44,9 +44,11 @@ void RE_engine_update_result(struct RenderEngine *engine, struct RenderResult *r
 void RE_engine_end_result(struct RenderEngine *engine, struct RenderResult *result);
 int RE_engine_test_break(struct RenderEngine *engine);
 void RE_engine_update_stats(struct RenderEngine *engine, const char *stats, const char *info);
+void RE_engine_update_progress(struct RenderEngine *engine, float progress);
 void engine_tag_redraw(void *engine);
 void engine_tag_update(void *engine);
 int rna_Object_is_modified(void *ob, void *scene, int settings);
+void BLI_timestr(double _time, char *str);
 
 }
 
index cf048582849796f5915cd7c89b627ae776fc107b..746bc7527643f0d7e7ca1fd5b8b2cab2718d7e63 100644 (file)
@@ -2566,6 +2566,32 @@ static int view3d_main_area_draw_engine(const bContext *C, ARegion *ar)
        return 1;
 }
 
+static void view3d_main_area_draw_engine_info(RegionView3D *rv3d, ARegion *ar)
+{
+       rcti rect;
+       const int header_height = 18;
+
+       if(!rv3d->render_engine || !rv3d->render_engine->text)
+               return;
+       
+       /* background box */
+       rect= ar->winrct;
+       rect.xmin= 0;
+       rect.ymin= ar->winrct.ymax - ar->winrct.ymin - header_height;
+       rect.xmax= ar->winrct.xmax - ar->winrct.xmin;
+       rect.ymax= ar->winrct.ymax - ar->winrct.ymin;
+
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+       glColor4f(0.0f, 0.0f, 0.0f, 0.25f);
+       glRecti(rect.xmin, rect.ymin, rect.xmax+1, rect.ymax+1);
+       glDisable(GL_BLEND);
+       
+       /* text */
+       UI_ThemeColor(TH_TEXT_HI);
+       UI_DrawString(12, rect.ymin + 5, rv3d->render_engine->text);
+}
+
 /* warning: this function has duplicate drawing in ED_view3d_draw_offscreen() */
 void view3d_main_area_draw(const bContext *C, ARegion *ar)
 {
@@ -2781,26 +2807,31 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
        else    
                draw_view_icon(rv3d);
        
-       if((U.uiflag & USER_SHOW_FPS) && (CTX_wm_screen(C)->animtimer)) {
-               draw_viewport_fps(scene, ar);
+       if(rv3d->render_engine) {
+               view3d_main_area_draw_engine_info(rv3d, ar);
        }
-       else if(U.uiflag & USER_SHOW_VIEWPORTNAME) {
-               draw_viewport_name(ar, v3d);
-       }
-       if (grid_unit) { /* draw below the viewport name */
-               char tstr[32]= "";
+       else {
+               if((U.uiflag & USER_SHOW_FPS) && (CTX_wm_screen(C)->animtimer)) {
+                       draw_viewport_fps(scene, ar);
+               }
+               else if(U.uiflag & USER_SHOW_VIEWPORTNAME) {
+                       draw_viewport_name(ar, v3d);
+               }
+               if (grid_unit) { /* draw below the viewport name */
+                       char tstr[32]= "";
 
-               UI_ThemeColor(TH_TEXT_HI);
-               if(v3d->grid != 1.0f) {
-                       BLI_snprintf(tstr, sizeof(tstr), "%s x %.4g", grid_unit, v3d->grid);
+                       UI_ThemeColor(TH_TEXT_HI);
+                       if(v3d->grid != 1.0f) {
+                               BLI_snprintf(tstr, sizeof(tstr), "%s x %.4g", grid_unit, v3d->grid);
+                       }
+
+                       BLF_draw_default_ascii(22,  ar->winy-(USER_SHOW_VIEWPORTNAME?40:20), 0.0f, tstr[0]?tstr : grid_unit, sizeof(tstr)); /* XXX, use real length */
                }
 
-               BLF_draw_default_ascii(22,  ar->winy-(USER_SHOW_VIEWPORTNAME?40:20), 0.0f, tstr[0]?tstr : grid_unit, sizeof(tstr)); /* XXX, use real length */
+               ob= OBACT;
+               if(U.uiflag & USER_DRAWVIEWINFO) 
+                       draw_selected_name(scene, ob);
        }
-
-       ob= OBACT;
-       if(U.uiflag & USER_DRAWVIEWINFO) 
-               draw_selected_name(scene, ob);
        
        /* XXX here was the blockhandlers for floating panels */
 
index f7a927ec5dbf1fcf8ac45f45f01290ceece5c500..7f01bc673d24ee7116fe4a1c9af8cbbe9deea573 100644 (file)
@@ -82,6 +82,7 @@ typedef struct RenderEngine {
 
        struct Render *re;
        ListBase fullresult;
+       char *text;
 
        int do_draw;
        int do_update;
index 68d3b2697c56d572d6227288de798d4d4712f423..0fc6a0320c8e3648065bf1d9b433b616febb1e13 100644 (file)
@@ -38,6 +38,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_listbase.h"
+#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_report.h"
@@ -133,6 +134,9 @@ void RE_engine_free(RenderEngine *engine)
        }
 #endif
 
+       if(engine->text)
+               MEM_freeN(engine->text);
+
        MEM_freeN(engine);
 }
 
@@ -204,7 +208,10 @@ int RE_engine_test_break(RenderEngine *engine)
 {
        Render *re= engine->re;
 
-       return re->test_break(re->tbh);
+       if(re)
+               return re->test_break(re->tbh);
+       
+       return 0;
 }
 
 /* Statistics */
@@ -213,19 +220,37 @@ void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char
 {
        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;
+       /* stats draw callback */
+       if(re) {
+               re->i.statstr= stats;
+               re->i.infostr= info;
+               re->stats_draw(re->sdh, &re->i);
+               re->i.infostr= NULL;
+               re->i.statstr= NULL;
+       }
+
+       /* set engine text */
+       if(engine->text) {
+               MEM_freeN(engine->text);
+               engine->text= NULL;
+       }
+
+       if(stats && stats[0] && info && info[0])
+               engine->text= BLI_sprintfN("%s | %s", stats, info);
+       else if(info && info[0])
+               engine->text= BLI_strdup(info);
+       else if(stats && stats[0])
+               engine->text= BLI_strdup(stats);
 }
 
 void RE_engine_update_progress(RenderEngine *engine, float progress)
 {
        Render *re= engine->re;
 
-       CLAMP(progress, 0.0f, 1.0f);
-       re->progress(re->prh, progress);
+       if(re) {
+               CLAMP(progress, 0.0f, 1.0f);
+               re->progress(re->prh, progress);
+       }
 }
 
 void RE_engine_report(RenderEngine *engine, int type, const char *msg)