2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2010-03-08 16:36:53 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/render/render_opengl.c
|
|
|
|
* \ingroup edrend
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
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"
|
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"
|
|
|
|
|
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-02-12 18:54:41 +01:00
|
|
|
#include "GPU_compositing.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;
|
2015-02-12 18:54:41 +01:00
|
|
|
GPUFX *fx;
|
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
|
|
|
{
|
2012-03-29 22:42:32 +00:00
|
|
|
Scene *scene = oglrender->scene;
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer = oglrender->view_layer;
|
2012-03-29 22:42:32 +00:00
|
|
|
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);
|
2013-04-11 15:15:06 +00:00
|
|
|
bool draw_bgpic = true;
|
2015-03-10 16:34:40 +01:00
|
|
|
bool draw_sky = (scene->r.alphamode == R_ADDSKY);
|
2013-04-11 15:15:06 +00:00
|
|
|
unsigned char *rect = 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;
|
2017-07-21 11:53:13 +02:00
|
|
|
EvaluationContext eval_ctx;
|
|
|
|
|
|
|
|
CTX_data_eval_ctx(C, &eval_ctx);
|
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
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
GPU_offscreen_bind(oglrender->ofs, true);
|
2014-06-14 03:25:07 +10:00
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
wmOrtho2(0, sizex, 0, sizey);
|
2017-03-21 16:08:14 -04:00
|
|
|
gpuTranslate2f(sizex / 2, sizey / 2);
|
2014-06-14 03:25:07 +10:00
|
|
|
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
G.f |= G_RENDER_OGL;
|
2014-12-20 16:18:18 +01:00
|
|
|
ED_gpencil_draw_ex(scene, gpd, sizex, sizey, scene->r.cfra, SPACE_SEQ);
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
G.f &= ~G_RENDER_OGL;
|
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);
|
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) {
|
2017-11-24 11:43:16 +01:00
|
|
|
draw_flags |= (draw_bgpic) ? V3D_OFSDRAW_USE_BACKGROUND : 0;
|
|
|
|
|
2015-11-11 21:56:25 +11:00
|
|
|
ibuf_view = ED_view3d_draw_offscreen_imbuf(
|
2017-11-22 10:52:39 -02:00
|
|
|
&eval_ctx, scene, view_layer, v3d, ar, sizex, sizey,
|
2017-11-24 11:43:16 +01:00
|
|
|
IB_rect, draw_flags, alpha_mode, oglrender->ofs_samples, viewname,
|
2015-11-11 21:56:25 +11:00
|
|
|
oglrender->fx, oglrender->ofs, err_out);
|
|
|
|
|
|
|
|
/* 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 {
|
2017-11-24 11:43:16 +01:00
|
|
|
draw_flags |= (V3D_OFSDRAW_USE_GPENCIL | V3D_OFSDRAW_USE_BACKGROUND);
|
2015-11-11 21:56:25 +11:00
|
|
|
ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
|
2017-11-22 10:52:39 -02:00
|
|
|
&eval_ctx, scene, view_layer, scene->camera, oglrender->sizex, oglrender->sizey,
|
2017-11-24 11:43:16 +01:00
|
|
|
IB_rect, draw_flags, OB_SOLID,
|
|
|
|
alpha_mode, oglrender->ofs_samples, viewname,
|
2015-11-11 21:56:25 +11:00
|
|
|
oglrender->fx, oglrender->ofs, err_out);
|
|
|
|
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;
|
2013-04-12 00:50:40 +00:00
|
|
|
rect = (unsigned char *)ibuf_view->rect;
|
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)) {
|
2016-09-15 15:34:37 +02:00
|
|
|
BKE_image_stamp_buf(scene, camera, NULL, rect, NULL, 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(
|
|
|
|
name, scene->r.pic, oglrender->bmain->name, scene->r.cfra,
|
|
|
|
&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);
|
|
|
|
}
|
|
|
|
|
2016-08-03 23:31:48 +02:00
|
|
|
static void addAlphaOverFloat(float dest[4], const float source[4])
|
|
|
|
{
|
|
|
|
/* 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];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add renderlayer and renderpass for each grease pencil layer for using in composition */
|
2017-07-21 11:53:13 +02:00
|
|
|
static void add_gpencil_renderpass(const bContext *C, OGLRender *oglrender, RenderResult *rr, RenderView *rv)
|
2016-08-03 23:31:48 +02:00
|
|
|
{
|
|
|
|
bGPdata *gpd = oglrender->scene->gpd;
|
|
|
|
Scene *scene = oglrender->scene;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (gpd == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (scene == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (BLI_listbase_is_empty(&gpd->layers)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-12 10:01:30 +02:00
|
|
|
if (oglrender->v3d != NULL && (oglrender->v3d->flag2 & V3D_SHOW_GPENCIL) == 0) {
|
2016-09-15 11:23:11 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-08-03 23:31:48 +02:00
|
|
|
|
|
|
|
/* save old alpha mode */
|
|
|
|
short oldalphamode = scene->r.alphamode;
|
|
|
|
/* set alpha transparent for gp */
|
|
|
|
scene->r.alphamode = R_ALPHAPREMUL;
|
|
|
|
|
|
|
|
/* saves layer status */
|
|
|
|
short *oldsts = MEM_mallocN(BLI_listbase_count(&gpd->layers) * sizeof(short), "temp_gplayers_flag");
|
|
|
|
int i = 0;
|
|
|
|
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
|
|
|
|
oldsts[i] = gpl->flag;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
/* loop all layers to create separate render */
|
|
|
|
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
|
|
|
|
/* dont draw layer if hidden */
|
|
|
|
if (gpl->flag & GP_LAYER_HIDE)
|
|
|
|
continue;
|
|
|
|
/* hide all layer except current */
|
|
|
|
for (bGPDlayer *gph = gpd->layers.first; gph; gph = gph->next) {
|
|
|
|
if (gpl != gph) {
|
|
|
|
gph->flag |= GP_LAYER_HIDE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* render this gp layer */
|
2017-07-21 11:53:13 +02:00
|
|
|
screen_opengl_render_doit(C, oglrender, rr);
|
2016-08-03 23:31:48 +02:00
|
|
|
|
|
|
|
/* add RendePass composite */
|
|
|
|
RenderPass *rp = RE_create_gp_pass(rr, gpl->info, rv->name);
|
|
|
|
|
|
|
|
/* copy image data from rectf */
|
2016-09-15 15:34:37 +02:00
|
|
|
// XXX: Needs conversion.
|
|
|
|
unsigned char *src = (unsigned char *)RE_RenderViewGetById(rr, oglrender->view_id)->rect32;
|
2016-11-11 22:27:10 +01:00
|
|
|
if (src != NULL) {
|
|
|
|
float *dest = rp->rect;
|
|
|
|
|
|
|
|
int x, y, rectx, recty;
|
|
|
|
rectx = rr->rectx;
|
|
|
|
recty = rr->recty;
|
|
|
|
for (y = 0; y < recty; y++) {
|
|
|
|
for (x = 0; x < rectx; x++) {
|
|
|
|
unsigned char *pixSrc = src + 4 * (rectx * y + x);
|
|
|
|
if (pixSrc[3] > 0) {
|
|
|
|
float *pixDest = dest + 4 * (rectx * y + x);
|
|
|
|
float float_src[4];
|
|
|
|
srgb_to_linearrgb_uchar4(float_src, pixSrc);
|
|
|
|
addAlphaOverFloat(pixDest, float_src);
|
|
|
|
}
|
2016-08-03 23:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* back layer status */
|
|
|
|
i = 0;
|
|
|
|
for (bGPDlayer *gph = gpd->layers.first; gph; gph = gph->next) {
|
|
|
|
gph->flag = oldsts[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* free memory */
|
|
|
|
MEM_freeN(oldsts);
|
|
|
|
|
|
|
|
/* back default alpha mode */
|
|
|
|
scene->r.alphamode = oldalphamode;
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
oglrender->bmain->eval_ctx, oglrender->bmain, scene,
|
|
|
|
oglrender->sizex, oglrender->sizey, 100.0f,
|
|
|
|
&context);
|
|
|
|
|
|
|
|
for (view_id = 0; view_id < oglrender->views_len; view_id++) {
|
|
|
|
context.view_id = view_id;
|
|
|
|
context.gpu_offscreen = oglrender->ofs;
|
|
|
|
context.gpu_fx = oglrender->fx;
|
|
|
|
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-11-16 21:33:47 +01:00
|
|
|
/* add grease pencil passes. For sequencer, the render does not include renderpasses
|
|
|
|
* TODO: The sequencer render of grease pencil should be rethought */
|
|
|
|
if (!oglrender->is_sequencer) {
|
2017-07-21 11:53:13 +02:00
|
|
|
add_gpencil_renderpass(C, oglrender, rr, rv);
|
2016-11-16 21:33:47 +01:00
|
|
|
}
|
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-01-03 13:15:32 +01:00
|
|
|
ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, true, err_out);
|
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) {
|
2012-01-14 12:24:25 +00:00
|
|
|
ED_view3d_context_user_region(C, &oglrender->v3d, &oglrender->ar); /* so quad view renders camera */
|
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 */
|
2013-05-01 14:34:12 +00:00
|
|
|
oglrender->scene->customdata_mask_modal = ED_view3d_datamask(oglrender->scene, oglrender->v3d);
|
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 */
|
|
|
|
oglrender->scene->customdata_mask |= oglrender->scene->customdata_mask_modal;
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
if (oglrender->v3d->fx_settings.fx_flag & (GPU_FX_FLAG_DOF | GPU_FX_FLAG_SSAO)) {
|
|
|
|
oglrender->fx = GPU_fx_compositor_create();
|
|
|
|
}
|
2010-05-23 10:47:19 +00:00
|
|
|
}
|
2017-11-24 12:19:26 +01:00
|
|
|
else if (is_sequencer) {
|
2017-11-27 14:24:16 +01:00
|
|
|
/* NOTE: We allow animation of DoF setting for flexibility in edits, so
|
|
|
|
* we can't check in advance whether we need FX compositor or not.
|
|
|
|
* We just always allocated it and make sure it doesn't add extra
|
|
|
|
* overhead rather than memory allocation here if it's not really
|
|
|
|
* needed.
|
|
|
|
*/
|
|
|
|
oglrender->fx = GPU_fx_compositor_create();
|
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);
|
2017-10-16 17:15:03 -02:00
|
|
|
ViewRender *view_render = BKE_viewrender_get(scene, workspace);
|
|
|
|
RE_SetEngineByID(oglrender->re, view_render->engine_id);
|
2011-11-29 22:37:16 +00:00
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
/* create image and image user */
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->ima = BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result");
|
2010-03-08 16:36:53 +00:00
|
|
|
BKE_image_signal(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 */
|
2017-11-22 10:52:39 -02:00
|
|
|
RE_InitState(oglrender->re, NULL, &scene->r, &scene->view_layers, scene->active_view_layer, view_render, 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;
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer = oglrender->view_layer;
|
2012-03-29 22:42:32 +00:00
|
|
|
scene->r.cfra = oglrender->cfrao;
|
2017-11-22 10:52:39 -02:00
|
|
|
BKE_scene_graph_update_for_newframe(bmain->eval_ctx, depsgraph, bmain, scene, view_layer);
|
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
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
if (oglrender->fx)
|
|
|
|
GPU_fx_compositor_destroy(oglrender->fx);
|
|
|
|
|
2010-03-08 16:36:53 +00:00
|
|
|
GPU_offscreen_free(oglrender->ofs);
|
|
|
|
|
2016-03-31 15:35:47 +11:00
|
|
|
if (oglrender->is_sequencer) {
|
|
|
|
MEM_freeN(oglrender->seq_data.ibufs_arr);
|
|
|
|
}
|
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
oglrender->scene->customdata_mask_modal = 0;
|
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,
|
|
|
|
oglrender->bmain->name,
|
|
|
|
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-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer = oglrender->view_layer;
|
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) {
|
2017-11-22 10:52:39 -02:00
|
|
|
BKE_scene_graph_update_for_newframe(bmain->eval_ctx, depsgraph, bmain, scene, view_layer);
|
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(
|
|
|
|
name, scene->r.pic, oglrender->bmain->name, 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
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
BKE_scene_graph_update_for_newframe(bmain->eval_ctx, depsgraph, bmain, scene, view_layer);
|
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);
|
2010-07-01 11:58:48 +00: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;
|
|
|
|
}
|
2010-12-27 18:00:35 +00: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);
|
2010-12-27 18:00:35 +00: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);
|
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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "OpenGL Render";
|
|
|
|
ot->description = "OpenGL render active viewport";
|
|
|
|
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;
|