Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Sat, 14 Oct 2017 06:58:29 +0000 (17:58 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 14 Oct 2017 06:58:29 +0000 (17:58 +1100)
1  2 
source/blender/blenkernel/intern/curve.c
source/blender/editors/curve/editcurve_paint.c

index 5fbaae7212b7994f8f93ee195ef12d250826d2ec,6c6019748d628902f9f861ad3921b5f2ba20641c..a93bda215a086bd9ff400a6a447f3efe0f78ad59
@@@ -52,6 -52,7 +52,6 @@@
  
  #include "BKE_animsys.h"
  #include "BKE_curve.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_displist.h"
  #include "BKE_font.h"
  #include "BKE_global.h"
@@@ -63,8 -64,6 +63,8 @@@
  #include "BKE_object.h"
  #include "BKE_material.h"
  
 +#include "DEG_depsgraph.h"
 +
  /* globals */
  
  /* local */
@@@ -127,8 -126,6 +127,8 @@@ void BKE_curve_free(Curve *cu
  {
        BKE_animdata_free((ID *)cu, false);
  
 +      BKE_curve_batch_cache_free(cu);
 +
        BKE_nurbList_free(&cu->nurb);
        BKE_curve_editfont_free(cu);
  
@@@ -209,7 -206,6 +209,7 @@@ void BKE_curve_copy_data(Main *bmain, C
        cu_dst->strinfo = MEM_dupallocN(cu_src->strinfo);
        cu_dst->tb = MEM_dupallocN(cu_src->tb);
        cu_dst->bb = MEM_dupallocN(cu_src->bb);
 +      cu_dst->batch_cache = NULL;
  
        if (cu_src->key) {
                BKE_id_copy_ex(bmain, &cu_src->key->id, (ID **)&cu_dst->key, flag, false);
@@@ -745,7 -741,7 +745,7 @@@ BezTriple *BKE_nurb_bezt_get_prev(Nurb 
        BezTriple *bezt_prev;
  
        BLI_assert(ARRAY_HAS_ITEM(bezt, nu->bezt, nu->pntsu));
-       BLI_assert(nu->pntsv == 1);
+       BLI_assert(nu->pntsv <= 1);
  
        if (bezt == nu->bezt) {
                if (nu->flagu & CU_NURB_CYCLIC) {
@@@ -1622,7 -1618,7 +1622,7 @@@ float *BKE_curve_surf_make_orco(Object 
  /* NOTE: This routine is tied to the order of vertex
   * built by displist and as passed to the renderer.
   */
 -float *BKE_curve_make_orco(Scene *scene, Object *ob, int *r_numVerts)
 +float *BKE_curve_make_orco(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, int *r_numVerts)
  {
        Curve *cu = ob->data;
        DispList *dl;
        float *fp, *coord_array;
        ListBase disp = {NULL, NULL};
  
 -      BKE_displist_make_curveTypes_forOrco(scene, ob, &disp);
 +      BKE_displist_make_curveTypes_forOrco(eval_ctx, scene, ob, &disp);
  
        numVerts = 0;
        for (dl = disp.first; dl; dl = dl->next) {
  
  /* ***************** BEVEL ****************** */
  
 -void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp,
 -                          const bool for_render, const bool use_render_resolution)
 +void BKE_curve_bevel_make(
 +        const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *disp,
 +        const bool for_render, const bool use_render_resolution)
  {
        DispList *dl, *dlnew;
        Curve *bevcu, *cu;
                        facy = cu->bevobj->size[1];
  
                        if (for_render) {
 -                              BKE_displist_make_curveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, false, use_render_resolution);
 +                              BKE_displist_make_curveTypes_forRender(eval_ctx, scene, cu->bevobj, &bevdisp, NULL, false, use_render_resolution);
                                dl = bevdisp.first;
                        }
                        else if (cu->bevobj->curve_cache) {
@@@ -4144,6 -4139,7 +4144,7 @@@ bool BKE_nurb_type_convert(Nurb *nu, co
                        MEM_freeN(nu->bp);
                        nu->bp = NULL;
                        nu->pntsu = nr;
+                       nu->pntsv = 0;
                        nu->type = CU_BEZIER;
                        BKE_nurb_handles_calc(nu);
                }
@@@ -4608,7 -4604,7 +4609,7 @@@ int BKE_curve_material_index_validate(C
        }
  
        if (!is_valid) {
 -              DAG_id_tag_update(&cu->id, OB_RECALC_DATA);
 +              DEG_id_tag_update(&cu->id, OB_RECALC_DATA);
                return true;
        }
        else {
@@@ -4675,7 -4671,7 +4676,7 @@@ void BKE_curve_rect_from_textbox(const 
  
  /* **** Depsgraph evaluation **** */
  
 -void BKE_curve_eval_geometry(EvaluationContext *UNUSED(eval_ctx),
 +void BKE_curve_eval_geometry(const EvaluationContext *UNUSED(eval_ctx),
                               Curve *curve)
  {
        if (G.debug & G_DEBUG_DEPSGRAPH) {
                BKE_curve_texspace_calc(curve);
        }
  }
 +
 +/* Draw Engine */
 +void (*BKE_curve_batch_cache_dirty_cb)(Curve *cu, int mode) = NULL;
 +void (*BKE_curve_batch_cache_free_cb)(Curve *cu) = NULL;
 +
 +void BKE_curve_batch_cache_dirty(Curve *cu, int mode)
 +{
 +      if (cu->batch_cache) {
 +              BKE_curve_batch_cache_dirty_cb(cu, mode);
 +      }
 +}
 +void BKE_curve_batch_cache_free(Curve *cu)
 +{
 +      if (cu->batch_cache) {
 +              BKE_curve_batch_cache_free_cb(cu);
 +      }
 +}
index f6bbff2f5d4b7c05e6b71d102718f60fe32380d7,4602945d11ce3ee33fc4e69c8e806a17c1cb9f86..a1b73a54e3db213a6b46445da15d07f11f51a8be
  
  #include "BKE_context.h"
  #include "BKE_curve.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_fcurve.h"
  #include "BKE_report.h"
  
 +#include "DEG_depsgraph.h"
 +
  #include "WM_api.h"
  #include "WM_types.h"
  
  #include "ED_curve.h"
  
  #include "BIF_gl.h"
 -#include "BIF_glutil.h"
 +
 +#include "GPU_batch.h"
 +#include "GPU_immediate.h"
 +#include "GPU_immediate_util.h"
 +#include "GPU_matrix.h"
  
  #include "curve_intern.h"
  
@@@ -133,6 -128,7 +133,6 @@@ struct CurveDrawData 
        } prev;
  
        ViewContext vc;
 -      bglMats mats;
        enum {
                CURVE_DRAW_IDLE = 0,
                CURVE_DRAW_PAINTING = 1,
@@@ -218,7 -214,7 +218,7 @@@ static bool stroke_elem_project
                {
                        const double depth = (double)ED_view3d_depth_read_cached(&cdd->vc, mval_i);
                        if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
 -                              if (ED_view3d_depth_unproject(ar, &cdd->mats, mval_i, depth, r_location_world)) {
 +                              if (ED_view3d_depth_unproject(ar, mval_i, depth, r_location_world)) {
                                        is_location_world_set = true;
                                        if (r_normal_world) {
                                                zero_v3(r_normal_world);
                                        if (surface_offset != 0.0f) {
                                                const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
                                                float normal[3];
 -                                              if (ED_view3d_depth_read_cached_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
 +                                              if (ED_view3d_depth_read_cached_normal(&cdd->vc, mval_i, normal)) {
                                                        madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
                                                        if (r_normal_world) {
                                                                copy_v3_v3(r_normal_world, normal);
@@@ -373,43 -369,39 +373,43 @@@ static void curve_draw_stroke_3d(const 
        Object *obedit = cdd->vc.obedit;
        Curve *cu = obedit->data;
  
 -      UI_ThemeColor(TH_WIRE);
 -
        if (cu->ext2 > 0.0f) {
 -              GLUquadricObj *qobj = gluNewQuadric();
 -
 -              gluQuadricDrawStyle(qobj, GLU_FILL);
 -
                BLI_mempool_iter iter;
                const struct StrokeElem *selem;
  
                const float  location_zero[3] = {0};
                const float *location_prev = location_zero;
  
 +              float color[3];
 +              UI_GetThemeColor3fv(TH_WIRE, color);
 +
 +              Gwn_Batch *sphere = GPU_batch_preset_sphere(0);
 +              GWN_batch_program_set_builtin(sphere, GPU_SHADER_3D_UNIFORM_COLOR);
 +              GWN_batch_uniform_3fv(sphere, "color", color);
 +
                /* scale to edit-mode space */
 -              glPushMatrix();
 -              glMultMatrixf(obedit->obmat);
 +              gpuPushMatrix();
 +              gpuMultMatrix(obedit->obmat);
  
                BLI_mempool_iternew(cdd->stroke_elem_pool, &iter);
                for (selem = BLI_mempool_iterstep(&iter); selem; selem = BLI_mempool_iterstep(&iter)) {
 -                      glTranslatef(
 +                      gpuTranslate3f(
                                selem->location_local[0] - location_prev[0],
                                selem->location_local[1] - location_prev[1],
                                selem->location_local[2] - location_prev[2]);
                        location_prev = selem->location_local;
 +
                        const float radius = stroke_elem_radius(cdd, selem);
 -                      gluSphere(qobj, radius, 12, 8);
 +
 +                      gpuPushMatrix();
 +                      gpuScaleUniform(radius);
 +                      GWN_batch_draw(sphere);
 +                      gpuPopMatrix();
  
                        location_prev = selem->location_local;
                }
  
 -              glPopMatrix();
 -
 -              gluDeleteQuadric(qobj);
 +              gpuPopMatrix();
        }
  
        if (stroke_len > 1) {
                }
  
                {
 +                      Gwn_VertFormat *format = immVertexFormat();
 +                      unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
 +                      immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
 +
                        glEnable(GL_BLEND);
                        glEnable(GL_LINE_SMOOTH);
  
 -                      glEnableClientState(GL_VERTEX_ARRAY);
 -                      glVertexPointer(3, GL_FLOAT, 0, coord_array);
 -
 -                      cpack(0x0);
 +                      imm_cpack(0x0);
 +                      immBegin(GWN_PRIM_LINE_STRIP, stroke_len);
                        glLineWidth(3.0f);
 -                      glDrawArrays(GL_LINE_STRIP, 0, stroke_len);
  
 -                      if (v3d->zbuf)
 +                      if (v3d->zbuf) {
                                glDisable(GL_DEPTH_TEST);
 +                      }
 +
 +                      for (int i = 0; i < stroke_len; i++) {
 +                              immVertex3fv(pos, coord_array[i]);
 +                      }
 +
 +                      immEnd();
  
 -                      cpack(0xffffffff);
 +                      imm_cpack(0xffffffff);
 +                      immBegin(GWN_PRIM_LINE_STRIP, stroke_len);
                        glLineWidth(1.0f);
 -                      glDrawArrays(GL_LINE_STRIP, 0, stroke_len);
  
 -                      if (v3d->zbuf)
 -                              glEnable(GL_DEPTH_TEST);
 +                      for (int i = 0; i < stroke_len; i++) {
 +                              immVertex3fv(pos, coord_array[i]);
 +                      }
  
 -                      glDisableClientState(GL_VERTEX_ARRAY);
 +                      immEnd();
 +
 +                      if (v3d->zbuf) {
 +                              glEnable(GL_DEPTH_TEST);
 +                      }
  
                        glDisable(GL_BLEND);
                        glDisable(GL_LINE_SMOOTH);
 +
 +                      immUnbindProgram();
                }
  
                MEM_freeN(coord_array);
@@@ -554,7 -531,7 +554,7 @@@ static void curve_draw_event_add_first(
                         CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW,
                         CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE))
                {
 -                      if (ED_view3d_depth_read_cached_normal(&cdd->vc, &cdd->mats, event->mval, normal)) {
 +                      if (ED_view3d_depth_read_cached_normal(&cdd->vc, event->mval, normal)) {
                                if (cps->surface_plane == CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW) {
                                        float cross_a[3], cross_b[3];
                                        cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
@@@ -612,9 -589,7 +612,9 @@@ static bool curve_draw_init(bContext *C
                }
        }
        else {
 +              cdd->vc.depsgraph = CTX_data_depsgraph(C);
                cdd->vc.scene = CTX_data_scene(C);
 +              cdd->vc.scene_layer = CTX_data_scene_layer(C);
                cdd->vc.obedit = CTX_data_edit_object(C);
        }
  
@@@ -805,7 -780,7 +805,7 @@@ static int curve_draw_exec(bContext *C
        const float radius_range = cps->radius_max - cps->radius_min;
  
        Nurb *nu = MEM_callocN(sizeof(Nurb), __func__);
-       nu->pntsv = 1;
+       nu->pntsv = 0;
        nu->resolu = cu->resolu;
        nu->resolv = cu->resolv;
        nu->flag |= CU_SMOOTH;
        cu->actvert = nu->pntsu - 1;
  
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
 -      DAG_id_tag_update(obedit->data, 0);
 +      DEG_id_tag_update(obedit->data, 0);
  
        curve_draw_exit(op);
  
@@@ -1091,13 -1066,12 +1091,13 @@@ static int curve_draw_invoke(bContext *
                        if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) &&
                            (v3d->drawtype > OB_WIRE))
                        {
 -                              view3d_get_transformation(cdd->vc.ar, cdd->vc.rv3d, NULL, &cdd->mats);
 +                              EvaluationContext eval_ctx;
 +                              CTX_data_eval_ctx(C, &eval_ctx);
  
                                /* needed or else the draw matrix can be incorrect */
                                view3d_operator_needs_opengl(C);
  
 -                              ED_view3d_autodist_init(cdd->vc.scene, cdd->vc.ar, cdd->vc.v3d, 0);
 +                              ED_view3d_autodist_init(&eval_ctx, cdd->vc.depsgraph, cdd->vc.ar, cdd->vc.v3d, 0);
  
                                if (cdd->vc.rv3d->depths) {
                                        cdd->vc.rv3d->depths->damaged = true;