Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_wireframe.cc
- This file was moved from source/blender/draw/engines/overlay/overlay_wireframe.c.
| Show All 21 Lines | |||||
| #include "BLI_hash.h" | #include "BLI_hash.h" | ||||
| #include "DRW_render.h" | #include "DRW_render.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "overlay_private.h" | #include "overlay_private.hh" | ||||
| void OVERLAY_wireframe_init(OVERLAY_Data *vedata) | void OVERLAY_wireframe_init(OVERLAY_Data *vedata) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| DRWView *default_view = (DRWView *)DRW_view_default_get(); | DRWView *default_view = (DRWView *)DRW_view_default_get(); | ||||
| pd->view_wires = DRW_view_create_with_zoffset(default_view, draw_ctx->rv3d, 0.5f); | pd->view_wires = DRW_view_create_with_zoffset(default_view, draw_ctx->rv3d, 0.5f); | ||||
| } | } | ||||
| void OVERLAY_wireframe_cache_init(OVERLAY_Data *vedata) | void OVERLAY_wireframe_cache_init(OVERLAY_Data *vedata) | ||||
| { | { | ||||
| OVERLAY_PassList *psl = vedata->psl; | OVERLAY_PassList *psl = vedata->psl; | ||||
| OVERLAY_TextureList *txl = vedata->txl; | OVERLAY_TextureList *txl = vedata->txl; | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| DRWShadingGroup *grp = NULL; | DRWShadingGroup *grp = nullptr; | ||||
| View3DShading *shading = &draw_ctx->v3d->shading; | View3DShading *shading = &draw_ctx->v3d->shading; | ||||
| pd->shdata.wire_step_param = pd->overlay.wireframe_threshold - 254.0f / 255.0f; | pd->shdata.wire_step_param = pd->overlay.wireframe_threshold - 254.0f / 255.0f; | ||||
| pd->shdata.wire_opacity = pd->overlay.wireframe_opacity; | pd->shdata.wire_opacity = pd->overlay.wireframe_opacity; | ||||
| bool is_wire_shmode = (shading->type == OB_WIRE); | bool is_wire_shmode = (shading->type == OB_WIRE); | ||||
| bool is_material_shmode = (shading->type > OB_SOLID); | bool is_material_shmode = (shading->type > OB_SOLID); | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | void OVERLAY_wireframe_cache_init(OVERLAY_Data *vedata) | ||||
| if (is_material_shmode) { | if (is_material_shmode) { | ||||
| /* Make all drawcalls go into the non-xray shading groups. */ | /* Make all drawcalls go into the non-xray shading groups. */ | ||||
| for (int use_coloring = 0; use_coloring < 2; use_coloring++) { | for (int use_coloring = 0; use_coloring < 2; use_coloring++) { | ||||
| pd->wires_grp[1][use_coloring] = pd->wires_grp[0][use_coloring]; | pd->wires_grp[1][use_coloring] = pd->wires_grp[0][use_coloring]; | ||||
| pd->wires_all_grp[1][use_coloring] = pd->wires_all_grp[0][use_coloring]; | pd->wires_all_grp[1][use_coloring] = pd->wires_all_grp[0][use_coloring]; | ||||
| pd->wires_hair_grp[1][use_coloring] = pd->wires_hair_grp[0][use_coloring]; | pd->wires_hair_grp[1][use_coloring] = pd->wires_hair_grp[0][use_coloring]; | ||||
| } | } | ||||
| pd->wires_sculpt_grp[1] = pd->wires_sculpt_grp[0]; | pd->wires_sculpt_grp[1] = pd->wires_sculpt_grp[0]; | ||||
| psl->wireframe_xray_ps = NULL; | psl->wireframe_xray_ps = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| static void wireframe_hair_cache_populate(OVERLAY_Data *vedata, Object *ob, ParticleSystem *psys) | static void wireframe_hair_cache_populate(OVERLAY_Data *vedata, Object *ob, ParticleSystem *psys) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0; | const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0; | ||||
| Object *dupli_parent = DRW_object_get_dupli_parent(ob); | Object *dupli_parent = DRW_object_get_dupli_parent(ob); | ||||
| DupliObject *dupli_object = DRW_object_get_dupli(ob); | DupliObject *dupli_object = DRW_object_get_dupli(ob); | ||||
| float dupli_mat[4][4]; | float dupli_mat[4][4]; | ||||
| if ((dupli_parent != NULL) && (dupli_object != NULL)) { | if ((dupli_parent != nullptr) && (dupli_object != nullptr)) { | ||||
| if (dupli_object->type & OB_DUPLICOLLECTION) { | if (dupli_object->type & OB_DUPLICOLLECTION) { | ||||
| unit_m4(dupli_mat); | unit_m4(dupli_mat); | ||||
| Collection *collection = dupli_parent->instance_collection; | Collection *collection = dupli_parent->instance_collection; | ||||
| if (collection != NULL) { | if (collection != nullptr) { | ||||
| sub_v3_v3(dupli_mat[3], collection->instance_offset); | sub_v3_v3(dupli_mat[3], collection->instance_offset); | ||||
| } | } | ||||
| mul_m4_m4m4(dupli_mat, dupli_parent->obmat, dupli_mat); | mul_m4_m4m4(dupli_mat, dupli_parent->obmat, dupli_mat); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_m4_m4(dupli_mat, dupli_object->ob->obmat); | copy_m4_m4(dupli_mat, dupli_object->ob->obmat); | ||||
| invert_m4(dupli_mat); | invert_m4(dupli_mat); | ||||
| mul_m4_m4m4(dupli_mat, ob->obmat, dupli_mat); | mul_m4_m4m4(dupli_mat, ob->obmat, dupli_mat); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| unit_m4(dupli_mat); | unit_m4(dupli_mat); | ||||
| } | } | ||||
| struct GPUBatch *hairs = DRW_cache_particles_get_hair(ob, psys, NULL); | struct GPUBatch *hairs = DRW_cache_particles_get_hair(ob, psys, nullptr); | ||||
| const bool use_coloring = true; | const bool use_coloring = true; | ||||
| DRWShadingGroup *shgrp = DRW_shgroup_create_sub(pd->wires_hair_grp[is_xray][use_coloring]); | DRWShadingGroup *shgrp = DRW_shgroup_create_sub(pd->wires_hair_grp[is_xray][use_coloring]); | ||||
| DRW_shgroup_uniform_mat4_copy(shgrp, "hairDupliMatrix", dupli_mat); | DRW_shgroup_uniform_mat4_copy(shgrp, "hairDupliMatrix", dupli_mat); | ||||
| DRW_shgroup_call_no_cull(shgrp, hairs, ob); | DRW_shgroup_call_no_cull(shgrp, hairs, ob); | ||||
| } | } | ||||
| void OVERLAY_wireframe_cache_populate(OVERLAY_Data *vedata, | void OVERLAY_wireframe_cache_populate(OVERLAY_Data *vedata, | ||||
| Object *ob, | Object *ob, | ||||
| OVERLAY_DupliData *dupli, | OVERLAY_DupliData *dupli, | ||||
| bool init_dupli) | bool init_dupli) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| const bool all_wires = (ob->dtx & OB_DRAW_ALL_EDGES) != 0; | const bool all_wires = (ob->dtx & OB_DRAW_ALL_EDGES) != 0; | ||||
| const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0; | const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0; | ||||
| const bool is_mesh = ob->type == OB_MESH; | const bool is_mesh = ob->type == OB_MESH; | ||||
| const bool is_edit_mode = DRW_object_is_in_edit_mode(ob); | const bool is_edit_mode = DRW_object_is_in_edit_mode(ob); | ||||
| bool has_edit_mesh_cage = false; | bool has_edit_mesh_cage = false; | ||||
| bool is_mesh_verts_only = false; | bool is_mesh_verts_only = false; | ||||
| if (is_mesh) { | if (is_mesh) { | ||||
| /* TODO: Should be its own function. */ | /* TODO: Should be its own function. */ | ||||
| Mesh *me = ob->data; | Mesh *me = static_cast<Mesh *>(ob->data); | ||||
| if (is_edit_mode) { | if (is_edit_mode) { | ||||
| BLI_assert(me->edit_mesh); | BLI_assert(me->edit_mesh); | ||||
| Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob); | Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob); | ||||
| Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob); | Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob); | ||||
| has_edit_mesh_cage = editmesh_eval_cage && (editmesh_eval_cage != editmesh_eval_final); | has_edit_mesh_cage = editmesh_eval_cage && (editmesh_eval_cage != editmesh_eval_final); | ||||
| if (editmesh_eval_final) { | if (editmesh_eval_final) { | ||||
| me = editmesh_eval_final; | me = editmesh_eval_final; | ||||
| } | } | ||||
| } | } | ||||
| is_mesh_verts_only = me->totedge == 0 && me->totvert > 0; | is_mesh_verts_only = me->totedge == 0 && me->totvert > 0; | ||||
| } | } | ||||
| const bool use_wire = !is_mesh_verts_only && ((pd->overlay.flag & V3D_OVERLAY_WIREFRAMES) || | const bool use_wire = !is_mesh_verts_only && ((pd->overlay.flag & V3D_OVERLAY_WIREFRAMES) || | ||||
| (ob->dtx & OB_DRAWWIRE) || (ob->dt == OB_WIRE)); | (ob->dtx & OB_DRAWWIRE) || (ob->dt == OB_WIRE)); | ||||
| if (use_wire && pd->wireframe_mode && ob->particlesystem.first) { | if (use_wire && pd->wireframe_mode && ob->particlesystem.first) { | ||||
| for (ParticleSystem *psys = ob->particlesystem.first; psys != NULL; psys = psys->next) { | for (ParticleSystem *psys = static_cast<ParticleSystem *>(ob->particlesystem.first); | ||||
| psys != nullptr; | |||||
| psys = psys->next) { | |||||
| if (!DRW_object_is_visible_psys_in_active_context(ob, psys)) { | if (!DRW_object_is_visible_psys_in_active_context(ob, psys)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| ParticleSettings *part = psys->part; | ParticleSettings *part = psys->part; | ||||
| const int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as; | const int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as; | ||||
| if (draw_as == PART_DRAW_PATH) { | if (draw_as == PART_DRAW_PATH) { | ||||
| wireframe_hair_cache_populate(vedata, ob, psys); | wireframe_hair_cache_populate(vedata, ob, psys); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) { | if (ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) { | ||||
| OVERLAY_ExtraCallBuffers *cb = OVERLAY_extra_call_buffer_get(vedata, ob); | OVERLAY_ExtraCallBuffers *cb = OVERLAY_extra_call_buffer_get(vedata, ob); | ||||
| float *color; | float *color; | ||||
| DRW_object_wire_theme_get(ob, draw_ctx->view_layer, &color); | DRW_object_wire_theme_get(ob, draw_ctx->view_layer, &color); | ||||
| struct GPUBatch *geom = NULL; | struct GPUBatch *geom = nullptr; | ||||
| switch (ob->type) { | switch (ob->type) { | ||||
| case OB_CURVES_LEGACY: | case OB_CURVES_LEGACY: | ||||
| geom = DRW_cache_curve_edge_wire_get(ob); | geom = DRW_cache_curve_edge_wire_get(ob); | ||||
| break; | break; | ||||
| case OB_FONT: | case OB_FONT: | ||||
| geom = DRW_cache_text_edge_wire_get(ob); | geom = DRW_cache_text_edge_wire_get(ob); | ||||
| break; | break; | ||||
| case OB_SURF: | case OB_SURF: | ||||
| Show All 33 Lines | else { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| if (use_wire && ELEM(ob->type, OB_VOLUME, OB_POINTCLOUD)) { | if (use_wire && ELEM(ob->type, OB_VOLUME, OB_POINTCLOUD)) { | ||||
| bool draw_as_points = true; | bool draw_as_points = true; | ||||
| if (ob->type == OB_VOLUME) { | if (ob->type == OB_VOLUME) { | ||||
| /* Volume object as points exception. */ | /* Volume object as points exception. */ | ||||
| Volume *volume = ob->data; | Volume *volume = static_cast<Volume *>(ob->data); | ||||
| draw_as_points = volume->display.wireframe_type == VOLUME_WIREFRAME_POINTS; | draw_as_points = volume->display.wireframe_type == VOLUME_WIREFRAME_POINTS; | ||||
| } | } | ||||
| if (draw_as_points) { | if (draw_as_points) { | ||||
| float *color; | float *color; | ||||
| OVERLAY_ExtraCallBuffers *cb = OVERLAY_extra_call_buffer_get(vedata, ob); | OVERLAY_ExtraCallBuffers *cb = OVERLAY_extra_call_buffer_get(vedata, ob); | ||||
| DRW_object_wire_theme_get(ob, draw_ctx->view_layer, &color); | DRW_object_wire_theme_get(ob, draw_ctx->view_layer, &color); | ||||
| struct GPUBatch *geom = DRW_cache_object_face_wireframe_get(ob); | struct GPUBatch *geom = DRW_cache_object_face_wireframe_get(ob); | ||||
| if (geom) { | if (geom) { | ||||
| OVERLAY_extra_loose_points(cb, geom, ob->obmat, color); | OVERLAY_extra_loose_points(cb, geom, ob->obmat, color); | ||||
| } | } | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| DRWShadingGroup *shgrp = NULL; | DRWShadingGroup *shgrp = nullptr; | ||||
| struct GPUBatch *geom = NULL; | struct GPUBatch *geom = nullptr; | ||||
| /* Don't do that in edit Mesh mode, unless there is a modifier preview. */ | /* Don't do that in edit Mesh mode, unless there is a modifier preview. */ | ||||
| if (use_wire && (!is_mesh || (!is_edit_mode || has_edit_mesh_cage))) { | if (use_wire && (!is_mesh || (!is_edit_mode || has_edit_mesh_cage))) { | ||||
| const bool is_sculpt_mode = ((ob->mode & OB_MODE_SCULPT) != 0) && (ob->sculpt != NULL); | const bool is_sculpt_mode = ((ob->mode & OB_MODE_SCULPT) != 0) && (ob->sculpt != nullptr); | ||||
| const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) && | const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) && | ||||
| !DRW_state_is_image_render(); | !DRW_state_is_image_render(); | ||||
| const bool is_instance = (ob->base_flag & BASE_FROM_DUPLI); | const bool is_instance = (ob->base_flag & BASE_FROM_DUPLI); | ||||
| const bool instance_parent_in_edit_mode = is_instance ? DRW_object_is_in_edit_mode( | const bool instance_parent_in_edit_mode = is_instance ? DRW_object_is_in_edit_mode( | ||||
| DRW_object_get_dupli_parent(ob)) : | DRW_object_get_dupli_parent(ob)) : | ||||
| false; | false; | ||||
| const bool use_coloring = (use_wire && !is_edit_mode && !is_sculpt_mode && | const bool use_coloring = (use_wire && !is_edit_mode && !is_sculpt_mode && | ||||
| !has_edit_mesh_cage && !instance_parent_in_edit_mode); | !has_edit_mesh_cage && !instance_parent_in_edit_mode); | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
| void OVERLAY_wireframe_draw(OVERLAY_Data *data) | void OVERLAY_wireframe_draw(OVERLAY_Data *data) | ||||
| { | { | ||||
| OVERLAY_PassList *psl = data->psl; | OVERLAY_PassList *psl = data->psl; | ||||
| OVERLAY_PrivateData *pd = data->stl->pd; | OVERLAY_PrivateData *pd = data->stl->pd; | ||||
| DRW_view_set_active(pd->view_wires); | DRW_view_set_active(pd->view_wires); | ||||
| DRW_draw_pass(psl->wireframe_ps); | DRW_draw_pass(psl->wireframe_ps); | ||||
| DRW_view_set_active(NULL); | DRW_view_set_active(nullptr); | ||||
| } | } | ||||
| void OVERLAY_wireframe_in_front_draw(OVERLAY_Data *data) | void OVERLAY_wireframe_in_front_draw(OVERLAY_Data *data) | ||||
| { | { | ||||
| OVERLAY_PassList *psl = data->psl; | OVERLAY_PassList *psl = data->psl; | ||||
| OVERLAY_PrivateData *pd = data->stl->pd; | OVERLAY_PrivateData *pd = data->stl->pd; | ||||
| if (psl->wireframe_xray_ps) { | if (psl->wireframe_xray_ps) { | ||||
| DRW_view_set_active(pd->view_wires); | DRW_view_set_active(pd->view_wires); | ||||
| DRW_draw_pass(psl->wireframe_xray_ps); | DRW_draw_pass(psl->wireframe_xray_ps); | ||||
| DRW_view_set_active(NULL); | DRW_view_set_active(nullptr); | ||||
| } | } | ||||
| } | } | ||||