DRW: de-duplicate vertex & weight paint engines
authorCampbell Barton <ideasman42@gmail.com>
Thu, 14 Feb 2019 02:59:30 +0000 (13:59 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 14 Feb 2019 04:22:58 +0000 (15:22 +1100)
These were almost exact duplicates, use one engine for drawing both
kinds of vertex color.

source/blender/draw/CMakeLists.txt
source/blender/draw/intern/draw_manager.c
source/blender/draw/modes/draw_mode_engines.h
source/blender/draw/modes/paint_vertex_mode.c
source/blender/draw/modes/paint_weight_mode.c [deleted file]

index 74a9b3a..80878ae 100644 (file)
@@ -80,7 +80,6 @@ set(SRC
        modes/overlay_mode.c
        modes/paint_texture_mode.c
        modes/paint_vertex_mode.c
        modes/overlay_mode.c
        modes/paint_texture_mode.c
        modes/paint_vertex_mode.c
-       modes/paint_weight_mode.c
        modes/particle_mode.c
        modes/pose_mode.c
        modes/sculpt_mode.c
        modes/particle_mode.c
        modes/pose_mode.c
        modes/sculpt_mode.c
index bd43a35..4647782 100644 (file)
@@ -1218,8 +1218,6 @@ static void drw_engines_enable_from_paint_mode(int mode)
                        use_drw_engine(&draw_engine_sculpt_type);
                        break;
                case CTX_MODE_PAINT_WEIGHT:
                        use_drw_engine(&draw_engine_sculpt_type);
                        break;
                case CTX_MODE_PAINT_WEIGHT:
-                       use_drw_engine(&draw_engine_paint_weight_type);
-                       break;
                case CTX_MODE_PAINT_VERTEX:
                        use_drw_engine(&draw_engine_paint_vertex_type);
                        break;
                case CTX_MODE_PAINT_VERTEX:
                        use_drw_engine(&draw_engine_paint_vertex_type);
                        break;
@@ -2541,7 +2539,6 @@ void DRW_engines_register(void)
        DRW_engine_register(&draw_engine_overlay_type);
        DRW_engine_register(&draw_engine_paint_texture_type);
        DRW_engine_register(&draw_engine_paint_vertex_type);
        DRW_engine_register(&draw_engine_overlay_type);
        DRW_engine_register(&draw_engine_paint_texture_type);
        DRW_engine_register(&draw_engine_paint_vertex_type);
-       DRW_engine_register(&draw_engine_paint_weight_type);
        DRW_engine_register(&draw_engine_particle_type);
        DRW_engine_register(&draw_engine_pose_type);
        DRW_engine_register(&draw_engine_sculpt_type);
        DRW_engine_register(&draw_engine_particle_type);
        DRW_engine_register(&draw_engine_pose_type);
        DRW_engine_register(&draw_engine_sculpt_type);
index 1472393..0ad7b06 100644 (file)
@@ -32,7 +32,6 @@ extern DrawEngineType draw_engine_edit_text_type;
 extern DrawEngineType draw_engine_motion_path_type;
 extern DrawEngineType draw_engine_paint_texture_type;
 extern DrawEngineType draw_engine_paint_vertex_type;
 extern DrawEngineType draw_engine_motion_path_type;
 extern DrawEngineType draw_engine_paint_texture_type;
 extern DrawEngineType draw_engine_paint_vertex_type;
-extern DrawEngineType draw_engine_paint_weight_type;
 extern DrawEngineType draw_engine_particle_type;
 extern DrawEngineType draw_engine_pose_type;
 extern DrawEngineType draw_engine_sculpt_type;
 extern DrawEngineType draw_engine_particle_type;
 extern DrawEngineType draw_engine_pose_type;
 extern DrawEngineType draw_engine_sculpt_type;
index 51eeacd..e58399c 100644 (file)
 
 #include "draw_common.h"
 
 
 #include "draw_common.h"
 
-
 #include "DNA_mesh_types.h"
 #include "DNA_view3d_types.h"
 
 #include "DEG_depsgraph_query.h"
 
 #include "DNA_mesh_types.h"
 #include "DNA_view3d_types.h"
 
 #include "DEG_depsgraph_query.h"
 
+extern char datatoc_paint_face_vert_glsl[];
+extern char datatoc_paint_weight_vert_glsl[];
+extern char datatoc_paint_weight_frag_glsl[];
 extern char datatoc_paint_vertex_vert_glsl[];
 extern char datatoc_paint_vertex_frag_glsl[];
 extern char datatoc_paint_wire_vert_glsl[];
 extern char datatoc_paint_wire_frag_glsl[];
 extern char datatoc_paint_vertex_vert_glsl[];
 extern char datatoc_paint_vertex_frag_glsl[];
 extern char datatoc_paint_wire_vert_glsl[];
 extern char datatoc_paint_wire_frag_glsl[];
-extern char datatoc_paint_face_vert_glsl[];
 extern char datatoc_paint_vert_frag_glsl[];
 extern char datatoc_common_globals_lib_glsl[];
 
 extern char datatoc_paint_vert_frag_glsl[];
 extern char datatoc_common_globals_lib_glsl[];
 
@@ -44,8 +45,16 @@ extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
 
 /* *********** LISTS *********** */
 
 
 /* *********** LISTS *********** */
 
+enum {
+       VERTEX_MODE = 0,
+       WEIGHT_MODE = 1,
+};
+#define MODE_LEN (WEIGHT_MODE + 1)
+
 typedef struct PAINT_VERTEX_PassList {
 typedef struct PAINT_VERTEX_PassList {
-       struct DRWPass *vcolor_faces;
+       struct {
+               struct DRWPass *color_faces;
+       } by_mode[MODE_LEN];
        struct DRWPass *wire_overlay;
        struct DRWPass *wire_select_overlay;
        struct DRWPass *face_select_overlay;
        struct DRWPass *wire_overlay;
        struct DRWPass *wire_select_overlay;
        struct DRWPass *face_select_overlay;
@@ -65,9 +74,11 @@ typedef struct PAINT_VERTEX_Data {
 } PAINT_VERTEX_Data;
 
 typedef struct PAINT_VERTEX_Shaders {
 } PAINT_VERTEX_Data;
 
 typedef struct PAINT_VERTEX_Shaders {
-       struct GPUShader *vcolor_face;
-       struct GPUShader *wire_overlay;
-       struct GPUShader *wire_select_overlay;
+       struct {
+               struct GPUShader *color_face;
+               struct GPUShader *wire_overlay;
+               struct GPUShader *wire_select_overlay;
+       } by_mode[MODE_LEN];
        struct GPUShader *face_select_overlay;
        struct GPUShader *vert_select_overlay;
 } PAINT_VERTEX_Shaders;
        struct GPUShader *face_select_overlay;
        struct GPUShader *vert_select_overlay;
 } PAINT_VERTEX_Shaders;
@@ -76,12 +87,14 @@ typedef struct PAINT_VERTEX_Shaders {
 
 static struct {
        PAINT_VERTEX_Shaders sh_data[GPU_SHADER_CFG_LEN];
 
 static struct {
        PAINT_VERTEX_Shaders sh_data[GPU_SHADER_CFG_LEN];
-} e_data = {{{NULL}}}; /* Engine data */
+} e_data = {{{{{NULL}}}}}; /* Engine data */
 
 typedef struct PAINT_VERTEX_PrivateData {
 
 typedef struct PAINT_VERTEX_PrivateData {
-       DRWShadingGroup *fvcolor_shgrp;
-       DRWShadingGroup *lwire_shgrp;
-       DRWShadingGroup *lwire_select_shgrp;
+       struct {
+               DRWShadingGroup *color_shgrp;
+               DRWShadingGroup *lwire_shgrp;
+               DRWShadingGroup *lwire_select_shgrp;
+       } by_mode[MODE_LEN];
        DRWShadingGroup *face_select_shgrp;
        DRWShadingGroup *vert_select_shgrp;
 } PAINT_VERTEX_PrivateData; /* Transient data */
        DRWShadingGroup *face_select_shgrp;
        DRWShadingGroup *vert_select_shgrp;
 } PAINT_VERTEX_PrivateData; /* Transient data */
@@ -98,23 +111,18 @@ static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
        }
        const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
        }
        const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
-       if (!sh_data->vcolor_face) {
-
-               sh_data->vcolor_face = GPU_shader_create_from_arrays({
+       if (!sh_data->face_select_overlay) {
+               sh_data->by_mode[VERTEX_MODE].color_face = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_vertex_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_paint_vertex_frag_glsl, NULL},
                        .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
                        .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_vertex_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_paint_vertex_frag_glsl, NULL},
                        .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
-               sh_data->wire_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
-                       .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
-                       .defs = (const char *[]){sh_cfg_data->def, "#define VERTEX_MODE\n", NULL},
-               });
-               sh_data->wire_select_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
-                       .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
-                       .defs = (const char *[]){sh_cfg_data->def, "#define VERTEX_MODE\n" "#define USE_SELECT\n", NULL},
+               sh_data->by_mode[WEIGHT_MODE].color_face = GPU_shader_create_from_arrays({
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_weight_vert_glsl, NULL},
+                       .frag = (const char *[]){datatoc_common_globals_lib_glsl, datatoc_paint_weight_frag_glsl, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
                });
+
                sh_data->face_select_overlay = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_face_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
                sh_data->face_select_overlay = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_face_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
@@ -125,6 +133,23 @@ static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
                        .frag = (const char *[]){datatoc_paint_vert_frag_glsl, NULL},
                        .defs = (const char *[]){sh_cfg_data->def, "#define USE_SELECT\n", NULL},
                });
                        .frag = (const char *[]){datatoc_paint_vert_frag_glsl, NULL},
                        .defs = (const char *[]){sh_cfg_data->def, "#define USE_SELECT\n", NULL},
                });
+
+               const char *mode_defs[MODE_LEN] = {
+                       "#define VERTEX_MODE\n",
+                       "#define WEIGHT_MODE\n",
+               };
+               for (int i = 0; i < MODE_LEN; i++) {
+                       sh_data->by_mode[i].wire_overlay = GPU_shader_create_from_arrays({
+                               .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
+                               .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
+                               .defs = (const char *[]){sh_cfg_data->def, mode_defs[i], NULL},
+                       });
+                       sh_data->by_mode[i].wire_select_overlay = GPU_shader_create_from_arrays({
+                               .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
+                               .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
+                               .defs = (const char *[]){sh_cfg_data->def, mode_defs[i], "#define USE_SELECT\n", NULL},
+                       });
+               }
        }
 }
 
        }
 }
 
@@ -142,52 +167,74 @@ static void PAINT_VERTEX_cache_init(void *vedata)
                stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
        }
 
                stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
        }
 
+       /* Vertex color pass */
        {
        {
-               /* Create a pass */
                DRWPass *pass = DRW_pass_create(
                        "Vert Color Pass",
                        DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_MULTIPLY);
                DRWPass *pass = DRW_pass_create(
                        "Vert Color Pass",
                        DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_MULTIPLY);
-               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->vcolor_face, pass);
+               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->by_mode[VERTEX_MODE].color_face, pass);
                DRW_shgroup_uniform_float_copy(shgrp, "white_factor", 1.0f - v3d->overlay.vertex_paint_mode_opacity);
                if (rv3d->rflag & RV3D_CLIPPING) {
                        DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
                }
                DRW_shgroup_uniform_float_copy(shgrp, "white_factor", 1.0f - v3d->overlay.vertex_paint_mode_opacity);
                if (rv3d->rflag & RV3D_CLIPPING) {
                        DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
                }
-               psl->vcolor_faces = pass;
-               stl->g_data->fvcolor_shgrp = shgrp;
+               psl->by_mode[VERTEX_MODE].color_faces = pass;
+               stl->g_data->by_mode[VERTEX_MODE].color_shgrp = shgrp;
        }
 
        }
 
+       /* Weight color pass */
        {
                DRWPass *pass = DRW_pass_create(
        {
                DRWPass *pass = DRW_pass_create(
-                       "Wire Pass",
-                       DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_OFFSET_NEGATIVE);
-               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->wire_overlay, pass);
+                       "Weight Pass",
+                       DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_MULTIPLY);
+               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->by_mode[WEIGHT_MODE].color_face, pass);
+               DRW_shgroup_uniform_bool_copy(shgrp, "drawContours", (v3d->overlay.wpaint_flag & V3D_OVERLAY_WPAINT_CONTOURS) != 0);
+               DRW_shgroup_uniform_float(shgrp, "opacity", &v3d->overlay.weight_paint_mode_opacity, 1);
+               DRW_shgroup_uniform_texture(shgrp, "colorramp", G_draw.weight_ramp);
                DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
                if (rv3d->rflag & RV3D_CLIPPING) {
                        DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
                }
                DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
                if (rv3d->rflag & RV3D_CLIPPING) {
                        DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
                }
+               psl->by_mode[WEIGHT_MODE].color_faces = pass;
+               stl->g_data->by_mode[WEIGHT_MODE].color_shgrp = shgrp;
+       }
+
+       {
+               DRWPass *pass = DRW_pass_create(
+                       "Wire Pass",
+                       DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_OFFSET_NEGATIVE);
+               for (int i = 0; i < MODE_LEN; i++) {
+                       DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->by_mode[i].wire_overlay, pass);
+                       DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
+                       if (rv3d->rflag & RV3D_CLIPPING) {
+                               DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
+                       }
+                       stl->g_data->by_mode[i].lwire_shgrp = shgrp;
+               }
                psl->wire_overlay = pass;
                psl->wire_overlay = pass;
-               stl->g_data->lwire_shgrp = shgrp;
        }
 
        }
 
+
        {
                DRWPass *pass = DRW_pass_create(
                        "Wire Mask Pass",
                        DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_OFFSET_NEGATIVE);
        {
                DRWPass *pass = DRW_pass_create(
                        "Wire Mask Pass",
                        DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_OFFSET_NEGATIVE);
-               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->wire_select_overlay, pass);
-               DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
-               if (rv3d->rflag & RV3D_CLIPPING) {
-                       DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
+               for (int i = 0; i < MODE_LEN; i++) {
+                       DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->by_mode[i].wire_select_overlay, pass);
+                       DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
+                       if (rv3d->rflag & RV3D_CLIPPING) {
+                               DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
+                       }
+                       stl->g_data->by_mode[i].lwire_select_shgrp = shgrp;
                }
                psl->wire_select_overlay = pass;
                }
                psl->wire_select_overlay = pass;
-               stl->g_data->lwire_select_shgrp = shgrp;
        }
 
        {
        }
 
        {
+               static float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
                DRWPass *pass = DRW_pass_create(
                        "Face Mask Pass",
                        DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND);
                DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->face_select_overlay, pass);
                DRWPass *pass = DRW_pass_create(
                        "Face Mask Pass",
                        DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND);
                DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->face_select_overlay, pass);
-               static float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
                DRW_shgroup_uniform_vec4(shgrp, "color", col, 1);
                if (rv3d->rflag & RV3D_CLIPPING) {
                        DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
                DRW_shgroup_uniform_vec4(shgrp, "color", col, 1);
                if (rv3d->rflag & RV3D_CLIPPING) {
                        DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
@@ -217,25 +264,35 @@ static void PAINT_VERTEX_cache_populate(void *vedata, Object *ob)
        const View3D *v3d = draw_ctx->v3d;
 
        if ((ob->type == OB_MESH) && (ob == draw_ctx->obact)) {
        const View3D *v3d = draw_ctx->v3d;
 
        if ((ob->type == OB_MESH) && (ob == draw_ctx->obact)) {
+               const int draw_mode = (ob->mode == OB_MODE_VERTEX_PAINT) ? VERTEX_MODE : WEIGHT_MODE;
                const Mesh *me = ob->data;
                const Mesh *me_orig = DEG_get_original_object(ob)->data;
                const bool use_wire = (v3d->overlay.paint_flag & V3D_OVERLAY_PAINT_WIRE) != 0;
                const Mesh *me = ob->data;
                const Mesh *me_orig = DEG_get_original_object(ob)->data;
                const bool use_wire = (v3d->overlay.paint_flag & V3D_OVERLAY_PAINT_WIRE) != 0;
-               const bool use_surface = v3d->overlay.vertex_paint_mode_opacity != 0.0f;
                const bool use_face_sel = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
                const bool use_vert_sel = (me_orig->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
                const bool use_face_sel = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
                const bool use_vert_sel = (me_orig->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
-               struct GPUBatch *geom;
 
 
-               if (me->mloopcol == NULL) {
-                       return;
+               struct GPUBatch *geom = NULL;
+               if (draw_mode == VERTEX_MODE) {
+                       if (me->mloopcol == NULL) {
+                               return;
+                       }
+                       if (v3d->overlay.vertex_paint_mode_opacity != 0.0f) {
+                               geom = DRW_cache_mesh_surface_vertpaint_get(ob);
+                       }
                }
                }
-
-               if (use_surface) {
-                       geom = DRW_cache_mesh_surface_vertpaint_get(ob);
-                       DRW_shgroup_call_add(stl->g_data->fvcolor_shgrp, geom, ob->obmat);
+               else {
+                       if (v3d->overlay.weight_paint_mode_opacity != 0.0f) {
+                               geom = DRW_cache_mesh_surface_weights_get(ob);
+                       }
+               }
+               if (geom != NULL) {
+                       DRW_shgroup_call_add(stl->g_data->by_mode[draw_mode].color_shgrp, geom, ob->obmat);
                }
 
                if (use_face_sel || use_wire) {
                }
 
                if (use_face_sel || use_wire) {
-                       DRWShadingGroup *shgrp = use_face_sel ? stl->g_data->lwire_select_shgrp : stl->g_data->lwire_shgrp;
+                       DRWShadingGroup *shgrp = use_face_sel ?
+                               stl->g_data->by_mode[draw_mode].lwire_select_shgrp :
+                               stl->g_data->by_mode[draw_mode].lwire_shgrp;
                        geom = DRW_cache_mesh_surface_edges_get(ob);
                        DRW_shgroup_call_add(shgrp, geom, ob->obmat);
                }
                        geom = DRW_cache_mesh_surface_edges_get(ob);
                        DRW_shgroup_call_add(shgrp, geom, ob->obmat);
                }
@@ -255,8 +312,9 @@ static void PAINT_VERTEX_cache_populate(void *vedata, Object *ob)
 static void PAINT_VERTEX_draw_scene(void *vedata)
 {
        PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl;
 static void PAINT_VERTEX_draw_scene(void *vedata)
 {
        PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl;
-
-       DRW_draw_pass(psl->vcolor_faces);
+       for (int i = 0; i < MODE_LEN; i++) {
+               DRW_draw_pass(psl->by_mode[i].color_faces);
+       }
        DRW_draw_pass(psl->wire_overlay);
        DRW_draw_pass(psl->wire_select_overlay);
        DRW_draw_pass(psl->vert_select_overlay);
        DRW_draw_pass(psl->wire_overlay);
        DRW_draw_pass(psl->wire_select_overlay);
        DRW_draw_pass(psl->vert_select_overlay);
diff --git a/source/blender/draw/modes/paint_weight_mode.c b/source/blender/draw/modes/paint_weight_mode.c
deleted file mode 100644 (file)
index 42c46f6..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright 2016, Blender Foundation.
- */
-
-/** \file \ingroup draw
- */
-
-#include "DRW_render.h"
-
-/* If builtin shaders are needed */
-#include "GPU_shader.h"
-
-#include "draw_common.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_view3d_types.h"
-
-#include "DEG_depsgraph_query.h"
-
-extern char datatoc_paint_face_vert_glsl[];
-extern char datatoc_paint_weight_vert_glsl[];
-extern char datatoc_paint_weight_frag_glsl[];
-extern char datatoc_paint_wire_vert_glsl[];
-extern char datatoc_paint_wire_frag_glsl[];
-extern char datatoc_paint_vert_frag_glsl[];
-extern char datatoc_common_globals_lib_glsl[];
-
-extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
-
-/* *********** LISTS *********** */
-
-typedef struct PAINT_WEIGHT_PassList {
-       struct DRWPass *weight_faces;
-       struct DRWPass *wire_overlay;
-       struct DRWPass *wire_select_overlay;
-       struct DRWPass *face_select_overlay;
-       struct DRWPass *vert_select_overlay;
-} PAINT_WEIGHT_PassList;
-
-typedef struct PAINT_WEIGHT_StorageList {
-       struct PAINT_WEIGHT_PrivateData *g_data;
-} PAINT_WEIGHT_StorageList;
-
-typedef struct PAINT_WEIGHT_Data {
-       void *engine_type;
-       DRWViewportEmptyList *fbl;
-       DRWViewportEmptyList *txl;
-       PAINT_WEIGHT_PassList *psl;
-       PAINT_WEIGHT_StorageList *stl;
-} PAINT_WEIGHT_Data;
-
-typedef struct PAINT_WEIGHT_Shaders {
-       struct GPUShader *weight_face;
-       struct GPUShader *wire_overlay;
-       struct GPUShader *wire_select_overlay;
-       struct GPUShader *face_select_overlay;
-       struct GPUShader *vert_select_overlay;
-} PAINT_WEIGHT_Shaders;
-
-/* *********** STATIC *********** */
-
-static struct {
-       PAINT_WEIGHT_Shaders sh_data[GPU_SHADER_CFG_LEN];
-
-       int actdef;
-} e_data = {NULL}; /* Engine data */
-
-typedef struct PAINT_WEIGHT_PrivateData {
-       DRWShadingGroup *fweights_shgrp;
-       DRWShadingGroup *lwire_shgrp;
-       DRWShadingGroup *lwire_select_shgrp;
-       DRWShadingGroup *face_shgrp;
-       DRWShadingGroup *vert_select_shgrp;
-} PAINT_WEIGHT_PrivateData;
-
-/* *********** FUNCTIONS *********** */
-
-static void PAINT_WEIGHT_engine_init(void *UNUSED(vedata))
-{
-       const DRWContextState *draw_ctx = DRW_context_state_get();
-       PAINT_WEIGHT_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
-       const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
-
-       if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
-               DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
-       }
-
-       if (!sh_data->weight_face) {
-               sh_data->weight_face = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_weight_vert_glsl, NULL},
-                       .frag = (const char *[]){datatoc_common_globals_lib_glsl, datatoc_paint_weight_frag_glsl, NULL},
-                       .defs = (const char *[]){sh_cfg_data->def, NULL},
-               });
-
-               sh_data->wire_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
-                       .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
-                       .defs = (const char *[]){sh_cfg_data->def, "#define WEIGHT_MODE\n", NULL},
-               });
-               sh_data->wire_select_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
-                       .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
-                       .defs = (const char *[]){sh_cfg_data->def, "#define WEIGHT_MODE\n" "#define USE_SELECT\n", NULL},
-               });
-               sh_data->face_select_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_face_vert_glsl, NULL},
-                       .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-                       .defs = (const char *[]){sh_cfg_data->def, NULL},
-               });
-
-               sh_data->vert_select_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
-                       .frag = (const char *[]){datatoc_common_globals_lib_glsl, datatoc_paint_vert_frag_glsl, NULL},
-                       .defs = (const char *[]){sh_cfg_data->def, "#define USE_SELECT\n", NULL},
-               });
-       }
-}
-
-static void PAINT_WEIGHT_cache_init(void *vedata)
-{
-       PAINT_WEIGHT_PassList *psl = ((PAINT_WEIGHT_Data *)vedata)->psl;
-       PAINT_WEIGHT_StorageList *stl = ((PAINT_WEIGHT_Data *)vedata)->stl;
-       const DRWContextState *draw_ctx = DRW_context_state_get();
-       const View3D *v3d = draw_ctx->v3d;
-       RegionView3D *rv3d = draw_ctx->rv3d;
-       PAINT_WEIGHT_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
-
-       if (!stl->g_data) {
-               /* Alloc transient pointers */
-               stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
-       }
-
-       {
-               /* Create a pass */
-               DRWPass *pass = DRW_pass_create(
-                       "Weight Pass",
-                       DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_MULTIPLY);
-               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->weight_face, pass);
-               DRW_shgroup_uniform_bool_copy(shgrp, "drawContours", (v3d->overlay.wpaint_flag & V3D_OVERLAY_WPAINT_CONTOURS) != 0);
-               DRW_shgroup_uniform_float(shgrp, "opacity", &v3d->overlay.weight_paint_mode_opacity, 1);
-               DRW_shgroup_uniform_texture(shgrp, "colorramp", G_draw.weight_ramp);
-               DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
-               if (rv3d->rflag & RV3D_CLIPPING) {
-                       DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
-               }
-               psl->weight_faces = pass;
-               stl->g_data->fweights_shgrp = shgrp;
-       }
-
-       {
-               DRWPass *pass = DRW_pass_create(
-                       "Wire Pass",
-                       DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_OFFSET_NEGATIVE);
-               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->wire_overlay, pass);
-               DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
-               if (rv3d->rflag & RV3D_CLIPPING) {
-                       DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
-               }
-               psl->wire_overlay = pass;
-               stl->g_data->lwire_shgrp = shgrp;
-       }
-
-       {
-               DRWPass *pass = DRW_pass_create(
-                       "Wire Mask Pass",
-                       DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_OFFSET_NEGATIVE);
-               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->wire_select_overlay, pass);
-               DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
-               if (rv3d->rflag & RV3D_CLIPPING) {
-                       DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
-               }
-               psl->wire_select_overlay = pass;
-               stl->g_data->lwire_select_shgrp = shgrp;
-       }
-
-       {
-               static float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
-               DRWPass *pass = DRW_pass_create(
-                       "Face Mask Pass",
-                       DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND);
-               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->face_select_overlay, pass);
-               DRW_shgroup_uniform_vec4(shgrp, "color", col, 1);
-               if (rv3d->rflag & RV3D_CLIPPING) {
-                       DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
-               }
-               psl->face_select_overlay = pass;
-               stl->g_data->face_shgrp = shgrp;
-       }
-
-       {
-               DRWPass *pass = DRW_pass_create(
-                       "Vert Mask Pass",
-                       DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_OFFSET_NEGATIVE);
-               DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->vert_select_overlay, pass);
-               DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
-               if (rv3d->rflag & RV3D_CLIPPING) {
-                       DRW_shgroup_world_clip_planes_from_rv3d(shgrp, rv3d);
-               }
-               psl->vert_select_overlay = pass;
-               stl->g_data->vert_select_shgrp = shgrp;
-       }
-}
-
-static void PAINT_WEIGHT_cache_populate(void *vedata, Object *ob)
-{
-       PAINT_WEIGHT_StorageList *stl = ((PAINT_WEIGHT_Data *)vedata)->stl;
-       const DRWContextState *draw_ctx = DRW_context_state_get();
-       const View3D *v3d = draw_ctx->v3d;
-
-       if ((ob->type == OB_MESH) && (ob == draw_ctx->obact)) {
-               const Mesh *me_orig = DEG_get_original_object(ob)->data;
-               const bool use_wire = (v3d->overlay.paint_flag & V3D_OVERLAY_PAINT_WIRE) != 0;
-               const bool use_surface = v3d->overlay.weight_paint_mode_opacity != 0.0f;
-               const bool use_face_sel = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
-               const bool use_vert_sel = (me_orig->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
-               struct GPUBatch *geom;
-
-               if (use_surface) {
-                       geom = DRW_cache_mesh_surface_weights_get(ob);
-                       DRW_shgroup_call_add(stl->g_data->fweights_shgrp, geom, ob->obmat);
-               }
-
-               if (use_face_sel || use_wire) {
-                       DRWShadingGroup *shgrp = use_face_sel ? stl->g_data->lwire_select_shgrp : stl->g_data->lwire_shgrp;
-                       geom = DRW_cache_mesh_surface_edges_get(ob);
-                       DRW_shgroup_call_add(shgrp, geom, ob->obmat);
-               }
-
-               if (use_face_sel) {
-                       geom = DRW_cache_mesh_surface_get(ob);
-                       DRW_shgroup_call_add(stl->g_data->face_shgrp, geom, ob->obmat);
-               }
-
-               if (use_vert_sel) {
-                       geom = DRW_cache_mesh_all_verts_get(ob);
-                       DRW_shgroup_call_add(stl->g_data->vert_select_shgrp, geom, ob->obmat);
-               }
-       }
-}
-
-static void PAINT_WEIGHT_draw_scene(void *vedata)
-{
-       PAINT_WEIGHT_PassList *psl = ((PAINT_WEIGHT_Data *)vedata)->psl;
-
-       DRW_draw_pass(psl->weight_faces);
-       DRW_draw_pass(psl->wire_overlay);
-       DRW_draw_pass(psl->wire_select_overlay);
-       DRW_draw_pass(psl->vert_select_overlay);
-       DRW_draw_pass(psl->face_select_overlay);
-}
-
-static void PAINT_WEIGHT_engine_free(void)
-{
-       for (int sh_data_index = 0; sh_data_index < ARRAY_SIZE(e_data.sh_data); sh_data_index++) {
-               PAINT_WEIGHT_Shaders *sh_data = &e_data.sh_data[sh_data_index];
-               GPUShader **sh_data_as_array = (GPUShader **)sh_data;
-               for (int i = 0; i < (sizeof(PAINT_WEIGHT_Shaders) / sizeof(GPUShader *)); i++) {
-                       DRW_SHADER_FREE_SAFE(sh_data_as_array[i]);
-               }
-       }
-}
-
-static const DrawEngineDataSize PAINT_WEIGHT_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_WEIGHT_Data);
-
-DrawEngineType draw_engine_paint_weight_type = {
-       NULL, NULL,
-       N_("PaintWeightMode"),
-       &PAINT_WEIGHT_data_size,
-       &PAINT_WEIGHT_engine_init,
-       &PAINT_WEIGHT_engine_free,
-       &PAINT_WEIGHT_cache_init,
-       &PAINT_WEIGHT_cache_populate,
-       NULL,
-       NULL,
-       &PAINT_WEIGHT_draw_scene,
-       NULL,
-       NULL,
-};