diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-03-02 03:07:03 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-03-02 03:08:32 +0300 |
commit | b463cd2ab8f1a48200e6b348002ac88d3a8507ca (patch) | |
tree | 0dc31f194e4ab344657651484dc2f65054ed2faa /source/blender/draw/modes/edit_mesh_mode.c | |
parent | aa102283daf0fd7a6a59d241c0b353f3e0ecfffc (diff) |
Edit Mode overlay: Moved Shaders to draw modules and resolved some draw issue.
We don't want to clutter gpu_shader.c with engine specific code
Added face's center dot
Simplified loose vert shader
Diffstat (limited to 'source/blender/draw/modes/edit_mesh_mode.c')
-rw-r--r-- | source/blender/draw/modes/edit_mesh_mode.c | 154 |
1 files changed, 128 insertions, 26 deletions
diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index 1f394870c40..4177e7b843f 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -46,43 +46,117 @@ static DRWShadingGroup *depth_shgrp_hidden_wire; static DRWShadingGroup *face_overlay_shgrp; static DRWShadingGroup *ledges_overlay_shgrp; static DRWShadingGroup *lverts_overlay_shgrp; +static DRWShadingGroup *facedot_overlay_shgrp; extern struct GPUUniformBuffer *globals_ubo; /* draw_mode_pass.c */ +static struct GPUShader *overlay_tri_sh = NULL; +static struct GPUShader *overlay_tri_fast_sh = NULL; +static struct GPUShader *overlay_tri_vcol_sh = NULL; +static struct GPUShader *overlay_tri_vcol_fast_sh = NULL; +static struct GPUShader *overlay_edge_sh = NULL; +static struct GPUShader *overlay_edge_vcol_sh = NULL; +static struct GPUShader *overlay_vert_sh = NULL; +static struct GPUShader *overlay_facedot_sh = NULL; + +extern char datatoc_edit_overlay_frag_glsl[]; +extern char datatoc_edit_overlay_vert_glsl[]; +extern char datatoc_edit_overlay_geom_tri_glsl[]; +extern char datatoc_edit_overlay_geom_edge_glsl[]; +extern char datatoc_edit_overlay_loosevert_vert_glsl[]; +extern char datatoc_edit_overlay_facedot_frag_glsl[]; +extern char datatoc_edit_overlay_facedot_vert_glsl[]; + void EDIT_MESH_cache_init(void) { EDIT_MESH_PassList *psl = DRW_mode_pass_list_get(); - static struct GPUShader *depth_sh; - static struct GPUShader *over_tri_sh, *over_vert_sh, *over_edge_sh, *over_tri_fast_sh; + static struct GPUShader *depth_sh, *tri_sh, *ledge_sh; const struct bContext *C = DRW_get_context(); struct RegionView3D *rv3d = CTX_wm_region_view3d(C); + Scene *scene = CTX_data_scene(C); + ToolSettings *ts = scene->toolsettings; if (!depth_sh) depth_sh = DRW_shader_create_3D_depth_only(); - if (!over_tri_fast_sh) - over_tri_fast_sh = GPU_shader_get_builtin_shader(GPU_SHADER_EDGES_OVERLAY_EDIT_TRI_FAST); - if (!over_tri_sh) - over_tri_sh = GPU_shader_get_builtin_shader(GPU_SHADER_EDGES_OVERLAY_EDIT_TRI); - if (!over_edge_sh) - over_edge_sh = GPU_shader_get_builtin_shader(GPU_SHADER_EDGES_OVERLAY_EDIT_EDGE); - if (!over_vert_sh) - over_vert_sh = GPU_shader_get_builtin_shader(GPU_SHADER_EDGES_OVERLAY_EDIT_VERT); + + if (!overlay_tri_sh) { + overlay_tri_sh = DRW_shader_create(datatoc_edit_overlay_vert_glsl, + datatoc_edit_overlay_geom_tri_glsl, + datatoc_edit_overlay_frag_glsl, "#define EDGE_FIX\n"); + } + if (!overlay_tri_fast_sh) { + overlay_tri_fast_sh = DRW_shader_create(datatoc_edit_overlay_vert_glsl, + datatoc_edit_overlay_geom_tri_glsl, + datatoc_edit_overlay_frag_glsl, NULL); + } + if (!overlay_tri_vcol_sh) { + overlay_tri_vcol_sh = DRW_shader_create(datatoc_edit_overlay_vert_glsl, + datatoc_edit_overlay_geom_tri_glsl, + datatoc_edit_overlay_frag_glsl, "#define EDGE_FIX\n" + "#define VERTEX_SELECTION\n"); + } + if (!overlay_tri_vcol_fast_sh) { + overlay_tri_vcol_fast_sh = DRW_shader_create(datatoc_edit_overlay_vert_glsl, + datatoc_edit_overlay_geom_tri_glsl, + datatoc_edit_overlay_frag_glsl, "#define VERTEX_SELECTION\n"); + } + if (!overlay_edge_sh) { + overlay_edge_sh = DRW_shader_create(datatoc_edit_overlay_vert_glsl, + datatoc_edit_overlay_geom_edge_glsl, + datatoc_edit_overlay_frag_glsl, NULL); + } + if (!overlay_edge_vcol_sh) { + overlay_edge_vcol_sh = DRW_shader_create(datatoc_edit_overlay_vert_glsl, + datatoc_edit_overlay_geom_edge_glsl, + datatoc_edit_overlay_frag_glsl, "#define VERTEX_SELECTION\n"); + } + if (!overlay_vert_sh) { + overlay_vert_sh = DRW_shader_create(datatoc_edit_overlay_loosevert_vert_glsl, NULL, + datatoc_edit_overlay_frag_glsl, "#define VERTEX_SELECTION\n"); + } + if (!overlay_facedot_sh) { + overlay_facedot_sh = DRW_shader_create(datatoc_edit_overlay_facedot_vert_glsl, NULL, + datatoc_edit_overlay_facedot_frag_glsl, NULL); + } + + if ((ts->selectmode & SCE_SELECT_VERTEX) != 0) { + ledge_sh = overlay_edge_vcol_sh; + + if ((rv3d->rflag & RV3D_NAVIGATING) != 0) + tri_sh = overlay_tri_vcol_fast_sh; + else + tri_sh = overlay_tri_vcol_sh; + } + else { + ledge_sh = overlay_edge_sh; + + if ((rv3d->rflag & RV3D_NAVIGATING) != 0) + tri_sh = overlay_tri_fast_sh; + else + tri_sh = overlay_tri_sh; + } psl->depth_pass_hidden_wire = DRW_pass_create("Depth Pass Hidden Wire", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK); depth_shgrp_hidden_wire = DRW_shgroup_create(depth_sh, psl->depth_pass_hidden_wire); - psl->edit_face_overlay_pass = DRW_pass_create("Edit Mesh Face Overlay Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND); - if ((rv3d->rflag & RV3D_NAVIGATING) != 0) - face_overlay_shgrp = DRW_shgroup_create(over_tri_fast_sh, psl->edit_face_overlay_pass); - else - face_overlay_shgrp = DRW_shgroup_create(over_tri_sh, psl->edit_face_overlay_pass); - ledges_overlay_shgrp = DRW_shgroup_create(over_edge_sh, psl->edit_face_overlay_pass); - lverts_overlay_shgrp = DRW_shgroup_create(over_vert_sh, psl->edit_face_overlay_pass); - DRW_shgroup_uniform_vec2(face_overlay_shgrp, "viewportSize", DRW_viewport_size_get(), 1); + psl->edit_face_overlay_pass = DRW_pass_create("Edit Mesh Face Overlay Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_POINT); + + face_overlay_shgrp = DRW_shgroup_create(tri_sh, psl->edit_face_overlay_pass); DRW_shgroup_uniform_block(face_overlay_shgrp, "globalsBlock", globals_ubo, 0); + DRW_shgroup_uniform_vec2(face_overlay_shgrp, "viewportSize", DRW_viewport_size_get(), 1); + + ledges_overlay_shgrp = DRW_shgroup_create(ledge_sh, psl->edit_face_overlay_pass); DRW_shgroup_uniform_vec2(ledges_overlay_shgrp, "viewportSize", DRW_viewport_size_get(), 1); - DRW_shgroup_uniform_vec2(lverts_overlay_shgrp, "viewportSize", DRW_viewport_size_get(), 1); + + if ((ts->selectmode & (SCE_SELECT_VERTEX)) != 0) { + lverts_overlay_shgrp = DRW_shgroup_create(overlay_vert_sh, psl->edit_face_overlay_pass); + DRW_shgroup_uniform_vec2(lverts_overlay_shgrp, "viewportSize", DRW_viewport_size_get(), 1); + } + + if ((ts->selectmode & (SCE_SELECT_FACE)) != 0) { + facedot_overlay_shgrp = DRW_shgroup_create(overlay_facedot_sh, psl->edit_face_overlay_pass); + } DRW_mode_passes_setup(NULL, NULL, @@ -96,26 +170,34 @@ void EDIT_MESH_cache_init(void) void EDIT_MESH_cache_populate(Object *ob) { struct Batch *geom; - struct Batch *geo_ovl_tris, *geo_ovl_ledges, *geo_ovl_lverts; + struct Batch *geo_ovl_tris, *geo_ovl_ledges, *geo_ovl_lverts, *geo_ovl_fcenter; const struct bContext *C = DRW_get_context(); Scene *scene = CTX_data_scene(C); Object *obedit = scene->obedit; + ToolSettings *ts = scene->toolsettings; CollectionEngineSettings *ces_mode_ed = BKE_object_collection_engine_get(ob, COLLECTION_MODE_EDIT, ""); bool do_occlude_wire = BKE_collection_engine_property_value_get_bool(ces_mode_ed, "show_occlude_wire"); switch (ob->type) { case OB_MESH: - geom = DRW_cache_surface_get(ob); if (ob == obedit) { DRW_cache_wire_overlay_get(ob, &geo_ovl_tris, &geo_ovl_ledges, &geo_ovl_lverts); DRW_shgroup_call_add(face_overlay_shgrp, geo_ovl_tris, ob->obmat); DRW_shgroup_call_add(ledges_overlay_shgrp, geo_ovl_ledges, ob->obmat); - DRW_shgroup_call_add(lverts_overlay_shgrp, geo_ovl_lverts, ob->obmat); - } - if (do_occlude_wire) { - DRW_shgroup_call_add(depth_shgrp_hidden_wire, geom, ob->obmat); - DRW_shgroup_wire_outline(ob, true, false, true); + + if ((ts->selectmode & SCE_SELECT_VERTEX) != 0) + DRW_shgroup_call_add(lverts_overlay_shgrp, geo_ovl_lverts, ob->obmat); + + if ((ts->selectmode & SCE_SELECT_FACE) != 0) { + geo_ovl_fcenter = DRW_cache_face_centers_get(ob); + DRW_shgroup_call_add(facedot_overlay_shgrp, geo_ovl_fcenter, ob->obmat); + } + + if (do_occlude_wire) { + geom = DRW_cache_surface_get(ob); + DRW_shgroup_call_add(depth_shgrp_hidden_wire, geom, ob->obmat); + } } break; case OB_LAMP: @@ -160,3 +242,23 @@ void EDIT_MESH_collection_settings_create(CollectionEngineSettings *ces) BLI_assert(ces); BKE_collection_engine_property_add_int(ces, "show_occlude_wire", false); } + +void EDIT_MESH_engine_free(void) +{ + if (overlay_tri_sh) + DRW_shader_free(overlay_tri_sh); + if (overlay_tri_fast_sh) + DRW_shader_free(overlay_tri_fast_sh); + if (overlay_tri_vcol_sh) + DRW_shader_free(overlay_tri_vcol_sh); + if (overlay_tri_vcol_fast_sh) + DRW_shader_free(overlay_tri_vcol_fast_sh); + if (overlay_edge_sh) + DRW_shader_free(overlay_edge_sh); + if (overlay_edge_vcol_sh) + DRW_shader_free(overlay_edge_vcol_sh); + if (overlay_vert_sh) + DRW_shader_free(overlay_vert_sh); + if (overlay_facedot_sh) + DRW_shader_free(overlay_facedot_sh); +}
\ No newline at end of file |