2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2010-03-08 16:36:53 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edrend
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2015-06-30 14:47:31 +10:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
#include "BLI_timecode.h"
|
2010-03-28 13:45:19 +00:00
|
|
|
#include "BLI_math.h"
|
2014-06-24 14:23:33 +06:00
|
|
|
#include "BLI_threads.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2013-06-24 22:41:24 +00:00
|
|
|
#include "PIL_time.h"
|
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-03-10 16:55:01 +00:00
|
|
|
|
2013-05-15 08:25:42 +00:00
|
|
|
#include "DNA_object_types.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "DNA_scene_types.h"
|
Blender Internal Render in viewport
Because of our release soon, feature has been added behind the Debug Menu.
CTRL+ALT+D and set it to -1. Or commandline --debug-value -1.
When debug set to -1, you can put the viewport to 'render' mode, just like
for Cycles. Notes for testers: (and please no bugs in tracker for this :)
- It renders without AA, MBlur, Panorama, Sequence, Composite
- Only active render layer gets rendered. Select another layer will re-render.
- But yes: it works for FreeStyle renders!
- Also does great for local view.
- BI is not well suited for incremental renders on view changes. This only
works for non-raytrace scenes, or zoom in ortho or camera mode, or for
Material changes. In most cases a full re-render is being done.
- ESC works to stop the preview render.
- Borders render as well. (CTRL+B)
- Force a refresh with arrow key left/right. A lot of settings don't trigger
re-render yet.
Tech notes:
- FreeStyle is adding a lot of temp objects/meshes in the Main database. This
caused DepsGraph to trigger changes (and redraws). I've prepended the names
for these temp objects with char number 27 (ESC), and made these names be
ignored for tag update checking.
- Fixed some bugs that were noticable with such excessive re-renders, like
for opening file window, quit during renders.
2013-04-16 17:39:20 +00:00
|
|
|
#include "DNA_view3d_types.h"
|
2013-05-12 19:01:23 +00:00
|
|
|
#include "DNA_userdef_types.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_blender_undo.h"
|
|
|
|
#include "BKE_blender_version.h"
|
2015-04-06 10:40:12 -03:00
|
|
|
#include "BKE_camera.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_context.h"
|
2014-01-01 16:59:38 +06:00
|
|
|
#include "BKE_colortools.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_image.h"
|
2017-10-16 17:15:03 -02:00
|
|
|
#include "BKE_layer.h"
|
2010-08-13 14:29:56 +00:00
|
|
|
#include "BKE_library.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_main.h"
|
2010-12-17 17:06:36 +00:00
|
|
|
#include "BKE_node.h"
|
Option to lock the interface while rendering
Added function called WM_set_locked_interface which does
two things:
- Prevents event queue from being handled, so no operators
(see below) or values are even possible to run or change.
This prevents any kind of "destructive" action performed
from user while rendering.
- Locks interface refresh for regions which does have lock
set to truth in their template. Currently it's just a 3D
viewport, but in the future more regions could be considered
unsafe, or we could want to lock different parts of
interface when doing different jobs.
This is needed because 3D viewport could be using or changing
the same data as renderer currently uses, leading to threading
conflict.
Notifiers are still allowed to handle, so render progress is
seen on the screen, but would need to doublecheck on this, in
terms some notifiers could be changing the data.
For now interface locking happens for render job only in case
"Lock Interface" checkbox is enabled.
Other tools like backing would also benefit of this option.
It is possible to mark operator as safe to be used in locked
interface mode by adding OPTYPE_ALLOW_LOCKED bit to operator
template flags.
This bit is completely handled by wm_evem_system, not
with operator run routines, so it's still possible to
run operators from drivers and handlers.
Currently allowed image editor navigation and zooming.
Reviewers: brecht, campbellbarton
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D142
2014-01-29 16:07:14 +06:00
|
|
|
#include "BKE_object.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_report.h"
|
2010-08-08 16:47:58 +00:00
|
|
|
#include "BKE_sequencer.h"
|
2011-03-25 17:11:32 +00:00
|
|
|
#include "BKE_screen.h"
|
2011-04-19 06:37:29 +00:00
|
|
|
#include "BKE_scene.h"
|
2018-03-19 14:17:59 +01:00
|
|
|
#include "BKE_undo_system.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "ED_object.h"
|
Blender Internal Render in viewport
Because of our release soon, feature has been added behind the Debug Menu.
CTRL+ALT+D and set it to -1. Or commandline --debug-value -1.
When debug set to -1, you can put the viewport to 'render' mode, just like
for Cycles. Notes for testers: (and please no bugs in tracker for this :)
- It renders without AA, MBlur, Panorama, Sequence, Composite
- Only active render layer gets rendered. Select another layer will re-render.
- But yes: it works for FreeStyle renders!
- Also does great for local view.
- BI is not well suited for incremental renders on view changes. This only
works for non-raytrace scenes, or zoom in ortho or camera mode, or for
Material changes. In most cases a full re-render is being done.
- ESC works to stop the preview render.
- Borders render as well. (CTRL+B)
- Force a refresh with arrow key left/right. A lot of settings don't trigger
re-render yet.
Tech notes:
- FreeStyle is adding a lot of temp objects/meshes in the Main database. This
caused DepsGraph to trigger changes (and redraws). I've prepended the names
for these temp objects with char number 27 (ESC), and made these names be
ignored for tag update checking.
- Fixed some bugs that were noticable with such excessive re-renders, like
for opening file window, quit during renders.
2013-04-16 17:39:20 +00:00
|
|
|
#include "ED_render.h"
|
|
|
|
#include "ED_screen.h"
|
2014-01-20 14:11:12 +01:00
|
|
|
#include "ED_util.h"
|
2018-04-02 15:02:08 +02:00
|
|
|
#include "ED_undo.h"
|
Blender Internal Render in viewport
Because of our release soon, feature has been added behind the Debug Menu.
CTRL+ALT+D and set it to -1. Or commandline --debug-value -1.
When debug set to -1, you can put the viewport to 'render' mode, just like
for Cycles. Notes for testers: (and please no bugs in tracker for this :)
- It renders without AA, MBlur, Panorama, Sequence, Composite
- Only active render layer gets rendered. Select another layer will re-render.
- But yes: it works for FreeStyle renders!
- Also does great for local view.
- BI is not well suited for incremental renders on view changes. This only
works for non-raytrace scenes, or zoom in ortho or camera mode, or for
Material changes. In most cases a full re-render is being done.
- ESC works to stop the preview render.
- Borders render as well. (CTRL+B)
- Force a refresh with arrow key left/right. A lot of settings don't trigger
re-render yet.
Tech notes:
- FreeStyle is adding a lot of temp objects/meshes in the Main database. This
caused DepsGraph to trigger changes (and redraws). I've prepended the names
for these temp objects with char number 27 (ESC), and made these names be
ignored for tag update checking.
- Fixed some bugs that were noticable with such excessive re-renders, like
for opening file window, quit during renders.
2013-04-16 17:39:20 +00:00
|
|
|
#include "ED_view3d.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-20 12:47:06 +02:00
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "RE_pipeline.h"
|
Blender Internal Render in viewport
Because of our release soon, feature has been added behind the Debug Menu.
CTRL+ALT+D and set it to -1. Or commandline --debug-value -1.
When debug set to -1, you can put the viewport to 'render' mode, just like
for Cycles. Notes for testers: (and please no bugs in tracker for this :)
- It renders without AA, MBlur, Panorama, Sequence, Composite
- Only active render layer gets rendered. Select another layer will re-render.
- But yes: it works for FreeStyle renders!
- Also does great for local view.
- BI is not well suited for incremental renders on view changes. This only
works for non-raytrace scenes, or zoom in ortho or camera mode, or for
Material changes. In most cases a full re-render is being done.
- ESC works to stop the preview render.
- Borders render as well. (CTRL+B)
- Force a refresh with arrow key left/right. A lot of settings don't trigger
re-render yet.
Tech notes:
- FreeStyle is adding a lot of temp objects/meshes in the Main database. This
caused DepsGraph to trigger changes (and redraws). I've prepended the names
for these temp objects with char number 27 (ESC), and made these names be
ignored for tag update checking.
- Fixed some bugs that were noticable with such excessive re-renders, like
for opening file window, quit during renders.
2013-04-16 17:39:20 +00:00
|
|
|
#include "RE_engine.h"
|
|
|
|
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
#include "IMB_colormanagement.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
#include "BLO_undofile.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
#include "render_intern.h"
|
|
|
|
|
2011-05-19 11:34:11 +00:00
|
|
|
/* Render Callbacks */
|
2013-01-22 02:21:21 +00:00
|
|
|
static int render_break(void *rjv);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2014-01-01 16:59:38 +06:00
|
|
|
typedef struct RenderJob {
|
2019-04-17 06:17:24 +02:00
|
|
|
Main *main;
|
|
|
|
Scene *scene;
|
|
|
|
ViewLayer *single_layer;
|
|
|
|
Scene *current_scene;
|
|
|
|
/* TODO(sergey): Should not be needed once engine will have own
|
|
|
|
* depsgraph and copy-on-write will be implemented.
|
|
|
|
*/
|
|
|
|
Depsgraph *depsgraph;
|
|
|
|
Render *re;
|
|
|
|
struct Object *camera_override;
|
|
|
|
bool v3d_override;
|
|
|
|
bool anim, write_still;
|
|
|
|
Image *image;
|
|
|
|
ImageUser iuser;
|
|
|
|
bool image_outdated;
|
|
|
|
short *stop;
|
|
|
|
short *do_update;
|
|
|
|
float *progress;
|
|
|
|
ReportList *reports;
|
|
|
|
int orig_layer;
|
|
|
|
int last_layer;
|
|
|
|
ScrArea *sa;
|
|
|
|
ColorManagedViewSettings view_settings;
|
|
|
|
ColorManagedDisplaySettings display_settings;
|
|
|
|
bool supports_glsl_draw;
|
|
|
|
bool interface_locked;
|
2014-01-01 16:59:38 +06:00
|
|
|
} RenderJob;
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* called inside thread! */
|
2019-04-17 06:17:24 +02:00
|
|
|
static void image_buffer_rect_update(RenderJob *rj,
|
|
|
|
RenderResult *rr,
|
|
|
|
ImBuf *ibuf,
|
|
|
|
ImageUser *iuser,
|
|
|
|
volatile rcti *renrect,
|
|
|
|
const char *viewname)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = rj->scene;
|
|
|
|
const float *rectf = NULL;
|
|
|
|
int ymin, ymax, xmin, xmax;
|
|
|
|
int rymin, rxmin;
|
|
|
|
int linear_stride, linear_offset_x, linear_offset_y;
|
|
|
|
ColorManagedViewSettings *view_settings;
|
|
|
|
ColorManagedDisplaySettings *display_settings;
|
|
|
|
|
2019-06-18 12:47:16 +02:00
|
|
|
if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* The whole image buffer it so be color managed again anyway. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if renrect argument, we only refresh scanlines */
|
|
|
|
if (renrect) {
|
|
|
|
/* if (ymax == recty), rendering of layer is ready,
|
|
|
|
* we should not draw, other things happen... */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rr->renlay == NULL || renrect->ymax >= rr->recty) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* xmin here is first subrect x coord, xmax defines subrect width */
|
|
|
|
xmin = renrect->xmin + rr->crop;
|
|
|
|
xmax = renrect->xmax - xmin + rr->crop;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (xmax < 2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
ymin = renrect->ymin + rr->crop;
|
|
|
|
ymax = renrect->ymax - ymin + rr->crop;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ymax < 2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
renrect->ymin = renrect->ymax;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xmin = ymin = rr->crop;
|
|
|
|
xmax = rr->rectx - 2 * rr->crop;
|
|
|
|
ymax = rr->recty - 2 * rr->crop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* xmin ymin is in tile coords. transform to ibuf */
|
|
|
|
rxmin = rr->tilerect.xmin + xmin;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rxmin >= ibuf->x) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
rymin = rr->tilerect.ymin + ymin;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rymin >= ibuf->y) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rxmin + xmax > ibuf->x) {
|
2019-04-17 06:17:24 +02:00
|
|
|
xmax = ibuf->x - rxmin;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (rymin + ymax > ibuf->y) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ymax = ibuf->y - rymin;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (xmax < 1 || ymax < 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* The thing here is, the logic below (which was default behavior
|
|
|
|
* of how rectf is acquiring since forever) gives float buffer for
|
|
|
|
* composite output only. This buffer can not be used for other
|
|
|
|
* passes obviously.
|
|
|
|
*
|
|
|
|
* We might try finding corresponding for pass buffer in render result
|
|
|
|
* (which is actually missing when rendering with Cycles, who only
|
|
|
|
* writes all the passes when the tile is finished) or use float
|
|
|
|
* buffer from image buffer as reference, which is easier to use and
|
|
|
|
* contains all the data we need anyway.
|
|
|
|
* - sergey -
|
|
|
|
*/
|
|
|
|
/* TODO(sergey): Need to check has_combined here? */
|
|
|
|
if (iuser->pass == 0) {
|
|
|
|
RenderView *rv;
|
|
|
|
const int view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
|
|
|
|
rv = RE_RenderViewGetById(rr, view_id);
|
|
|
|
|
|
|
|
/* find current float rect for display, first case is after composite... still weak */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rv->rectf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
rectf = rv->rectf;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else {
|
|
|
|
if (rv->rect32) {
|
|
|
|
/* special case, currently only happens with sequencer rendering,
|
|
|
|
* which updates the whole frame, so we can only mark display buffer
|
|
|
|
* as invalid here (sergey)
|
|
|
|
*/
|
|
|
|
ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rr->renlay == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
rectf = RE_RenderLayerGetPass(rr->renlay, RE_PASSNAME_COMBINED, viewname);
|
|
|
|
}
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rectf == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
rectf += 4 * (rr->rectx * ymin + xmin);
|
|
|
|
linear_stride = rr->rectx;
|
|
|
|
linear_offset_x = rxmin;
|
|
|
|
linear_offset_y = rymin;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rectf = ibuf->rect_float;
|
|
|
|
linear_stride = ibuf->x;
|
|
|
|
linear_offset_x = 0;
|
|
|
|
linear_offset_y = 0;
|
|
|
|
}
|
|
|
|
|
2019-06-18 12:36:42 +02:00
|
|
|
view_settings = &scene->view_settings;
|
|
|
|
display_settings = &scene->display_settings;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
IMB_partial_display_buffer_update(ibuf,
|
|
|
|
rectf,
|
|
|
|
NULL,
|
|
|
|
linear_stride,
|
|
|
|
linear_offset_x,
|
|
|
|
linear_offset_y,
|
|
|
|
view_settings,
|
|
|
|
display_settings,
|
|
|
|
rxmin,
|
|
|
|
rymin,
|
|
|
|
rxmin + xmax,
|
2019-06-18 12:36:42 +02:00
|
|
|
rymin + ymax);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************************** render invoking ***************** */
|
|
|
|
|
|
|
|
/* set callbacks, exported to sequence render too.
|
2012-03-03 16:31:46 +00:00
|
|
|
* Only call in foreground (UI) renders. */
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void screen_render_single_layer_set(
|
|
|
|
wmOperator *op, Main *mainp, ViewLayer *active_layer, Scene **scene, ViewLayer **single_layer)
|
2011-10-23 17:52:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* single layer re-render */
|
|
|
|
if (RNA_struct_property_is_set(op->ptr, "scene")) {
|
|
|
|
Scene *scn;
|
|
|
|
char scene_name[MAX_ID_NAME - 2];
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "scene", scene_name);
|
|
|
|
scn = (Scene *)BLI_findstring(&mainp->scenes, scene_name, offsetof(ID, name) + 2);
|
|
|
|
|
|
|
|
if (scn) {
|
|
|
|
/* camera switch wont have updated */
|
|
|
|
scn->r.cfra = (*scene)->r.cfra;
|
|
|
|
BKE_scene_camera_switch_update(scn);
|
|
|
|
|
|
|
|
*scene = scn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RNA_struct_property_is_set(op->ptr, "layer")) {
|
|
|
|
ViewLayer *rl;
|
|
|
|
char rl_name[RE_MAXNAME];
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "layer", rl_name);
|
|
|
|
rl = (ViewLayer *)BLI_findstring(&(*scene)->view_layers, rl_name, offsetof(ViewLayer, name));
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rl) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*single_layer = rl;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (((*scene)->r.scemode & R_SINGLE_LAYER) && active_layer) {
|
|
|
|
*single_layer = active_layer;
|
|
|
|
}
|
2011-10-23 17:52:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* executes blocking render */
|
|
|
|
static int screen_render_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
RenderEngineType *re_type = RE_engines_find(scene->r.engine);
|
|
|
|
ViewLayer *active_layer = CTX_data_view_layer(C);
|
|
|
|
ViewLayer *single_layer = NULL;
|
|
|
|
Render *re;
|
|
|
|
Image *ima;
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
Main *mainp = CTX_data_main(C);
|
|
|
|
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
|
|
|
|
const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
|
|
|
|
struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL;
|
|
|
|
|
|
|
|
/* Cannot do render if there is not this function. */
|
|
|
|
if (re_type->render == NULL) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* custom scene and single layer re-render */
|
|
|
|
screen_render_single_layer_set(op, mainp, active_layer, &scene, &single_layer);
|
|
|
|
|
|
|
|
if (!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
|
|
|
BKE_report(
|
|
|
|
op->reports, RPT_ERROR, "Cannot write a single file with an animation format selected");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
re = RE_NewSceneRender(scene);
|
|
|
|
|
|
|
|
G.is_break = false;
|
|
|
|
RE_test_break_cb(re, NULL, render_break);
|
|
|
|
|
|
|
|
ima = BKE_image_verify_viewer(mainp, IMA_TYPE_R_RESULT, "Render Result");
|
|
|
|
BKE_image_signal(mainp, ima, NULL, IMA_SIGNAL_FREE);
|
|
|
|
BKE_image_backup_render(scene, ima, true);
|
|
|
|
|
|
|
|
/* cleanup sequencer caches before starting user triggered render.
|
|
|
|
* otherwise, invalidated cache entries can make their way into
|
2019-05-06 17:36:34 +02:00
|
|
|
* the output rendering. We can't put that into RE_RenderFrame,
|
2019-04-17 06:17:24 +02:00
|
|
|
* since sequence rendering can call that recursively... (peter) */
|
2019-04-28 14:13:41 -07:00
|
|
|
BKE_sequencer_cache_cleanup(scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
RE_SetReports(re, op->reports);
|
|
|
|
|
|
|
|
BLI_threaded_malloc_begin();
|
2019-04-22 09:19:45 +10:00
|
|
|
if (is_animation) {
|
2019-05-06 17:36:34 +02:00
|
|
|
RE_RenderAnim(re,
|
|
|
|
mainp,
|
|
|
|
scene,
|
|
|
|
single_layer,
|
|
|
|
camera_override,
|
|
|
|
scene->r.sfra,
|
|
|
|
scene->r.efra,
|
|
|
|
scene->r.frame_step);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-05-06 17:36:34 +02:00
|
|
|
RE_RenderFrame(re, mainp, scene, single_layer, camera_override, scene->r.cfra, is_write_still);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_threaded_malloc_end();
|
|
|
|
|
|
|
|
RE_SetReports(re, NULL);
|
|
|
|
|
|
|
|
// no redraw needed, we leave state as we entered it
|
2019-07-25 16:36:22 +02:00
|
|
|
ED_update_for_newframe(mainp, CTX_data_depsgraph_pointer(C));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void render_freejob(void *rjv)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_color_managed_view_settings_free(&rj->view_settings);
|
|
|
|
MEM_freeN(rj);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2010-03-27 15:35:34 +00:00
|
|
|
/* str is IMA_MAX_RENDER_TEXT in size */
|
2014-12-05 21:56:29 +05:00
|
|
|
static void make_renderinfo_string(const RenderStats *rs,
|
|
|
|
const Scene *scene,
|
|
|
|
const bool v3d_override,
|
|
|
|
const char *error,
|
|
|
|
char *str)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char info_time_str[32]; // used to be extern to header_info.c
|
|
|
|
uintptr_t mem_in_use, mmap_in_use, peak_memory;
|
|
|
|
float megs_used_memory, mmap_used_memory, megs_peak_memory;
|
|
|
|
char *spos = str;
|
|
|
|
|
|
|
|
mem_in_use = MEM_get_memory_in_use();
|
|
|
|
mmap_in_use = MEM_get_mapped_memory_in_use();
|
|
|
|
peak_memory = MEM_get_peak_memory();
|
|
|
|
|
|
|
|
megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0);
|
|
|
|
mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0);
|
|
|
|
megs_peak_memory = (peak_memory) / (1024.0 * 1024.0);
|
|
|
|
|
|
|
|
/* local view */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rs->localview) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, "%s | ", TIP_("3D Local View"));
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else if (v3d_override) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, "%s | ", TIP_("3D View"));
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* frame number */
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("Frame:%d "), (scene->r.cfra));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* previous and elapsed time */
|
|
|
|
BLI_timecode_string_from_time_simple(info_time_str, sizeof(info_time_str), rs->lastframetime);
|
|
|
|
|
|
|
|
if (rs->infostr && rs->infostr[0]) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rs->lastframetime != 0.0) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("| Last:%s "), info_time_str);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
spos += sprintf(spos, "| ");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
BLI_timecode_string_from_time_simple(
|
|
|
|
info_time_str, sizeof(info_time_str), PIL_check_seconds_timer() - rs->starttime);
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
spos += sprintf(spos, "| ");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("Time:%s "), info_time_str);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* statistics */
|
|
|
|
if (rs->statstr) {
|
|
|
|
if (rs->statstr[0]) {
|
|
|
|
spos += sprintf(spos, "| %s ", rs->statstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rs->totvert || rs->totface || rs->tothalo || rs->totstrand || rs->totlamp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
spos += sprintf(spos, "| ");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rs->totvert) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("Ve:%d "), rs->totvert);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (rs->totface) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("Fa:%d "), rs->totface);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (rs->tothalo) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("Ha:%d "), rs->tothalo);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (rs->totstrand) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("St:%d "), rs->totstrand);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (rs->totlamp) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("Li:%d "), rs->totlamp);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rs->mem_peak == 0.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
spos += sprintf(spos,
|
2019-06-11 22:25:01 +02:00
|
|
|
TIP_("| Mem:%.2fM (%.2fM, Peak %.2fM) "),
|
2019-04-17 06:17:24 +02:00
|
|
|
megs_used_memory,
|
|
|
|
mmap_used_memory,
|
|
|
|
megs_peak_memory);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("| Mem:%.2fM, Peak: %.2fM "), rs->mem_used, rs->mem_peak);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rs->curfield) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("Field %d "), rs->curfield);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (rs->curblur) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("Blur %d "), rs->curblur);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* full sample */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rs->curfsa) {
|
2019-06-11 22:25:01 +02:00
|
|
|
spos += sprintf(spos, TIP_("| Full Sample %d "), rs->curfsa);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* extra info */
|
|
|
|
if (rs->infostr && rs->infostr[0]) {
|
|
|
|
spos += sprintf(spos, "| %s ", rs->infostr);
|
|
|
|
}
|
|
|
|
else if (error && error[0]) {
|
|
|
|
spos += sprintf(spos, "| %s ", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* very weak... but 512 characters is quite safe */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (spos >= str + IMA_MAX_RENDER_TEXT) {
|
|
|
|
if (G.debug & G_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
printf("WARNING! renderwin text beyond limit\n");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void image_renderinfo_cb(void *rjv, RenderStats *rs)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
|
|
|
RenderResult *rr;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
rr = RE_AcquireResultRead(rj->re);
|
2010-07-05 09:31:24 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (rr) {
|
|
|
|
/* malloc OK here, stats_draw is not in tile threads */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rr->text == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
rr->text = MEM_callocN(IMA_MAX_RENDER_TEXT, "rendertext");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
make_renderinfo_string(rs, rj->scene, rj->v3d_override, rr->error, rr->text);
|
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RE_ReleaseResult(rj->re);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* make jobs timer to send notifier */
|
|
|
|
*(rj->do_update) = true;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-27 08:22:16 +00:00
|
|
|
static void render_progress_update(void *rjv, float progress)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (rj->progress && *rj->progress != progress) {
|
|
|
|
*rj->progress = progress;
|
2011-12-07 11:29:24 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* make jobs timer to send notifier */
|
|
|
|
*(rj->do_update) = true;
|
|
|
|
}
|
2010-05-27 08:22:16 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:42:38 +06:00
|
|
|
/* Not totally reliable, but works fine in most of cases and
|
|
|
|
* in worst case would just make it so extra color management
|
|
|
|
* for the whole render result is applied (which was already
|
|
|
|
* happening already).
|
|
|
|
*/
|
|
|
|
static void render_image_update_pass_and_layer(RenderJob *rj, RenderResult *rr, ImageUser *iuser)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindowManager *wm;
|
|
|
|
ScrArea *first_sa = NULL, *matched_sa = NULL;
|
|
|
|
|
|
|
|
/* image window, compo node users */
|
|
|
|
for (wm = rj->main->wm.first; wm && matched_sa == NULL; wm = wm->id.next) { /* only 1 wm */
|
|
|
|
wmWindow *win;
|
|
|
|
for (win = wm->windows.first; win && matched_sa == NULL; win = win->next) {
|
|
|
|
const bScreen *screen = WM_window_get_active_screen(win);
|
|
|
|
|
|
|
|
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
|
|
|
|
if (sa->spacetype == SPACE_IMAGE) {
|
|
|
|
SpaceImage *sima = sa->spacedata.first;
|
|
|
|
// sa->spacedata might be empty when toggling fullscreen mode.
|
|
|
|
if (sima != NULL && sima->image == rj->image) {
|
|
|
|
if (first_sa == NULL) {
|
|
|
|
first_sa = sa;
|
|
|
|
}
|
|
|
|
if (sa == rj->sa) {
|
|
|
|
matched_sa = sa;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matched_sa == NULL) {
|
|
|
|
matched_sa = first_sa;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matched_sa) {
|
|
|
|
SpaceImage *sima = matched_sa->spacedata.first;
|
|
|
|
RenderResult *main_rr = RE_AcquireResultRead(rj->re);
|
|
|
|
|
|
|
|
/* TODO(sergey): is there faster way to get the layer index? */
|
|
|
|
if (rr->renlay) {
|
|
|
|
int layer = BLI_findstringindex(
|
|
|
|
&main_rr->layers, (char *)rr->renlay->name, offsetof(RenderLayer, name));
|
|
|
|
sima->iuser.layer = layer;
|
|
|
|
rj->last_layer = layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
iuser->pass = sima->iuser.pass;
|
|
|
|
iuser->layer = sima->iuser.layer;
|
|
|
|
|
|
|
|
RE_ReleaseResult(rj->re);
|
|
|
|
}
|
2013-12-17 23:42:38 +06:00
|
|
|
}
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrect)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
|
|
|
Image *ima = rj->image;
|
|
|
|
ImBuf *ibuf;
|
|
|
|
void *lock;
|
|
|
|
const char *viewname = RE_GetActiveRenderView(rj->re);
|
|
|
|
|
|
|
|
/* only update if we are displaying the slot being rendered */
|
|
|
|
if (ima->render_slot != ima->last_render_slot) {
|
|
|
|
rj->image_outdated = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (rj->image_outdated) {
|
|
|
|
/* update entire render */
|
|
|
|
rj->image_outdated = false;
|
|
|
|
BKE_image_signal(rj->main, ima, NULL, IMA_SIGNAL_COLORMANAGE);
|
|
|
|
*(rj->do_update) = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rr == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* update part of render */
|
|
|
|
render_image_update_pass_and_layer(rj, rr, &rj->iuser);
|
|
|
|
ibuf = BKE_image_acquire_ibuf(ima, &rj->iuser, &lock);
|
|
|
|
if (ibuf) {
|
|
|
|
/* Don't waste time on CPU side color management if
|
|
|
|
* image will be displayed using GLSL.
|
|
|
|
*
|
|
|
|
* Need to update rect if Save Buffers enabled because in
|
|
|
|
* this case GLSL doesn't have original float buffer to
|
|
|
|
* operate with.
|
|
|
|
*/
|
2019-06-18 12:47:16 +02:00
|
|
|
if (!rj->supports_glsl_draw || ibuf->channels == 1 ||
|
2019-04-20 12:47:06 +02:00
|
|
|
ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
image_buffer_rect_update(rj, rr, ibuf, &rj->iuser, renrect, viewname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make jobs timer to send notifier */
|
|
|
|
*(rj->do_update) = true;
|
|
|
|
}
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 14:52:19 +02:00
|
|
|
static void current_scene_update(void *rjv, Scene *scene)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
|
|
|
rj->current_scene = scene;
|
|
|
|
rj->iuser.scene = scene;
|
2014-05-02 14:52:19 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 08:22:16 +00:00
|
|
|
static void render_startjob(void *rjv, short *stop, short *do_update, float *progress)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
|
|
|
|
|
|
|
rj->stop = stop;
|
|
|
|
rj->do_update = do_update;
|
|
|
|
rj->progress = progress;
|
|
|
|
|
|
|
|
RE_SetReports(rj->re, rj->reports);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rj->anim) {
|
2019-05-06 17:36:34 +02:00
|
|
|
RE_RenderAnim(rj->re,
|
|
|
|
rj->main,
|
|
|
|
rj->scene,
|
|
|
|
rj->single_layer,
|
|
|
|
rj->camera_override,
|
|
|
|
rj->scene->r.sfra,
|
|
|
|
rj->scene->r.efra,
|
|
|
|
rj->scene->r.frame_step);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RE_RenderFrame(rj->re,
|
2019-04-17 06:17:24 +02:00
|
|
|
rj->main,
|
|
|
|
rj->scene,
|
|
|
|
rj->single_layer,
|
|
|
|
rj->camera_override,
|
2019-05-06 17:36:34 +02:00
|
|
|
rj->scene->r.cfra,
|
|
|
|
rj->write_still);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
RE_SetReports(rj->re, NULL);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:42:38 +06:00
|
|
|
static void render_image_restore_layer(RenderJob *rj)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindowManager *wm;
|
|
|
|
|
|
|
|
/* image window, compo node users */
|
|
|
|
for (wm = rj->main->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
|
|
|
|
wmWindow *win;
|
|
|
|
for (win = wm->windows.first; win; win = win->next) {
|
|
|
|
const bScreen *screen = WM_window_get_active_screen(win);
|
|
|
|
|
|
|
|
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
|
|
|
|
if (sa == rj->sa) {
|
|
|
|
if (sa->spacetype == SPACE_IMAGE) {
|
|
|
|
SpaceImage *sima = sa->spacedata.first;
|
|
|
|
|
|
|
|
if (RE_HasSingleLayer(rj->re)) {
|
|
|
|
/* For single layer renders keep the active layer
|
|
|
|
* visible, or show the compositing result. */
|
|
|
|
RenderResult *rr = RE_AcquireResultRead(rj->re);
|
|
|
|
if (RE_HasCombinedLayer(rr)) {
|
|
|
|
sima->iuser.layer = 0;
|
|
|
|
}
|
|
|
|
RE_ReleaseResult(rj->re);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* For multiple layer render, set back the layer
|
|
|
|
* that was set at the start of rendering. */
|
|
|
|
sima->iuser.layer = rj->orig_layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-17 23:42:38 +06:00
|
|
|
}
|
|
|
|
|
2010-04-15 10:28:32 +00:00
|
|
|
static void render_endjob(void *rjv)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
|
|
|
|
|
|
|
/* this render may be used again by the sequencer without the active
|
|
|
|
* 'Render' where the callbacks would be re-assigned. assign dummy callbacks
|
|
|
|
* to avoid referencing freed renderjobs bug T24508. */
|
|
|
|
RE_InitRenderCB(rj->re);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rj->main != G_MAIN) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_main_free(rj->main);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* else the frame will not update for the original value */
|
|
|
|
if (rj->anim && !(rj->scene->r.scemode & R_NO_FRAME_UPDATE)) {
|
|
|
|
/* possible this fails of loading new file while rendering */
|
|
|
|
if (G_MAIN->wm.first) {
|
|
|
|
ED_update_for_newframe(G_MAIN, rj->depsgraph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX above function sets all tags in nodes */
|
|
|
|
ntreeCompositClearTags(rj->scene->nodetree);
|
|
|
|
|
|
|
|
/* potentially set by caller */
|
|
|
|
rj->scene->r.scemode &= ~R_NO_FRAME_UPDATE;
|
|
|
|
|
|
|
|
if (rj->single_layer) {
|
|
|
|
nodeUpdateID(rj->scene->nodetree, &rj->scene->id);
|
|
|
|
WM_main_add_notifier(NC_NODE | NA_EDITED, rj->scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rj->sa) {
|
|
|
|
render_image_restore_layer(rj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX render stability hack */
|
|
|
|
G.is_rendering = false;
|
|
|
|
WM_main_add_notifier(NC_SCENE | ND_RENDER_RESULT, NULL);
|
|
|
|
|
|
|
|
/* Partial render result will always update display buffer
|
|
|
|
* for first render layer only. This is nice because you'll
|
|
|
|
* see render progress during rendering, but it ends up in
|
|
|
|
* wrong display buffer shown after rendering.
|
|
|
|
*
|
|
|
|
* The code below will mark display buffer as invalid after
|
|
|
|
* rendering in case multiple layers were rendered, which
|
|
|
|
* ensures display buffer matches render layer after
|
|
|
|
* rendering.
|
|
|
|
*
|
|
|
|
* Perhaps proper way would be to toggle active render
|
|
|
|
* layer in image editor and job, so we always display
|
|
|
|
* layer being currently rendered. But this is not so much
|
|
|
|
* trivial at this moment, especially because of external
|
|
|
|
* engine API, so lets use simple and robust way for now
|
|
|
|
* - sergey -
|
|
|
|
*/
|
|
|
|
if (rj->scene->view_layers.first != rj->scene->view_layers.last || rj->image_outdated) {
|
|
|
|
void *lock;
|
|
|
|
Image *ima = rj->image;
|
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &rj->iuser, &lock);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally unlock the user interface (if it was locked). */
|
|
|
|
if (rj->interface_locked) {
|
|
|
|
/* Interface was locked, so window manager couldn't have been changed
|
|
|
|
* and using one from Global will unlock exactly the same manager as
|
|
|
|
* was locked before running the job.
|
|
|
|
*/
|
|
|
|
WM_set_locked_interface(G_MAIN->wm.first, false);
|
|
|
|
DEG_on_visible_update(G_MAIN, false);
|
|
|
|
}
|
2010-04-15 10:28:32 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* called by render, check job 'stop' value or the global */
|
|
|
|
static int render_breakjob(void *rjv)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.is_break) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (rj->stop && *(rj->stop)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 02:21:21 +00:00
|
|
|
/* for exec() when there is no render job
|
|
|
|
* note: this wont check for the escape key being pressed, but doing so isnt threadsafe */
|
|
|
|
static int render_break(void *UNUSED(rjv))
|
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.is_break) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2013-01-22 02:21:21 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 17:11:32 +00:00
|
|
|
/* runs in thread, no cursor setting here works. careful with notifiers too (malloc conflicts) */
|
2018-09-27 15:35:22 +02:00
|
|
|
/* maybe need a way to get job send notifier? */
|
Option to lock the interface while rendering
Added function called WM_set_locked_interface which does
two things:
- Prevents event queue from being handled, so no operators
(see below) or values are even possible to run or change.
This prevents any kind of "destructive" action performed
from user while rendering.
- Locks interface refresh for regions which does have lock
set to truth in their template. Currently it's just a 3D
viewport, but in the future more regions could be considered
unsafe, or we could want to lock different parts of
interface when doing different jobs.
This is needed because 3D viewport could be using or changing
the same data as renderer currently uses, leading to threading
conflict.
Notifiers are still allowed to handle, so render progress is
seen on the screen, but would need to doublecheck on this, in
terms some notifiers could be changing the data.
For now interface locking happens for render job only in case
"Lock Interface" checkbox is enabled.
Other tools like backing would also benefit of this option.
It is possible to mark operator as safe to be used in locked
interface mode by adding OPTYPE_ALLOW_LOCKED bit to operator
template flags.
This bit is completely handled by wm_evem_system, not
with operator run routines, so it's still possible to
run operators from drivers and handlers.
Currently allowed image editor navigation and zooming.
Reviewers: brecht, campbellbarton
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D142
2014-01-29 16:07:14 +06:00
|
|
|
static void render_drawlock(void *rjv, int lock)
|
2011-03-25 17:11:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderJob *rj = rjv;
|
Option to lock the interface while rendering
Added function called WM_set_locked_interface which does
two things:
- Prevents event queue from being handled, so no operators
(see below) or values are even possible to run or change.
This prevents any kind of "destructive" action performed
from user while rendering.
- Locks interface refresh for regions which does have lock
set to truth in their template. Currently it's just a 3D
viewport, but in the future more regions could be considered
unsafe, or we could want to lock different parts of
interface when doing different jobs.
This is needed because 3D viewport could be using or changing
the same data as renderer currently uses, leading to threading
conflict.
Notifiers are still allowed to handle, so render progress is
seen on the screen, but would need to doublecheck on this, in
terms some notifiers could be changing the data.
For now interface locking happens for render job only in case
"Lock Interface" checkbox is enabled.
Other tools like backing would also benefit of this option.
It is possible to mark operator as safe to be used in locked
interface mode by adding OPTYPE_ALLOW_LOCKED bit to operator
template flags.
This bit is completely handled by wm_evem_system, not
with operator run routines, so it's still possible to
run operators from drivers and handlers.
Currently allowed image editor navigation and zooming.
Reviewers: brecht, campbellbarton
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D142
2014-01-29 16:07:14 +06:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* If interface is locked, renderer callback shall do nothing. */
|
|
|
|
if (!rj->interface_locked) {
|
|
|
|
BKE_spacedata_draw_locks(lock);
|
|
|
|
}
|
2011-03-25 17:11:32 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* catch esc */
|
2013-03-13 09:03:46 +00:00
|
|
|
static int screen_render_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = (Scene *)op->customdata;
|
|
|
|
|
|
|
|
/* no running blender, remove handler and pass through */
|
|
|
|
if (0 == WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER)) {
|
|
|
|
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* running render */
|
|
|
|
switch (event->type) {
|
|
|
|
case ESCKEY:
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
static void screen_render_cancel(bContext *C, wmOperator *op)
|
2013-09-23 19:35:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
Scene *scene = (Scene *)op->customdata;
|
2013-09-23 19:35:21 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* kill on cancel, because job is using op->reports */
|
|
|
|
WM_jobs_kill_type(wm, scene, WM_JOB_TYPE_RENDER);
|
2013-09-23 19:35:21 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 17:15:03 -02:00
|
|
|
static void clean_viewport_memory_base(Base *base)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((base->flag & BASE_VISIBLE) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-16 17:15:03 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *object = base->object;
|
2017-10-16 17:15:03 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (object->id.tag & LIB_TAG_DOIT) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-16 17:15:03 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
object->id.tag &= ~LIB_TAG_DOIT;
|
|
|
|
if (RE_allow_render_generic_object(object)) {
|
|
|
|
BKE_object_free_derived_caches(object);
|
|
|
|
}
|
2017-10-16 17:15:03 -02:00
|
|
|
}
|
|
|
|
|
2017-02-15 14:40:41 +01:00
|
|
|
static void clean_viewport_memory(Main *bmain, Scene *scene)
|
Option to lock the interface while rendering
Added function called WM_set_locked_interface which does
two things:
- Prevents event queue from being handled, so no operators
(see below) or values are even possible to run or change.
This prevents any kind of "destructive" action performed
from user while rendering.
- Locks interface refresh for regions which does have lock
set to truth in their template. Currently it's just a 3D
viewport, but in the future more regions could be considered
unsafe, or we could want to lock different parts of
interface when doing different jobs.
This is needed because 3D viewport could be using or changing
the same data as renderer currently uses, leading to threading
conflict.
Notifiers are still allowed to handle, so render progress is
seen on the screen, but would need to doublecheck on this, in
terms some notifiers could be changing the data.
For now interface locking happens for render job only in case
"Lock Interface" checkbox is enabled.
Other tools like backing would also benefit of this option.
It is possible to mark operator as safe to be used in locked
interface mode by adding OPTYPE_ALLOW_LOCKED bit to operator
template flags.
This bit is completely handled by wm_evem_system, not
with operator run routines, so it's still possible to
run operators from drivers and handlers.
Currently allowed image editor navigation and zooming.
Reviewers: brecht, campbellbarton
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D142
2014-01-29 16:07:14 +06:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *sce_iter;
|
|
|
|
Base *base;
|
|
|
|
|
|
|
|
/* Tag all the available objects. */
|
|
|
|
BKE_main_id_tag_listbase(&bmain->objects, LIB_TAG_DOIT, true);
|
|
|
|
|
|
|
|
/* Go over all the visible objects. */
|
|
|
|
for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
|
|
|
|
for (wmWindow *win = wm->windows.first; win; win = win->next) {
|
|
|
|
ViewLayer *view_layer = WM_window_get_active_view_layer(win);
|
|
|
|
|
|
|
|
for (base = view_layer->object_bases.first; base; base = base->next) {
|
|
|
|
clean_viewport_memory_base(base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SETLOOPER_SET_ONLY(scene, sce_iter, base)) {
|
|
|
|
clean_viewport_memory_base(base);
|
|
|
|
}
|
Option to lock the interface while rendering
Added function called WM_set_locked_interface which does
two things:
- Prevents event queue from being handled, so no operators
(see below) or values are even possible to run or change.
This prevents any kind of "destructive" action performed
from user while rendering.
- Locks interface refresh for regions which does have lock
set to truth in their template. Currently it's just a 3D
viewport, but in the future more regions could be considered
unsafe, or we could want to lock different parts of
interface when doing different jobs.
This is needed because 3D viewport could be using or changing
the same data as renderer currently uses, leading to threading
conflict.
Notifiers are still allowed to handle, so render progress is
seen on the screen, but would need to doublecheck on this, in
terms some notifiers could be changing the data.
For now interface locking happens for render job only in case
"Lock Interface" checkbox is enabled.
Other tools like backing would also benefit of this option.
It is possible to mark operator as safe to be used in locked
interface mode by adding OPTYPE_ALLOW_LOCKED bit to operator
template flags.
This bit is completely handled by wm_evem_system, not
with operator run routines, so it's still possible to
run operators from drivers and handlers.
Currently allowed image editor navigation and zooming.
Reviewers: brecht, campbellbarton
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D142
2014-01-29 16:07:14 +06:00
|
|
|
}
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* using context, starts job */
|
2013-03-13 09:03:46 +00:00
|
|
|
static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* new render clears all callbacks */
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ViewLayer *active_layer = CTX_data_view_layer(C);
|
|
|
|
ViewLayer *single_layer = NULL;
|
|
|
|
RenderEngineType *re_type = RE_engines_find(scene->r.engine);
|
|
|
|
Render *re;
|
|
|
|
wmJob *wm_job;
|
|
|
|
RenderJob *rj;
|
|
|
|
Image *ima;
|
|
|
|
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
|
|
|
|
const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
|
|
|
|
const bool use_viewport = RNA_boolean_get(op->ptr, "use_viewport");
|
|
|
|
View3D *v3d = use_viewport ? CTX_wm_view3d(C) : NULL;
|
|
|
|
struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL;
|
|
|
|
const char *name;
|
|
|
|
ScrArea *sa;
|
|
|
|
|
|
|
|
/* Cannot do render if there is not this function. */
|
|
|
|
if (re_type->render == NULL) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* custom scene and single layer re-render */
|
|
|
|
screen_render_single_layer_set(op, bmain, active_layer, &scene, &single_layer);
|
|
|
|
|
|
|
|
/* only one render job at a time */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (!RE_is_rendering_allowed(scene, single_layer, camera_override, op->reports)) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
|
|
|
BKE_report(
|
|
|
|
op->reports, RPT_ERROR, "Cannot write a single file with an animation format selected");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stop all running jobs, except screen one. currently previews frustrate Render */
|
|
|
|
WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C));
|
|
|
|
|
|
|
|
/* cancel animation playback */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ED_screen_animation_playing(CTX_wm_manager(C))) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ED_screen_animation_play(C, 0, 0);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* handle UI stuff */
|
|
|
|
WM_cursor_wait(1);
|
|
|
|
|
|
|
|
/* flush sculpt and editmode changes */
|
|
|
|
ED_editors_flush_edits(bmain, true);
|
|
|
|
|
|
|
|
/* cleanup sequencer caches before starting user triggered render.
|
|
|
|
* otherwise, invalidated cache entries can make their way into
|
2019-05-06 17:36:34 +02:00
|
|
|
* the output rendering. We can't put that into RE_RenderFrame,
|
2019-04-17 06:17:24 +02:00
|
|
|
* since sequence rendering can call that recursively... (peter) */
|
2019-04-28 14:13:41 -07:00
|
|
|
BKE_sequencer_cache_cleanup(scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
// store spare
|
|
|
|
// get view3d layer, local layer, make this nice api call to render
|
|
|
|
// store spare
|
|
|
|
|
|
|
|
/* ensure at least 1 area shows result */
|
|
|
|
sa = render_view_open(C, event->x, event->y, op->reports);
|
|
|
|
|
|
|
|
/* job custom data */
|
|
|
|
rj = MEM_callocN(sizeof(RenderJob), "render job");
|
|
|
|
rj->main = bmain;
|
|
|
|
rj->scene = scene;
|
|
|
|
rj->current_scene = rj->scene;
|
|
|
|
rj->single_layer = single_layer;
|
2019-07-25 16:36:22 +02:00
|
|
|
/* TODO(sergey): Render engine should be using own depsgraph.
|
|
|
|
*
|
|
|
|
* NOTE: Currently is only used by ED_update_for_newframe() at the end of the render, so no
|
|
|
|
* need to ensure evaluation here. */
|
|
|
|
rj->depsgraph = CTX_data_depsgraph_pointer(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
rj->camera_override = camera_override;
|
|
|
|
rj->anim = is_animation;
|
|
|
|
rj->write_still = is_write_still && !is_animation;
|
|
|
|
rj->iuser.scene = scene;
|
|
|
|
rj->iuser.ok = 1;
|
|
|
|
rj->reports = op->reports;
|
|
|
|
rj->orig_layer = 0;
|
|
|
|
rj->last_layer = 0;
|
|
|
|
rj->sa = sa;
|
|
|
|
rj->supports_glsl_draw = IMB_colormanagement_support_glsl_draw(&scene->view_settings);
|
|
|
|
|
|
|
|
BKE_color_managed_display_settings_copy(&rj->display_settings, &scene->display_settings);
|
|
|
|
BKE_color_managed_view_settings_copy(&rj->view_settings, &scene->view_settings);
|
|
|
|
|
|
|
|
if (sa) {
|
|
|
|
SpaceImage *sima = sa->spacedata.first;
|
|
|
|
rj->orig_layer = sima->iuser.layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v3d) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (camera_override && camera_override != scene->camera) {
|
2019-04-17 06:17:24 +02:00
|
|
|
rj->v3d_override = true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lock the user interface depending on render settings. */
|
|
|
|
if (scene->r.use_lock_interface) {
|
|
|
|
WM_set_locked_interface(CTX_wm_manager(C), true);
|
|
|
|
|
|
|
|
/* Set flag interface need to be unlocked.
|
|
|
|
*
|
|
|
|
* This is so because we don't have copy of render settings
|
|
|
|
* accessible from render job and copy is needed in case
|
|
|
|
* of non-locked rendering, so we wouldn't try to unlock
|
|
|
|
* anything if option was initially unset but then was
|
|
|
|
* enabled during rendering.
|
|
|
|
*/
|
|
|
|
rj->interface_locked = true;
|
|
|
|
|
|
|
|
/* Clean memory used by viewport? */
|
|
|
|
clean_viewport_memory(rj->main, scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup job */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (RE_seq_render_active(scene, &scene->r)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
name = "Sequence Render";
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
name = "Render";
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-07-01 15:23:42 +02:00
|
|
|
wm_job = WM_jobs_get(CTX_wm_manager(C),
|
|
|
|
CTX_wm_window(C),
|
|
|
|
scene,
|
|
|
|
name,
|
|
|
|
WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS,
|
|
|
|
WM_JOB_TYPE_RENDER);
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_jobs_customdata_set(wm_job, rj, render_freejob);
|
|
|
|
WM_jobs_timer(wm_job, 0.2, NC_SCENE | ND_RENDER_RESULT, 0);
|
|
|
|
WM_jobs_callbacks(wm_job, render_startjob, NULL, NULL, render_endjob);
|
|
|
|
|
2019-07-01 15:23:42 +02:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "layer")) {
|
|
|
|
WM_jobs_delay_start(wm_job, 0.2);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* get a render result image, and make sure it is empty */
|
|
|
|
ima = BKE_image_verify_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result");
|
|
|
|
BKE_image_signal(rj->main, ima, NULL, IMA_SIGNAL_FREE);
|
|
|
|
BKE_image_backup_render(rj->scene, ima, true);
|
|
|
|
rj->image = ima;
|
|
|
|
|
|
|
|
/* setup new render */
|
|
|
|
re = RE_NewSceneRender(scene);
|
|
|
|
RE_test_break_cb(re, rj, render_breakjob);
|
|
|
|
RE_draw_lock_cb(re, rj, render_drawlock);
|
|
|
|
RE_display_update_cb(re, rj, image_rect_update);
|
|
|
|
RE_current_scene_update_cb(re, rj, current_scene_update);
|
|
|
|
RE_stats_draw_cb(re, rj, image_renderinfo_cb);
|
|
|
|
RE_progress_cb(re, rj, render_progress_update);
|
|
|
|
RE_gl_context_create(re);
|
|
|
|
|
|
|
|
rj->re = re;
|
|
|
|
G.is_break = false;
|
|
|
|
|
|
|
|
/* store actual owner of job, so modal operator could check for it,
|
|
|
|
* the reason of this is that active scene could change when rendering
|
|
|
|
* several layers from compositor [#31800]
|
|
|
|
*/
|
|
|
|
op->customdata = scene;
|
|
|
|
|
|
|
|
WM_jobs_start(CTX_wm_manager(C), wm_job);
|
|
|
|
|
|
|
|
WM_cursor_wait(0);
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
|
|
|
|
|
|
|
|
/* we set G.is_rendering here already instead of only in the job, this ensure
|
|
|
|
* main loop or other scene updates are disabled in time, since they may
|
|
|
|
* have started before the job thread */
|
|
|
|
G.is_rendering = true;
|
|
|
|
|
|
|
|
/* add modal handler for ESC */
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* contextual render, using current scene, view3d? */
|
|
|
|
void RENDER_OT_render(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Render";
|
|
|
|
ot->description = "Render active scene";
|
|
|
|
ot->idname = "RENDER_OT_render";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke = screen_render_invoke;
|
|
|
|
ot->modal = screen_render_modal;
|
|
|
|
ot->cancel = screen_render_cancel;
|
|
|
|
ot->exec = screen_render_exec;
|
|
|
|
|
2019-04-29 19:29:41 +10:00
|
|
|
/* this isn't needed, causes failer in background mode */
|
|
|
|
#if 0
|
|
|
|
ot->poll = ED_operator_screenactive;
|
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
"animation",
|
|
|
|
0,
|
|
|
|
"Animation",
|
|
|
|
"Render files from the animation range of this scene");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
RNA_def_boolean(
|
|
|
|
ot->srna,
|
|
|
|
"write_still",
|
|
|
|
0,
|
|
|
|
"Write Image",
|
|
|
|
"Save rendered the image to the output path (used only when animation is disabled)");
|
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
"use_viewport",
|
|
|
|
0,
|
|
|
|
"Use 3D Viewport",
|
|
|
|
"When inside a 3D viewport, use layers and camera of the viewport");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
prop = RNA_def_string(ot->srna,
|
|
|
|
"layer",
|
|
|
|
NULL,
|
|
|
|
RE_MAXNAME,
|
|
|
|
"Render Layer",
|
|
|
|
"Single render layer to re-render (used only when animation is disabled)");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
prop = RNA_def_string(ot->srna,
|
|
|
|
"scene",
|
|
|
|
NULL,
|
|
|
|
MAX_ID_NAME - 2,
|
|
|
|
"Scene",
|
|
|
|
"Scene to render, current scene if not specified");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 17:20:31 +00:00
|
|
|
Scene *ED_render_job_get_scene(const bContext *C)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
RenderJob *rj = (RenderJob *)WM_jobs_customdata_from_type(wm, WM_JOB_TYPE_RENDER);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rj) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return rj->scene;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2013-10-31 17:20:31 +00:00
|
|
|
}
|
2015-03-11 00:01:53 +05:00
|
|
|
|
|
|
|
Scene *ED_render_job_get_current_scene(const bContext *C)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
RenderJob *rj = (RenderJob *)WM_jobs_customdata_from_type(wm, WM_JOB_TYPE_RENDER);
|
|
|
|
if (rj) {
|
|
|
|
return rj->current_scene;
|
|
|
|
}
|
|
|
|
return NULL;
|
2015-03-11 00:01:53 +05:00
|
|
|
}
|
2015-10-27 19:00:51 +05:00
|
|
|
|
|
|
|
/* Motion blur curve preset */
|
|
|
|
|
|
|
|
static int render_shutter_curve_preset_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
CurveMapping *mblur_shutter_curve = &scene->r.mblur_shutter_curve;
|
|
|
|
CurveMap *cm = mblur_shutter_curve->cm;
|
|
|
|
int preset = RNA_enum_get(op->ptr, "shape");
|
|
|
|
|
|
|
|
cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
|
|
|
|
mblur_shutter_curve->preset = preset;
|
2019-08-07 03:21:55 +10:00
|
|
|
BKE_curvemap_reset(
|
2019-04-17 06:17:24 +02:00
|
|
|
cm, &mblur_shutter_curve->clipr, mblur_shutter_curve->preset, CURVEMAP_SLOPE_POS_NEG);
|
2019-08-07 03:21:55 +10:00
|
|
|
BKE_curvemapping_changed(mblur_shutter_curve, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2015-10-27 19:00:51 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RENDER_OT_shutter_curve_preset(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
static const EnumPropertyItem prop_shape_items[] = {
|
|
|
|
{CURVE_PRESET_SHARP, "SHARP", 0, "Sharp", ""},
|
|
|
|
{CURVE_PRESET_SMOOTH, "SMOOTH", 0, "Smooth", ""},
|
|
|
|
{CURVE_PRESET_MAX, "MAX", 0, "Max", ""},
|
|
|
|
{CURVE_PRESET_LINE, "LINE", 0, "Line", ""},
|
|
|
|
{CURVE_PRESET_ROUND, "ROUND", 0, "Round", ""},
|
|
|
|
{CURVE_PRESET_ROOT, "ROOT", 0, "Root", ""},
|
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
ot->name = "Shutter Curve Preset";
|
|
|
|
ot->description = "Set shutter curve";
|
|
|
|
ot->idname = "RENDER_OT_shutter_curve_preset";
|
|
|
|
|
|
|
|
ot->exec = render_shutter_curve_preset_exec;
|
|
|
|
|
|
|
|
prop = RNA_def_enum(ot->srna, "shape", prop_shape_items, CURVE_PRESET_SMOOTH, "Mode", "");
|
|
|
|
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
|
2015-10-27 19:00:51 +05:00
|
|
|
}
|