Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_edit_mesh.cc
- This file was moved from source/blender/draw/engines/overlay/overlay_edit_mesh.c.
| Show All 12 Lines | |||||
| #include "BKE_customdata.h" | #include "BKE_customdata.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "draw_cache_impl.h" | #include "draw_cache_impl.h" | ||||
| #include "draw_manager_text.h" | #include "draw_manager_text.h" | ||||
| #include "overlay_private.h" | #include "overlay_private.hh" | ||||
| #define OVERLAY_EDIT_TEXT \ | #define OVERLAY_EDIT_TEXT \ | ||||
| (V3D_OVERLAY_EDIT_EDGE_LEN | V3D_OVERLAY_EDIT_FACE_AREA | V3D_OVERLAY_EDIT_FACE_ANG | \ | (V3D_OVERLAY_EDIT_EDGE_LEN | V3D_OVERLAY_EDIT_FACE_AREA | V3D_OVERLAY_EDIT_FACE_ANG | \ | ||||
| V3D_OVERLAY_EDIT_EDGE_ANG | V3D_OVERLAY_EDIT_INDICES) | V3D_OVERLAY_EDIT_EDGE_ANG | V3D_OVERLAY_EDIT_INDICES) | ||||
| void OVERLAY_edit_mesh_init(OVERLAY_Data *vedata) | void OVERLAY_edit_mesh_init(OVERLAY_Data *vedata) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| Show All 10 Lines | |||||
| } | } | ||||
| void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata) | void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata) | ||||
| { | { | ||||
| OVERLAY_TextureList *txl = vedata->txl; | OVERLAY_TextureList *txl = vedata->txl; | ||||
| OVERLAY_PassList *psl = vedata->psl; | OVERLAY_PassList *psl = vedata->psl; | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| OVERLAY_ShadingData *shdata = &pd->shdata; | OVERLAY_ShadingData *shdata = &pd->shdata; | ||||
| DRWShadingGroup *grp = NULL; | DRWShadingGroup *grp = nullptr; | ||||
| GPUShader *sh = NULL; | GPUShader *sh = nullptr; | ||||
| DRWState state = 0; | DRWState state = DRWState(0); | ||||
| DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| ToolSettings *tsettings = draw_ctx->scene->toolsettings; | ToolSettings *tsettings = draw_ctx->scene->toolsettings; | ||||
| View3D *v3d = draw_ctx->v3d; | View3D *v3d = draw_ctx->v3d; | ||||
| bool select_vert = pd->edit_mesh.select_vert = (tsettings->selectmode & SCE_SELECT_VERTEX) != 0; | bool select_vert = pd->edit_mesh.select_vert = (tsettings->selectmode & SCE_SELECT_VERTEX) != 0; | ||||
| bool select_face = pd->edit_mesh.select_face = (tsettings->selectmode & SCE_SELECT_FACE) != 0; | bool select_face = pd->edit_mesh.select_face = (tsettings->selectmode & SCE_SELECT_FACE) != 0; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | for (int i = 0; i < 2; i++) { | ||||
| DRW_PASS_CREATE(psl->edit_mesh_depth_ps[i], state | pd->clipping_state); | DRW_PASS_CREATE(psl->edit_mesh_depth_ps[i], state | pd->clipping_state); | ||||
| sh = OVERLAY_shader_depth_only(); | sh = OVERLAY_shader_depth_only(); | ||||
| pd->edit_mesh_depth_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_depth_ps[i]); | pd->edit_mesh_depth_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_depth_ps[i]); | ||||
| } | } | ||||
| { | { | ||||
| /* Normals */ | /* Normals */ | ||||
| state = DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | | state = DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | | ||||
| (pd->edit_mesh.do_zbufclip ? DRW_STATE_BLEND_ALPHA : 0); | (pd->edit_mesh.do_zbufclip ? DRW_STATE_BLEND_ALPHA : DRWState(0)); | ||||
| DRW_PASS_CREATE(psl->edit_mesh_normals_ps, state | pd->clipping_state); | DRW_PASS_CREATE(psl->edit_mesh_normals_ps, state | pd->clipping_state); | ||||
| sh = OVERLAY_shader_edit_mesh_normal(); | sh = OVERLAY_shader_edit_mesh_normal(); | ||||
| pd->edit_mesh_normals_grp = grp = DRW_shgroup_create(sh, psl->edit_mesh_normals_ps); | pd->edit_mesh_normals_grp = grp = DRW_shgroup_create(sh, psl->edit_mesh_normals_ps); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_float_copy(grp, "normalSize", v3d->overlay.normals_length); | DRW_shgroup_uniform_float_copy(grp, "normalSize", v3d->overlay.normals_length); | ||||
| DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity); | DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex); | DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex); | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if (select_face && show_face_dots) { | ||||
| grp = pd->edit_mesh_facedots_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_verts_ps[i]); | grp = pd->edit_mesh_facedots_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_verts_ps[i]); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity); | DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex); | DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex); | ||||
| DRW_shgroup_uniform_ivec4_copy(grp, "dataMask", vert_mask); | DRW_shgroup_uniform_ivec4_copy(grp, "dataMask", vert_mask); | ||||
| DRW_shgroup_state_enable(grp, DRW_STATE_WRITE_DEPTH); | DRW_shgroup_state_enable(grp, DRW_STATE_WRITE_DEPTH); | ||||
| } | } | ||||
| else { | else { | ||||
| pd->edit_mesh_facedots_grp[i] = NULL; | pd->edit_mesh_facedots_grp[i] = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void overlay_edit_mesh_add_ob_to_pass(OVERLAY_PrivateData *pd, Object *ob, bool in_front) | static void overlay_edit_mesh_add_ob_to_pass(OVERLAY_PrivateData *pd, Object *ob, bool in_front) | ||||
| { | { | ||||
| struct GPUBatch *geom_tris, *geom_verts, *geom_edges, *geom_fcenter, *skin_roots, *circle; | struct GPUBatch *geom_tris, *geom_verts, *geom_edges, *geom_fcenter, *skin_roots, *circle; | ||||
| DRWShadingGroup *vert_shgrp, *edge_shgrp, *fdot_shgrp, *face_shgrp, *skin_roots_shgrp; | DRWShadingGroup *vert_shgrp, *edge_shgrp, *fdot_shgrp, *face_shgrp, *skin_roots_shgrp; | ||||
| Show All 13 Lines | static void overlay_edit_mesh_add_ob_to_pass(OVERLAY_PrivateData *pd, Object *ob, bool in_front) | ||||
| vert_shgrp = pd->edit_mesh_verts_grp[in_front]; | vert_shgrp = pd->edit_mesh_verts_grp[in_front]; | ||||
| edge_shgrp = pd->edit_mesh_edges_grp[in_front]; | edge_shgrp = pd->edit_mesh_edges_grp[in_front]; | ||||
| fdot_shgrp = pd->edit_mesh_facedots_grp[in_front]; | fdot_shgrp = pd->edit_mesh_facedots_grp[in_front]; | ||||
| face_shgrp = (has_edit_mesh_cage) ? pd->edit_mesh_faces_cage_grp[in_front] : | face_shgrp = (has_edit_mesh_cage) ? pd->edit_mesh_faces_cage_grp[in_front] : | ||||
| pd->edit_mesh_faces_grp[in_front]; | pd->edit_mesh_faces_grp[in_front]; | ||||
| skin_roots_shgrp = pd->edit_mesh_skin_roots_grp[in_front]; | skin_roots_shgrp = pd->edit_mesh_skin_roots_grp[in_front]; | ||||
| geom_edges = DRW_mesh_batch_cache_get_edit_edges(ob->data); | geom_edges = DRW_mesh_batch_cache_get_edit_edges(me); | ||||
| geom_tris = DRW_mesh_batch_cache_get_edit_triangles(ob->data); | geom_tris = DRW_mesh_batch_cache_get_edit_triangles(me); | ||||
| DRW_shgroup_call_no_cull(edge_shgrp, geom_edges, ob); | DRW_shgroup_call_no_cull(edge_shgrp, geom_edges, ob); | ||||
| DRW_shgroup_call_no_cull(face_shgrp, geom_tris, ob); | DRW_shgroup_call_no_cull(face_shgrp, geom_tris, ob); | ||||
| if (pd->edit_mesh.select_vert) { | if (pd->edit_mesh.select_vert) { | ||||
| geom_verts = DRW_mesh_batch_cache_get_edit_vertices(ob->data); | geom_verts = DRW_mesh_batch_cache_get_edit_vertices(me); | ||||
| DRW_shgroup_call_no_cull(vert_shgrp, geom_verts, ob); | DRW_shgroup_call_no_cull(vert_shgrp, geom_verts, ob); | ||||
| if (has_skin_roots) { | if (has_skin_roots) { | ||||
| circle = DRW_cache_circle_get(); | circle = DRW_cache_circle_get(); | ||||
| skin_roots = DRW_mesh_batch_cache_get_edit_skin_roots(ob->data); | skin_roots = DRW_mesh_batch_cache_get_edit_skin_roots(me); | ||||
| DRW_shgroup_call_instances_with_attrs(skin_roots_shgrp, ob, circle, skin_roots); | DRW_shgroup_call_instances_with_attrs(skin_roots_shgrp, ob, circle, skin_roots); | ||||
| } | } | ||||
| } | } | ||||
| if (fdot_shgrp) { | if (fdot_shgrp) { | ||||
| geom_fcenter = DRW_mesh_batch_cache_get_edit_facedots(ob->data); | geom_fcenter = DRW_mesh_batch_cache_get_edit_facedots(me); | ||||
| DRW_shgroup_call_no_cull(fdot_shgrp, geom_fcenter, ob); | DRW_shgroup_call_no_cull(fdot_shgrp, geom_fcenter, ob); | ||||
| } | } | ||||
| } | } | ||||
| void OVERLAY_edit_mesh_cache_populate(OVERLAY_Data *vedata, Object *ob) | void OVERLAY_edit_mesh_cache_populate(OVERLAY_Data *vedata, Object *ob) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| struct GPUBatch *geom = NULL; | struct GPUBatch *geom = nullptr; | ||||
| bool draw_as_solid = (ob->dt > OB_WIRE); | bool draw_as_solid = (ob->dt > OB_WIRE); | ||||
| bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0; | bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0; | ||||
| bool do_occlude_wire = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) != 0; | bool do_occlude_wire = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) != 0; | ||||
| bool do_show_mesh_analysis = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_STATVIS) != 0; | bool do_show_mesh_analysis = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_STATVIS) != 0; | ||||
| bool fnormals_do = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_FACE_NORMALS) != 0; | bool fnormals_do = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_FACE_NORMALS) != 0; | ||||
| bool vnormals_do = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_VERT_NORMALS) != 0; | bool vnormals_do = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_VERT_NORMALS) != 0; | ||||
| bool lnormals_do = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_LOOP_NORMALS) != 0; | bool lnormals_do = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_LOOP_NORMALS) != 0; | ||||
| if (do_show_mesh_analysis && !pd->xray_enabled) { | if (do_show_mesh_analysis && !pd->xray_enabled) { | ||||
| geom = DRW_cache_mesh_surface_mesh_analysis_get(ob); | geom = DRW_cache_mesh_surface_mesh_analysis_get(ob); | ||||
| if (geom) { | if (geom) { | ||||
| DRW_shgroup_call_no_cull(pd->edit_mesh_analysis_grp, geom, ob); | DRW_shgroup_call_no_cull(pd->edit_mesh_analysis_grp, geom, ob); | ||||
| } | } | ||||
| } | } | ||||
| if (do_occlude_wire || (do_in_front && draw_as_solid)) { | if (do_occlude_wire || (do_in_front && draw_as_solid)) { | ||||
| geom = DRW_cache_mesh_surface_get(ob); | geom = DRW_cache_mesh_surface_get(ob); | ||||
| DRW_shgroup_call_no_cull(pd->edit_mesh_depth_grp[do_in_front], geom, ob); | DRW_shgroup_call_no_cull(pd->edit_mesh_depth_grp[do_in_front], geom, ob); | ||||
| } | } | ||||
| if (vnormals_do || lnormals_do || fnormals_do) { | if (vnormals_do || lnormals_do || fnormals_do) { | ||||
| struct GPUBatch *normal_geom = DRW_cache_normal_arrow_get(); | struct GPUBatch *normal_geom = DRW_cache_normal_arrow_get(); | ||||
| Mesh *me = static_cast<Mesh *>(ob->data); | |||||
| if (vnormals_do) { | if (vnormals_do) { | ||||
| geom = DRW_mesh_batch_cache_get_edit_vnors(ob->data); | geom = DRW_mesh_batch_cache_get_edit_vnors(me); | ||||
| DRW_shgroup_call_instances_with_attrs(pd->edit_mesh_normals_grp, ob, normal_geom, geom); | DRW_shgroup_call_instances_with_attrs(pd->edit_mesh_normals_grp, ob, normal_geom, geom); | ||||
| } | } | ||||
| if (lnormals_do) { | if (lnormals_do) { | ||||
| geom = DRW_mesh_batch_cache_get_edit_lnors(ob->data); | geom = DRW_mesh_batch_cache_get_edit_lnors(me); | ||||
| DRW_shgroup_call_instances_with_attrs(pd->edit_mesh_normals_grp, ob, normal_geom, geom); | DRW_shgroup_call_instances_with_attrs(pd->edit_mesh_normals_grp, ob, normal_geom, geom); | ||||
| } | } | ||||
| if (fnormals_do) { | if (fnormals_do) { | ||||
| geom = DRW_mesh_batch_cache_get_edit_facedots(ob->data); | geom = DRW_mesh_batch_cache_get_edit_facedots(me); | ||||
| DRW_shgroup_call_instances_with_attrs(pd->edit_mesh_normals_grp, ob, normal_geom, geom); | DRW_shgroup_call_instances_with_attrs(pd->edit_mesh_normals_grp, ob, normal_geom, geom); | ||||
| } | } | ||||
| } | } | ||||
| if (pd->edit_mesh.do_zbufclip) { | if (pd->edit_mesh.do_zbufclip) { | ||||
| overlay_edit_mesh_add_ob_to_pass(pd, ob, false); | overlay_edit_mesh_add_ob_to_pass(pd, ob, false); | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (pd->edit_mesh.do_zbufclip) { | ||||
| /* Render face-fill. */ | /* Render face-fill. */ | ||||
| DRW_view_set_active(pd->view_edit_faces); | DRW_view_set_active(pd->view_edit_faces); | ||||
| DRW_draw_pass(psl->edit_mesh_faces_ps[NOT_IN_FRONT]); | DRW_draw_pass(psl->edit_mesh_faces_ps[NOT_IN_FRONT]); | ||||
| DRW_view_set_active(pd->view_edit_faces_cage); | DRW_view_set_active(pd->view_edit_faces_cage); | ||||
| DRW_draw_pass(psl->edit_mesh_faces_cage_ps[NOT_IN_FRONT]); | DRW_draw_pass(psl->edit_mesh_faces_cage_ps[NOT_IN_FRONT]); | ||||
| DRW_view_set_active(NULL); | DRW_view_set_active(nullptr); | ||||
| GPU_framebuffer_bind(fbl->overlay_in_front_fb); | GPU_framebuffer_bind(fbl->overlay_in_front_fb); | ||||
| GPU_framebuffer_clear_depth(fbl->overlay_in_front_fb, 1.0f); | GPU_framebuffer_clear_depth(fbl->overlay_in_front_fb, 1.0f); | ||||
| DRW_draw_pass(psl->edit_mesh_normals_ps); | DRW_draw_pass(psl->edit_mesh_normals_ps); | ||||
| DRW_view_set_active(pd->view_edit_edges); | DRW_view_set_active(pd->view_edit_edges); | ||||
| DRW_draw_pass(psl->edit_mesh_edges_ps[NOT_IN_FRONT]); | DRW_draw_pass(psl->edit_mesh_edges_ps[NOT_IN_FRONT]); | ||||
| DRW_view_set_active(pd->view_edit_verts); | DRW_view_set_active(pd->view_edit_verts); | ||||
| DRW_draw_pass(psl->edit_mesh_verts_ps[NOT_IN_FRONT]); | DRW_draw_pass(psl->edit_mesh_verts_ps[NOT_IN_FRONT]); | ||||
| } | } | ||||
| else { | else { | ||||
| DRW_draw_pass(psl->edit_mesh_normals_ps); | DRW_draw_pass(psl->edit_mesh_normals_ps); | ||||
| overlay_edit_mesh_draw_components(psl, pd, false); | overlay_edit_mesh_draw_components(psl, pd, false); | ||||
| if (DRW_state_is_fbo()) { | if (DRW_state_is_fbo()) { | ||||
| GPU_framebuffer_bind(fbl->overlay_in_front_fb); | GPU_framebuffer_bind(fbl->overlay_in_front_fb); | ||||
| } | } | ||||
| if (!DRW_pass_is_empty(psl->edit_mesh_depth_ps[IN_FRONT])) { | if (!DRW_pass_is_empty(psl->edit_mesh_depth_ps[IN_FRONT])) { | ||||
| DRW_view_set_active(NULL); | DRW_view_set_active(nullptr); | ||||
| DRW_draw_pass(psl->edit_mesh_depth_ps[IN_FRONT]); | DRW_draw_pass(psl->edit_mesh_depth_ps[IN_FRONT]); | ||||
| } | } | ||||
| overlay_edit_mesh_draw_components(psl, pd, true); | overlay_edit_mesh_draw_components(psl, pd, true); | ||||
| } | } | ||||
| } | } | ||||