Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Mon, 5 Feb 2018 06:58:31 +0000 (17:58 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 5 Feb 2018 06:58:31 +0000 (17:58 +1100)
1  2 
source/blender/blenkernel/BKE_paint.h
source/blender/editors/util/ed_util.c

index 0d55b65fe659afcea01e34c5547adcb384190d53,de2c862651ced0400970921982f14e6579dff447..7fd08ba541fe089c21d27a6dc8c8af0ab3eb50da
@@@ -52,13 -52,11 +52,13 @@@ struct PaletteColor
  struct PBVH;
  struct ReportList;
  struct Scene;
 +struct ViewLayer;
  struct Sculpt;
  struct StrokeCache;
  struct Tex;
  struct ImagePool;
  struct UnifiedPaintSettings;
 +struct EvaluationContext;
  
  enum eOverlayFlags;
  
@@@ -91,8 -89,8 +91,8 @@@ typedef enum eOverlayControlFlags 
                                                     PAINT_OVERLAY_OVERRIDE_PRIMARY | \
                                                     PAINT_OVERLAY_OVERRIDE_CURSOR)
  
 -void BKE_paint_invalidate_overlay_tex(struct Scene *scene, const struct Tex *tex);
 -void BKE_paint_invalidate_cursor_overlay(struct Scene *scene, struct CurveMapping *curve);
 +void BKE_paint_invalidate_overlay_tex(struct Scene *scene, struct ViewLayer *view_layer, const struct Tex *tex);
 +void BKE_paint_invalidate_cursor_overlay(struct Scene *scene, struct ViewLayer *view_layer, struct CurveMapping *curve);
  void BKE_paint_invalidate_overlay_all(void);
  eOverlayControlFlags BKE_paint_get_overlay_flags(void);
  void BKE_paint_reset_overlay_invalid(eOverlayControlFlags flag);
@@@ -126,7 -124,7 +126,7 @@@ void BKE_paint_cavity_curve_preset(stru
  
  short BKE_paint_object_mode_from_paint_mode(ePaintMode mode);
  struct Paint *BKE_paint_get_active_from_paintmode(struct Scene *sce, ePaintMode mode);
 -struct Paint *BKE_paint_get_active(struct Scene *sce);
 +struct Paint *BKE_paint_get_active(struct Scene *sce, struct ViewLayer *view_layer);
  struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
  ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C);
  struct Brush *BKE_paint_brush(struct Paint *paint);
@@@ -214,7 -212,6 +214,6 @@@ typedef struct SculptSession 
        /* Layer brush persistence between strokes */
        float (*layer_co)[3]; /* Copy of the mesh vertices' locations */
  
-       struct SculptStroke *stroke;
        struct StrokeCache *cache;
  
        union {
@@@ -250,9 -247,8 +249,9 @@@ void BKE_sculptsession_free_deformMats(
  void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss);
  void BKE_sculptsession_bm_to_me(struct Object *ob, bool reorder);
  void BKE_sculptsession_bm_to_me_for_render(struct Object *object);
 -void BKE_sculpt_update_mesh_elements(struct Scene *scene, struct Sculpt *sd, struct Object *ob,
 -                                     bool need_pmap, bool need_mask);
 +void BKE_sculpt_update_mesh_elements(
 +        const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Sculpt *sd, struct Object *ob,
 +        bool need_pmap, bool need_mask);
  struct MultiresModifierData *BKE_sculpt_multires_active(struct Scene *scene, struct Object *ob);
  int BKE_sculpt_mask_layers_ensure(struct Object *ob,
                                    struct MultiresModifierData *mmd);
index b52cc20f71f1d0ca92c554fbe7fa20e9f371de1e,b34605f6af3f03064681f077e46880291e6b4ee3..8973c96c438564b9a5cb5297a28240c49cf5a95c
@@@ -70,8 -70,6 +70,8 @@@
  #include "ED_space_api.h"
  #include "ED_util.h"
  
 +#include "GPU_immediate.h"
 +
  #include "UI_interface.h"
  #include "UI_resources.h"
  
@@@ -88,8 -86,7 +88,8 @@@ void ED_editors_init(bContext *C
        wmWindowManager *wm = CTX_wm_manager(C);
        Main *bmain = CTX_data_main(C);
        Scene *sce = CTX_data_scene(C);
 -      Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL;
 +      ViewLayer *view_layer = CTX_data_view_layer(C);
 +      Object *ob, *obact = (view_layer && view_layer->basact) ? view_layer->basact->object : NULL;
        ID *data;
  
        /* This is called during initialization, so we don't want to store any reports */
        for (ob = bmain->object.first; ob; ob = ob->id.next) {
                int mode = ob->mode;
  
 -              if (!ELEM(mode, OB_MODE_OBJECT, OB_MODE_POSE)) {
 -                      ob->mode = OB_MODE_OBJECT;
 +              if (mode == OB_MODE_OBJECT) {
 +                      /* pass */
 +              }
 +              else {
                        data = ob->data;
 -
 -                      if (ob == obact && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data)))
 +                      ob->mode = OB_MODE_OBJECT;
 +                      if ((ob == obact) && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data))) {
                                ED_object_toggle_modes(C, mode);
 +                      }
                }
        }
  
@@@ -175,18 -169,22 +175,22 @@@ bool ED_editors_flush_edits(const bCont
         * objects can exist at the same time */
        for (ob = bmain->object.first; ob; ob = ob->id.next) {
                if (ob->mode & OB_MODE_SCULPT) {
-                       /* flush multires changes (for sculpt) */
-                       multires_force_update(ob);
-                       has_edited = true;
-                       if (for_render) {
-                               /* flush changes from dynamic topology sculpt */
-                               BKE_sculptsession_bm_to_me_for_render(ob);
-                       }
-                       else {
-                               /* Set reorder=false so that saving the file doesn't reorder
-                                * the BMesh's elements */
-                               BKE_sculptsession_bm_to_me(ob, false);
+                       /* Don't allow flushing while in the middle of a stroke (frees data in use).
+                        * Auto-save prevents this from happening but scripts may cause a flush on saving: T53986. */
+                       if ((ob->sculpt && ob->sculpt->cache) == 0) {
+                               /* flush multires changes (for sculpt) */
+                               multires_force_update(ob);
+                               has_edited = true;
+                               if (for_render) {
+                                       /* flush changes from dynamic topology sculpt */
+                                       BKE_sculptsession_bm_to_me_for_render(ob);
+                               }
+                               else {
+                                       /* Set reorder=false so that saving the file doesn't reorder
+                                        * the BMesh's elements */
+                                       BKE_sculptsession_bm_to_me(ob, false);
+                               }
                        }
                }
                else if (ob->mode & OB_MODE_EDIT) {
@@@ -319,28 -317,16 +323,28 @@@ void ED_region_draw_mouse_line_cb(cons
  {
        wmWindow *win = CTX_wm_window(C);
        const float *mval_src = (float *)arg_info;
 -      const int mval_dst[2] = {win->eventstate->x - ar->winrct.xmin,
 -                               win->eventstate->y - ar->winrct.ymin};
 -
 -      UI_ThemeColor(TH_VIEW_OVERLAY);
 -      setlinestyle(3);
 -      glBegin(GL_LINES);
 -      glVertex2iv(mval_dst);
 -      glVertex2fv(mval_src);
 -      glEnd();
 -      setlinestyle(0);
 +      const float mval_dst[2] = {win->eventstate->x - ar->winrct.xmin,
 +                                 win->eventstate->y - ar->winrct.ymin};
 +
 +      const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
 +
 +      immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
 +
 +      float viewport_size[4];
 +      glGetFloatv(GL_VIEWPORT, viewport_size);
 +      immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
 +
 +      immUniform1i("num_colors", 0);  /* "simple" mode */
 +      immUniformThemeColor(TH_VIEW_OVERLAY);
 +      immUniform1f("dash_width", 6.0f);
 +      immUniform1f("dash_factor", 0.5f);
 +
 +      immBegin(GWN_PRIM_LINES, 2);
 +      immVertex2fv(shdr_pos, mval_src);
 +      immVertex2fv(shdr_pos, mval_dst);
 +      immEnd();
 +
 +      immUnbindProgram();
  }
  
  /**