Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/drawobject.c
| Show All 35 Lines | |||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "GPU_draw.h" | #include "GPU_draw.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "GPU_state.h" | #include "GPU_state.h" | ||||
| #include "GPU_framebuffer.h" | |||||
| #include "ED_mesh.h" | #include "ED_mesh.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "DRW_engine.h" | #include "DRW_engine.h" | ||||
| #include "view3d_intern.h" /* bad level include */ | #include "view3d_intern.h" /* bad level include */ | ||||
| #include "../../draw/intern/draw_cache_impl.h" /* bad level include (temporary) */ | |||||
| int view3d_effective_drawtype(const struct View3D *v3d) | int view3d_effective_drawtype(const struct View3D *v3d) | ||||
| { | { | ||||
| if (v3d->shading.type == OB_RENDER) { | if (v3d->shading.type == OB_RENDER) { | ||||
| return v3d->shading.prev_type; | return v3d->shading.prev_type; | ||||
| } | } | ||||
| return v3d->shading.type; | return v3d->shading.type; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
| #ifdef VIEW3D_CAMERA_BORDER_HACK | #ifdef VIEW3D_CAMERA_BORDER_HACK | ||||
| uchar view3d_camera_border_hack_col[3]; | uchar view3d_camera_border_hack_col[3]; | ||||
| bool view3d_camera_border_hack_test = false; | bool view3d_camera_border_hack_test = false; | ||||
| #endif | #endif | ||||
| /* ***************** BACKBUF SEL (BBS) ********* */ | /* ***************** BACKBUF SEL (BBS) ********* */ | ||||
| /** See #DRW_shgroup_world_clip_planes_from_rv3d, same function for draw manager. */ | |||||
| static void bbs_world_clip_planes_from_rv3d(GPUBatch *batch, const float world_clip_planes[6][4]) | |||||
| { | |||||
| GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, world_clip_planes[0]); | |||||
| } | |||||
| static void bbs_mesh_verts(GPUBatch *batch, int offset, const float world_clip_planes[6][4]) | |||||
| { | |||||
| GPU_point_size(UI_GetThemeValuef(TH_VERTEX_SIZE)); | |||||
| const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : | |||||
| GPU_SHADER_CFG_DEFAULT; | |||||
| GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_FLAT_SELECT_ID, sh_cfg); | |||||
| GPU_batch_uniform_1ui(batch, "offset", offset); | |||||
| if (world_clip_planes != NULL) { | |||||
| bbs_world_clip_planes_from_rv3d(batch, world_clip_planes); | |||||
| } | |||||
| GPU_batch_draw(batch); | |||||
| } | |||||
| static void bbs_mesh_wire(GPUBatch *batch, int offset, const float world_clip_planes[6][4]) | |||||
| { | |||||
| GPU_line_width(1.0f); | |||||
| glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); | |||||
| const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : | |||||
| GPU_SHADER_CFG_DEFAULT; | |||||
| GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_FLAT_SELECT_ID, sh_cfg); | |||||
| GPU_batch_uniform_1ui(batch, "offset", offset); | |||||
| if (world_clip_planes != NULL) { | |||||
| bbs_world_clip_planes_from_rv3d(batch, world_clip_planes); | |||||
| } | |||||
| GPU_batch_draw(batch); | |||||
| glProvokingVertex(GL_LAST_VERTEX_CONVENTION); | |||||
| } | |||||
| /* two options, facecolors or black */ | |||||
| static void bbs_mesh_face(GPUBatch *batch, | |||||
| const bool use_select, | |||||
| const float world_clip_planes[6][4]) | |||||
| { | |||||
| if (use_select) { | |||||
| const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : | |||||
| GPU_SHADER_CFG_DEFAULT; | |||||
| GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_FLAT_SELECT_ID, sh_cfg); | |||||
| GPU_batch_uniform_1ui(batch, "offset", 1); | |||||
| if (world_clip_planes != NULL) { | |||||
| bbs_world_clip_planes_from_rv3d(batch, world_clip_planes); | |||||
| } | |||||
| GPU_batch_draw(batch); | |||||
| } | |||||
| else { | |||||
| const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : | |||||
| GPU_SHADER_CFG_DEFAULT; | |||||
| GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_UNIFORM_SELECT_ID, sh_cfg); | |||||
| GPU_batch_uniform_1ui(batch, "id", 0); | |||||
| if (world_clip_planes != NULL) { | |||||
| bbs_world_clip_planes_from_rv3d(batch, world_clip_planes); | |||||
| } | |||||
| GPU_batch_draw(batch); | |||||
| } | |||||
| } | |||||
| static void bbs_mesh_face_dot(GPUBatch *batch, const float world_clip_planes[6][4]) | |||||
| { | |||||
| const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : | |||||
| GPU_SHADER_CFG_DEFAULT; | |||||
| GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_FLAT_SELECT_ID, sh_cfg); | |||||
| GPU_batch_uniform_1ui(batch, "offset", 1); | |||||
| if (world_clip_planes != NULL) { | |||||
| bbs_world_clip_planes_from_rv3d(batch, world_clip_planes); | |||||
| } | |||||
| GPU_batch_draw(batch); | |||||
| } | |||||
| static void bbs_mesh_solid_verts(Depsgraph *UNUSED(depsgraph), | |||||
| Scene *UNUSED(scene), | |||||
| Object *ob, | |||||
| const float world_clip_planes[6][4]) | |||||
| { | |||||
| Mesh *me = ob->data; | |||||
| DRW_mesh_batch_cache_validate(me); | |||||
| GPUBatch *geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me); | |||||
| GPUBatch *geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me); | |||||
| DRW_mesh_batch_cache_create_requested(ob, me, NULL, false, true); | |||||
| /* Only draw faces to mask out verts, we don't want their selection ID's. */ | |||||
| bbs_mesh_face(geom_faces, false, world_clip_planes); | |||||
| bbs_mesh_verts(geom_verts, 1, world_clip_planes); | |||||
| bm_vertoffs = me->totvert + 1; | |||||
| } | |||||
| static void bbs_mesh_solid_faces(Scene *UNUSED(scene), | |||||
| Object *ob, | |||||
| const float world_clip_planes[6][4]) | |||||
| { | |||||
| Mesh *me = ob->data; | |||||
| Mesh *me_orig = DEG_get_original_object(ob)->data; | |||||
| DRW_mesh_batch_cache_validate(me); | |||||
| const bool use_hide = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL); | |||||
| GPUBatch *geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me); | |||||
| DRW_mesh_batch_cache_create_requested(ob, me, NULL, false, use_hide); | |||||
| bbs_mesh_face(geom_faces, true, world_clip_planes); | |||||
| } | |||||
| void draw_object_select_id(Depsgraph *depsgraph, | |||||
| Scene *scene, | |||||
| View3D *v3d, | |||||
| RegionView3D *rv3d, | |||||
| Object *ob, | |||||
| short select_mode) | |||||
| { | |||||
| ToolSettings *ts = scene->toolsettings; | |||||
| if (select_mode == -1) { | |||||
| select_mode = ts->selectmode; | |||||
| } | |||||
| GPU_matrix_mul(ob->obmat); | |||||
| GPU_depth_test(true); | |||||
| const float(*world_clip_planes)[4] = NULL; | |||||
| if (rv3d->rflag & RV3D_CLIPPING) { | |||||
| ED_view3d_clipping_local(rv3d, ob->obmat); | |||||
| world_clip_planes = rv3d->clip_local; | |||||
| } | |||||
| switch (ob->type) { | |||||
| case OB_MESH: | |||||
| if (ob->mode & OB_MODE_EDIT) { | |||||
| Mesh *me = ob->data; | |||||
| BMEditMesh *em = me->edit_mesh; | |||||
| const bool draw_facedot = check_ob_drawface_dot(scene, v3d, ob->dt); | |||||
| const bool use_faceselect = (select_mode & SCE_SELECT_FACE) != 0; | |||||
| DRW_mesh_batch_cache_validate(me); | |||||
| BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE); | |||||
| GPUBatch *geom_faces, *geom_edges, *geom_verts, *geom_facedots; | |||||
| geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me); | |||||
| if (select_mode & SCE_SELECT_EDGE) { | |||||
| geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me); | |||||
| } | |||||
| if (select_mode & SCE_SELECT_VERTEX) { | |||||
| geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me); | |||||
| } | |||||
| if (draw_facedot) { | |||||
| geom_facedots = DRW_mesh_batch_cache_get_facedots_with_select_id(me); | |||||
| } | |||||
| DRW_mesh_batch_cache_create_requested(ob, me, NULL, false, true); | |||||
| bbs_mesh_face(geom_faces, use_faceselect, world_clip_planes); | |||||
| if (use_faceselect && draw_facedot) { | |||||
| bbs_mesh_face_dot(geom_facedots, world_clip_planes); | |||||
| } | |||||
| if (select_mode & SCE_SELECT_FACE) { | |||||
| bm_solidoffs = 1 + em->bm->totface; | |||||
| } | |||||
| else { | |||||
| bm_solidoffs = 1; | |||||
| } | |||||
| ED_view3d_polygon_offset(rv3d, 1.0); | |||||
| /* we draw edges if edge select mode */ | |||||
| if (select_mode & SCE_SELECT_EDGE) { | |||||
| bbs_mesh_wire(geom_edges, bm_solidoffs, world_clip_planes); | |||||
| bm_wireoffs = bm_solidoffs + em->bm->totedge; | |||||
| } | |||||
| else { | |||||
| /* `bm_vertoffs` is calculated from `bm_wireoffs`. (otherwise see T53512) */ | |||||
| bm_wireoffs = bm_solidoffs; | |||||
| } | |||||
| ED_view3d_polygon_offset(rv3d, 1.1); | |||||
| /* we draw verts if vert select mode. */ | |||||
| if (select_mode & SCE_SELECT_VERTEX) { | |||||
| bbs_mesh_verts(geom_verts, bm_wireoffs, world_clip_planes); | |||||
| bm_vertoffs = bm_wireoffs + em->bm->totvert; | |||||
| } | |||||
| else { | |||||
| bm_vertoffs = bm_wireoffs; | |||||
| } | |||||
| ED_view3d_polygon_offset(rv3d, 0.0); | |||||
| } | |||||
| else { | |||||
| Mesh *me = DEG_get_original_object(ob)->data; | |||||
| if ((me->editflag & ME_EDIT_PAINT_VERT_SEL) && | |||||
| /* currently vertex select supports weight paint and vertex paint*/ | |||||
| ((ob->mode & OB_MODE_WEIGHT_PAINT) || (ob->mode & OB_MODE_VERTEX_PAINT))) { | |||||
| bbs_mesh_solid_verts(depsgraph, scene, ob, world_clip_planes); | |||||
| } | |||||
| else { | |||||
| bbs_mesh_solid_faces(scene, ob, world_clip_planes); | |||||
| } | |||||
| } | |||||
| break; | |||||
| case OB_CURVE: | |||||
| case OB_SURF: | |||||
| break; | |||||
| } | |||||
| GPU_matrix_set(rv3d->viewmat); | |||||
| } | |||||
| void ED_draw_object_facemap(Depsgraph *depsgraph, | void ED_draw_object_facemap(Depsgraph *depsgraph, | ||||
| Object *ob, | Object *ob, | ||||
| const float col[4], | const float col[4], | ||||
| const int facemap) | const int facemap) | ||||
| { | { | ||||
| /* happens on undo */ | /* happens on undo */ | ||||
| if (ob->type != OB_MESH || !ob->data) { | if (ob->type != OB_MESH || !ob->data) { | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines | |||||