Depsgraph: remove EvaluationContext, pass Depsgraph instead.
[blender.git] / source / blender / editors / sculpt_paint / paint_utils.c
index 70fd57830c0a66823393e76d2c59b5aa0d89d554..82589857ba5e2559d8736062aa733ba786b8e8b0 100644 (file)
 #include "BKE_paint.h"
 #include "BKE_report.h"
 
+#include "DEG_depsgraph.h"
+
 #include "RNA_access.h"
 #include "RNA_define.h"
 
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_glew.h"
+#include "GPU_matrix.h"
 
 #include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
@@ -130,17 +132,12 @@ bool paint_convert_bb_to_rect(rcti *rect,
  * 2D screens-space bounding box into four 3D planes) */
 void paint_calc_redraw_planes(float planes[4][4],
                               const ARegion *ar,
-                              RegionView3D *rv3d,
                               Object *ob,
                               const rcti *screen_rect)
 {
        BoundBox bb;
-       bglMats mats;
        rcti rect;
 
-       memset(&bb, 0, sizeof(BoundBox));
-       view3d_get_transformation(ar, rv3d, ob, &mats);
-
        /* use some extra space just in case */
        rect = *screen_rect;
        rect.xmin -= 2;
@@ -148,7 +145,7 @@ void paint_calc_redraw_planes(float planes[4][4],
        rect.ymin -= 2;
        rect.ymax += 2;
 
-       ED_view3d_clipping_calc(&bb, planes, &mats, &rect);
+       ED_view3d_clipping_calc(&bb, planes, ar, ob, &rect);
        negate_m4(planes);
 }
 
@@ -277,9 +274,9 @@ static void imapaint_tri_weights(float matrix[4][4], GLint view[4],
 }
 
 /* compute uv coordinates of mouse in face */
-static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2])
+static void imapaint_pick_uv(Depsgraph *depsgraph, Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2])
 {
-       DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+       DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
        const int tottri = dm->getNumLoopTri(dm);
        int i, findex;
        float p[2], w[3], absw, minabsw;
@@ -293,8 +290,8 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
 
        /* get the needed opengl matrices */
        glGetIntegerv(GL_VIEWPORT, view);
-       glGetFloatv(GL_MODELVIEW_MATRIX,  (float *)matrix);
-       glGetFloatv(GL_PROJECTION_MATRIX, (float *)proj);
+       gpuGetModelViewMatrix(matrix);
+       gpuGetProjectionMatrix(proj);
        view[0] = view[1] = 0;
        mul_m4_m4m4(matrix, matrix, ob->obmat);
        mul_m4_m4m4(matrix, proj, matrix);
@@ -355,7 +352,9 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
 }
 
 /* returns 0 if not found, otherwise 1 */
-static int imapaint_pick_face(ViewContext *vc, const int mval[2], unsigned int *r_index, unsigned int totpoly)
+static int imapaint_pick_face(
+        ViewContext *vc, const int mval[2],
+        unsigned int *r_index, unsigned int totpoly)
 {
        if (totpoly == 0)
                return 0;
@@ -427,6 +426,7 @@ void flip_qt_qt(float out[4], const float in[4], const char symm)
 void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_proj, bool use_palette)
 {
        Scene *scene = CTX_data_scene(C);
+       Depsgraph *depsgraph = CTX_data_depsgraph(C);
        Paint *paint = BKE_paint_get_active_from_context(C);
        Palette *palette = BKE_paint_palette(paint);
        PaletteColor *color = NULL;
@@ -450,14 +450,15 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr
 
        if (CTX_wm_view3d(C) && texpaint_proj) {
                /* first try getting a colour directly from the mesh faces if possible */
-               Object *ob = OBACT;
+               ViewLayer *view_layer = CTX_data_view_layer(C);
+               Object *ob = OBACT(view_layer);
                bool sample_success = false;
                ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
                bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL);
 
                if (ob) {
                        Mesh *me = (Mesh *)ob->data;
-                       DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+                       DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
 
                        ViewContext vc;
                        const int mval[2] = {x, y};
@@ -482,7 +483,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr
                                                if (ibuf && ibuf->rect) {
                                                        float uv[2];
                                                        float u, v;
-                                                       imapaint_pick_uv(scene, ob, faceindex, mval, uv);
+                                                       imapaint_pick_uv(depsgraph, scene, ob, faceindex, mval, uv);
                                                        sample_success = true;
                                                        
                                                        u = fmodf(uv[0], 1.0f);
@@ -564,8 +565,9 @@ static int brush_curve_preset_exec(bContext *C, wmOperator *op)
 
        if (br) {
                Scene *scene = CTX_data_scene(C);
+               ViewLayer *view_layer = CTX_data_view_layer(C);
                BKE_brush_curve_preset(br, RNA_enum_get(op->ptr, "shape"));
-               BKE_paint_invalidate_cursor_overlay(scene, br->curve);
+               BKE_paint_invalidate_cursor_overlay(scene, view_layer, br->curve);
        }
 
        return OPERATOR_FINISHED;