diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-06-19 14:21:17 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-06-20 15:32:45 +0400 |
commit | ca0c0e754931df011ff5421a57e02f8bdfa4559a (patch) | |
tree | c28374646a16be488ab649ea3ddf3a8e6210ac28 /source/blender/editors/render/render_internal.c | |
parent | 98af2622602e0760a887b4e61e18a9a507066b05 (diff) |
Implement resolution divider in the Blender Internal
Currently resolution divider is not exposed to the
interface yet, and i'm not even sure it needs to be
exposed because it's somewhat weird configuration.
Need to check how often artists are changing start
resolution in Cycles.
Pretty much straightforward implementation with the
only weak part: render result is getting re-allocated
and upscaled when current resolution is finished.
Not sure how to make it faster actually. Maybe it's
just a matter of making upscale fast enough.
Needed to fix some possible memory leak happening
in Freestyle when canceling rendering on a special
stage -- it was missing temp bmain free,
Reviewers: campbellbarton, dingto
CC: sebastian_k, fsiddi, venomgfx
Differential Revision: https://developer.blender.org/D609
Diffstat (limited to 'source/blender/editors/render/render_internal.c')
-rw-r--r-- | source/blender/editors/render/render_internal.c | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 9fa312884da..1bf48064fbe 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -1011,6 +1011,8 @@ void RENDER_OT_render(wmOperatorType *ot) #define PR_UPDATE_MATERIAL 4 #define PR_UPDATE_DATABASE 8 +#define START_RESOLUTION_DIVIDER 8 + typedef struct RenderPreview { /* from wmJob */ void *owner; @@ -1026,6 +1028,8 @@ typedef struct RenderPreview { RenderEngine *engine; float viewmat[4][4]; + + int resolution_divider; } RenderPreview; static int render_view3d_disprect(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rcti *disprect) @@ -1127,7 +1131,6 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda RenderPreview *rp = customdata; Render *re; RenderStats *rstats; - RenderData rdata; rctf viewplane; rcti cliprct; float clipsta, clipend, pixsize; @@ -1161,23 +1164,36 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda rstats = RE_GetStats(re); + if (update_flag & PR_UPDATE_VIEW) { + rp->resolution_divider = START_RESOLUTION_DIVIDER; + } + if ((update_flag & (PR_UPDATE_RENDERSIZE | PR_UPDATE_DATABASE)) || rstats->convertdone == 0) { + RenderData rdata; + int winx = rp->ar->winx / rp->resolution_divider, + winy = rp->ar->winy / rp->resolution_divider; + /* no osa, blur, seq, layers, etc for preview render */ rdata = rp->scene->r; rdata.mode &= ~(R_OSA | R_MBLUR | R_BORDER | R_PANORAMA); rdata.scemode &= ~(R_DOSEQ | R_DOCOMP | R_FREE_IMAGE); rdata.scemode |= R_VIEWPORT_PREVIEW; - + /* we do use layers, but only active */ rdata.scemode |= R_SINGLE_LAYER; /* initalize always */ if (render_view3d_disprect(rp->scene, rp->ar, rp->v3d, rp->rv3d, &cliprct)) { rdata.mode |= R_BORDER; - RE_InitState(re, NULL, &rdata, NULL, rp->ar->winx, rp->ar->winy, &cliprct); + RE_InitState(re, NULL, &rdata, NULL, winx, winy, &cliprct); } else - RE_InitState(re, NULL, &rdata, NULL, rp->ar->winx, rp->ar->winy, NULL); + RE_InitState(re, NULL, &rdata, NULL, winx, winy, NULL); + } + else if (update_flag & PR_UPDATE_VIEW) { + int winx = rp->ar->winx / rp->resolution_divider, + winy = rp->ar->winy / rp->resolution_divider; + RE_ChangeResolution(re, winx, winy, NULL); } if (orth) @@ -1225,8 +1241,30 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda /* OK, can we enter render code? */ if (rstats->convertdone) { - RE_TileProcessor(re); - + for (;;) { + RE_TileProcessor(re); + + if (!*stop && rp->resolution_divider > 1) { + int winx, winy; + rp->resolution_divider /= 2; + winx = rp->ar->winx / rp->resolution_divider; + winy = rp->ar->winy / rp->resolution_divider; + *do_update = 1; + RE_ChangeResolution(re, winx, winy, NULL); + + /* Otherwise shadows are incorrect. */ + if (orth) { + RE_SetOrtho(re, &viewplane, clipsta, clipend); + } + else { + RE_SetWindow(re, &viewplane, clipsta, clipend); + } + } + else { + break; + } + } + /* always rotate back */ if (restore) RE_DataBase_IncrementalView(re, rp->viewmat, 1); @@ -1341,6 +1379,7 @@ static void render_view3d_do(RenderEngine *engine, const bContext *C) rp->v3d = rp->sa->spacedata.first; rp->rv3d = CTX_wm_region_view3d(C); rp->bmain = CTX_data_main(C); + rp->resolution_divider = START_RESOLUTION_DIVIDER; copy_m4_m4(rp->viewmat, rp->rv3d->viewmat); /* clear info text */ @@ -1386,9 +1425,12 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C) if (rres.rectf) { Scene *scene = CTX_data_scene(C); + ARegion *ar = CTX_wm_region(C); bool force_fallback = false; bool need_fallback = true; float dither = scene->r.dither_intensity; + float scale_x = (float) ar->winx / rres.rectx; + float scale_y = (float) ar->winy / rres.recty; /* Dithering is not supported on GLSL yet */ force_fallback |= dither != 0.0f; @@ -1420,8 +1462,10 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C) glEnable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glPixelZoom(scale_x, scale_y); glaDrawPixelsAuto(rres.xof, rres.yof, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer); + glPixelZoom(1.0f, 1.0f); glDisable(GL_BLEND); MEM_freeN(display_buffer); |