* Update progress bar during render (patch by Thomas)
* Show status/pass/time during render in 3d view
This commit is contained in:
Brecht Van Lommel 2011-08-22 13:17:43 +00:00
parent f7b9c85871
commit 9ccc60ed8c
7 changed files with 114 additions and 67 deletions

@ -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

@ -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()
{
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;
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, set stats and redraw if timeout passed */
string status, substatus;
get_status(status, substatus);
if(substatus.size() > 0)
status += " | " + substatus;
RE_engine_update_stats((RenderEngine*)b_engine.ptr.data, "", status.c_str());
/* 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);

@ -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;

@ -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);
}

@ -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 */

@ -82,6 +82,7 @@ typedef struct RenderEngine {
struct Render *re;
ListBase fullresult;
char *text;
int do_draw;
int do_update;

@ -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)