2012-04-30 14:24:11 +00:00
|
|
|
|
/*
|
2009-01-20 11:09:26 +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,
|
2010-02-12 13:34:04 +00:00
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-01-20 11:09:26 +00:00
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup edrend
|
2011-02-27 20:29:51 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2009-01-20 11:09:26 +00:00
|
|
|
|
/* global includes */
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32
|
2019-04-17 06:17:24 +02:00
|
|
|
|
# include <unistd.h>
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
|
# include <io.h>
|
2018-06-04 09:31:30 +02:00
|
|
|
|
#endif
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
|
#include "BLI_math.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
|
#include "BLI_utildefines.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
|
2013-04-05 17:56:54 +00:00
|
|
|
|
#include "BLO_readfile.h"
|
|
|
|
|
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "DNA_world_types.h"
|
|
|
|
|
#include "DNA_camera_types.h"
|
2018-08-29 15:32:50 +02:00
|
|
|
|
#include "DNA_collection_types.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "DNA_material_types.h"
|
2010-12-20 13:02:33 +00:00
|
|
|
|
#include "DNA_node_types.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "DNA_object_types.h"
|
2019-02-27 12:34:56 +11:00
|
|
|
|
#include "DNA_light_types.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
|
#include "DNA_brush_types.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
2014-11-23 14:37:13 +01:00
|
|
|
|
#include "BKE_appdir.h"
|
2011-08-28 05:06:30 +00:00
|
|
|
|
#include "BKE_brush.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "BKE_context.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 "BKE_colortools.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "BKE_global.h"
|
2011-03-03 18:53:07 +00:00
|
|
|
|
#include "BKE_idprop.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "BKE_image.h"
|
|
|
|
|
#include "BKE_icons.h"
|
2019-03-18 13:55:26 +01:00
|
|
|
|
#include "BKE_library.h"
|
2019-02-27 12:34:56 +11:00
|
|
|
|
#include "BKE_light.h"
|
2017-02-14 16:33:13 +01:00
|
|
|
|
#include "BKE_layer.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_material.h"
|
|
|
|
|
#include "BKE_node.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 "BKE_scene.h"
|
2011-03-03 18:53:07 +00:00
|
|
|
|
#include "BKE_texture.h"
|
2011-05-19 11:37:08 +00:00
|
|
|
|
#include "BKE_world.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
|
#include "DEG_depsgraph.h"
|
2018-05-03 12:58:48 +02:00
|
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-04-25 16:18:24 +02:00
|
|
|
|
#include "DEG_depsgraph_build.h"
|
|
|
|
|
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
2015-05-11 16:29:12 +02:00
|
|
|
|
#include "IMB_thumbs.h"
|
2013-01-05 17:57:17 +00:00
|
|
|
|
|
2009-01-20 11:09:26 +00:00
|
|
|
|
#include "BIF_gl.h"
|
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
2017-02-24 11:11:43 +01:00
|
|
|
|
#include "GPU_shader.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
|
|
|
|
|
#include "RE_pipeline.h"
|
2014-10-07 14:21:10 +02:00
|
|
|
|
#include "RE_engine.h"
|
2018-09-06 16:33:41 +02:00
|
|
|
|
#include "RE_shader_ext.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2013-01-28 17:37:51 +00:00
|
|
|
|
#include "ED_datafiles.h"
|
Sorry, three commits in one, became difficult to untangle..
Editors Modules
* render/ module added in editors, moved the preview render code there and
also shading related operators.
* physics/ module made more consistent with other modules. renaming files,
making a single physics_ops.c for operators and keymaps. Also move all
particle related operators here now.
* space_buttons/ now should have only operators relevant to the buttons
specificially.
Updates & Notifiers
* Material/Texture/World/Lamp can now be passed to DAG_id_flush_update,
which will go back to a callback in editors. Eventually these should
be in the depsgraph itself, but for now this gives a unified call for
doing updates.
* GLSL materials are now refreshed on changes. There's still various
cases missing,
* Preview icons now hook into this system, solving various update cases
that were missed before.
* Also fixes issue in my last commit, where some preview would not render,
problem is avoided in the new system.
Icon Rendering
* On systems with support for non-power of two textures, an OpenGL texture
is now used instead of glDrawPixels. This avoids problems with icons get
clipped on region borders. On my Linux desktop, this gives an 1.1x speedup,
and on my Mac laptop a 2.3x speedup overall in redrawing the full window,
with the default setup. The glDrawPixels implementation on Mac seems to
have a lot of overhread.
* Preview icons are now drawn using proper premul alpha, and never faded so
you can see them clearly.
* Also tried to fix issue with texture node preview rendering, globals can't
be used with threads reliably.
2009-09-29 19:12:12 +00:00
|
|
|
|
#include "ED_render.h"
|
2016-12-01 16:43:57 +01:00
|
|
|
|
#include "ED_screen.h"
|
2009-01-20 11:09:26 +00:00
|
|
|
|
|
2015-07-22 11:24:38 +02:00
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
/* Used for database init assert(). */
|
|
|
|
|
# include "BLI_threads.h"
|
|
|
|
|
#endif
|
2009-01-20 11:09:26 +00:00
|
|
|
|
|
2012-03-29 22:42:32 +00:00
|
|
|
|
ImBuf *get_brush_icon(Brush *brush)
|
2010-07-20 13:42:27 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
static const int flags = IB_rect | IB_multilayer | IB_metadata;
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
char path[FILE_MAX];
|
|
|
|
|
const char *folder;
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (!(brush->icon_imbuf)) {
|
|
|
|
|
if (brush->flag & BRUSH_CUSTOM_ICON) {
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (brush->icon_filepath[0]) {
|
|
|
|
|
// first use the path directly to try and load the file
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BLI_strncpy(path, brush->icon_filepath, sizeof(brush->icon_filepath));
|
|
|
|
|
BLI_path_abs(path, BKE_main_blendfile_path_from_global());
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
/* use default colorspaces for brushes */
|
|
|
|
|
brush->icon_imbuf = IMB_loadiffname(path, flags, NULL);
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
// otherwise lets try to find it in other directories
|
|
|
|
|
if (!(brush->icon_imbuf)) {
|
|
|
|
|
folder = BKE_appdir_folder_id(BLENDER_DATAFILES, "brushicons");
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BLI_make_file_string(
|
|
|
|
|
BKE_main_blendfile_path_from_global(), path, folder, brush->icon_filepath);
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (path[0]) {
|
|
|
|
|
/* use fefault color spaces */
|
|
|
|
|
brush->icon_imbuf = IMB_loadiffname(path, flags, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-27 01:16:24 +00:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (brush->icon_imbuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE_icon_changed(BKE_icon_id_ensure(&brush->id));
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (!(brush->icon_imbuf)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
brush->id.icon_id = 0;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return brush->icon_imbuf;
|
2010-07-20 13:42:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
typedef struct ShaderPreview {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
/* from wmJob */
|
|
|
|
|
void *owner;
|
|
|
|
|
short *stop, *do_update;
|
|
|
|
|
|
|
|
|
|
Scene *scene;
|
|
|
|
|
Depsgraph *depsgraph;
|
|
|
|
|
ID *id, *id_copy;
|
|
|
|
|
ID *parent;
|
|
|
|
|
MTex *slot;
|
|
|
|
|
|
|
|
|
|
/* datablocks with nodes need full copy during preview render, glsl uses it too */
|
|
|
|
|
Material *matcopy;
|
|
|
|
|
Tex *texcopy;
|
|
|
|
|
Light *lampcopy;
|
|
|
|
|
World *worldcopy;
|
|
|
|
|
|
|
|
|
|
/** Copy of the active objects #Object.color */
|
|
|
|
|
float color[4];
|
|
|
|
|
|
|
|
|
|
int sizex, sizey;
|
|
|
|
|
unsigned int *pr_rect;
|
|
|
|
|
int pr_method;
|
|
|
|
|
bool own_id_copy;
|
|
|
|
|
|
|
|
|
|
Main *bmain;
|
|
|
|
|
Main *pr_main;
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
} ShaderPreview;
|
|
|
|
|
|
2012-02-17 16:06:32 +00:00
|
|
|
|
typedef struct IconPreviewSize {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
struct IconPreviewSize *next, *prev;
|
|
|
|
|
int sizex, sizey;
|
|
|
|
|
unsigned int *rect;
|
2012-02-17 16:06:32 +00:00
|
|
|
|
} IconPreviewSize;
|
|
|
|
|
|
|
|
|
|
typedef struct IconPreview {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Main *bmain;
|
|
|
|
|
Scene *scene;
|
|
|
|
|
Depsgraph *depsgraph;
|
|
|
|
|
void *owner;
|
|
|
|
|
ID *id, *id_copy;
|
|
|
|
|
ListBase sizes;
|
2012-02-17 16:06:32 +00:00
|
|
|
|
} IconPreview;
|
|
|
|
|
|
2009-01-20 11:09:26 +00:00
|
|
|
|
/* *************************** Preview for buttons *********************** */
|
|
|
|
|
|
2019-04-14 18:41:10 +02:00
|
|
|
|
static Main *G_pr_main = NULL;
|
2018-07-31 10:22:19 +02:00
|
|
|
|
static Main *G_pr_main_grease_pencil = NULL;
|
2009-01-20 11:09:26 +00:00
|
|
|
|
|
2011-07-13 19:27:42 +00:00
|
|
|
|
#ifndef WITH_HEADLESS
|
2013-03-17 19:13:04 +00:00
|
|
|
|
static Main *load_main_from_memory(const void *blend, int blend_size)
|
2013-01-28 17:37:51 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
const int fileflags = G.fileflags;
|
|
|
|
|
Main *bmain = NULL;
|
|
|
|
|
BlendFileData *bfd;
|
2013-01-28 17:37:51 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
G.fileflags |= G_FILE_NO_UI;
|
|
|
|
|
bfd = BLO_read_from_memory(blend, blend_size, BLO_READ_SKIP_NONE, NULL);
|
|
|
|
|
if (bfd) {
|
|
|
|
|
bmain = bfd->main;
|
2013-01-28 17:37:51 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
MEM_freeN(bfd);
|
|
|
|
|
}
|
|
|
|
|
G.fileflags = fileflags;
|
2013-01-28 17:37:51 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return bmain;
|
2013-01-28 17:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-22 11:24:38 +02:00
|
|
|
|
void ED_preview_ensure_dbase(void)
|
2013-01-28 17:37:51 +00:00
|
|
|
|
{
|
|
|
|
|
#ifndef WITH_HEADLESS
|
2019-04-17 06:17:24 +02:00
|
|
|
|
static bool base_initialized = false;
|
|
|
|
|
BLI_assert(BLI_thread_is_main());
|
|
|
|
|
if (!base_initialized) {
|
|
|
|
|
G_pr_main = load_main_from_memory(datatoc_preview_blend, datatoc_preview_blend_size);
|
|
|
|
|
G_pr_main_grease_pencil = load_main_from_memory(datatoc_preview_grease_pencil_blend,
|
|
|
|
|
datatoc_preview_grease_pencil_blend_size);
|
|
|
|
|
base_initialized = true;
|
|
|
|
|
}
|
2011-07-13 19:27:42 +00:00
|
|
|
|
#endif
|
2009-01-20 11:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 12:04:00 +02:00
|
|
|
|
static bool check_engine_supports_preview(Scene *scene)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
RenderEngineType *type = RE_engines_find(scene->r.engine);
|
|
|
|
|
return (type->flag & RE_USE_PREVIEW) != 0;
|
2014-10-07 14:21:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
void ED_preview_free_dbase(void)
|
2009-01-20 11:09:26 +00:00
|
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (G_pr_main) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE_main_free(G_pr_main);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (G_pr_main_grease_pencil) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE_main_free(G_pr_main_grease_pencil);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2009-01-20 11:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-28 17:37:51 +00:00
|
|
|
|
static Scene *preview_get_scene(Main *pr_main)
|
2012-11-06 15:54:04 +00:00
|
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (pr_main == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return NULL;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2018-06-04 09:39:04 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return pr_main->scenes.first;
|
2012-11-06 15:54:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
|
|
|
|
static const char *preview_collection_name(const char pr_type)
|
2017-04-26 14:36:32 +02:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
switch (pr_type) {
|
|
|
|
|
case MA_FLAT:
|
|
|
|
|
return "Flat";
|
|
|
|
|
case MA_SPHERE:
|
|
|
|
|
return "Sphere";
|
|
|
|
|
case MA_CUBE:
|
|
|
|
|
return "Cube";
|
|
|
|
|
case MA_SHADERBALL:
|
|
|
|
|
return "Shader Ball";
|
|
|
|
|
case MA_CLOTH:
|
|
|
|
|
return "Cloth";
|
|
|
|
|
case MA_FLUID:
|
|
|
|
|
return "Fluid";
|
|
|
|
|
case MA_SPHERE_A:
|
2019-05-14 17:57:10 +02:00
|
|
|
|
return "World Sphere";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
case MA_LAMP:
|
|
|
|
|
return "Lamp";
|
|
|
|
|
case MA_SKY:
|
|
|
|
|
return "Sky";
|
|
|
|
|
case MA_HAIR:
|
|
|
|
|
return "Hair";
|
|
|
|
|
case MA_ATMOS:
|
|
|
|
|
return "Atmosphere";
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(!"Unknown preview type");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2017-04-26 14:36:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
static void set_preview_visibility(Scene *scene,
|
|
|
|
|
ViewLayer *view_layer,
|
|
|
|
|
char pr_type,
|
|
|
|
|
int pr_method)
|
2017-04-26 14:36:32 +02:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
/* Set appropriate layer as visibile. */
|
|
|
|
|
LayerCollection *lc = view_layer->layer_collections.first;
|
|
|
|
|
const char *collection_name = preview_collection_name(pr_type);
|
|
|
|
|
|
|
|
|
|
for (lc = lc->layer_collections.first; lc; lc = lc->next) {
|
|
|
|
|
if (STREQ(lc->collection->id.name + 2, collection_name)) {
|
|
|
|
|
lc->collection->flag &= ~COLLECTION_RESTRICT_RENDER;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
lc->collection->flag |= COLLECTION_RESTRICT_RENDER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Hide floor for icon renders. */
|
|
|
|
|
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
|
|
|
|
|
if (STREQ(base->object->id.name + 2, "Floor")) {
|
|
|
|
|
if (pr_method == PR_ICON_RENDER) {
|
|
|
|
|
base->object->restrictflag |= OB_RESTRICT_RENDER;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
base->object->restrictflag &= ~OB_RESTRICT_RENDER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_layer_collection_sync(scene, view_layer);
|
2017-04-26 14:36:32 +02:00
|
|
|
|
}
|
2012-11-06 15:54:04 +00:00
|
|
|
|
|
2017-07-24 14:50:26 +02:00
|
|
|
|
static World *preview_get_localized_world(ShaderPreview *sp, World *world)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (world == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (sp->worldcopy != NULL) {
|
|
|
|
|
return sp->worldcopy;
|
|
|
|
|
}
|
|
|
|
|
sp->worldcopy = BKE_world_localize(world);
|
|
|
|
|
BLI_addtail(&sp->pr_main->worlds, sp->worldcopy);
|
|
|
|
|
return sp->worldcopy;
|
2017-07-24 14:50:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 15:54:03 +02:00
|
|
|
|
static ID *duplicate_ids(ID *id)
|
2018-07-18 19:09:05 +02:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (id == NULL) {
|
|
|
|
|
/* Non-ID preview render. */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
|
case ID_MA:
|
2019-05-02 15:54:03 +02:00
|
|
|
|
return (ID *)BKE_material_localize((Material *)id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
case ID_TE:
|
2019-05-02 15:54:03 +02:00
|
|
|
|
return (ID *)BKE_texture_localize((Tex *)id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
case ID_LA:
|
2019-05-02 15:54:03 +02:00
|
|
|
|
return (ID *)BKE_light_localize((Light *)id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
case ID_WO:
|
2019-05-02 15:54:03 +02:00
|
|
|
|
return (ID *)BKE_world_localize((World *)id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
case ID_IM:
|
|
|
|
|
case ID_BR:
|
|
|
|
|
case ID_SCR:
|
|
|
|
|
return NULL;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(!"ID type preview not supported.");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2018-07-18 19:09:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
/* call this with a pointer to initialize preview scene */
|
|
|
|
|
/* call this with NULL to restore assigned ID pointers in preview scene */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
static Scene *preview_prepare_scene(
|
|
|
|
|
Main *bmain, Scene *scene, ID *id, int id_type, ShaderPreview *sp)
|
2009-01-20 11:09:26 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Scene *sce;
|
|
|
|
|
Main *pr_main = sp->pr_main;
|
|
|
|
|
|
|
|
|
|
memcpy(pr_main->name, BKE_main_blendfile_path(bmain), sizeof(pr_main->name));
|
|
|
|
|
|
|
|
|
|
sce = preview_get_scene(pr_main);
|
|
|
|
|
if (sce) {
|
|
|
|
|
ViewLayer *view_layer = sce->view_layers.first;
|
|
|
|
|
|
|
|
|
|
/* this flag tells render to not execute depsgraph or ipos etc */
|
|
|
|
|
sce->r.scemode |= R_BUTS_PREVIEW;
|
|
|
|
|
/* set world always back, is used now */
|
|
|
|
|
sce->world = pr_main->worlds.first;
|
|
|
|
|
/* now: exposure copy */
|
|
|
|
|
if (scene->world) {
|
|
|
|
|
sce->world->exp = scene->world->exp;
|
|
|
|
|
sce->world->range = scene->world->range;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sce->r.color_mgt_flag = scene->r.color_mgt_flag;
|
|
|
|
|
BKE_color_managed_display_settings_copy(&sce->display_settings, &scene->display_settings);
|
|
|
|
|
|
|
|
|
|
BKE_color_managed_view_settings_free(&sce->view_settings);
|
|
|
|
|
BKE_color_managed_view_settings_copy(&sce->view_settings, &scene->view_settings);
|
|
|
|
|
|
|
|
|
|
/* prevent overhead for small renders and icons (32) */
|
|
|
|
|
if (id && sp->sizex < 40) {
|
|
|
|
|
sce->r.tilex = sce->r.tiley = 64;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sce->r.tilex = sce->r.xsch / 4;
|
|
|
|
|
sce->r.tiley = sce->r.ysch / 4;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if ((id && sp->pr_method == PR_ICON_RENDER) && id_type != ID_WO) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sce->r.alphamode = R_ALPHAPREMUL;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sce->r.alphamode = R_ADDSKY;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
sce->r.cfra = scene->r.cfra;
|
|
|
|
|
|
|
|
|
|
if (id_type == ID_TE) {
|
|
|
|
|
/* Texture is not actually rendered with engine, just set dummy value. */
|
|
|
|
|
BLI_strncpy(sce->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(sce->r.engine));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_strncpy(sce->r.engine, scene->r.engine, sizeof(sce->r.engine));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id_type == ID_MA) {
|
|
|
|
|
Material *mat = NULL, *origmat = (Material *)id;
|
|
|
|
|
|
|
|
|
|
if (origmat) {
|
|
|
|
|
/* work on a copy */
|
|
|
|
|
BLI_assert(sp->id_copy != NULL);
|
|
|
|
|
mat = sp->matcopy = (Material *)sp->id_copy;
|
|
|
|
|
sp->id_copy = NULL;
|
|
|
|
|
BLI_addtail(&pr_main->materials, mat);
|
|
|
|
|
|
|
|
|
|
/* Use current scene world for lighting. */
|
|
|
|
|
if (mat->pr_flag == MA_PREVIEW_WORLD && sp->pr_method == PR_BUTS_RENDER) {
|
|
|
|
|
/* Use current scene world to light sphere. */
|
|
|
|
|
sce->world = preview_get_localized_world(sp, scene->world);
|
|
|
|
|
}
|
|
|
|
|
else if (sce->world) {
|
|
|
|
|
/* Use a default world color. Using the current
|
|
|
|
|
* scene world can be slow if it has big textures. */
|
|
|
|
|
sce->world->use_nodes = false;
|
|
|
|
|
sce->world->horr = 0.05f;
|
|
|
|
|
sce->world->horg = 0.05f;
|
|
|
|
|
sce->world->horb = 0.05f;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 17:57:10 +02:00
|
|
|
|
if (sp->pr_method == PR_ICON_RENDER && sp->pr_main == G_pr_main_grease_pencil) {
|
|
|
|
|
/* For grease pencil, always use sphere for icon renders. */
|
|
|
|
|
set_preview_visibility(sce, view_layer, MA_SPHERE_A, sp->pr_method);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Use specified preview shape for both preview panel and icon previews. */
|
|
|
|
|
set_preview_visibility(sce, view_layer, mat->pr_type, sp->pr_method);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
if (sp->pr_method != PR_ICON_RENDER) {
|
|
|
|
|
if (mat->nodetree && sp->pr_method == PR_NODE_RENDER) {
|
|
|
|
|
/* two previews, they get copied by wmJob */
|
|
|
|
|
BKE_node_preview_init_tree(mat->nodetree, sp->sizex, sp->sizey, true);
|
|
|
|
|
/* WATCH: Accessing origmat is not safe! */
|
|
|
|
|
BKE_node_preview_init_tree(origmat->nodetree, sp->sizex, sp->sizey, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-05-02 15:18:53 +02:00
|
|
|
|
sce->display.render_aa = SCE_DISPLAY_AA_OFF;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
|
|
|
|
|
if (base->object->id.name[2] == 'p') {
|
|
|
|
|
/* copy over object color, in case material uses it */
|
|
|
|
|
copy_v4_v4(base->object->color, sp->color);
|
|
|
|
|
|
|
|
|
|
if (OB_TYPE_SUPPORT_MATERIAL(base->object->type)) {
|
|
|
|
|
/* don't use assign_material, it changed mat->id.us, which shows in the UI */
|
|
|
|
|
Material ***matar = give_matarar(base->object);
|
|
|
|
|
int actcol = max_ii(base->object->actcol - 1, 0);
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (matar && actcol < base->object->totcol) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
(*matar)[actcol] = mat;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
else if (base->object->type == OB_LAMP) {
|
|
|
|
|
base->flag |= BASE_VISIBLE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (id_type == ID_TE) {
|
|
|
|
|
Tex *tex = NULL, *origtex = (Tex *)id;
|
|
|
|
|
|
|
|
|
|
if (origtex) {
|
|
|
|
|
BLI_assert(sp->id_copy != NULL);
|
|
|
|
|
tex = sp->texcopy = (Tex *)sp->id_copy;
|
|
|
|
|
sp->id_copy = NULL;
|
|
|
|
|
BLI_addtail(&pr_main->textures, tex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tex && tex->nodetree && sp->pr_method == PR_NODE_RENDER) {
|
|
|
|
|
/* two previews, they get copied by wmJob */
|
|
|
|
|
BKE_node_preview_init_tree(tex->nodetree, sp->sizex, sp->sizey, true);
|
|
|
|
|
/* WATCH: Accessing origtex is not safe! */
|
|
|
|
|
BKE_node_preview_init_tree(origtex->nodetree, sp->sizex, sp->sizey, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (id_type == ID_LA) {
|
|
|
|
|
Light *la = NULL, *origla = (Light *)id;
|
|
|
|
|
|
|
|
|
|
/* work on a copy */
|
|
|
|
|
if (origla) {
|
|
|
|
|
BLI_assert(sp->id_copy != NULL);
|
|
|
|
|
la = sp->lampcopy = (Light *)sp->id_copy;
|
|
|
|
|
sp->id_copy = NULL;
|
|
|
|
|
BLI_addtail(&pr_main->lights, la);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_preview_visibility(sce, view_layer, MA_LAMP, sp->pr_method);
|
|
|
|
|
|
|
|
|
|
if (sce->world) {
|
|
|
|
|
/* Only use lighting from the light. */
|
|
|
|
|
sce->world->use_nodes = false;
|
|
|
|
|
sce->world->horr = 0.0f;
|
|
|
|
|
sce->world->horg = 0.0f;
|
|
|
|
|
sce->world->horb = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
|
|
|
|
|
if (base->object->id.name[2] == 'p') {
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (base->object->type == OB_LAMP) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
base->object->data = la;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (la && la->nodetree && sp->pr_method == PR_NODE_RENDER) {
|
|
|
|
|
/* two previews, they get copied by wmJob */
|
|
|
|
|
BKE_node_preview_init_tree(la->nodetree, sp->sizex, sp->sizey, true);
|
|
|
|
|
/* WATCH: Accessing origla is not safe! */
|
|
|
|
|
BKE_node_preview_init_tree(origla->nodetree, sp->sizex, sp->sizey, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (id_type == ID_WO) {
|
|
|
|
|
World *wrld = NULL, *origwrld = (World *)id;
|
|
|
|
|
|
|
|
|
|
if (origwrld) {
|
|
|
|
|
BLI_assert(sp->id_copy != NULL);
|
|
|
|
|
wrld = sp->worldcopy = (World *)sp->id_copy;
|
|
|
|
|
sp->id_copy = NULL;
|
|
|
|
|
BLI_addtail(&pr_main->worlds, wrld);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_preview_visibility(sce, view_layer, MA_SKY, sp->pr_method);
|
|
|
|
|
sce->world = wrld;
|
|
|
|
|
|
|
|
|
|
if (wrld && wrld->nodetree && sp->pr_method == PR_NODE_RENDER) {
|
|
|
|
|
/* two previews, they get copied by wmJob */
|
|
|
|
|
BKE_node_preview_init_tree(wrld->nodetree, sp->sizex, sp->sizey, true);
|
|
|
|
|
/* WATCH: Accessing origwrld is not safe! */
|
|
|
|
|
BKE_node_preview_init_tree(origwrld->nodetree, sp->sizex, sp->sizey, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sce;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2009-01-20 11:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-07 11:12:35 +00:00
|
|
|
|
/* new UI convention: draw is in pixel space already. */
|
2014-11-09 21:20:40 +01:00
|
|
|
|
/* uses UI_BTYPE_ROUNDBOX button in block to get the rect */
|
2014-04-11 11:25:41 +10:00
|
|
|
|
static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect, rcti *newrect)
|
2009-07-21 01:57:46 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Render *re;
|
|
|
|
|
RenderView *rv;
|
|
|
|
|
RenderResult rres;
|
|
|
|
|
char name[32];
|
|
|
|
|
int offx = 0;
|
|
|
|
|
int newx = BLI_rcti_size_x(rect);
|
|
|
|
|
int newy = BLI_rcti_size_y(rect);
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (!split || first) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sprintf(name, "Preview %p", (void *)sa);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sprintf(name, "SecondPreview %p", (void *)sa);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
if (split) {
|
|
|
|
|
if (first) {
|
|
|
|
|
offx = 0;
|
|
|
|
|
newx = newx / 2;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
offx = newx / 2;
|
|
|
|
|
newx = newx - newx / 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* test if something rendered ok */
|
|
|
|
|
re = RE_GetRender(name);
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (re == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
RE_AcquireResultImageViews(re, &rres);
|
|
|
|
|
|
|
|
|
|
if (!BLI_listbase_is_empty(&rres.views)) {
|
|
|
|
|
/* material preview only needs monoscopy (view 0) */
|
|
|
|
|
rv = RE_RenderViewGetById(&rres, 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* possible the job clears the views but we're still drawing T45496 */
|
|
|
|
|
rv = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rv && rv->rectf) {
|
|
|
|
|
|
|
|
|
|
if (ABS(rres.rectx - newx) < 2 && ABS(rres.recty - newy) < 2) {
|
|
|
|
|
|
|
|
|
|
newrect->xmax = max_ii(newrect->xmax, rect->xmin + rres.rectx + offx);
|
|
|
|
|
newrect->ymax = max_ii(newrect->ymax, rect->ymin + rres.recty);
|
|
|
|
|
|
|
|
|
|
if (rres.rectx && rres.recty) {
|
|
|
|
|
unsigned char *rect_byte = MEM_mallocN(rres.rectx * rres.recty * sizeof(int),
|
|
|
|
|
"ed_preview_draw_rect");
|
|
|
|
|
float fx = rect->xmin + offx;
|
|
|
|
|
float fy = rect->ymin;
|
|
|
|
|
|
|
|
|
|
/* material preview only needs monoscopy (view 0) */
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (re) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte, 0);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
|
|
|
|
immDrawPixelsTex(&state,
|
|
|
|
|
fx,
|
|
|
|
|
fy,
|
|
|
|
|
rres.rectx,
|
|
|
|
|
rres.recty,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
|
GL_NEAREST,
|
|
|
|
|
rect_byte,
|
|
|
|
|
1.0f,
|
|
|
|
|
1.0f,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(rect_byte);
|
|
|
|
|
|
|
|
|
|
ok = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RE_ReleaseResultImageViews(re, &rres);
|
|
|
|
|
|
|
|
|
|
return ok;
|
2009-07-21 01:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 19:58:27 +00:00
|
|
|
|
void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, rcti *rect)
|
2009-01-20 11:09:26 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (idp) {
|
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
|
ID *id = (ID *)idp;
|
|
|
|
|
ID *parent = (ID *)parentp;
|
|
|
|
|
MTex *slot = (MTex *)slotp;
|
|
|
|
|
SpaceProperties *sbuts = CTX_wm_space_properties(C);
|
|
|
|
|
ShaderPreview *sp = WM_jobs_customdata(wm, sa);
|
|
|
|
|
rcti newrect;
|
|
|
|
|
int ok;
|
|
|
|
|
int newx = BLI_rcti_size_x(rect);
|
|
|
|
|
int newy = BLI_rcti_size_y(rect);
|
|
|
|
|
|
|
|
|
|
newrect.xmin = rect->xmin;
|
|
|
|
|
newrect.xmax = rect->xmin;
|
|
|
|
|
newrect.ymin = rect->ymin;
|
|
|
|
|
newrect.ymax = rect->ymin;
|
|
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
|
ok = ed_preview_draw_rect(sa, 1, 1, rect, &newrect);
|
|
|
|
|
ok &= ed_preview_draw_rect(sa, 1, 0, rect, &newrect);
|
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ok = ed_preview_draw_rect(sa, 0, 0, rect, &newrect);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (ok) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
*rect = newrect;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
/* start a new preview render job if signaled through sbuts->preview,
|
|
|
|
|
* if no render result was found and no preview render job is running,
|
|
|
|
|
* or if the job is running and the size of preview changed */
|
|
|
|
|
if ((sbuts != NULL && sbuts->preview) ||
|
|
|
|
|
(!ok && !WM_jobs_test(wm, sa, WM_JOB_TYPE_RENDER_PREVIEW)) ||
|
|
|
|
|
(sp && (ABS(sp->sizex - newx) >= 2 || ABS(sp->sizey - newy) > 2))) {
|
|
|
|
|
if (sbuts != NULL) {
|
|
|
|
|
sbuts->preview = 0;
|
|
|
|
|
}
|
|
|
|
|
ED_preview_shader_job(C, sa, id, parent, slot, newx, newy, PR_BUTS_RENDER);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 11:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-28 18:33:45 +00:00
|
|
|
|
/* **************************** new shader preview system ****************** */
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
|
2009-06-07 11:12:35 +00:00
|
|
|
|
/* inside thread, called by renderer, sets job update value */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
static void shader_preview_update(void *spv,
|
|
|
|
|
RenderResult *UNUSED(rr),
|
|
|
|
|
volatile struct rcti *UNUSED(rect))
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ShaderPreview *sp = spv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
*(sp->do_update) = true;
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* called by renderer, checks job value */
|
|
|
|
|
static int shader_preview_break(void *spv)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ShaderPreview *sp = spv;
|
2011-01-02 19:46:32 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return *(sp->stop);
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-07 11:12:35 +00:00
|
|
|
|
/* outside thread, called before redraw notifiers, it moves finished preview over */
|
2010-12-19 20:12:12 +00:00
|
|
|
|
static void shader_preview_updatejob(void *spv)
|
2009-06-07 11:12:35 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ShaderPreview *sp = spv;
|
|
|
|
|
|
|
|
|
|
if (sp->id) {
|
|
|
|
|
if (sp->pr_method == PR_NODE_RENDER) {
|
|
|
|
|
if (GS(sp->id->name) == ID_MA) {
|
|
|
|
|
Material *mat = (Material *)sp->id;
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (sp->matcopy && mat->nodetree && sp->matcopy->nodetree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ntreeLocalSync(sp->matcopy->nodetree, mat->nodetree);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
else if (GS(sp->id->name) == ID_TE) {
|
|
|
|
|
Tex *tex = (Tex *)sp->id;
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (sp->texcopy && tex->nodetree && sp->texcopy->nodetree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ntreeLocalSync(sp->texcopy->nodetree, tex->nodetree);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
else if (GS(sp->id->name) == ID_WO) {
|
|
|
|
|
World *wrld = (World *)sp->id;
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (sp->worldcopy && wrld->nodetree && sp->worldcopy->nodetree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ntreeLocalSync(sp->worldcopy->nodetree, wrld->nodetree);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
else if (GS(sp->id->name) == ID_LA) {
|
|
|
|
|
Light *la = (Light *)sp->id;
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (sp->lampcopy && la->nodetree && sp->lampcopy->nodetree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ntreeLocalSync(sp->lampcopy->nodetree, la->nodetree);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-06-07 11:12:35 +00:00
|
|
|
|
}
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
|
2018-09-06 16:33:41 +02:00
|
|
|
|
/* Renders texture directly to render buffer. */
|
2018-09-08 07:02:58 +10:00
|
|
|
|
static void shader_preview_texture(ShaderPreview *sp, Tex *tex, Scene *sce, Render *re)
|
2018-09-06 16:33:41 +02:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
/* Setup output buffer. */
|
|
|
|
|
int width = sp->sizex;
|
|
|
|
|
int height = sp->sizey;
|
|
|
|
|
|
|
|
|
|
/* This is needed otherwise no RenderResult is created. */
|
|
|
|
|
sce->r.scemode &= ~R_BUTS_PREVIEW;
|
|
|
|
|
RE_InitState(re, NULL, &sce->r, &sce->view_layers, NULL, width, height, NULL);
|
|
|
|
|
RE_SetScene(re, sce);
|
|
|
|
|
|
|
|
|
|
/* Create buffer in empty RenderView created in the init step. */
|
|
|
|
|
RenderResult *rr = RE_AcquireResultWrite(re);
|
|
|
|
|
RenderView *rv = (RenderView *)rr->views.first;
|
|
|
|
|
rv->rectf = MEM_callocN(sizeof(float) * 4 * width * height, "texture render result");
|
|
|
|
|
RE_ReleaseResult(re);
|
|
|
|
|
|
|
|
|
|
/* Get texture image pool (if any) */
|
|
|
|
|
struct ImagePool *img_pool = BKE_image_pool_new();
|
|
|
|
|
BKE_texture_fetch_images_for_pool(tex, img_pool);
|
|
|
|
|
|
|
|
|
|
/* Fill in image buffer. */
|
|
|
|
|
float *rect_float = rv->rectf;
|
|
|
|
|
float tex_coord[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
bool color_manage = true;
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
|
/* Tex coords between -1.0f and 1.0f. */
|
|
|
|
|
tex_coord[1] = ((float)y / (float)height) * 2.0f - 1.0f;
|
|
|
|
|
|
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
|
|
|
tex_coord[0] = ((float)x / (float)height) * 2.0f - 1.0f;
|
|
|
|
|
|
|
|
|
|
/* Evaluate texture at tex_coord .*/
|
|
|
|
|
TexResult texres = {0};
|
|
|
|
|
BKE_texture_get_value_ex(sce, tex, tex_coord, &texres, img_pool, color_manage);
|
|
|
|
|
|
|
|
|
|
rect_float[0] = texres.tr;
|
|
|
|
|
rect_float[1] = texres.tg;
|
|
|
|
|
rect_float[2] = texres.tb;
|
|
|
|
|
rect_float[3] = 1.0f;
|
|
|
|
|
|
|
|
|
|
rect_float += 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if we should cancel texture preview. */
|
|
|
|
|
if (shader_preview_break(sp)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_image_pool_free(img_pool);
|
2018-09-06 16:33:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 01:57:46 +00:00
|
|
|
|
static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int first)
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Render *re;
|
|
|
|
|
Scene *sce;
|
|
|
|
|
float oldlens;
|
|
|
|
|
short idtype = GS(id->name);
|
|
|
|
|
char name[32];
|
|
|
|
|
int sizex;
|
|
|
|
|
Main *pr_main = sp->pr_main;
|
|
|
|
|
|
|
|
|
|
/* in case of split preview, use border render */
|
|
|
|
|
if (split) {
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (first) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sizex = sp->sizex / 2;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sizex = sp->sizex - sp->sizex / 2;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sizex = sp->sizex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* we have to set preview variables first */
|
|
|
|
|
sce = preview_get_scene(pr_main);
|
|
|
|
|
if (sce) {
|
|
|
|
|
sce->r.xsch = sizex;
|
|
|
|
|
sce->r.ysch = sp->sizey;
|
|
|
|
|
sce->r.size = 100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get the stuff from the builtin preview dbase */
|
2019-05-02 15:54:03 +02:00
|
|
|
|
sce = preview_prepare_scene(sp->bmain, sp->scene, id, idtype, sp);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (sce == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (!split || first) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sprintf(name, "Preview %p", sp->owner);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sprintf(name, "SecondPreview %p", sp->owner);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
re = RE_GetRender(name);
|
|
|
|
|
|
|
|
|
|
/* full refreshed render from first tile */
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (re == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
re = RE_NewRender(name);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
/* sce->r gets copied in RE_InitState! */
|
|
|
|
|
sce->r.scemode &= ~(R_MATNODE_PREVIEW | R_TEXNODE_PREVIEW);
|
|
|
|
|
sce->r.scemode &= ~R_NO_IMAGE_LOAD;
|
|
|
|
|
|
|
|
|
|
if (sp->pr_method == PR_ICON_RENDER) {
|
|
|
|
|
sce->r.scemode |= R_NO_IMAGE_LOAD;
|
2019-05-02 15:18:53 +02:00
|
|
|
|
sce->display.render_aa = SCE_DISPLAY_AA_SAMPLES_8;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
else if (sp->pr_method == PR_NODE_RENDER) {
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (idtype == ID_MA) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sce->r.scemode |= R_MATNODE_PREVIEW;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
|
|
|
|
else if (idtype == ID_TE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sce->r.scemode |= R_TEXNODE_PREVIEW;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-05-02 15:18:53 +02:00
|
|
|
|
sce->display.render_aa = SCE_DISPLAY_AA_OFF;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
else { /* PR_BUTS_RENDER */
|
2019-05-02 15:18:53 +02:00
|
|
|
|
sce->display.render_aa = SCE_DISPLAY_AA_SAMPLES_8;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* callbacs are cleared on GetRender() */
|
|
|
|
|
if (ELEM(sp->pr_method, PR_BUTS_RENDER, PR_NODE_RENDER)) {
|
|
|
|
|
RE_display_update_cb(re, sp, shader_preview_update);
|
|
|
|
|
}
|
|
|
|
|
/* set this for all previews, default is react to G.is_break still */
|
|
|
|
|
RE_test_break_cb(re, sp, shader_preview_break);
|
|
|
|
|
|
|
|
|
|
/* lens adjust */
|
|
|
|
|
oldlens = ((Camera *)sce->camera->data)->lens;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (sizex > sp->sizey) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
((Camera *)sce->camera->data)->lens *= (float)sp->sizey / (float)sizex;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
/* entire cycle for render engine */
|
|
|
|
|
if (idtype == ID_TE) {
|
|
|
|
|
shader_preview_texture(sp, (Tex *)id, sce, re);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Render preview scene */
|
|
|
|
|
RE_PreviewRender(re, pr_main, sce);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
((Camera *)sce->camera->data)->lens = oldlens;
|
|
|
|
|
|
|
|
|
|
/* handle results */
|
|
|
|
|
if (sp->pr_method == PR_ICON_RENDER) {
|
|
|
|
|
// char *rct= (char *)(sp->pr_rect + 32*16 + 16);
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (sp->pr_rect) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
RE_ResultGet32(re, sp->pr_rect);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* unassign the pointers, reset vars */
|
|
|
|
|
preview_prepare_scene(sp->bmain, sp->scene, NULL, GS(id->name), sp);
|
|
|
|
|
|
|
|
|
|
/* XXX bad exception, end-exec is not being called in render, because it uses local main */
|
|
|
|
|
// if (idtype == ID_TE) {
|
|
|
|
|
// Tex *tex= (Tex *)id;
|
|
|
|
|
// if (tex->use_nodes && tex->nodetree)
|
|
|
|
|
// ntreeEndExecTree(tex->nodetree);
|
|
|
|
|
// }
|
2009-07-21 01:57:46 +00:00
|
|
|
|
}
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
|
2009-09-28 18:33:45 +00:00
|
|
|
|
/* runs inside thread for material and icons */
|
2009-07-21 01:57:46 +00:00
|
|
|
|
static void shader_preview_startjob(void *customdata, short *stop, short *do_update)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ShaderPreview *sp = customdata;
|
2009-07-21 01:57:46 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sp->stop = stop;
|
|
|
|
|
sp->do_update = do_update;
|
2009-07-21 01:57:46 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (sp->parent) {
|
|
|
|
|
shader_preview_render(sp, sp->id, 1, 1);
|
|
|
|
|
shader_preview_render(sp, sp->parent, 1, 0);
|
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
shader_preview_render(sp, sp->id, 0, 0);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2009-07-21 01:57:46 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
*do_update = true;
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void shader_preview_free(void *customdata)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ShaderPreview *sp = customdata;
|
|
|
|
|
Main *pr_main = sp->pr_main;
|
|
|
|
|
|
|
|
|
|
if (sp->matcopy) {
|
|
|
|
|
sp->id_copy = (ID *)sp->matcopy;
|
|
|
|
|
BLI_remlink(&pr_main->materials, sp->matcopy);
|
|
|
|
|
}
|
|
|
|
|
if (sp->texcopy) {
|
|
|
|
|
sp->id_copy = (ID *)sp->texcopy;
|
|
|
|
|
BLI_remlink(&pr_main->textures, sp->texcopy);
|
|
|
|
|
}
|
|
|
|
|
if (sp->worldcopy) {
|
|
|
|
|
sp->id_copy = (ID *)sp->worldcopy;
|
|
|
|
|
BLI_remlink(&pr_main->worlds, sp->worldcopy);
|
|
|
|
|
}
|
|
|
|
|
if (sp->lampcopy) {
|
|
|
|
|
sp->id_copy = (ID *)sp->lampcopy;
|
|
|
|
|
BLI_remlink(&pr_main->lights, sp->lampcopy);
|
|
|
|
|
}
|
|
|
|
|
if (sp->id_copy) {
|
|
|
|
|
/* node previews */
|
|
|
|
|
shader_preview_updatejob(sp);
|
|
|
|
|
}
|
|
|
|
|
if (sp->id_copy && sp->own_id_copy) {
|
|
|
|
|
struct IDProperty *properties;
|
|
|
|
|
/* get rid of copied ID */
|
|
|
|
|
properties = IDP_GetProperties(sp->id_copy, false);
|
|
|
|
|
if (properties) {
|
2019-05-16 14:17:11 +02:00
|
|
|
|
IDP_FreePropertyContent_ex(properties, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
MEM_freeN(properties);
|
|
|
|
|
}
|
|
|
|
|
switch (GS(sp->id_copy->name)) {
|
|
|
|
|
case ID_MA:
|
|
|
|
|
BKE_material_free((Material *)sp->id_copy);
|
|
|
|
|
break;
|
|
|
|
|
case ID_TE:
|
|
|
|
|
BKE_texture_free((Tex *)sp->id_copy);
|
|
|
|
|
break;
|
|
|
|
|
case ID_LA:
|
|
|
|
|
BKE_light_free((Light *)sp->id_copy);
|
|
|
|
|
break;
|
|
|
|
|
case ID_WO:
|
|
|
|
|
BKE_world_free((World *)sp->id_copy);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(!"ID type preview not supported.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(sp->id_copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(sp);
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-28 18:33:45 +00:00
|
|
|
|
/* ************************* icon preview ********************** */
|
|
|
|
|
|
|
|
|
|
static void icon_copy_rect(ImBuf *ibuf, unsigned int w, unsigned int h, unsigned int *rect)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
struct ImBuf *ima;
|
|
|
|
|
unsigned int *drect, *srect;
|
|
|
|
|
float scaledx, scaledy;
|
|
|
|
|
short ex, ey, dx, dy;
|
2009-09-28 18:33:45 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
/* paranoia test */
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (ibuf == NULL || (ibuf->rect == NULL && ibuf->rect_float == NULL)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
/* waste of cpu cyles... but the imbuf API has no other way to scale fast (ton) */
|
|
|
|
|
ima = IMB_dupImBuf(ibuf);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (!ima) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (ima->x > ima->y) {
|
|
|
|
|
scaledx = (float)w;
|
|
|
|
|
scaledy = ((float)ima->y / (float)ima->x) * (float)w;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
scaledx = ((float)ima->x / (float)ima->y) * (float)h;
|
|
|
|
|
scaledy = (float)h;
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ex = (short)scaledx;
|
|
|
|
|
ey = (short)scaledy;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
dx = (w - ex) / 2;
|
|
|
|
|
dy = (h - ey) / 2;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
IMB_scalefastImBuf(ima, ex, ey);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
/* if needed, convert to 32 bits */
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (ima->rect == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
IMB_rect_from_float(ima);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2009-09-28 18:33:45 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
srect = ima->rect;
|
|
|
|
|
drect = rect;
|
2009-09-28 18:33:45 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
drect += dy * w + dx;
|
|
|
|
|
for (; ey > 0; ey--) {
|
|
|
|
|
memcpy(drect, srect, ex * sizeof(int));
|
|
|
|
|
drect += w;
|
|
|
|
|
srect += ima->x;
|
|
|
|
|
}
|
2009-09-28 18:33:45 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
IMB_freeImBuf(ima);
|
2009-09-28 18:33:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-04 09:31:30 +02:00
|
|
|
|
static void set_alpha(char *cp, int sizex, int sizey, char alpha)
|
2009-09-28 18:33:45 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
int a, size = sizex * sizey;
|
2009-09-28 18:33:45 +00:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
for (a = 0; a < size; a++, cp += 4) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
cp[3] = alpha;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2009-09-28 18:33:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void icon_preview_startjob(void *customdata, short *stop, short *do_update)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ShaderPreview *sp = customdata;
|
|
|
|
|
|
|
|
|
|
if (sp->pr_method == PR_ICON_DEFERRED) {
|
|
|
|
|
PreviewImage *prv = sp->owner;
|
|
|
|
|
ImBuf *thumb;
|
|
|
|
|
char *deferred_data = PRV_DEFERRED_DATA(prv);
|
|
|
|
|
int source = deferred_data[0];
|
|
|
|
|
char *path = &deferred_data[1];
|
|
|
|
|
|
|
|
|
|
// printf("generating deferred %d×%d preview for %s\n", sp->sizex, sp->sizey, path);
|
|
|
|
|
|
|
|
|
|
thumb = IMB_thumb_manage(path, THB_LARGE, source);
|
|
|
|
|
|
|
|
|
|
if (thumb) {
|
|
|
|
|
/* PreviewImage assumes premultiplied alhpa... */
|
|
|
|
|
IMB_premultiply_alpha(thumb);
|
|
|
|
|
|
|
|
|
|
icon_copy_rect(thumb, sp->sizex, sp->sizey, sp->pr_rect);
|
|
|
|
|
IMB_freeImBuf(thumb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ID *id = sp->id;
|
|
|
|
|
short idtype = GS(id->name);
|
|
|
|
|
|
|
|
|
|
if (idtype == ID_IM) {
|
|
|
|
|
Image *ima = (Image *)id;
|
|
|
|
|
ImBuf *ibuf = NULL;
|
|
|
|
|
ImageUser iuser = {NULL};
|
|
|
|
|
|
|
|
|
|
/* ima->ok is zero when Image cannot load */
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (ima == NULL || ima->ok == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
/* setup dummy image user */
|
|
|
|
|
iuser.ok = iuser.framenr = 1;
|
|
|
|
|
iuser.scene = sp->scene;
|
|
|
|
|
|
|
|
|
|
/* elubie: this needs to be changed: here image is always loaded if not
|
|
|
|
|
* already there. Very expensive for large images. Need to find a way to
|
|
|
|
|
* only get existing ibuf */
|
|
|
|
|
ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
|
|
|
|
|
if (ibuf == NULL || ibuf->rect == NULL) {
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, NULL);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
icon_copy_rect(ibuf, sp->sizex, sp->sizey, sp->pr_rect);
|
|
|
|
|
|
|
|
|
|
*do_update = true;
|
|
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, NULL);
|
|
|
|
|
}
|
|
|
|
|
else if (idtype == ID_BR) {
|
|
|
|
|
Brush *br = (Brush *)id;
|
|
|
|
|
|
|
|
|
|
br->icon_imbuf = get_brush_icon(br);
|
|
|
|
|
|
|
|
|
|
memset(sp->pr_rect, 0x88, sp->sizex * sp->sizey * sizeof(unsigned int));
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (!(br->icon_imbuf) || !(br->icon_imbuf->rect)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
icon_copy_rect(br->icon_imbuf, sp->sizex, sp->sizey, sp->pr_rect);
|
|
|
|
|
|
|
|
|
|
*do_update = true;
|
|
|
|
|
}
|
|
|
|
|
else if (idtype == ID_SCR) {
|
|
|
|
|
bScreen *screen = (bScreen *)id;
|
|
|
|
|
|
|
|
|
|
ED_screen_preview_render(screen, sp->sizex, sp->sizey, sp->pr_rect);
|
|
|
|
|
*do_update = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* re-use shader job */
|
|
|
|
|
shader_preview_startjob(customdata, stop, do_update);
|
|
|
|
|
|
|
|
|
|
/* world is rendered with alpha=0, so it wasn't displayed
|
|
|
|
|
* this could be render option for sky to, for later */
|
|
|
|
|
if (idtype == ID_WO) {
|
|
|
|
|
set_alpha((char *)sp->pr_rect, sp->sizex, sp->sizey, 255);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-28 18:33:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* use same function for icon & shader, so the job manager
|
2012-03-03 16:31:46 +00:00
|
|
|
|
* does not run two of them at the same time. */
|
2009-09-28 18:33:45 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
static void common_preview_startjob(void *customdata,
|
|
|
|
|
short *stop,
|
|
|
|
|
short *do_update,
|
|
|
|
|
float *UNUSED(progress))
|
2009-09-28 18:33:45 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ShaderPreview *sp = customdata;
|
2009-09-28 18:33:45 +00:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (ELEM(sp->pr_method, PR_ICON_RENDER, PR_ICON_DEFERRED)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
icon_preview_startjob(customdata, stop, do_update);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
shader_preview_startjob(customdata, stop, do_update);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2009-09-28 18:33:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-17 16:06:32 +00:00
|
|
|
|
/* exported functions */
|
|
|
|
|
|
|
|
|
|
static void icon_preview_add_size(IconPreview *ip, unsigned int *rect, int sizex, int sizey)
|
2010-07-20 13:42:27 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
IconPreviewSize *cur_size = ip->sizes.first, *new_size;
|
2010-07-20 13:42:27 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
while (cur_size) {
|
|
|
|
|
if (cur_size->sizex == sizex && cur_size->sizey == sizey) {
|
|
|
|
|
/* requested size is already in list, no need to add it again */
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-02-17 16:06:32 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
cur_size = cur_size->next;
|
|
|
|
|
}
|
2012-02-17 16:06:32 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
new_size = MEM_callocN(sizeof(IconPreviewSize), "IconPreviewSize");
|
|
|
|
|
new_size->sizex = sizex;
|
|
|
|
|
new_size->sizey = sizey;
|
|
|
|
|
new_size->rect = rect;
|
2012-02-17 16:06:32 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BLI_addtail(&ip->sizes, new_size);
|
2010-07-20 13:42:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
static void icon_preview_startjob_all_sizes(void *customdata,
|
|
|
|
|
short *stop,
|
|
|
|
|
short *do_update,
|
|
|
|
|
float *progress)
|
2012-02-17 16:06:32 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
IconPreview *ip = (IconPreview *)customdata;
|
|
|
|
|
IconPreviewSize *cur_size;
|
|
|
|
|
|
|
|
|
|
for (cur_size = ip->sizes.first; cur_size; cur_size = cur_size->next) {
|
|
|
|
|
PreviewImage *prv = ip->owner;
|
|
|
|
|
|
|
|
|
|
if (prv->tag & PRV_TAG_DEFFERED_DELETE) {
|
|
|
|
|
/* Non-thread-protected reading is not an issue here. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!check_engine_supports_preview(ip->scene)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShaderPreview *sp = MEM_callocN(sizeof(ShaderPreview), "Icon ShaderPreview");
|
|
|
|
|
const bool is_render = !(prv->tag & PRV_TAG_DEFFERED);
|
|
|
|
|
|
|
|
|
|
/* construct shader preview from image size and previewcustomdata */
|
|
|
|
|
sp->scene = ip->scene;
|
|
|
|
|
sp->depsgraph = ip->depsgraph;
|
|
|
|
|
sp->owner = ip->owner;
|
|
|
|
|
sp->sizex = cur_size->sizex;
|
|
|
|
|
sp->sizey = cur_size->sizey;
|
|
|
|
|
sp->pr_method = is_render ? PR_ICON_RENDER : PR_ICON_DEFERRED;
|
|
|
|
|
sp->pr_rect = cur_size->rect;
|
|
|
|
|
sp->id = ip->id;
|
|
|
|
|
sp->id_copy = ip->id_copy;
|
|
|
|
|
sp->bmain = ip->bmain;
|
|
|
|
|
sp->own_id_copy = false;
|
|
|
|
|
Material *ma = NULL;
|
|
|
|
|
|
|
|
|
|
if (is_render) {
|
|
|
|
|
BLI_assert(ip->id);
|
|
|
|
|
|
|
|
|
|
/* grease pencil use its own preview file */
|
|
|
|
|
if (GS(ip->id->name) == ID_MA) {
|
|
|
|
|
ma = (Material *)ip->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((ma == NULL) || (ma->gp_style == NULL)) {
|
|
|
|
|
sp->pr_main = G_pr_main;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sp->pr_main = G_pr_main_grease_pencil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
common_preview_startjob(sp, stop, do_update, progress);
|
|
|
|
|
shader_preview_free(sp);
|
|
|
|
|
}
|
2012-02-17 16:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void icon_preview_endjob(void *customdata)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
IconPreview *ip = customdata;
|
2012-02-17 16:06:32 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (ip->id) {
|
2013-01-05 17:57:17 +00:00
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (GS(ip->id->name) == ID_BR) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
WM_main_add_notifier(NC_BRUSH | NA_EDITED, ip->id);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
#if 0
|
2019-04-17 06:17:24 +02:00
|
|
|
|
if (GS(ip->id->name) == ID_MA) {
|
|
|
|
|
Material *ma = (Material *)ip->id;
|
|
|
|
|
PreviewImage *prv_img = ma->preview;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* signal to gpu texture */
|
|
|
|
|
for (i = 0; i < NUM_ICON_SIZES; ++i) {
|
|
|
|
|
if (prv_img->gputexture[i]) {
|
|
|
|
|
GPU_texture_free(prv_img->gputexture[i]);
|
|
|
|
|
prv_img->gputexture[i] = NULL;
|
2019-04-17 08:24:14 +02:00
|
|
|
|
WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ip->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-05 18:23:05 +00:00
|
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ip->owner) {
|
|
|
|
|
PreviewImage *prv_img = ip->owner;
|
|
|
|
|
prv_img->tag &= ~PRV_TAG_DEFFERED_RENDERING;
|
|
|
|
|
if (prv_img->tag & PRV_TAG_DEFFERED_DELETE) {
|
|
|
|
|
BLI_assert(prv_img->tag & PRV_TAG_DEFFERED);
|
|
|
|
|
BKE_previewimg_cached_release_pointer(prv_img);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-17 16:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void icon_preview_free(void *customdata)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
IconPreview *ip = (IconPreview *)customdata;
|
|
|
|
|
|
|
|
|
|
if (ip->id_copy) {
|
|
|
|
|
/* Feels a bit hacky just to reuse shader_preview_free() */
|
|
|
|
|
ShaderPreview *sp = MEM_callocN(sizeof(ShaderPreview), "Icon ShaderPreview");
|
|
|
|
|
sp->id_copy = ip->id_copy;
|
|
|
|
|
sp->own_id_copy = true;
|
|
|
|
|
shader_preview_free(sp);
|
|
|
|
|
ip->id_copy = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_freelistN(&ip->sizes);
|
|
|
|
|
MEM_freeN(ip);
|
2012-02-17 16:06:32 +00:00
|
|
|
|
}
|
2009-09-28 18:33:45 +00:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
void ED_preview_icon_render(
|
|
|
|
|
Main *bmain, Scene *scene, ID *id, unsigned int *rect, int sizex, int sizey)
|
2015-01-07 12:31:25 +01:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
IconPreview ip = {NULL};
|
|
|
|
|
short stop = false, update = false;
|
|
|
|
|
float progress = 0.0f;
|
2015-01-07 12:31:25 +01:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ED_preview_ensure_dbase();
|
2015-07-22 11:24:38 +02:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
ip.bmain = bmain;
|
|
|
|
|
ip.scene = scene;
|
|
|
|
|
ip.owner = BKE_previewimg_id_ensure(id);
|
|
|
|
|
ip.id = id;
|
2019-05-02 15:54:03 +02:00
|
|
|
|
ip.id_copy = duplicate_ids(id);
|
2015-01-07 12:31:25 +01:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
icon_preview_add_size(&ip, rect, sizex, sizey);
|
2015-01-07 12:31:25 +01:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
icon_preview_startjob_all_sizes(&ip, &stop, &update, &progress);
|
2015-01-07 12:31:25 +01:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
icon_preview_endjob(&ip);
|
2015-01-07 12:31:25 +01:00
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BLI_freelistN(&ip.sizes);
|
2015-01-07 12:31:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
void ED_preview_icon_job(
|
|
|
|
|
const bContext *C, void *owner, ID *id, unsigned int *rect, int sizex, int sizey)
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
wmJob *wm_job;
|
|
|
|
|
IconPreview *ip, *old_ip;
|
|
|
|
|
|
|
|
|
|
ED_preview_ensure_dbase();
|
|
|
|
|
|
|
|
|
|
/* suspended start means it starts after 1 timer step, see WM_jobs_timer below */
|
|
|
|
|
wm_job = WM_jobs_get(CTX_wm_manager(C),
|
|
|
|
|
CTX_wm_window(C),
|
|
|
|
|
owner,
|
|
|
|
|
"Icon Preview",
|
|
|
|
|
WM_JOB_EXCL_RENDER | WM_JOB_SUSPEND,
|
|
|
|
|
WM_JOB_TYPE_RENDER_PREVIEW);
|
|
|
|
|
|
|
|
|
|
ip = MEM_callocN(sizeof(IconPreview), "icon preview");
|
|
|
|
|
|
|
|
|
|
/* render all resolutions from suspended job too */
|
|
|
|
|
old_ip = WM_jobs_customdata_get(wm_job);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (old_ip) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BLI_movelisttolist(&ip->sizes, &old_ip->sizes);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
/* customdata for preview thread */
|
|
|
|
|
ip->bmain = CTX_data_main(C);
|
|
|
|
|
ip->scene = CTX_data_scene(C);
|
|
|
|
|
ip->depsgraph = CTX_data_depsgraph(C);
|
|
|
|
|
ip->owner = owner;
|
|
|
|
|
ip->id = id;
|
2019-05-02 15:54:03 +02:00
|
|
|
|
ip->id_copy = duplicate_ids(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
icon_preview_add_size(ip, rect, sizex, sizey);
|
|
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
|
/* Special threading hack:
|
|
|
|
|
* warn main code that this preview is being rendered and cannot be freed... */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
{
|
|
|
|
|
PreviewImage *prv_img = owner;
|
|
|
|
|
if (prv_img->tag & PRV_TAG_DEFFERED) {
|
|
|
|
|
prv_img->tag |= PRV_TAG_DEFFERED_RENDERING;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* setup job */
|
|
|
|
|
WM_jobs_customdata_set(wm_job, ip, icon_preview_free);
|
|
|
|
|
WM_jobs_timer(wm_job, 0.1, NC_WINDOW, NC_WINDOW);
|
|
|
|
|
WM_jobs_callbacks(wm_job, icon_preview_startjob_all_sizes, NULL, NULL, icon_preview_endjob);
|
|
|
|
|
|
|
|
|
|
WM_jobs_start(CTX_wm_manager(C), wm_job);
|
2.5
Added WM Jobs manager
- WM can manage threaded jobs for you; just provide a couple
of components to get it work:
- customdata, free callback for it
- timer step, notifier code
- start callback, update callback
- Once started, each job runs an own timer, and will for
every time step check necessary updates, or close the
job when ready.
- No drawing happens in jobs, that's for notifiers!
- Every job stores an owner pointer, and based on this owner
it will prevent multiple jobs to enter the stack.
Instead it will re-use a running job, signal it to stop
and allow caller to re-initialize it even.
- Check new wm_jobs.c for more explanation. Jobs API is still
under construction.
Fun: BLI_addtail(&wm->jobs, steve); :)
Put Node shader previews back using wmJobs
- Preview calculating is now fully threaded (1 thread still)
- Thanks to new event system + notifiers, you can see
previews update even while dragging sliders!
- Currently it only starts when you change a node setting.
Warning: the thread render shares Node data, so don't delete
nodes while it renders! This topic is on the todo to make safe.
Also:
- bug in region initialize (do_versions) showed channel list in
node editor wrong.
- flagged the channel list 'hidden' now, it was really in the
way! This is for later to work on anyway.
- recoded Render API callbacks so it gets handlers passed on,
no globals to use anymore, remember?
- previewrender code gets now so much nicer! Will remove a lot
of stuff from code soon.
2009-01-22 14:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
|
void ED_preview_shader_job(const bContext *C,
|
|
|
|
|
void *owner,
|
|
|
|
|
ID *id,
|
|
|
|
|
ID *parent,
|
|
|
|
|
MTex *slot,
|
|
|
|
|
int sizex,
|
|
|
|
|
int sizey,
|
|
|
|
|
int method)
|
2009-06-25 15:41:27 +00:00
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
wmJob *wm_job;
|
|
|
|
|
ShaderPreview *sp;
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
short id_type = GS(id->name);
|
|
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
|
/* Use workspace render only for buttons Window,
|
|
|
|
|
* since the other previews are related to the datablock. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
|
if (!check_engine_supports_preview(scene)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Only texture node preview is supported with Cycles. */
|
|
|
|
|
if (method == PR_NODE_RENDER && id_type != ID_TE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_preview_ensure_dbase();
|
|
|
|
|
|
|
|
|
|
wm_job = WM_jobs_get(CTX_wm_manager(C),
|
|
|
|
|
CTX_wm_window(C),
|
|
|
|
|
owner,
|
|
|
|
|
"Shader Preview",
|
|
|
|
|
WM_JOB_EXCL_RENDER,
|
|
|
|
|
WM_JOB_TYPE_RENDER_PREVIEW);
|
|
|
|
|
sp = MEM_callocN(sizeof(ShaderPreview), "shader preview");
|
|
|
|
|
|
|
|
|
|
/* customdata for preview thread */
|
|
|
|
|
sp->scene = scene;
|
|
|
|
|
sp->depsgraph = CTX_data_depsgraph(C);
|
|
|
|
|
sp->owner = owner;
|
|
|
|
|
sp->sizex = sizex;
|
|
|
|
|
sp->sizey = sizey;
|
|
|
|
|
sp->pr_method = method;
|
|
|
|
|
sp->id = id;
|
2019-05-02 15:54:03 +02:00
|
|
|
|
sp->id_copy = duplicate_ids(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
sp->own_id_copy = true;
|
|
|
|
|
sp->parent = parent;
|
|
|
|
|
sp->slot = slot;
|
|
|
|
|
sp->bmain = CTX_data_main(C);
|
|
|
|
|
Material *ma = NULL;
|
|
|
|
|
|
|
|
|
|
/* hardcoded preview .blend for Eevee + Cycles, this should be solved
|
|
|
|
|
* once with custom preview .blend path for external engines */
|
|
|
|
|
|
|
|
|
|
/* grease pencil use its own preview file */
|
|
|
|
|
if (GS(id->name) == ID_MA) {
|
|
|
|
|
ma = (Material *)id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((ma == NULL) || (ma->gp_style == NULL)) {
|
|
|
|
|
sp->pr_main = G_pr_main;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sp->pr_main = G_pr_main_grease_pencil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ob && ob->totcol) {
|
|
|
|
|
copy_v4_v4(sp->color, ob->color);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ARRAY_SET_ITEMS(sp->color, 0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* setup job */
|
|
|
|
|
WM_jobs_customdata_set(wm_job, sp, shader_preview_free);
|
|
|
|
|
WM_jobs_timer(wm_job, 0.1, NC_MATERIAL, NC_MATERIAL);
|
|
|
|
|
WM_jobs_callbacks(wm_job, common_preview_startjob, NULL, shader_preview_updatejob, NULL);
|
|
|
|
|
|
|
|
|
|
WM_jobs_start(CTX_wm_manager(C), wm_job);
|
2009-06-25 15:41:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
void ED_preview_kill_jobs(wmWindowManager *wm, Main *UNUSED(bmain))
|
2010-07-04 19:58:52 +00:00
|
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
|
if (wm) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
WM_jobs_kill(wm, NULL, common_preview_startjob);
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2010-07-04 19:58:52 +00:00
|
|
|
|
}
|