Cleanup: use a struct to backup/restore values for offscreen drawing
Variables to temporarily override values was scattered, making it harder to follow.
This commit is contained in:
parent
cf780e0f67
commit
f0b75cc19d
|
@ -1675,11 +1675,28 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
|
|||
RegionView3D *rv3d = region->regiondata;
|
||||
RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype);
|
||||
|
||||
/* set temporary new size */
|
||||
int bwinx = region->winx;
|
||||
int bwiny = region->winy;
|
||||
rcti brect = region->winrct;
|
||||
/* Store `orig` variables. */
|
||||
struct {
|
||||
struct bThemeState theme_state;
|
||||
|
||||
/* #View3D */
|
||||
eDrawType v3d_shading_type;
|
||||
|
||||
/* #Region */
|
||||
int region_winx, region_winy;
|
||||
rcti region_winrct;
|
||||
} orig = {
|
||||
.v3d_shading_type = v3d->shading.type,
|
||||
|
||||
.region_winx = region->winx,
|
||||
.region_winy = region->winy,
|
||||
.region_winrct = region->winrct,
|
||||
};
|
||||
|
||||
UI_Theme_Store(&orig.theme_state);
|
||||
UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
|
||||
|
||||
/* Set temporary new size. */
|
||||
region->winx = winx;
|
||||
region->winy = winy;
|
||||
region->winrct.xmin = 0;
|
||||
|
@ -1687,18 +1704,13 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
|
|||
region->winrct.xmax = winx;
|
||||
region->winrct.ymax = winy;
|
||||
|
||||
struct bThemeState theme_state;
|
||||
UI_Theme_Store(&theme_state);
|
||||
UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
|
||||
|
||||
/* set flags */
|
||||
G.f |= G_FLAG_RENDER_VIEWPORT;
|
||||
|
||||
/* There are too many functions inside the draw manager that check the shading type,
|
||||
* so use a temporary override instead. */
|
||||
const eDrawType drawtype_orig = v3d->shading.type;
|
||||
v3d->shading.type = drawtype;
|
||||
|
||||
/* Set flags. */
|
||||
G.f |= G_FLAG_RENDER_VIEWPORT;
|
||||
|
||||
{
|
||||
/* free images which can have changed on frame-change
|
||||
* warning! can be slow so only free animated images - campbell */
|
||||
|
@ -1728,18 +1740,18 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
|
|||
do_color_management,
|
||||
ofs,
|
||||
viewport);
|
||||
|
||||
/* restore size */
|
||||
region->winx = bwinx;
|
||||
region->winy = bwiny;
|
||||
region->winrct = brect;
|
||||
|
||||
GPU_matrix_pop_projection();
|
||||
GPU_matrix_pop();
|
||||
|
||||
UI_Theme_Restore(&theme_state);
|
||||
/* Restore all `orig` members. */
|
||||
region->winx = orig.region_winx;
|
||||
region->winy = orig.region_winy;
|
||||
region->winrct = orig.region_winrct;
|
||||
|
||||
UI_Theme_Restore(&orig.theme_state);
|
||||
|
||||
v3d->shading.type = orig.v3d_shading_type;
|
||||
|
||||
v3d->shading.type = drawtype_orig;
|
||||
G.f &= ~G_FLAG_RENDER_VIEWPORT;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue