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
|
2019-11-05 16:55:51 +01:00
|
|
|
* \ingroup render
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stddef.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <string.h>
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2019-12-18 15:19:59 +01:00
|
|
|
#include "BLI_bitmap.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_blenlib.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BLI_math.h"
|
2014-06-14 03:25:07 +10:00
|
|
|
#include "BLI_math_color_blend.h"
|
2016-09-16 10:28:41 +02:00
|
|
|
#include "BLI_task.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_threads.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#include "DNA_camera_types.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-12-18 15:19:59 +01:00
|
|
|
#include "DNA_action_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_anim_types.h"
|
2019-12-18 15:19:59 +01:00
|
|
|
#include "DNA_curve_types.h"
|
2016-08-03 23:31:48 +02:00
|
|
|
#include "DNA_gpencil_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2020-04-03 13:07:36 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2015-02-12 18:54:41 +01:00
|
|
|
#include "BKE_camera.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_context.h"
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
#include "BKE_customdata.h"
|
2019-12-18 15:19:59 +01:00
|
|
|
#include "BKE_fcurve.h"
|
2012-01-13 06:59:16 +00:00
|
|
|
#include "BKE_global.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_image.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_query.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_report.h"
|
|
|
|
#include "BKE_scene.h"
|
2012-03-29 23:33:50 +00:00
|
|
|
#include "BKE_sequencer.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_writeavi.h"
|
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2019-06-11 15:40:03 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-07-21 11:53:13 +02:00
|
|
|
|
2018-02-26 19:41:17 +01:00
|
|
|
#include "DRW_engine.h"
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_gpencil.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_view3d.h"
|
2020-03-06 12:08:03 +01:00
|
|
|
#include "ED_view3d_offscreen.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
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"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
#include "RE_pipeline.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
#include "GPU_framebuffer.h"
|
2017-03-21 16:08:14 -04:00
|
|
|
#include "GPU_matrix.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
#include "render_intern.h"
|
|
|
|
|
2016-09-15 15:04:19 +02:00
|
|
|
/* Define this to get timing information. */
|
2019-11-05 16:55:51 +01:00
|
|
|
// #define DEBUG_TIME
|
2016-09-15 15:04:19 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_TIME
|
|
|
|
# include "PIL_time.h"
|
|
|
|
#endif
|
|
|
|
|
2016-10-07 17:46:13 +02:00
|
|
|
// TODO(sergey): Find better approximation of the scheduled frames.
|
|
|
|
// For really highres renders it might fail still.
|
|
|
|
#define MAX_SCHEDULED_FRAMES 8
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
typedef struct OGLRender {
|
2019-04-17 06:17:24 +02:00
|
|
|
Main *bmain;
|
|
|
|
Render *re;
|
|
|
|
Scene *scene;
|
|
|
|
WorkSpace *workspace;
|
|
|
|
ViewLayer *view_layer;
|
|
|
|
Depsgraph *depsgraph;
|
|
|
|
|
|
|
|
View3D *v3d;
|
|
|
|
RegionView3D *rv3d;
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
ScrArea *prevsa;
|
|
|
|
ARegion *prevar;
|
|
|
|
|
|
|
|
int views_len; /* multi-view views */
|
|
|
|
|
|
|
|
bool is_sequencer;
|
|
|
|
SpaceSeq *sseq;
|
|
|
|
struct {
|
|
|
|
ImBuf **ibufs_arr;
|
|
|
|
} seq_data;
|
|
|
|
|
|
|
|
Image *ima;
|
|
|
|
ImageUser iuser;
|
|
|
|
|
|
|
|
GPUOffScreen *ofs;
|
|
|
|
int sizex, sizey;
|
|
|
|
int write_still;
|
|
|
|
|
|
|
|
ReportList *reports;
|
|
|
|
bMovieHandle *mh;
|
|
|
|
int cfrao, nfra;
|
|
|
|
|
|
|
|
int totvideos;
|
|
|
|
|
2019-12-18 15:19:59 +01:00
|
|
|
/* For only rendering frames that have a key in animation data. */
|
2019-12-20 10:42:32 +11:00
|
|
|
BLI_bitmap *render_frames;
|
2019-12-18 15:19:59 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* quick lookup */
|
|
|
|
int view_id;
|
|
|
|
|
|
|
|
/* wm vars for timer and progress cursor */
|
|
|
|
wmWindowManager *wm;
|
|
|
|
wmWindow *win;
|
|
|
|
|
|
|
|
wmTimer *timer; /* use to check if running modal or not (invoke'd or exec'd)*/
|
|
|
|
void **movie_ctx_arr;
|
|
|
|
|
|
|
|
TaskPool *task_pool;
|
|
|
|
bool pool_ok;
|
|
|
|
bool is_animation;
|
2019-11-05 16:55:51 +01:00
|
|
|
|
|
|
|
eImageFormatDepth color_depth;
|
2019-04-17 06:17:24 +02:00
|
|
|
SpinLock reports_lock;
|
2020-04-03 16:21:24 +11:00
|
|
|
uint num_scheduled_frames;
|
2019-04-17 06:17:24 +02:00
|
|
|
ThreadMutex task_mutex;
|
|
|
|
ThreadCondition task_condition;
|
2016-09-16 10:28:41 +02:00
|
|
|
|
2016-09-15 15:04:19 +02:00
|
|
|
#ifdef DEBUG_TIME
|
2019-04-17 06:17:24 +02:00
|
|
|
double time_start;
|
2016-09-15 15:04:19 +02:00
|
|
|
#endif
|
2010-03-08 16:36:53 +00:00
|
|
|
} OGLRender;
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
static bool screen_opengl_is_multiview(OGLRender *oglrender)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
View3D *v3d = oglrender->v3d;
|
|
|
|
RegionView3D *rv3d = oglrender->rv3d;
|
|
|
|
RenderData *rd = &oglrender->scene->r;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((rd == NULL) || ((v3d != NULL) && (rv3d == NULL))) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (rd->scemode & R_MULTIVIEW) &&
|
|
|
|
((v3d == NULL) || (rv3d->persp == RV3D_CAMOB && v3d->camera));
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void screen_opengl_views_setup(OGLRender *oglrender)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderResult *rr;
|
|
|
|
RenderView *rv;
|
|
|
|
SceneRenderView *srv;
|
|
|
|
bool is_multiview;
|
|
|
|
Object *camera;
|
|
|
|
View3D *v3d = oglrender->v3d;
|
|
|
|
|
|
|
|
RenderData *rd = &oglrender->scene->r;
|
|
|
|
|
|
|
|
rr = RE_AcquireResultWrite(oglrender->re);
|
|
|
|
|
|
|
|
is_multiview = screen_opengl_is_multiview(oglrender);
|
|
|
|
|
|
|
|
if (!is_multiview) {
|
|
|
|
/* we only have one view when multiview is off */
|
|
|
|
rv = rr->views.first;
|
|
|
|
|
|
|
|
if (rv == NULL) {
|
|
|
|
rv = MEM_callocN(sizeof(RenderView), "new opengl render view");
|
|
|
|
BLI_addtail(&rr->views, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (rv->next) {
|
|
|
|
RenderView *rv_del = rv->next;
|
|
|
|
BLI_remlink(&rr->views, rv_del);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rv_del->rectf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(rv_del->rectf);
|
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 (rv_del->rectz) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(rv_del->rectz);
|
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 (rv_del->rect32) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(rv_del->rect32);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
MEM_freeN(rv_del);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (v3d) {
|
|
|
|
RE_SetOverrideCamera(oglrender->re, V3D_CAMERA_SCENE(oglrender->scene, v3d));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove all the views that are not needed */
|
|
|
|
rv = rr->views.last;
|
|
|
|
while (rv) {
|
|
|
|
srv = BLI_findstring(&rd->views, rv->name, offsetof(SceneRenderView, name));
|
|
|
|
if (BKE_scene_multiview_is_render_view_active(rd, srv)) {
|
|
|
|
rv = rv->prev;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RenderView *rv_del = rv;
|
|
|
|
rv = rv_del->prev;
|
|
|
|
|
|
|
|
BLI_remlink(&rr->views, rv_del);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (rv_del->rectf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(rv_del->rectf);
|
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 (rv_del->rectz) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(rv_del->rectz);
|
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 (rv_del->rect32) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(rv_del->rect32);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
MEM_freeN(rv_del);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create all the views that are needed */
|
|
|
|
for (srv = rd->views.first; srv; srv = srv->next) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
rv = BLI_findstring(&rr->views, srv->name, offsetof(SceneRenderView, name));
|
|
|
|
|
|
|
|
if (rv == NULL) {
|
|
|
|
rv = MEM_callocN(sizeof(RenderView), "new opengl render view");
|
|
|
|
BLI_strncpy(rv->name, srv->name, sizeof(rv->name));
|
|
|
|
BLI_addtail(&rr->views, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!(is_multiview && BKE_scene_multiview_is_stereo3d(rd))) {
|
2019-04-17 06:17:24 +02:00
|
|
|
oglrender->iuser.flag &= ~IMA_SHOW_STEREO;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* will only work for non multiview correctly */
|
|
|
|
if (v3d) {
|
|
|
|
camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, "new opengl render view");
|
|
|
|
BKE_render_result_stamp_info(oglrender->scene, camera, rr, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_render_result_stamp_info(oglrender->scene, oglrender->scene->camera, rr, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
RE_ReleaseResult(oglrender->re);
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, RenderResult *rr)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-07-25 16:36:22 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = oglrender->scene;
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = oglrender->region;
|
2019-04-17 06:17:24 +02:00
|
|
|
View3D *v3d = oglrender->v3d;
|
|
|
|
RegionView3D *rv3d = oglrender->rv3d;
|
|
|
|
Object *camera = NULL;
|
|
|
|
int sizex = oglrender->sizex;
|
|
|
|
int sizey = oglrender->sizey;
|
|
|
|
const short view_context = (v3d != NULL);
|
|
|
|
bool draw_sky = (scene->r.alphamode == R_ADDSKY);
|
|
|
|
float *rectf = NULL;
|
2020-04-03 16:21:24 +11:00
|
|
|
uchar *rect = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *viewname = RE_GetActiveRenderView(oglrender->re);
|
|
|
|
ImBuf *ibuf_result = NULL;
|
|
|
|
|
|
|
|
if (oglrender->is_sequencer) {
|
|
|
|
SpaceSeq *sseq = oglrender->sseq;
|
|
|
|
struct bGPdata *gpd = (sseq && (sseq->flag & SEQ_SHOW_GPENCIL)) ? sseq->gpd : NULL;
|
|
|
|
|
|
|
|
/* use pre-calculated ImBuf (avoids deadlock), see: */
|
|
|
|
ImBuf *ibuf = oglrender->seq_data.ibufs_arr[oglrender->view_id];
|
|
|
|
|
|
|
|
if (ibuf) {
|
|
|
|
ImBuf *out = IMB_dupImBuf(ibuf);
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
/* OpenGL render is considered to be preview and should be
|
|
|
|
* as fast as possible. So currently we're making sure sequencer
|
|
|
|
* result is always byte to simplify color management pipeline.
|
|
|
|
*
|
|
|
|
* TODO(sergey): In the case of output to float container (EXR)
|
|
|
|
* it actually makes sense to keep float buffer instead.
|
|
|
|
*/
|
|
|
|
if (out->rect_float != NULL) {
|
|
|
|
IMB_rect_from_float(out);
|
|
|
|
imb_freerectfloatImBuf(out);
|
|
|
|
}
|
|
|
|
BLI_assert((oglrender->sizex == ibuf->x) && (oglrender->sizey == ibuf->y));
|
|
|
|
RE_render_result_rect_from_ibuf(rr, &scene->r, out, oglrender->view_id);
|
|
|
|
IMB_freeImBuf(out);
|
|
|
|
}
|
|
|
|
else if (gpd) {
|
|
|
|
/* If there are no strips, Grease Pencil still needs a buffer to draw on */
|
|
|
|
ImBuf *out = IMB_allocImBuf(oglrender->sizex, oglrender->sizey, 32, IB_rect);
|
|
|
|
RE_render_result_rect_from_ibuf(rr, &scene->r, out, oglrender->view_id);
|
|
|
|
IMB_freeImBuf(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gpd) {
|
|
|
|
int i;
|
2020-04-03 16:21:24 +11:00
|
|
|
uchar *gp_rect;
|
|
|
|
uchar *render_rect = (uchar *)RE_RenderViewGetById(rr, oglrender->view_id)->rect32;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
DRW_opengl_context_enable();
|
|
|
|
GPU_offscreen_bind(oglrender->ofs, true);
|
|
|
|
|
|
|
|
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
|
2020-08-23 11:11:27 +02:00
|
|
|
GPU_clear_depth(1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-06-14 10:49:05 +02:00
|
|
|
GPU_matrix_reset();
|
2019-06-06 14:41:54 +02:00
|
|
|
wmOrtho2(0, scene->r.xsch, 0, scene->r.ysch);
|
|
|
|
GPU_matrix_translate_2f(scene->r.xsch / 2, scene->r.ysch / 2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
G.f |= G_FLAG_RENDER_VIEWPORT;
|
|
|
|
ED_annotation_draw_ex(scene, gpd, sizex, sizey, scene->r.cfra, SPACE_SEQ);
|
|
|
|
G.f &= ~G_FLAG_RENDER_VIEWPORT;
|
|
|
|
|
2020-08-08 13:29:21 +10:00
|
|
|
gp_rect = MEM_mallocN(sizeof(uchar[4]) * sizex * sizey, "offscreen rect");
|
2020-07-25 18:53:04 +02:00
|
|
|
GPU_offscreen_read_pixels(oglrender->ofs, GPU_DATA_UNSIGNED_BYTE, gp_rect);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
for (i = 0; i < sizex * sizey * 4; i += 4) {
|
|
|
|
blend_color_mix_byte(&render_rect[i], &render_rect[i], &gp_rect[i]);
|
|
|
|
}
|
|
|
|
GPU_offscreen_unbind(oglrender->ofs, true);
|
|
|
|
DRW_opengl_context_disable();
|
|
|
|
|
|
|
|
MEM_freeN(gp_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* shouldnt suddenly give errors mid-render but possible */
|
|
|
|
char err_out[256] = "unknown";
|
|
|
|
ImBuf *ibuf_view;
|
|
|
|
const int alpha_mode = (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL;
|
2020-03-06 12:08:03 +01:00
|
|
|
eImBufFlags imbuf_flags = oglrender->color_depth <= R_IMF_CHAN_DEPTH_8 ? IB_rect :
|
|
|
|
IB_rectfloat;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (view_context) {
|
|
|
|
ibuf_view = ED_view3d_draw_offscreen_imbuf(depsgraph,
|
|
|
|
scene,
|
|
|
|
v3d->shading.type,
|
|
|
|
v3d,
|
2020-03-06 16:56:42 +01:00
|
|
|
region,
|
2019-04-17 06:17:24 +02:00
|
|
|
sizex,
|
|
|
|
sizey,
|
2020-03-06 12:08:03 +01:00
|
|
|
imbuf_flags,
|
2019-04-17 06:17:24 +02:00
|
|
|
alpha_mode,
|
|
|
|
viewname,
|
|
|
|
oglrender->ofs,
|
|
|
|
err_out);
|
|
|
|
|
|
|
|
/* for stamp only */
|
|
|
|
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
|
|
|
|
camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, viewname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(depsgraph,
|
|
|
|
scene,
|
2019-04-25 16:24:06 +02:00
|
|
|
NULL,
|
2019-04-17 06:17:24 +02:00
|
|
|
OB_SOLID,
|
|
|
|
scene->camera,
|
|
|
|
oglrender->sizex,
|
|
|
|
oglrender->sizey,
|
2020-03-06 12:08:03 +01:00
|
|
|
imbuf_flags,
|
2019-05-21 10:33:45 +02:00
|
|
|
V3D_OFSDRAW_SHOW_ANNOTATION,
|
2019-04-17 06:17:24 +02:00
|
|
|
alpha_mode,
|
|
|
|
viewname,
|
|
|
|
oglrender->ofs,
|
|
|
|
err_out);
|
|
|
|
camera = scene->camera;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ibuf_view) {
|
|
|
|
ibuf_result = ibuf_view;
|
2019-12-04 15:02:31 +01:00
|
|
|
if (ibuf_view->rect_float) {
|
|
|
|
rectf = ibuf_view->rect_float;
|
|
|
|
}
|
|
|
|
else {
|
2020-04-03 16:21:24 +11:00
|
|
|
rect = (uchar *)ibuf_view->rect;
|
2019-12-04 15:02:31 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "%s: failed to get buffer, %s\n", __func__, err_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ibuf_result != NULL) {
|
|
|
|
if ((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW)) {
|
2019-12-04 15:02:31 +01:00
|
|
|
BKE_image_stamp_buf(scene, camera, NULL, rect, rectf, rr->rectx, rr->recty, 4);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
RE_render_result_rect_from_ibuf(rr, &scene->r, ibuf_result, oglrender->view_id);
|
|
|
|
IMB_freeImBuf(ibuf_result);
|
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
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
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
static void screen_opengl_render_write(OGLRender *oglrender)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
RenderResult *rr;
|
|
|
|
bool ok;
|
|
|
|
char name[FILE_MAX];
|
|
|
|
|
|
|
|
rr = RE_AcquireResultRead(oglrender->re);
|
|
|
|
|
|
|
|
BKE_image_path_from_imformat(name,
|
|
|
|
scene->r.pic,
|
|
|
|
BKE_main_blendfile_path(oglrender->bmain),
|
|
|
|
scene->r.cfra,
|
|
|
|
&scene->r.im_format,
|
|
|
|
(scene->r.scemode & R_EXTENSION) != 0,
|
|
|
|
false,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* write images as individual images or stereo */
|
|
|
|
BKE_render_result_stamp_info(scene, scene->camera, rr, false);
|
|
|
|
ok = RE_WriteRenderViewsImage(oglrender->reports, rr, scene, false, name);
|
|
|
|
|
|
|
|
RE_ReleaseResultImage(oglrender->re);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ok) {
|
2019-04-17 06:17:24 +02:00
|
|
|
printf("OpenGL Render written to '%s'\n", name);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
printf("OpenGL Render failed to write '%s'\n", name);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
static void UNUSED_FUNCTION(addAlphaOverFloat)(float dest[4], const float source[4])
|
2016-08-03 23:31:48 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* d = s + (1-alpha_s)d*/
|
|
|
|
float mul;
|
2016-08-03 23:31:48 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
mul = 1.0f - source[3];
|
2016-08-03 23:31:48 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
dest[0] = (mul * dest[0]) + source[0];
|
|
|
|
dest[1] = (mul * dest[1]) + source[1];
|
|
|
|
dest[2] = (mul * dest[2]) + source[2];
|
|
|
|
dest[3] = (mul * dest[3]) + source[3];
|
2016-08-03 23:31:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
static void screen_opengl_render_apply(const bContext *C, OGLRender *oglrender)
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderResult *rr;
|
|
|
|
RenderView *rv;
|
|
|
|
int view_id;
|
|
|
|
ImBuf *ibuf;
|
|
|
|
void *lock;
|
|
|
|
|
|
|
|
if (oglrender->is_sequencer) {
|
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
|
|
|
|
SeqRenderData context;
|
|
|
|
SpaceSeq *sseq = oglrender->sseq;
|
|
|
|
int chanshown = sseq ? sseq->chanshown : 0;
|
|
|
|
|
|
|
|
BKE_sequencer_new_render_data(oglrender->bmain,
|
|
|
|
oglrender->depsgraph,
|
|
|
|
scene,
|
|
|
|
oglrender->sizex,
|
|
|
|
oglrender->sizey,
|
2020-05-18 16:12:17 +10:00
|
|
|
100,
|
2019-04-17 06:17:24 +02:00
|
|
|
false,
|
|
|
|
&context);
|
|
|
|
|
|
|
|
for (view_id = 0; view_id < oglrender->views_len; view_id++) {
|
|
|
|
context.view_id = view_id;
|
|
|
|
context.gpu_offscreen = oglrender->ofs;
|
|
|
|
oglrender->seq_data.ibufs_arr[view_id] = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rr = RE_AcquireResultRead(oglrender->re);
|
|
|
|
for (rv = rr->views.first, view_id = 0; rv; rv = rv->next, view_id++) {
|
|
|
|
BLI_assert(view_id < oglrender->views_len);
|
|
|
|
RE_SetActiveRenderView(oglrender->re, rv->name);
|
|
|
|
oglrender->view_id = view_id;
|
|
|
|
/* render composite */
|
|
|
|
screen_opengl_render_doit(C, oglrender, rr);
|
|
|
|
}
|
|
|
|
|
|
|
|
RE_ReleaseResult(oglrender->re);
|
|
|
|
|
|
|
|
ibuf = BKE_image_acquire_ibuf(oglrender->ima, &oglrender->iuser, &lock);
|
|
|
|
if (ibuf) {
|
|
|
|
ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
|
|
|
|
}
|
|
|
|
BKE_image_release_ibuf(oglrender->ima, ibuf, lock);
|
|
|
|
|
|
|
|
if (oglrender->write_still) {
|
|
|
|
screen_opengl_render_write(oglrender);
|
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 17:54:07 +01:00
|
|
|
static void gather_frames_to_render_for_adt(const OGLRender *oglrender, const AnimData *adt)
|
2019-12-18 15:19:59 +01:00
|
|
|
{
|
|
|
|
if (adt == NULL || adt->action == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-10 17:54:07 +01:00
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
int frame_start = PSFRA;
|
|
|
|
int frame_end = PEFRA;
|
|
|
|
|
2019-12-18 15:19:59 +01:00
|
|
|
LISTBASE_FOREACH (FCurve *, fcu, &adt->action->curves) {
|
|
|
|
if (fcu->driver != NULL || fcu->fpt != NULL) {
|
|
|
|
/* Drivers have values for any point in time, so to get "the keyed frames" they are
|
|
|
|
* useless. Same for baked FCurves, they also have keys for every frame, which is not
|
|
|
|
* useful for rendering the keyed subset of the frames. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool found = false; /* Not interesting, we just want a starting point for the for-loop.*/
|
|
|
|
int key_index = binarysearch_bezt_index(fcu->bezt, frame_start, fcu->totvert, &found);
|
|
|
|
for (; key_index < fcu->totvert; key_index++) {
|
|
|
|
BezTriple *bezt = &fcu->bezt[key_index];
|
|
|
|
/* The frame range to render uses integer frame numbers, and the frame
|
|
|
|
* step is also an integer, so we always render on the frame. */
|
|
|
|
int frame_nr = round_fl_to_int(bezt->vec[1][0]);
|
|
|
|
|
|
|
|
/* (frame_nr < frame_start) cannot happen because of the binary search above. */
|
|
|
|
BLI_assert(frame_nr >= frame_start);
|
|
|
|
if (frame_nr > frame_end) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BLI_BITMAP_ENABLE(oglrender->render_frames, frame_nr - frame_start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 17:54:07 +01:00
|
|
|
static void gather_frames_to_render_for_grease_pencil(const OGLRender *oglrender,
|
|
|
|
const bGPdata *gp)
|
|
|
|
{
|
|
|
|
if (gp == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
int frame_start = PSFRA;
|
|
|
|
int frame_end = PEFRA;
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (const bGPDlayer *, gp_layer, &gp->layers) {
|
|
|
|
LISTBASE_FOREACH (const bGPDframe *, gp_frame, &gp_layer->frames) {
|
|
|
|
if (gp_frame->framenum < frame_start || gp_frame->framenum > frame_end) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
BLI_BITMAP_ENABLE(oglrender->render_frames, gp_frame->framenum - frame_start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-13 12:56:10 +01:00
|
|
|
static int gather_frames_to_render_for_id(LibraryIDLinkCallbackData *cb_data)
|
2020-01-10 17:54:07 +01:00
|
|
|
{
|
2020-02-13 12:56:10 +01:00
|
|
|
ID **id_p = cb_data->id_pointer;
|
|
|
|
if (*id_p == NULL) {
|
2020-01-10 17:54:07 +01:00
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
}
|
|
|
|
ID *id = *id_p;
|
|
|
|
|
2020-02-13 12:56:10 +01:00
|
|
|
ID *id_self = cb_data->id_self;
|
|
|
|
const int cb_flag = cb_data->cb_flag;
|
2020-01-10 17:54:07 +01:00
|
|
|
if (cb_flag == IDWALK_CB_LOOPBACK || id == id_self) {
|
|
|
|
/* IDs may end up referencing themselves one way or the other, and those
|
|
|
|
* (the id_self ones) have always already been processed. */
|
|
|
|
return IDWALK_RET_STOP_RECURSION;
|
|
|
|
}
|
|
|
|
|
2020-02-13 12:56:10 +01:00
|
|
|
OGLRender *oglrender = cb_data->user_data;
|
2020-01-10 17:54:07 +01:00
|
|
|
|
|
|
|
/* Whitelist of datablocks to follow pointers into. */
|
|
|
|
const ID_Type id_type = GS(id->name);
|
|
|
|
switch (id_type) {
|
|
|
|
/* Whitelist: */
|
|
|
|
case ID_ME: /* Mesh */
|
|
|
|
case ID_CU: /* Curve */
|
|
|
|
case ID_MB: /* MetaBall */
|
|
|
|
case ID_MA: /* Material */
|
|
|
|
case ID_TE: /* Tex (Texture) */
|
|
|
|
case ID_IM: /* Image */
|
|
|
|
case ID_LT: /* Lattice */
|
|
|
|
case ID_LA: /* Light */
|
|
|
|
case ID_CA: /* Camera */
|
|
|
|
case ID_KE: /* Key (shape key) */
|
|
|
|
case ID_VF: /* VFont (Vector Font) */
|
|
|
|
case ID_TXT: /* Text */
|
|
|
|
case ID_SPK: /* Speaker */
|
|
|
|
case ID_SO: /* Sound */
|
|
|
|
case ID_AR: /* bArmature */
|
|
|
|
case ID_NT: /* bNodeTree */
|
|
|
|
case ID_PA: /* ParticleSettings */
|
|
|
|
case ID_MC: /* MovieClip */
|
|
|
|
case ID_MSK: /* Mask */
|
|
|
|
case ID_LP: /* LightProbe */
|
2020-03-17 14:41:48 +01:00
|
|
|
case ID_HA: /* Hair */
|
|
|
|
case ID_PT: /* PointCloud */
|
|
|
|
case ID_VO: /* Volume */
|
2020-04-20 10:37:38 +02:00
|
|
|
case ID_SIM: /* Simulation */
|
2020-01-10 17:54:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Blacklist: */
|
|
|
|
case ID_SCE: /* Scene */
|
|
|
|
case ID_LI: /* Library */
|
|
|
|
case ID_OB: /* Object */
|
|
|
|
case ID_IP: /* Ipo (depreciated, replaced by FCurves) */
|
|
|
|
case ID_WO: /* World */
|
|
|
|
case ID_SCR: /* Screen */
|
|
|
|
case ID_GR: /* Group */
|
|
|
|
case ID_AC: /* bAction */
|
|
|
|
case ID_BR: /* Brush */
|
|
|
|
case ID_WM: /* WindowManager */
|
|
|
|
case ID_LS: /* FreestyleLineStyle */
|
|
|
|
case ID_PAL: /* Palette */
|
|
|
|
case ID_PC: /* PaintCurve */
|
|
|
|
case ID_CF: /* CacheFile */
|
|
|
|
case ID_WS: /* WorkSpace */
|
|
|
|
/* Only follow pointers to specific datablocks, to avoid ending up in
|
|
|
|
* unrelated datablocks and exploding the number of blocks we follow. If the
|
|
|
|
* frames of the animation of certain objects should be taken into account,
|
|
|
|
* they should have been selected by the user. */
|
|
|
|
return IDWALK_RET_STOP_RECURSION;
|
|
|
|
|
|
|
|
/* Special cases: */
|
|
|
|
case ID_GD: /* bGPdata, (Grease Pencil) */
|
|
|
|
/* In addition to regular ID's animdata, GreasePencil uses a specific frame-based animation
|
|
|
|
* system that requires specific handling here. */
|
|
|
|
gather_frames_to_render_for_grease_pencil(oglrender, (bGPdata *)id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimData *adt = BKE_animdata_from_id(id);
|
|
|
|
gather_frames_to_render_for_adt(oglrender, adt);
|
|
|
|
|
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
}
|
|
|
|
|
2019-12-20 10:45:45 +11:00
|
|
|
/**
|
|
|
|
* Collect the frame numbers for which selected objects have keys in the animation data.
|
|
|
|
* The frames ares stored in #OGLRender.render_frames.
|
2020-01-10 17:54:07 +01:00
|
|
|
*
|
|
|
|
* Note that this follows all pointers to ID blocks, only filtering on ID type,
|
|
|
|
* so it will pick up keys from pointers in custom properties as well.
|
2019-12-20 10:45:45 +11:00
|
|
|
*/
|
2019-12-18 15:19:59 +01:00
|
|
|
static void gather_frames_to_render(bContext *C, OGLRender *oglrender)
|
|
|
|
{
|
2020-01-10 17:54:07 +01:00
|
|
|
Scene *scene = oglrender->scene;
|
2019-12-18 15:19:59 +01:00
|
|
|
int frame_start = PSFRA;
|
|
|
|
int frame_end = PEFRA;
|
|
|
|
|
|
|
|
/* Will be freed in screen_opengl_render_end(). */
|
|
|
|
oglrender->render_frames = BLI_BITMAP_NEW(frame_end - frame_start + 1,
|
|
|
|
"OGLRender::render_frames");
|
|
|
|
|
|
|
|
/* The first frame should always be rendered, otherwise there is nothing to write to file. */
|
|
|
|
BLI_BITMAP_ENABLE(oglrender->render_frames, 0);
|
|
|
|
|
|
|
|
CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
|
2020-01-10 17:54:07 +01:00
|
|
|
ID *id = &ob->id;
|
2019-12-18 15:19:59 +01:00
|
|
|
|
2020-01-10 17:54:07 +01:00
|
|
|
/* Gather the frames from the object animation data. */
|
|
|
|
AnimData *adt = BKE_animdata_from_id(id);
|
|
|
|
gather_frames_to_render_for_adt(oglrender, adt);
|
|
|
|
|
|
|
|
/* Gather the frames from linked datablocks (materials, shapkeys, etc.). */
|
|
|
|
BKE_library_foreach_ID_link(
|
|
|
|
NULL, id, gather_frames_to_render_for_id, oglrender, IDWALK_RECURSE);
|
2019-12-18 15:19:59 +01:00
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
}
|
|
|
|
|
2014-01-28 03:52:21 +11:00
|
|
|
static bool screen_opengl_render_init(bContext *C, wmOperator *op)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* new render clears all callbacks */
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
WorkSpace *workspace = CTX_wm_workspace(C);
|
|
|
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ScrArea *prevsa = CTX_wm_area(C);
|
|
|
|
ARegion *prevar = CTX_wm_region(C);
|
|
|
|
GPUOffScreen *ofs;
|
|
|
|
OGLRender *oglrender;
|
|
|
|
int sizex, sizey;
|
|
|
|
bool is_view_context = RNA_boolean_get(op->ptr, "view_context");
|
|
|
|
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
|
2019-12-18 15:19:59 +01:00
|
|
|
const bool is_render_keyed_only = RNA_boolean_get(op->ptr, "render_keyed_only");
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool is_sequencer = RNA_boolean_get(op->ptr, "sequencer");
|
|
|
|
const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
|
2019-11-05 16:55:51 +01:00
|
|
|
const eImageFormatDepth color_depth = (is_animation) ? scene->r.im_format.depth :
|
|
|
|
R_IMF_CHAN_DEPTH_32;
|
2019-04-17 06:17:24 +02:00
|
|
|
char err_out[256] = "unknown";
|
|
|
|
|
|
|
|
if (G.background) {
|
|
|
|
BKE_report(
|
|
|
|
op->reports, RPT_ERROR, "Cannot use OpenGL render in background mode (no opengl context)");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only one render job at a time */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (is_sequencer) {
|
|
|
|
is_view_context = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* ensure we have a 3d view */
|
|
|
|
if (!ED_view3d_context_activate(C)) {
|
|
|
|
RNA_boolean_set(op->ptr, "view_context", false);
|
|
|
|
is_view_context = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_view_context && scene->camera == NULL) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Scene has no camera");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stop all running jobs, except screen one. currently previews frustrate Render */
|
|
|
|
WM_jobs_kill_all_except(wm, CTX_wm_screen(C));
|
|
|
|
|
|
|
|
/* create offscreen buffer */
|
|
|
|
sizex = (scene->r.size * scene->r.xsch) / 100;
|
|
|
|
sizey = (scene->r.size * scene->r.ysch) / 100;
|
|
|
|
|
|
|
|
/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
|
|
|
|
DRW_opengl_context_enable(); /* Offscreen creation needs to be done in DRW context. */
|
2020-07-02 17:28:30 +02:00
|
|
|
ofs = GPU_offscreen_create(sizex, sizey, true, true, err_out);
|
2019-04-17 06:17:24 +02:00
|
|
|
DRW_opengl_context_disable();
|
|
|
|
|
|
|
|
if (!ofs) {
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer, %s", err_out);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate opengl render */
|
|
|
|
oglrender = MEM_callocN(sizeof(OGLRender), "OGLRender");
|
|
|
|
op->customdata = oglrender;
|
|
|
|
|
|
|
|
oglrender->ofs = ofs;
|
|
|
|
oglrender->sizex = sizex;
|
|
|
|
oglrender->sizey = sizey;
|
|
|
|
oglrender->bmain = CTX_data_main(C);
|
|
|
|
oglrender->scene = scene;
|
|
|
|
oglrender->workspace = workspace;
|
|
|
|
oglrender->view_layer = CTX_data_view_layer(C);
|
2019-07-25 16:36:22 +02:00
|
|
|
/* NOTE: The depsgraph is not only used to update scene for a new frames, but also to initialize
|
|
|
|
* output video handles, which does need evaluated scene. */
|
|
|
|
oglrender->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
oglrender->cfrao = scene->r.cfra;
|
|
|
|
|
|
|
|
oglrender->write_still = is_write_still && !is_animation;
|
|
|
|
oglrender->is_animation = is_animation;
|
2019-11-05 16:55:51 +01:00
|
|
|
oglrender->color_depth = color_depth;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
oglrender->views_len = BKE_scene_multiview_num_views_get(&scene->r);
|
|
|
|
|
|
|
|
oglrender->is_sequencer = is_sequencer;
|
|
|
|
if (is_sequencer) {
|
|
|
|
oglrender->sseq = CTX_wm_space_seq(C);
|
|
|
|
ImBuf **ibufs_arr = MEM_callocN(sizeof(*ibufs_arr) * oglrender->views_len, __func__);
|
|
|
|
oglrender->seq_data.ibufs_arr = ibufs_arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
oglrender->prevsa = prevsa;
|
|
|
|
oglrender->prevar = prevar;
|
|
|
|
|
|
|
|
if (is_view_context) {
|
|
|
|
/* so quad view renders camera */
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_view3d_context_user_region(C, &oglrender->v3d, &oglrender->region);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
oglrender->rv3d = oglrender->region->regiondata;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* MUST be cleared on exit */
|
|
|
|
memset(&oglrender->scene->customdata_mask_modal,
|
|
|
|
0,
|
|
|
|
sizeof(oglrender->scene->customdata_mask_modal));
|
|
|
|
ED_view3d_datamask(
|
|
|
|
C, oglrender->scene, oglrender->v3d, &oglrender->scene->customdata_mask_modal);
|
|
|
|
|
|
|
|
/* apply immediately in case we're rendering from a script,
|
|
|
|
* running notifiers again will overwrite */
|
|
|
|
CustomData_MeshMasks_update(&oglrender->scene->customdata_mask,
|
|
|
|
&oglrender->scene->customdata_mask_modal);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create render */
|
|
|
|
oglrender->re = RE_NewSceneRender(scene);
|
|
|
|
|
|
|
|
/* create image and image user */
|
2020-03-06 13:02:59 +11:00
|
|
|
oglrender->ima = BKE_image_ensure_viewer(oglrender->bmain, IMA_TYPE_R_RESULT, "Render Result");
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_image_signal(oglrender->bmain, oglrender->ima, NULL, IMA_SIGNAL_FREE);
|
|
|
|
BKE_image_backup_render(oglrender->scene, oglrender->ima, true);
|
|
|
|
|
|
|
|
oglrender->iuser.scene = scene;
|
|
|
|
oglrender->iuser.ok = 1;
|
|
|
|
|
|
|
|
/* create render result */
|
|
|
|
RE_InitState(oglrender->re, NULL, &scene->r, &scene->view_layers, NULL, sizex, sizey, NULL);
|
|
|
|
|
|
|
|
/* create render views */
|
|
|
|
screen_opengl_views_setup(oglrender);
|
|
|
|
|
|
|
|
/* wm vars */
|
|
|
|
oglrender->wm = wm;
|
|
|
|
oglrender->win = win;
|
|
|
|
|
|
|
|
oglrender->totvideos = 0;
|
|
|
|
oglrender->mh = NULL;
|
|
|
|
oglrender->movie_ctx_arr = NULL;
|
|
|
|
|
|
|
|
if (is_animation) {
|
2019-12-18 15:19:59 +01:00
|
|
|
if (is_render_keyed_only) {
|
|
|
|
gather_frames_to_render(C, oglrender);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
2020-04-30 07:59:23 +02:00
|
|
|
oglrender->task_pool = BLI_task_pool_create_background_serial(oglrender, TASK_PRIORITY_LOW);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-04-30 07:59:23 +02:00
|
|
|
oglrender->task_pool = BLI_task_pool_create(oglrender, TASK_PRIORITY_LOW);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
oglrender->pool_ok = true;
|
|
|
|
BLI_spin_init(&oglrender->reports_lock);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
oglrender->task_pool = NULL;
|
|
|
|
}
|
|
|
|
oglrender->num_scheduled_frames = 0;
|
|
|
|
BLI_mutex_init(&oglrender->task_mutex);
|
|
|
|
BLI_condition_init(&oglrender->task_condition);
|
2016-09-16 10:28:41 +02:00
|
|
|
|
2016-09-15 15:04:19 +02:00
|
|
|
#ifdef DEBUG_TIME
|
2019-04-17 06:17:24 +02:00
|
|
|
oglrender->time_start = PIL_check_seconds_timer();
|
2016-09-15 15:04:19 +02:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void screen_opengl_render_end(bContext *C, OGLRender *oglrender)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (oglrender->is_animation) {
|
|
|
|
/* Trickery part for movie output:
|
|
|
|
*
|
|
|
|
* We MUST write frames in an exact order, so we only let background
|
|
|
|
* thread to work on that, and main thread is simply waits for that
|
|
|
|
* thread to do all the dirty work.
|
|
|
|
*
|
|
|
|
* After this loop is done work_and_wait() will have nothing to do,
|
|
|
|
* so we don't run into wrong order of frames written to the stream.
|
|
|
|
*/
|
|
|
|
if (BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
|
|
|
BLI_mutex_lock(&oglrender->task_mutex);
|
|
|
|
while (oglrender->num_scheduled_frames > 0) {
|
|
|
|
BLI_condition_wait(&oglrender->task_condition, &oglrender->task_mutex);
|
|
|
|
}
|
|
|
|
BLI_mutex_unlock(&oglrender->task_mutex);
|
|
|
|
}
|
|
|
|
BLI_task_pool_work_and_wait(oglrender->task_pool);
|
|
|
|
BLI_task_pool_free(oglrender->task_pool);
|
|
|
|
BLI_spin_end(&oglrender->reports_lock);
|
|
|
|
}
|
|
|
|
BLI_mutex_end(&oglrender->task_mutex);
|
|
|
|
BLI_condition_end(&oglrender->task_condition);
|
2016-09-16 10:28:41 +02:00
|
|
|
|
2016-09-15 15:04:19 +02:00
|
|
|
#ifdef DEBUG_TIME
|
2019-04-17 06:17:24 +02:00
|
|
|
printf("Total render time: %f\n", PIL_check_seconds_timer() - oglrender->time_start);
|
2016-09-15 15:04:19 +02:00
|
|
|
#endif
|
|
|
|
|
2019-12-18 15:19:59 +01:00
|
|
|
MEM_SAFE_FREE(oglrender->render_frames);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (oglrender->mh) {
|
|
|
|
if (BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
|
|
|
for (i = 0; i < oglrender->totvideos; i++) {
|
|
|
|
oglrender->mh->end_movie(oglrender->movie_ctx_arr[i]);
|
|
|
|
oglrender->mh->context_free(oglrender->movie_ctx_arr[i]);
|
|
|
|
}
|
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (oglrender->movie_ctx_arr) {
|
|
|
|
MEM_freeN(oglrender->movie_ctx_arr);
|
|
|
|
}
|
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (oglrender->timer) { /* exec will not have a timer */
|
|
|
|
Depsgraph *depsgraph = oglrender->depsgraph;
|
|
|
|
scene->r.cfra = oglrender->cfrao;
|
2020-08-18 15:45:58 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_remove_timer(oglrender->wm, oglrender->win, oglrender->timer);
|
|
|
|
}
|
2013-07-17 09:57:02 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_cursor_modal_restore(oglrender->win);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, oglrender->scene);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
DRW_opengl_context_enable();
|
|
|
|
GPU_offscreen_free(oglrender->ofs);
|
|
|
|
DRW_opengl_context_disable();
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (oglrender->is_sequencer) {
|
|
|
|
MEM_freeN(oglrender->seq_data.ibufs_arr);
|
|
|
|
}
|
2016-03-31 15:35:47 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(&oglrender->scene->customdata_mask_modal,
|
|
|
|
0,
|
|
|
|
sizeof(oglrender->scene->customdata_mask_modal));
|
2011-03-13 02:44:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
CTX_wm_area_set(C, oglrender->prevsa);
|
|
|
|
CTX_wm_region_set(C, oglrender->prevar);
|
2012-01-13 15:35:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(oglrender);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
static void screen_opengl_render_cancel(bContext *C, wmOperator *op)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
screen_opengl_render_end(C, op->customdata);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* share between invoke and exec */
|
2020-08-01 13:02:21 +10:00
|
|
|
static bool screen_opengl_render_anim_init(bContext *C, wmOperator *op)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* initialize animation */
|
|
|
|
OGLRender *oglrender;
|
|
|
|
Scene *scene;
|
|
|
|
|
|
|
|
oglrender = op->customdata;
|
|
|
|
scene = oglrender->scene;
|
|
|
|
oglrender->totvideos = BKE_scene_multiview_num_videos_get(&scene->r);
|
|
|
|
|
|
|
|
oglrender->reports = op->reports;
|
|
|
|
|
|
|
|
if (BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
|
|
|
size_t width, height;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
BKE_scene_multiview_videos_dimensions_get(
|
|
|
|
&scene->r, oglrender->sizex, oglrender->sizey, &width, &height);
|
|
|
|
oglrender->mh = BKE_movie_handle_get(scene->r.im_format.imtype);
|
|
|
|
|
|
|
|
if (oglrender->mh == NULL) {
|
|
|
|
BKE_report(oglrender->reports, RPT_ERROR, "Movie format unsupported");
|
|
|
|
screen_opengl_render_end(C, oglrender);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
oglrender->movie_ctx_arr = MEM_mallocN(sizeof(void *) * oglrender->totvideos, "Movies");
|
|
|
|
|
|
|
|
for (i = 0; i < oglrender->totvideos; i++) {
|
2019-06-11 15:40:03 +02:00
|
|
|
Scene *scene_eval = DEG_get_evaluated_scene(oglrender->depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *suffix = BKE_scene_multiview_view_id_suffix_get(&scene->r, i);
|
|
|
|
|
|
|
|
oglrender->movie_ctx_arr[i] = oglrender->mh->context_create();
|
|
|
|
if (!oglrender->mh->start_movie(oglrender->movie_ctx_arr[i],
|
2019-06-11 15:40:03 +02:00
|
|
|
scene_eval,
|
2019-04-17 06:17:24 +02:00
|
|
|
&scene->r,
|
|
|
|
oglrender->sizex,
|
|
|
|
oglrender->sizey,
|
|
|
|
oglrender->reports,
|
|
|
|
PRVRANGEON != 0,
|
|
|
|
suffix)) {
|
|
|
|
screen_opengl_render_end(C, oglrender);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
oglrender->cfrao = scene->r.cfra;
|
|
|
|
oglrender->nfra = PSFRA;
|
|
|
|
scene->r.cfra = PSFRA;
|
|
|
|
|
|
|
|
return true;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2016-09-16 10:28:41 +02:00
|
|
|
typedef struct WriteTaskData {
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderResult *rr;
|
|
|
|
Scene tmp_scene;
|
2016-09-16 10:28:41 +02:00
|
|
|
} WriteTaskData;
|
|
|
|
|
2020-04-30 07:59:23 +02:00
|
|
|
static void write_result_func(TaskPool *__restrict pool, void *task_data_v)
|
2016-09-16 10:28:41 +02:00
|
|
|
{
|
2020-04-21 15:36:35 +02:00
|
|
|
OGLRender *oglrender = (OGLRender *)BLI_task_pool_user_data(pool);
|
2019-04-17 06:17:24 +02:00
|
|
|
WriteTaskData *task_data = (WriteTaskData *)task_data_v;
|
|
|
|
Scene *scene = &task_data->tmp_scene;
|
|
|
|
RenderResult *rr = task_data->rr;
|
|
|
|
const bool is_movie = BKE_imtype_is_movie(scene->r.im_format.imtype);
|
|
|
|
const int cfra = scene->r.cfra;
|
|
|
|
bool ok;
|
|
|
|
/* Don't attempt to write if we've got an error. */
|
|
|
|
if (!oglrender->pool_ok) {
|
|
|
|
RE_FreeRenderResult(rr);
|
|
|
|
BLI_mutex_lock(&oglrender->task_mutex);
|
|
|
|
oglrender->num_scheduled_frames--;
|
|
|
|
BLI_condition_notify_all(&oglrender->task_condition);
|
|
|
|
BLI_mutex_unlock(&oglrender->task_mutex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Construct local thread0safe copy of reports structure which we can
|
|
|
|
* safely pass to the underlying functions.
|
|
|
|
*/
|
|
|
|
ReportList reports;
|
|
|
|
BKE_reports_init(&reports, oglrender->reports->flag & ~RPT_PRINT);
|
|
|
|
/* Do actual save logic here, depending on the file format.
|
|
|
|
*
|
|
|
|
* NOTE: We have to construct temporary scene with proper scene->r.cfra.
|
|
|
|
* This is because underlying calls do not use r.cfra but use scene
|
|
|
|
* for that.
|
|
|
|
*/
|
|
|
|
if (is_movie) {
|
|
|
|
ok = RE_WriteRenderViewsMovie(&reports,
|
|
|
|
rr,
|
|
|
|
scene,
|
|
|
|
&scene->r,
|
|
|
|
oglrender->mh,
|
|
|
|
oglrender->movie_ctx_arr,
|
|
|
|
oglrender->totvideos,
|
|
|
|
PRVRANGEON != 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* TODO(sergey): We can in theory save some CPU ticks here because we
|
|
|
|
* calculate file name again here.
|
|
|
|
*/
|
|
|
|
char name[FILE_MAX];
|
|
|
|
BKE_image_path_from_imformat(name,
|
|
|
|
scene->r.pic,
|
|
|
|
BKE_main_blendfile_path(oglrender->bmain),
|
|
|
|
cfra,
|
|
|
|
&scene->r.im_format,
|
|
|
|
(scene->r.scemode & R_EXTENSION) != 0,
|
|
|
|
true,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
BKE_render_result_stamp_info(scene, scene->camera, rr, false);
|
|
|
|
ok = RE_WriteRenderViewsImage(NULL, rr, scene, true, name);
|
|
|
|
if (!ok) {
|
|
|
|
BKE_reportf(&reports, RPT_ERROR, "Write error: cannot save %s", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (reports.list.first != NULL) {
|
|
|
|
BLI_spin_lock(&oglrender->reports_lock);
|
|
|
|
for (Report *report = reports.list.first; report != NULL; report = report->next) {
|
|
|
|
BKE_report(oglrender->reports, report->type, report->message);
|
|
|
|
}
|
|
|
|
BLI_spin_unlock(&oglrender->reports_lock);
|
|
|
|
}
|
|
|
|
if (!ok) {
|
|
|
|
oglrender->pool_ok = false;
|
|
|
|
}
|
|
|
|
RE_FreeRenderResult(rr);
|
|
|
|
BLI_mutex_lock(&oglrender->task_mutex);
|
|
|
|
oglrender->num_scheduled_frames--;
|
|
|
|
BLI_condition_notify_all(&oglrender->task_condition);
|
|
|
|
BLI_mutex_unlock(&oglrender->task_mutex);
|
2016-09-16 10:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool schedule_write_result(OGLRender *oglrender, RenderResult *rr)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!oglrender->pool_ok) {
|
|
|
|
RE_FreeRenderResult(rr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
WriteTaskData *task_data = MEM_mallocN(sizeof(WriteTaskData), "write task data");
|
|
|
|
task_data->rr = rr;
|
|
|
|
task_data->tmp_scene = *scene;
|
|
|
|
BLI_mutex_lock(&oglrender->task_mutex);
|
|
|
|
oglrender->num_scheduled_frames++;
|
|
|
|
if (oglrender->num_scheduled_frames > MAX_SCHEDULED_FRAMES) {
|
|
|
|
BLI_condition_wait(&oglrender->task_condition, &oglrender->task_mutex);
|
|
|
|
}
|
|
|
|
BLI_mutex_unlock(&oglrender->task_mutex);
|
2020-04-09 15:51:44 +02:00
|
|
|
BLI_task_pool_push(oglrender->task_pool, write_result_func, task_data, true, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2016-09-16 10:28:41 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 08:21:12 +00:00
|
|
|
static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
OGLRender *oglrender = op->customdata;
|
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
Depsgraph *depsgraph = oglrender->depsgraph;
|
|
|
|
char name[FILE_MAX];
|
|
|
|
bool ok = false;
|
|
|
|
const bool view_context = (oglrender->v3d != NULL);
|
|
|
|
bool is_movie;
|
|
|
|
RenderResult *rr;
|
|
|
|
|
|
|
|
/* go to next frame */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (CFRA < oglrender->nfra) {
|
2019-04-17 06:17:24 +02:00
|
|
|
CFRA++;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
while (CFRA < oglrender->nfra) {
|
2020-08-18 15:45:58 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
CFRA++;
|
|
|
|
}
|
|
|
|
|
|
|
|
is_movie = BKE_imtype_is_movie(scene->r.im_format.imtype);
|
|
|
|
|
|
|
|
if (!is_movie) {
|
|
|
|
BKE_image_path_from_imformat(name,
|
|
|
|
scene->r.pic,
|
|
|
|
BKE_main_blendfile_path(oglrender->bmain),
|
|
|
|
scene->r.cfra,
|
|
|
|
&scene->r.im_format,
|
|
|
|
(scene->r.scemode & R_EXTENSION) != 0,
|
|
|
|
true,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if ((scene->r.mode & R_NO_OVERWRITE) && BLI_exists(name)) {
|
|
|
|
BLI_spin_lock(&oglrender->reports_lock);
|
|
|
|
BKE_reportf(op->reports, RPT_INFO, "Skipping existing frame \"%s\"", name);
|
|
|
|
BLI_spin_unlock(&oglrender->reports_lock);
|
|
|
|
ok = true;
|
|
|
|
goto finally;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WM_cursor_time(oglrender->win, scene->r.cfra);
|
|
|
|
|
2020-08-18 15:45:58 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (view_context) {
|
|
|
|
if (oglrender->rv3d->persp == RV3D_CAMOB && oglrender->v3d->camera &&
|
|
|
|
oglrender->v3d->scenelock) {
|
|
|
|
/* since BKE_scene_graph_update_for_newframe() is used rather
|
|
|
|
* then ED_update_for_newframe() the camera needs to be set */
|
|
|
|
if (BKE_scene_camera_switch_update(scene)) {
|
|
|
|
oglrender->v3d->camera = scene->camera;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_scene_camera_switch_update(scene);
|
|
|
|
}
|
|
|
|
|
2019-12-18 15:19:59 +01:00
|
|
|
if (oglrender->render_frames == NULL ||
|
|
|
|
BLI_BITMAP_TEST_BOOL(oglrender->render_frames, CFRA - PSFRA)) {
|
|
|
|
/* render into offscreen buffer */
|
|
|
|
screen_opengl_render_apply(C, oglrender);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* save to disk */
|
|
|
|
rr = RE_AcquireResultRead(oglrender->re);
|
|
|
|
RenderResult *new_rr = RE_DuplicateRenderResult(rr);
|
|
|
|
RE_ReleaseResult(oglrender->re);
|
|
|
|
|
|
|
|
ok = schedule_write_result(oglrender, new_rr);
|
|
|
|
|
|
|
|
finally: /* Step the frame and bail early if needed */
|
|
|
|
|
|
|
|
/* go to next frame */
|
|
|
|
oglrender->nfra += scene->r.frame_step;
|
|
|
|
|
|
|
|
/* stop at the end or on error */
|
|
|
|
if (CFRA >= PEFRA || !ok) {
|
|
|
|
screen_opengl_render_end(C, op->customdata);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int screen_opengl_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
|
|
|
OGLRender *oglrender = op->customdata;
|
|
|
|
const bool anim = RNA_boolean_get(op->ptr, "animation");
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
switch (event->type) {
|
2020-03-18 10:38:37 -06:00
|
|
|
case EVT_ESCKEY:
|
2019-04-17 06:17:24 +02:00
|
|
|
/* cancel */
|
|
|
|
oglrender->pool_ok = false; /* Flag pool for cancel. */
|
|
|
|
screen_opengl_render_end(C, op->customdata);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
case TIMER:
|
|
|
|
/* render frame? */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (oglrender->timer == event->customdata) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
ATTR_FALLTHROUGH;
|
|
|
|
default:
|
|
|
|
/* nothing to do */
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* run first because screen_opengl_render_anim_step can free oglrender */
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, oglrender->scene);
|
|
|
|
|
|
|
|
if (anim == 0) {
|
|
|
|
screen_opengl_render_apply(C, op->customdata);
|
|
|
|
screen_opengl_render_end(C, op->customdata);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2020-07-03 17:30:31 +02:00
|
|
|
|
|
|
|
ret = screen_opengl_render_anim_step(C, op);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* stop at the end or on error */
|
|
|
|
if (ret == false) {
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int screen_opengl_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
|
|
|
OGLRender *oglrender;
|
|
|
|
const bool anim = RNA_boolean_get(op->ptr, "animation");
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!screen_opengl_render_init(C, op)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (anim) {
|
2020-08-01 13:02:21 +10:00
|
|
|
if (!screen_opengl_render_anim_init(C, op)) {
|
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
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
oglrender = op->customdata;
|
|
|
|
render_view_open(C, event->x, event->y, op->reports);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-02-15 12:09:03 +11:00
|
|
|
/* View may be changed above #USER_RENDER_DISPLAY_WINDOW. */
|
2019-04-17 06:17:24 +02:00
|
|
|
oglrender->win = CTX_wm_window(C);
|
2013-07-22 23:44:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
oglrender->timer = WM_event_add_timer(oglrender->wm, oglrender->win, TIMER, 0.01f);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* executes blocking render */
|
|
|
|
static int screen_opengl_render_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!screen_opengl_render_init(C, op)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!is_animation) { /* same as invoke */
|
|
|
|
/* render image */
|
|
|
|
screen_opengl_render_apply(C, op->customdata);
|
|
|
|
screen_opengl_render_end(C, op->customdata);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2020-07-03 17:30:31 +02:00
|
|
|
bool ret = true;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2020-08-01 13:02:21 +10:00
|
|
|
if (!screen_opengl_render_anim_init(C, op)) {
|
2020-07-03 17:30:31 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ret) {
|
|
|
|
ret = screen_opengl_render_anim_step(C, op);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* no redraw needed, we leave state as we entered it */
|
|
|
|
// ED_update_for_newframe(C);
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, CTX_data_scene(C));
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 15:17:51 +01:00
|
|
|
static char *screen_opengl_render_description(struct bContext *UNUSED(C),
|
|
|
|
struct wmOperatorType *UNUSED(ot),
|
|
|
|
struct PointerRNA *ptr)
|
|
|
|
{
|
|
|
|
if (!RNA_boolean_get(ptr, "animation")) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-18 15:19:59 +01:00
|
|
|
if (RNA_boolean_get(ptr, "render_keyed_only")) {
|
|
|
|
return BLI_strdup(
|
|
|
|
"Render the viewport for the animation range of this scene, but only render keyframes of "
|
|
|
|
"selected objects");
|
|
|
|
}
|
|
|
|
|
2019-12-18 15:17:51 +01:00
|
|
|
return BLI_strdup("Render the viewport for the animation range of this scene");
|
|
|
|
}
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
void RENDER_OT_opengl(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Viewport Render";
|
|
|
|
ot->description = "Take a snapshot of the active viewport";
|
|
|
|
ot->idname = "RENDER_OT_opengl";
|
|
|
|
|
|
|
|
/* api callbacks */
|
2019-12-18 15:17:51 +01:00
|
|
|
ot->get_description = screen_opengl_render_description;
|
2019-04-17 06:17:24 +02:00
|
|
|
ot->invoke = screen_opengl_render_invoke;
|
|
|
|
ot->exec = screen_opengl_render_exec; /* blocking */
|
|
|
|
ot->modal = screen_opengl_render_modal;
|
|
|
|
ot->cancel = screen_opengl_render_cancel;
|
|
|
|
|
|
|
|
ot->poll = ED_operator_screenactive;
|
|
|
|
|
|
|
|
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);
|
2019-12-18 15:19:59 +01:00
|
|
|
|
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
"render_keyed_only",
|
|
|
|
0,
|
|
|
|
"Render Keyframes Only",
|
|
|
|
"Render only those frames where selected objects have a key in their "
|
|
|
|
"animation data. Only used when rendering animation");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
prop = RNA_def_boolean(
|
|
|
|
ot->srna, "sequencer", 0, "Sequencer", "Render using the sequencer's OpenGL display");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
prop = RNA_def_boolean(
|
|
|
|
ot->srna,
|
|
|
|
"write_still",
|
|
|
|
0,
|
|
|
|
"Write Image",
|
|
|
|
"Save rendered the image to the output path (used only when animation is disabled)");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
"view_context",
|
|
|
|
1,
|
|
|
|
"View Context",
|
|
|
|
"Use the current 3D view for rendering, else use scene settings");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|