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-02-12 18:54:41 +01:00
|
|
|
#include "DNA_camera_types.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"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2015-04-06 10:40:12 -03:00
|
|
|
#include "BLI_threads.h"
|
2016-09-16 10:28:41 +02:00
|
|
|
#include "BLI_task.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
2010-05-23 10:47:19 +00:00
|
|
|
#include "DNA_object_types.h"
|
2016-08-03 23:31:48 +02:00
|
|
|
#include "DNA_gpencil_types.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
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"
|
2012-01-13 06:59:16 +00:00
|
|
|
#include "BKE_global.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
#include "BKE_image.h"
|
|
|
|
#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"
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_view3d.h"
|
2014-06-14 03:25:07 +10:00
|
|
|
#include "ED_gpencil.h"
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
#include "RE_pipeline.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
2010-05-23 10:47:19 +00:00
|
|
|
#include "IMB_imbuf.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 "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
#include "GPU_framebuffer.h"
|
2017-08-21 01:39:03 +10:00
|
|
|
#include "GPU_glew.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. */
|
|
|
|
// #undef DEBUG_TIME
|
|
|
|
|
|
|
|
#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 {
|
2011-11-20 14:38:11 +00:00
|
|
|
Main *bmain;
|
2010-03-08 16:36:53 +00:00
|
|
|
Render *re;
|
|
|
|
Scene *scene;
|
2017-10-16 17:15:03 -02:00
|
|
|
WorkSpace *workspace;
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer;
|
2017-11-03 17:57:46 +01:00
|
|
|
Depsgraph *depsgraph;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
View3D *v3d;
|
|
|
|
RegionView3D *rv3d;
|
|
|
|
ARegion *ar;
|
|
|
|
|
2012-01-13 15:35:36 +00:00
|
|
|
ScrArea *prevsa;
|
|
|
|
ARegion *prevar;
|
|
|
|
|
2016-03-31 15:35:47 +11:00
|
|
|
int views_len; /* multi-view views */
|
|
|
|
|
2014-01-28 03:52:21 +11:00
|
|
|
bool is_sequencer;
|
2012-03-29 23:33:50 +00:00
|
|
|
SpaceSeq *sseq;
|
2016-03-31 15:35:47 +11:00
|
|
|
struct {
|
|
|
|
ImBuf **ibufs_arr;
|
|
|
|
} seq_data;
|
2012-03-29 23:33:50 +00:00
|
|
|
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
Image *ima;
|
|
|
|
ImageUser iuser;
|
|
|
|
|
|
|
|
GPUOffScreen *ofs;
|
2015-10-14 12:39:52 +11:00
|
|
|
int ofs_samples;
|
2015-11-12 00:06:26 +11:00
|
|
|
bool ofs_full_samples;
|
2010-03-08 16:36:53 +00:00
|
|
|
int sizex, sizey;
|
2010-11-16 15:15:20 +00:00
|
|
|
int write_still;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
ReportList *reports;
|
|
|
|
bMovieHandle *mh;
|
|
|
|
int cfrao, nfra;
|
|
|
|
|
2015-10-24 01:01:10 +11:00
|
|
|
int totvideos;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
/* quick lookup */
|
|
|
|
int view_id;
|
|
|
|
|
2013-07-17 09:57:02 +00:00
|
|
|
/* wm vars for timer and progress cursor */
|
|
|
|
wmWindowManager *wm;
|
|
|
|
wmWindow *win;
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
wmTimer *timer; /* use to check if running modal or not (invoke'd or exec'd)*/
|
2015-04-06 10:40:12 -03:00
|
|
|
void **movie_ctx_arr;
|
2016-09-15 15:04:19 +02:00
|
|
|
|
2016-10-07 17:12:27 +02:00
|
|
|
TaskScheduler *task_scheduler;
|
2016-09-16 10:28:41 +02:00
|
|
|
TaskPool *task_pool;
|
|
|
|
bool pool_ok;
|
2016-09-17 00:21:34 +02:00
|
|
|
bool is_animation;
|
2016-09-16 10:28:41 +02:00
|
|
|
SpinLock reports_lock;
|
2016-10-07 17:46:13 +02:00
|
|
|
unsigned int num_scheduled_frames;
|
|
|
|
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
|
|
|
|
double time_start;
|
|
|
|
#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)
|
|
|
|
{
|
|
|
|
View3D *v3d = oglrender->v3d;
|
|
|
|
RegionView3D *rv3d = oglrender->rv3d;
|
|
|
|
RenderData *rd = &oglrender->scene->r;
|
|
|
|
|
|
|
|
if ((rd == NULL) || ((!oglrender->is_sequencer) && ((rv3d == NULL) || (v3d == NULL))))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (rd->scemode & R_MULTIVIEW) && ((oglrender->is_sequencer) || (rv3d->persp == RV3D_CAMOB && v3d->camera));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void screen_opengl_views_setup(OGLRender *oglrender)
|
|
|
|
{
|
|
|
|
RenderResult *rr;
|
|
|
|
RenderView *rv;
|
|
|
|
SceneRenderView *srv;
|
|
|
|
bool is_multiview;
|
2015-05-06 14:46:45 +02:00
|
|
|
Object *camera;
|
2015-04-06 10:40:12 -03:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (rv_del->rectf)
|
|
|
|
MEM_freeN(rv_del->rectf);
|
|
|
|
|
|
|
|
if (rv_del->rectz)
|
|
|
|
MEM_freeN(rv_del->rectz);
|
|
|
|
|
2016-09-15 15:34:37 +02:00
|
|
|
if (rv_del->rect32)
|
|
|
|
MEM_freeN(rv_del->rect32);
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
MEM_freeN(rv_del);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!oglrender->is_sequencer)
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (rv_del->rectf)
|
|
|
|
MEM_freeN(rv_del->rectf);
|
|
|
|
|
|
|
|
if (rv_del->rectz)
|
|
|
|
MEM_freeN(rv_del->rectz);
|
|
|
|
|
2016-09-15 15:34:37 +02:00
|
|
|
if (rv_del->rect32)
|
|
|
|
MEM_freeN(rv_del->rect32);
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
MEM_freeN(rv_del);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create all the views that are needed */
|
|
|
|
for (srv = rd->views.first; srv; srv = srv->next) {
|
|
|
|
if (BKE_scene_multiview_is_render_view_active(rd, srv) == false)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:14:02 +02:00
|
|
|
if (!(is_multiview && BKE_scene_multiview_is_stereo3d(rd)))
|
2015-04-06 10:40:12 -03:00
|
|
|
oglrender->iuser.flag &= ~IMA_SHOW_STEREO;
|
|
|
|
|
2015-05-06 14:46:45 +02:00
|
|
|
/* will only work for non multiview correctly */
|
2015-05-07 14:08:28 +02:00
|
|
|
if (v3d) {
|
|
|
|
camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, "new opengl render view");
|
2015-07-01 15:23:09 +02:00
|
|
|
BKE_render_result_stamp_info(oglrender->scene, camera, rr, false);
|
2015-05-07 14:08:28 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-07-01 15:23:09 +02:00
|
|
|
BKE_render_result_stamp_info(oglrender->scene, oglrender->scene->camera, rr, false);
|
2015-05-07 14:08:28 +02:00
|
|
|
}
|
2015-05-06 14:46:45 +02:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
RE_ReleaseResult(oglrender->re);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2018-10-30 12:59:36 +01:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2012-03-29 22:42:32 +00:00
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
ARegion *ar = oglrender->ar;
|
|
|
|
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);
|
2015-03-10 16:34:40 +01:00
|
|
|
bool draw_sky = (scene->r.alphamode == R_ADDSKY);
|
2018-01-03 13:22:19 +01:00
|
|
|
float *rectf = NULL;
|
2015-04-06 10:40:12 -03:00
|
|
|
const char *viewname = RE_GetActiveRenderView(oglrender->re);
|
2016-09-15 15:34:37 +02:00
|
|
|
ImBuf *ibuf_result = NULL;
|
2012-03-29 23:33:50 +00:00
|
|
|
|
|
|
|
if (oglrender->is_sequencer) {
|
2014-06-14 03:25:07 +10:00
|
|
|
SpaceSeq *sseq = oglrender->sseq;
|
|
|
|
struct bGPdata *gpd = (sseq && (sseq->flag & SEQ_SHOW_GPENCIL)) ? sseq->gpd : NULL;
|
2012-03-29 23:33:50 +00:00
|
|
|
|
2016-03-31 15:35:47 +11:00
|
|
|
/* use pre-calculated ImBuf (avoids deadlock), see: */
|
|
|
|
ImBuf *ibuf = oglrender->seq_data.ibufs_arr[oglrender->view_id];
|
2012-03-29 23:33:50 +00:00
|
|
|
|
|
|
|
if (ibuf) {
|
2015-11-16 18:20:41 +05:00
|
|
|
ImBuf *out = IMB_dupImBuf(ibuf);
|
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
|
|
|
IMB_freeImBuf(ibuf);
|
2015-11-16 18:20:41 +05:00
|
|
|
/* 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);
|
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-11-16 18:20:41 +05:00
|
|
|
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);
|
2012-03-29 23:33:50 +00:00
|
|
|
}
|
2017-03-02 00:16:36 +11:00
|
|
|
else if (gpd) {
|
2016-11-10 12:23:09 +01:00
|
|
|
/* 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);
|
|
|
|
}
|
2014-06-14 03:25:07 +10:00
|
|
|
|
|
|
|
if (gpd) {
|
|
|
|
int i;
|
|
|
|
unsigned char *gp_rect;
|
2015-11-23 15:44:15 +11:00
|
|
|
unsigned char *render_rect = (unsigned char *)RE_RenderViewGetById(rr, oglrender->view_id)->rect32;
|
2014-06-14 03:25:07 +10:00
|
|
|
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_enable();
|
2015-02-12 18:54:41 +01:00
|
|
|
GPU_offscreen_bind(oglrender->ofs, true);
|
2014-06-14 03:25:07 +10:00
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
GPU_clear(GPU_COLOR_BIT | GPU_DEPTH_BIT);
|
2014-06-14 03:25:07 +10:00
|
|
|
|
|
|
|
wmOrtho2(0, sizex, 0, sizey);
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_translate_2f(sizex / 2, sizey / 2);
|
2014-06-14 03:25:07 +10:00
|
|
|
|
2019-02-02 13:39:51 +11:00
|
|
|
G.f |= G_FLAG_RENDER_VIEWPORT;
|
2018-10-30 12:59:36 +01:00
|
|
|
ED_gpencil_draw_ex(
|
2019-03-15 08:53:22 +11:00
|
|
|
view_layer, rv3d, scene, gpd, sizex, sizey, scene->r.cfra, SPACE_SEQ);
|
2019-02-02 13:39:51 +11:00
|
|
|
G.f &= ~G_FLAG_RENDER_VIEWPORT;
|
2014-06-14 03:25:07 +10:00
|
|
|
|
|
|
|
gp_rect = MEM_mallocN(sizex * sizey * sizeof(unsigned char) * 4, "offscreen rect");
|
2015-09-14 13:13:44 +10:00
|
|
|
GPU_offscreen_read_pixels(oglrender->ofs, GL_UNSIGNED_BYTE, gp_rect);
|
2014-06-14 03:25:07 +10:00
|
|
|
|
|
|
|
for (i = 0; i < sizex * sizey * 4; i += 4) {
|
2015-11-23 15:44:15 +11:00
|
|
|
blend_color_mix_byte(&render_rect[i], &render_rect[i], &gp_rect[i]);
|
2014-06-14 03:25:07 +10:00
|
|
|
}
|
2015-02-12 18:54:41 +01:00
|
|
|
GPU_offscreen_unbind(oglrender->ofs, true);
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_disable();
|
2014-06-14 03:25:07 +10:00
|
|
|
|
|
|
|
MEM_freeN(gp_rect);
|
|
|
|
}
|
2012-03-29 23:33:50 +00:00
|
|
|
}
|
2015-11-11 21:56:25 +11:00
|
|
|
else {
|
|
|
|
/* shouldnt suddenly give errors mid-render but possible */
|
|
|
|
char err_out[256] = "unknown";
|
|
|
|
ImBuf *ibuf_view;
|
2015-11-12 00:06:26 +11:00
|
|
|
const int alpha_mode = (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL;
|
2015-11-11 21:56:25 +11:00
|
|
|
|
2017-11-24 11:43:16 +01:00
|
|
|
unsigned int draw_flags = V3D_OFSDRAW_NONE;
|
|
|
|
draw_flags |= (oglrender->ofs_full_samples) ? V3D_OFSDRAW_USE_FULL_SAMPLE : 0;
|
|
|
|
|
2015-11-11 21:56:25 +11:00
|
|
|
if (view_context) {
|
|
|
|
ibuf_view = ED_view3d_draw_offscreen_imbuf(
|
2018-07-11 14:20:39 +02:00
|
|
|
depsgraph, scene, v3d->shading.type,
|
2018-04-06 10:55:11 +02:00
|
|
|
v3d, ar, sizex, sizey,
|
2018-01-03 13:22:19 +01:00
|
|
|
IB_rectfloat, draw_flags, alpha_mode, oglrender->ofs_samples, viewname,
|
2018-03-22 16:10:54 +01:00
|
|
|
oglrender->ofs, err_out);
|
2015-11-11 21:56:25 +11:00
|
|
|
|
|
|
|
/* for stamp only */
|
|
|
|
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
|
|
|
|
camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, viewname);
|
2015-03-25 15:05:36 +01:00
|
|
|
}
|
2010-10-02 17:10:28 +00:00
|
|
|
}
|
|
|
|
else {
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
draw_flags |= V3D_OFSDRAW_USE_GPENCIL;
|
2015-11-11 21:56:25 +11:00
|
|
|
ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
depsgraph, scene, OB_SOLID,
|
2018-04-06 10:55:11 +02:00
|
|
|
scene->camera, oglrender->sizex, oglrender->sizey,
|
2018-04-17 13:35:05 +02:00
|
|
|
IB_rectfloat, draw_flags,
|
2017-11-24 11:43:16 +01:00
|
|
|
alpha_mode, oglrender->ofs_samples, viewname,
|
2018-03-22 16:10:54 +01:00
|
|
|
oglrender->ofs, err_out);
|
2015-11-11 21:56:25 +11:00
|
|
|
camera = scene->camera;
|
2010-10-02 17:10:28 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ibuf_view) {
|
2016-09-15 15:34:37 +02:00
|
|
|
ibuf_result = ibuf_view;
|
2018-01-03 13:22:19 +01:00
|
|
|
rectf = (float *)ibuf_view->rect_float;
|
2011-03-06 23:12:12 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-29 23:33:50 +00:00
|
|
|
fprintf(stderr, "%s: failed to get buffer, %s\n", __func__, err_out);
|
2011-03-06 23:12:12 +00:00
|
|
|
}
|
2010-05-23 10:47:19 +00:00
|
|
|
}
|
2013-01-05 15:33:18 +00:00
|
|
|
|
2016-09-15 15:34:37 +02:00
|
|
|
if (ibuf_result != NULL) {
|
2016-09-22 09:42:09 +02:00
|
|
|
if ((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW)) {
|
2018-01-03 13:22:19 +01:00
|
|
|
BKE_image_stamp_buf(scene, camera, NULL, NULL, rectf, rr->rectx, rr->recty, 4);
|
2016-09-22 09:42:09 +02:00
|
|
|
}
|
|
|
|
RE_render_result_rect_from_ibuf(rr, &scene->r, ibuf_result, oglrender->view_id);
|
2016-09-15 15:34:37 +02:00
|
|
|
IMB_freeImBuf(ibuf_result);
|
2015-01-24 16:48:23 +11:00
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
RenderResult *rr;
|
|
|
|
bool ok;
|
|
|
|
char name[FILE_MAX];
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
rr = RE_AcquireResultRead(oglrender->re);
|
2010-11-16 15:15:20 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
BKE_image_path_from_imformat(
|
2018-06-05 15:10:33 +02:00
|
|
|
name, scene->r.pic, BKE_main_blendfile_path(oglrender->bmain), scene->r.cfra,
|
2015-04-06 10:40:12 -03:00
|
|
|
&scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, false, NULL);
|
2013-04-11 15:15:06 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
/* write images as individual images or stereo */
|
2015-07-01 15:23:09 +02:00
|
|
|
BKE_render_result_stamp_info(scene, scene->camera, rr, false);
|
2015-04-21 18:33:33 +02:00
|
|
|
ok = RE_WriteRenderViewsImage(oglrender->reports, rr, scene, false, name);
|
2011-06-24 03:49:56 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
RE_ReleaseResultImage(oglrender->re);
|
2011-06-24 03:49:56 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (ok) printf("OpenGL Render written to '%s'\n", name);
|
|
|
|
else printf("OpenGL Render failed to write '%s'\n", name);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
/* d = s + (1-alpha_s)d*/
|
|
|
|
float mul;
|
|
|
|
|
|
|
|
mul = 1.0f - source[3];
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
RenderResult *rr;
|
|
|
|
RenderView *rv;
|
|
|
|
int view_id;
|
2015-04-08 12:49:39 +02:00
|
|
|
ImBuf *ibuf;
|
|
|
|
void *lock;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2016-03-31 15:35:47 +11:00
|
|
|
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(
|
2018-05-31 12:46:32 +02:00
|
|
|
oglrender->bmain, oglrender->depsgraph, scene,
|
2018-04-06 12:07:27 +02:00
|
|
|
oglrender->sizex, oglrender->sizey, 100.0f, false,
|
2016-03-31 15:35:47 +11:00
|
|
|
&context);
|
|
|
|
|
|
|
|
for (view_id = 0; view_id < oglrender->views_len; view_id++) {
|
|
|
|
context.view_id = view_id;
|
|
|
|
context.gpu_offscreen = oglrender->ofs;
|
|
|
|
context.gpu_full_samples = oglrender->ofs_full_samples;
|
|
|
|
|
|
|
|
oglrender->seq_data.ibufs_arr[view_id] = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
rr = RE_AcquireResultRead(oglrender->re);
|
|
|
|
for (rv = rr->views.first, view_id = 0; rv; rv = rv->next, view_id++) {
|
2016-03-31 15:35:47 +11:00
|
|
|
BLI_assert(view_id < oglrender->views_len);
|
2015-04-06 10:40:12 -03:00
|
|
|
RE_SetActiveRenderView(oglrender->re, rv->name);
|
|
|
|
oglrender->view_id = view_id;
|
2016-08-03 23:31:48 +02:00
|
|
|
/* render composite */
|
2017-07-21 11:53:13 +02:00
|
|
|
screen_opengl_render_doit(C, oglrender, rr);
|
2010-11-16 15:15:20 +00:00
|
|
|
}
|
2013-04-11 15:15:06 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
RE_ReleaseResult(oglrender->re);
|
|
|
|
|
2015-04-08 12:49:39 +02:00
|
|
|
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);
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (oglrender->write_still) {
|
|
|
|
screen_opengl_render_write(oglrender);
|
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 18:30:21 +02:00
|
|
|
static bool screen_opengl_fullsample_enabled(Scene *scene)
|
|
|
|
{
|
|
|
|
if (scene->r.scemode & R_FULL_SAMPLE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* XXX TODO:
|
|
|
|
* Technically if the hardware supports MSAA we could keep using Blender 2.7x approach.
|
|
|
|
* However anti-aliasing without full_sample is not playing well even in 2.7x.
|
|
|
|
*
|
|
|
|
* For example, if you enable depth of field, there is aliasing, even if the viewport is fine.
|
|
|
|
* For 2.8x this is more complicated because so many things rely on shader.
|
|
|
|
* So until we fix the gpu_framebuffer anti-aliasing suupport we need to force full sample.
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
/* new render clears all callbacks */
|
2013-07-17 09:57:02 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
wmWindow *win = CTX_wm_window(C);
|
2017-10-16 17:15:03 -02:00
|
|
|
WorkSpace *workspace = CTX_wm_workspace(C);
|
2013-07-17 09:57:02 +00:00
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ScrArea *prevsa = CTX_wm_area(C);
|
|
|
|
ARegion *prevar = CTX_wm_region(C);
|
2010-03-08 16:36:53 +00:00
|
|
|
GPUOffScreen *ofs;
|
|
|
|
OGLRender *oglrender;
|
|
|
|
int sizex, sizey;
|
2015-10-14 12:39:52 +11:00
|
|
|
const int samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
|
2017-06-26 18:30:21 +02:00
|
|
|
const bool full_samples = (samples != 0) && screen_opengl_fullsample_enabled(scene);
|
2014-01-28 03:52:21 +11:00
|
|
|
bool is_view_context = RNA_boolean_get(op->ptr, "view_context");
|
|
|
|
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
|
|
|
|
const bool is_sequencer = RNA_boolean_get(op->ptr, "sequencer");
|
|
|
|
const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
|
2012-03-29 22:42:32 +00:00
|
|
|
char err_out[256] = "unknown";
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (G.background) {
|
2012-10-26 17:32:50 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Cannot use OpenGL render in background mode (no opengl context)");
|
2014-01-28 03:52:21 +11:00
|
|
|
return false;
|
2012-01-13 06:59:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-25 23:49:53 +10:00
|
|
|
/* only one render job at a time */
|
|
|
|
if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER))
|
|
|
|
return false;
|
2010-11-16 15:15:20 +00:00
|
|
|
|
2014-05-25 23:49:53 +10:00
|
|
|
if (is_sequencer) {
|
2014-01-28 03:52:21 +11:00
|
|
|
is_view_context = false;
|
2010-05-23 10:47:19 +00:00
|
|
|
}
|
2014-05-25 23:49:53 +10:00
|
|
|
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;
|
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2014-05-25 23:49:53 +10:00
|
|
|
if (!is_view_context && scene->camera == NULL) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Scene has no camera");
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-23 10:47:19 +00:00
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
2012-10-26 17:32:50 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Cannot write a single file with an animation format selected");
|
2014-01-28 03:52:21 +11:00
|
|
|
return false;
|
2010-11-16 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 17:41:19 +00:00
|
|
|
/* stop all running jobs, except screen one. currently previews frustrate Render */
|
2013-07-17 09:57:02 +00:00
|
|
|
WM_jobs_kill_all_except(wm, CTX_wm_screen(C));
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
/* create offscreen buffer */
|
2012-03-29 22:42:32 +00:00
|
|
|
sizex = (scene->r.size * scene->r.xsch) / 100;
|
|
|
|
sizey = (scene->r.size * scene->r.ysch) / 100;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2010-12-16 19:05:47 +00:00
|
|
|
/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_enable(); /* Offscreen creation needs to be done in DRW context. */
|
2018-02-13 18:18:04 +01:00
|
|
|
ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, true, true, err_out);
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_disable();
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ofs) {
|
2012-10-13 13:40:05 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer, %s", err_out);
|
2014-01-28 03:52:21 +11:00
|
|
|
return false;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate opengl render */
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender = MEM_callocN(sizeof(OGLRender), "OGLRender");
|
|
|
|
op->customdata = oglrender;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->ofs = ofs;
|
2015-10-14 12:39:52 +11:00
|
|
|
oglrender->ofs_samples = samples;
|
2015-11-12 00:06:26 +11:00
|
|
|
oglrender->ofs_full_samples = full_samples;
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->sizex = sizex;
|
|
|
|
oglrender->sizey = sizey;
|
|
|
|
oglrender->bmain = CTX_data_main(C);
|
|
|
|
oglrender->scene = scene;
|
2017-10-16 17:15:03 -02:00
|
|
|
oglrender->workspace = workspace;
|
2017-11-22 10:52:39 -02:00
|
|
|
oglrender->view_layer = CTX_data_view_layer(C);
|
2017-11-03 17:57:46 +01:00
|
|
|
oglrender->depsgraph = CTX_data_depsgraph(C);
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->cfrao = scene->r.cfra;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->write_still = is_write_still && !is_animation;
|
2016-09-17 00:21:34 +02:00
|
|
|
oglrender->is_animation = is_animation;
|
2010-11-16 15:15:20 +00:00
|
|
|
|
2016-03-31 15:35:47 +11:00
|
|
|
oglrender->views_len = BKE_scene_multiview_num_views_get(&scene->r);
|
|
|
|
|
2012-03-29 23:33:50 +00:00
|
|
|
oglrender->is_sequencer = is_sequencer;
|
|
|
|
if (is_sequencer) {
|
2012-04-29 15:47:02 +00:00
|
|
|
oglrender->sseq = CTX_wm_space_seq(C);
|
2016-03-31 15:35:47 +11:00
|
|
|
ImBuf **ibufs_arr = MEM_callocN(sizeof(*ibufs_arr) * oglrender->views_len, __func__);
|
|
|
|
oglrender->seq_data.ibufs_arr = ibufs_arr;
|
2012-03-29 23:33:50 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->prevsa = prevsa;
|
|
|
|
oglrender->prevar = prevar;
|
2012-01-13 15:35:36 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (is_view_context) {
|
2019-01-15 23:24:20 +11:00
|
|
|
/* so quad view renders camera */
|
|
|
|
ED_view3d_context_user_region(C, &oglrender->v3d, &oglrender->ar);
|
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->rv3d = oglrender->ar->regiondata;
|
2011-03-13 02:44:25 +00:00
|
|
|
|
|
|
|
/* MUST be cleared on exit */
|
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
|
|
|
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);
|
2012-01-09 02:50:09 +00:00
|
|
|
|
2012-03-09 00:41:09 +00:00
|
|
|
/* apply immediately in case we're rendering from a script,
|
2012-01-09 02:50:09 +00:00
|
|
|
* running notifiers again will overwrite */
|
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
|
|
|
CustomData_MeshMasks_update(&oglrender->scene->customdata_mask, &oglrender->scene->customdata_mask_modal);
|
2017-11-24 12:19:26 +01:00
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2011-11-29 22:37:16 +00:00
|
|
|
/* create render */
|
2017-09-12 11:27:22 +05:00
|
|
|
oglrender->re = RE_NewSceneRender(scene);
|
2011-11-29 22:37:16 +00:00
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* create image and image user */
|
2018-06-11 15:40:37 +02:00
|
|
|
oglrender->ima = BKE_image_verify_viewer(oglrender->bmain, IMA_TYPE_R_RESULT, "Render Result");
|
|
|
|
BKE_image_signal(oglrender->bmain, oglrender->ima, NULL, IMA_SIGNAL_FREE);
|
2015-11-30 00:51:30 +01:00
|
|
|
BKE_image_backup_render(oglrender->scene, oglrender->ima, true);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->iuser.scene = scene;
|
|
|
|
oglrender->iuser.ok = 1;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2011-11-29 22:37:16 +00:00
|
|
|
/* create render result */
|
2018-04-24 15:20:17 +02:00
|
|
|
RE_InitState(oglrender->re, NULL, &scene->r, &scene->view_layers, NULL, sizex, sizey, NULL);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
/* create render views */
|
|
|
|
screen_opengl_views_setup(oglrender);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2013-07-17 09:57:02 +00:00
|
|
|
/* wm vars */
|
|
|
|
oglrender->wm = wm;
|
|
|
|
oglrender->win = win;
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
oglrender->totvideos = 0;
|
|
|
|
oglrender->mh = NULL;
|
|
|
|
oglrender->movie_ctx_arr = NULL;
|
|
|
|
|
2016-09-16 10:28:41 +02:00
|
|
|
if (is_animation) {
|
|
|
|
TaskScheduler *task_scheduler = BLI_task_scheduler_get();
|
|
|
|
if (BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
2016-10-07 17:12:27 +02:00
|
|
|
task_scheduler = BLI_task_scheduler_create(1);
|
|
|
|
oglrender->task_scheduler = task_scheduler;
|
2016-09-16 10:28:41 +02:00
|
|
|
oglrender->task_pool = BLI_task_pool_create_background(task_scheduler,
|
|
|
|
oglrender);
|
|
|
|
}
|
|
|
|
else {
|
2016-10-07 17:12:27 +02:00
|
|
|
oglrender->task_scheduler = NULL;
|
2016-09-16 10:28:41 +02:00
|
|
|
oglrender->task_pool = BLI_task_pool_create(task_scheduler,
|
|
|
|
oglrender);
|
|
|
|
}
|
2016-09-17 00:21:34 +02:00
|
|
|
oglrender->pool_ok = true;
|
|
|
|
BLI_spin_init(&oglrender->reports_lock);
|
2016-09-16 10:28:41 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-10-07 17:12:27 +02:00
|
|
|
oglrender->task_scheduler = NULL;
|
2016-09-16 10:28:41 +02:00
|
|
|
oglrender->task_pool = NULL;
|
|
|
|
}
|
2016-10-07 17:46:13 +02:00
|
|
|
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
|
|
|
|
oglrender->time_start = PIL_check_seconds_timer();
|
|
|
|
#endif
|
|
|
|
|
2014-01-28 03:52:21 +11:00
|
|
|
return true;
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void screen_opengl_render_end(bContext *C, OGLRender *oglrender)
|
|
|
|
{
|
2012-03-29 22:42:32 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
Scene *scene = oglrender->scene;
|
2015-10-24 01:01:10 +11:00
|
|
|
int i;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2016-09-17 00:21:34 +02:00
|
|
|
if (oglrender->is_animation) {
|
2017-03-03 10:48:13 +01:00
|
|
|
/* 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);
|
|
|
|
}
|
2016-09-17 00:21:34 +02:00
|
|
|
BLI_task_pool_work_and_wait(oglrender->task_pool);
|
|
|
|
BLI_task_pool_free(oglrender->task_pool);
|
2016-10-14 18:45:49 +02:00
|
|
|
/* Depending on various things we might or might not use global scheduler. */
|
|
|
|
if (oglrender->task_scheduler != NULL) {
|
|
|
|
BLI_task_scheduler_free(oglrender->task_scheduler);
|
|
|
|
}
|
2016-09-17 00:21:34 +02:00
|
|
|
BLI_spin_end(&oglrender->reports_lock);
|
|
|
|
}
|
2016-10-07 17:46:13 +02:00
|
|
|
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
|
|
|
|
printf("Total render time: %f\n", PIL_check_seconds_timer() - oglrender->time_start);
|
|
|
|
#endif
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (oglrender->mh) {
|
2015-04-06 10:40:12 -03:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oglrender->movie_ctx_arr) {
|
|
|
|
MEM_freeN(oglrender->movie_ctx_arr);
|
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (oglrender->timer) { /* exec will not have a timer */
|
2017-11-09 11:20:17 +01:00
|
|
|
Depsgraph *depsgraph = oglrender->depsgraph;
|
2012-03-29 22:42:32 +00:00
|
|
|
scene->r.cfra = oglrender->cfrao;
|
2018-04-06 11:21:20 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph, bmain);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2013-07-17 09:57:02 +00:00
|
|
|
WM_event_remove_timer(oglrender->wm, oglrender->win, oglrender->timer);
|
|
|
|
}
|
|
|
|
|
2013-09-06 22:34:29 +00:00
|
|
|
WM_cursor_modal_restore(oglrender->win);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, oglrender->scene);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_enable();
|
2010-03-08 16:36:53 +00:00
|
|
|
GPU_offscreen_free(oglrender->ofs);
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_disable();
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2016-03-31 15:35:47 +11:00
|
|
|
if (oglrender->is_sequencer) {
|
|
|
|
MEM_freeN(oglrender->seq_data.ibufs_arr);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
memset(&oglrender->scene->customdata_mask_modal, 0, sizeof(oglrender->scene->customdata_mask_modal));
|
2011-03-13 02:44:25 +00:00
|
|
|
|
2012-01-13 15:35:36 +00:00
|
|
|
CTX_wm_area_set(C, oglrender->prevsa);
|
|
|
|
CTX_wm_region_set(C, oglrender->prevar);
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
MEM_freeN(oglrender);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
screen_opengl_render_end(C, op->customdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* share between invoke and exec */
|
2015-09-23 02:40:08 +10:00
|
|
|
static bool screen_opengl_render_anim_initialize(bContext *C, wmOperator *op)
|
2010-03-08 16:36:53 +00:00
|
|
|
{
|
|
|
|
/* initialize animation */
|
|
|
|
OGLRender *oglrender;
|
|
|
|
Scene *scene;
|
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender = op->customdata;
|
|
|
|
scene = oglrender->scene;
|
2015-04-06 10:40:12 -03:00
|
|
|
oglrender->totvideos = BKE_scene_multiview_num_videos_get(&scene->r);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->reports = op->reports;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
2015-10-24 01:01:10 +11:00
|
|
|
size_t width, height;
|
|
|
|
int i;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-09-23 02:40:08 +10:00
|
|
|
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");
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
for (i = 0; i < oglrender->totvideos; i++) {
|
|
|
|
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], scene, &scene->r, oglrender->sizex,
|
|
|
|
oglrender->sizey, oglrender->reports, PRVRANGEON != 0, suffix))
|
|
|
|
{
|
|
|
|
screen_opengl_render_end(C, oglrender);
|
2015-09-23 02:40:08 +10:00
|
|
|
return false;
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->cfrao = scene->r.cfra;
|
|
|
|
oglrender->nfra = PSFRA;
|
|
|
|
scene->r.cfra = PSFRA;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2015-09-23 02:40:08 +10:00
|
|
|
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 {
|
|
|
|
RenderResult *rr;
|
2017-04-26 15:11:58 +02:00
|
|
|
Scene tmp_scene;
|
2016-09-16 10:28:41 +02:00
|
|
|
} WriteTaskData;
|
|
|
|
|
|
|
|
static void write_result_func(TaskPool * __restrict pool,
|
|
|
|
void *task_data_v,
|
|
|
|
int UNUSED(thread_id))
|
|
|
|
{
|
|
|
|
OGLRender *oglrender = (OGLRender *) BLI_task_pool_userdata(pool);
|
|
|
|
WriteTaskData *task_data = (WriteTaskData *) task_data_v;
|
2017-04-26 15:11:58 +02:00
|
|
|
Scene *scene = &task_data->tmp_scene;
|
2016-09-16 10:28:41 +02:00
|
|
|
RenderResult *rr = task_data->rr;
|
|
|
|
const bool is_movie = BKE_imtype_is_movie(scene->r.im_format.imtype);
|
2017-04-26 15:11:58 +02:00
|
|
|
const int cfra = scene->r.cfra;
|
2016-09-16 10:28:41 +02:00
|
|
|
bool ok;
|
2016-10-07 16:05:51 +02:00
|
|
|
/* Don't attempt to write if we've got an error. */
|
2016-10-10 12:51:01 +02:00
|
|
|
if (!oglrender->pool_ok) {
|
2016-10-07 16:05:51 +02:00
|
|
|
RE_FreeRenderResult(rr);
|
2016-10-07 17:46:13 +02:00
|
|
|
BLI_mutex_lock(&oglrender->task_mutex);
|
|
|
|
oglrender->num_scheduled_frames--;
|
|
|
|
BLI_condition_notify_all(&oglrender->task_condition);
|
|
|
|
BLI_mutex_unlock(&oglrender->task_mutex);
|
2016-10-07 16:05:51 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-09-16 10:28:41 +02:00
|
|
|
/* 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);
|
2017-03-03 16:36:21 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
2016-09-16 10:28:41 +02:00
|
|
|
if (is_movie) {
|
|
|
|
ok = RE_WriteRenderViewsMovie(&reports,
|
|
|
|
rr,
|
2017-04-26 15:11:58 +02:00
|
|
|
scene,
|
|
|
|
&scene->r,
|
2016-09-16 10:28:41 +02:00
|
|
|
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,
|
2018-06-05 15:10:33 +02:00
|
|
|
BKE_main_blendfile_path(oglrender->bmain),
|
2016-09-16 10:28:41 +02:00
|
|
|
cfra,
|
|
|
|
&scene->r.im_format,
|
|
|
|
(scene->r.scemode & R_EXTENSION) != 0,
|
|
|
|
true,
|
|
|
|
NULL);
|
|
|
|
|
2017-04-26 15:11:58 +02:00
|
|
|
BKE_render_result_stamp_info(scene, scene->camera, rr, false);
|
|
|
|
ok = RE_WriteRenderViewsImage(NULL, rr, scene, true, name);
|
2016-09-16 10:28:41 +02:00
|
|
|
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);
|
2016-10-07 17:46:13 +02:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (!oglrender->pool_ok) {
|
2016-10-07 16:05:51 +02:00
|
|
|
RE_FreeRenderResult(rr);
|
2016-09-16 10:28:41 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
WriteTaskData *task_data = MEM_mallocN(sizeof(WriteTaskData), "write task data");
|
|
|
|
task_data->rr = rr;
|
2017-04-26 15:11:58 +02:00
|
|
|
task_data->tmp_scene = *scene;
|
2016-10-07 17:46:13 +02:00
|
|
|
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);
|
2016-09-16 10:28:41 +02:00
|
|
|
BLI_task_pool_push(oglrender->task_pool,
|
|
|
|
write_result_func,
|
|
|
|
task_data,
|
|
|
|
true,
|
|
|
|
TASK_PRIORITY_LOW);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-03-29 22:42:32 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
OGLRender *oglrender = op->customdata;
|
|
|
|
Scene *scene = oglrender->scene;
|
2017-11-09 11:20:17 +01:00
|
|
|
Depsgraph *depsgraph = oglrender->depsgraph;
|
2011-11-26 04:07:38 +00:00
|
|
|
char name[FILE_MAX];
|
2014-04-11 11:25:41 +10:00
|
|
|
bool ok = false;
|
|
|
|
const bool view_context = (oglrender->v3d != NULL);
|
2014-02-03 18:55:59 +11:00
|
|
|
bool is_movie;
|
2015-04-06 10:40:12 -03:00
|
|
|
RenderResult *rr;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
/* go to next frame */
|
2012-07-07 22:51:57 +00:00
|
|
|
if (CFRA < oglrender->nfra)
|
|
|
|
CFRA++;
|
2012-03-29 22:42:32 +00:00
|
|
|
while (CFRA < oglrender->nfra) {
|
2018-04-06 11:21:20 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph, bmain);
|
2010-03-08 16:36:53 +00:00
|
|
|
CFRA++;
|
|
|
|
}
|
|
|
|
|
2012-07-27 08:58:34 +00:00
|
|
|
is_movie = BKE_imtype_is_movie(scene->r.im_format.imtype);
|
|
|
|
|
|
|
|
if (!is_movie) {
|
2015-01-24 16:48:23 +11:00
|
|
|
BKE_image_path_from_imformat(
|
2018-06-05 15:10:33 +02:00
|
|
|
name, scene->r.pic, BKE_main_blendfile_path(oglrender->bmain), scene->r.cfra,
|
2015-04-06 10:40:12 -03:00
|
|
|
&scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, true, NULL);
|
2012-07-27 08:58:34 +00:00
|
|
|
|
|
|
|
if ((scene->r.mode & R_NO_OVERWRITE) && BLI_exists(name)) {
|
2016-09-16 10:28:41 +02:00
|
|
|
BLI_spin_lock(&oglrender->reports_lock);
|
2013-09-30 08:21:12 +00:00
|
|
|
BKE_reportf(op->reports, RPT_INFO, "Skipping existing frame \"%s\"", name);
|
2016-09-16 10:28:41 +02:00
|
|
|
BLI_spin_unlock(&oglrender->reports_lock);
|
2013-09-30 08:21:12 +00:00
|
|
|
ok = true;
|
|
|
|
goto finally;
|
2012-07-27 08:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-31 09:18:40 +00:00
|
|
|
WM_cursor_time(oglrender->win, scene->r.cfra);
|
2013-07-17 09:57:02 +00:00
|
|
|
|
2018-04-06 11:21:20 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph, bmain);
|
2010-05-23 10:47:19 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (view_context) {
|
2012-03-29 22:42:32 +00:00
|
|
|
if (oglrender->rv3d->persp == RV3D_CAMOB && oglrender->v3d->camera && oglrender->v3d->scenelock) {
|
2017-11-03 17:57:46 +01:00
|
|
|
/* since BKE_scene_graph_update_for_newframe() is used rather
|
2010-05-23 10:47:19 +00:00
|
|
|
* then ED_update_for_newframe() the camera needs to be set */
|
2012-05-05 14:33:36 +00:00
|
|
|
if (BKE_scene_camera_switch_update(scene)) {
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->v3d->camera = scene->camera;
|
2011-04-30 05:26:09 +00:00
|
|
|
}
|
2010-05-23 10:47:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-05 14:33:36 +00:00
|
|
|
BKE_scene_camera_switch_update(scene);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* render into offscreen buffer */
|
2017-07-21 11:53:13 +02:00
|
|
|
screen_opengl_render_apply(C, oglrender);
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
/* save to disk */
|
2015-04-06 10:40:12 -03:00
|
|
|
rr = RE_AcquireResultRead(oglrender->re);
|
2016-09-16 10:28:41 +02:00
|
|
|
RenderResult *new_rr = RE_DuplicateRenderResult(rr);
|
2015-04-06 10:40:12 -03:00
|
|
|
RE_ReleaseResult(oglrender->re);
|
|
|
|
|
2016-09-16 10:28:41 +02:00
|
|
|
ok = schedule_write_result(oglrender, new_rr);
|
2013-09-30 08:21:12 +00:00
|
|
|
|
|
|
|
finally: /* Step the frame and bail early if needed */
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* go to next frame */
|
|
|
|
oglrender->nfra += scene->r.frame_step;
|
|
|
|
|
|
|
|
/* stop at the end or on error */
|
2012-07-07 22:51:57 +00:00
|
|
|
if (CFRA >= PEFRA || !ok) {
|
2010-03-08 16:36:53 +00:00
|
|
|
screen_opengl_render_end(C, op->customdata);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-03-29 22:42:32 +00:00
|
|
|
OGLRender *oglrender = op->customdata;
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool anim = RNA_boolean_get(op->ptr, "animation");
|
2013-09-30 08:21:12 +00:00
|
|
|
bool ret;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
switch (event->type) {
|
2010-03-08 16:36:53 +00:00
|
|
|
case ESCKEY:
|
|
|
|
/* cancel */
|
2016-10-10 15:52:10 +02:00
|
|
|
oglrender->pool_ok = false; /* Flag pool for cancel. */
|
2010-03-08 16:36:53 +00:00
|
|
|
screen_opengl_render_end(C, op->customdata);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
case TIMER:
|
|
|
|
/* render frame? */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (oglrender->timer == event->customdata)
|
2010-03-08 16:36:53 +00:00
|
|
|
break;
|
2017-05-20 14:01:03 +10:00
|
|
|
ATTR_FALLTHROUGH;
|
2010-03-08 16:36:53 +00:00
|
|
|
default:
|
|
|
|
/* nothing to do */
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2010-07-01 11:58:48 +00:00
|
|
|
/* run first because screen_opengl_render_anim_step can free oglrender */
|
2012-03-29 22:42:32 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, oglrender->scene);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (anim == 0) {
|
2017-07-21 11:53:13 +02:00
|
|
|
screen_opengl_render_apply(C, op->customdata);
|
2010-12-27 18:00:35 +00:00
|
|
|
screen_opengl_render_end(C, op->customdata);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2013-09-30 08:21:12 +00:00
|
|
|
else {
|
2012-03-29 22:42:32 +00:00
|
|
|
ret = screen_opengl_render_anim_step(C, op);
|
2013-09-30 08:21:12 +00:00
|
|
|
}
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
/* stop at the end or on error */
|
2013-09-30 08:21:12 +00:00
|
|
|
if (ret == false) {
|
2010-03-08 16:36:53 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-12-27 18:00:35 +00:00
|
|
|
OGLRender *oglrender;
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool anim = RNA_boolean_get(op->ptr, "animation");
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!screen_opengl_render_init(C, op))
|
2010-03-08 16:36:53 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (anim) {
|
|
|
|
if (!screen_opengl_render_anim_initialize(C, op))
|
2010-03-08 16:36:53 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender = op->customdata;
|
2015-10-07 00:27:27 +11:00
|
|
|
render_view_open(C, event->x, event->y, op->reports);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-07-22 23:44:46 +00:00
|
|
|
/* view may be changed above (R_OUTPUT_WINDOW) */
|
|
|
|
oglrender->win = CTX_wm_window(C);
|
|
|
|
|
2010-12-27 18:00:35 +00:00
|
|
|
WM_event_add_modal_handler(C, op);
|
2013-07-17 09:57:02 +00:00
|
|
|
oglrender->timer = WM_event_add_timer(oglrender->wm, oglrender->win, TIMER, 0.01f);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-12-27 18:00:35 +00: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)
|
|
|
|
{
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!screen_opengl_render_init(C, op))
|
2010-03-08 16:36:53 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!is_animation) { /* same as invoke */
|
2010-03-08 16:36:53 +00:00
|
|
|
/* render image */
|
2017-07-21 11:53:13 +02:00
|
|
|
screen_opengl_render_apply(C, op->customdata);
|
2010-03-08 16:36:53 +00:00
|
|
|
screen_opengl_render_end(C, op->customdata);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
else {
|
2013-09-30 08:21:12 +00:00
|
|
|
bool ret = true;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!screen_opengl_render_anim_initialize(C, op))
|
2010-03-08 16:36:53 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
while (ret) {
|
2012-03-29 22:42:32 +00:00
|
|
|
ret = screen_opengl_render_anim_step(C, op);
|
2010-03-08 16:36:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-20 20:20:02 +00:00
|
|
|
/* no redraw needed, we leave state as we entered it */
|
2017-10-26 10:18:15 +02:00
|
|
|
// ED_update_for_newframe(C);
|
2012-03-29 22:42:32 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, CTX_data_scene(C));
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RENDER_OT_opengl(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-29 23:33:50 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* identifiers */
|
2018-10-31 00:29:45 +01:00
|
|
|
ot->name = "Viewport Render";
|
|
|
|
ot->description = "Take a snapshot of the active viewport";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "RENDER_OT_opengl";
|
2010-03-08 16:36:53 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00: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;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_screenactive;
|
2010-03-08 16:36:53 +00:00
|
|
|
|
2012-03-29 23:33:50 +00: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);
|
2012-04-02 06:56:16 +00:00
|
|
|
prop = RNA_def_boolean(ot->srna, "sequencer", 0, "Sequencer", "Render using the sequencer's OpenGL display");
|
2012-03-29 23:33:50 +00:00
|
|
|
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
|
|
|
}
|
2010-03-08 20:08:04 +00:00
|
|
|
|
|
|
|
/* function for getting an opengl buffer from a View3D, used by sequencer */
|
|
|
|
// extern void *sequencer_view3d_cb;
|