Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_grid.cc
- This file was moved from source/blender/draw/engines/overlay/overlay_grid.c.
| Show All 11 Lines | |||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "ED_image.h" | #include "ED_image.h" | ||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "overlay_private.h" | #include "overlay_private.hh" | ||||
| BLI_STATIC_ASSERT(SI_GRID_STEPS_LEN == OVERLAY_GRID_STEPS_LEN, "") | BLI_STATIC_ASSERT(SI_GRID_STEPS_LEN == OVERLAY_GRID_STEPS_LEN, "") | ||||
| void OVERLAY_grid_init(OVERLAY_Data *vedata) | void OVERLAY_grid_init(OVERLAY_Data *vedata) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| OVERLAY_GridData *grid = &pd->grid_data; | OVERLAY_GridData *grid = &pd->grid_data; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| float *grid_axes = pd->grid.grid_axes; | float *grid_axes = pd->grid.grid_axes; | ||||
| float *zplane_axes = pd->grid.zplane_axes; | float *zplane_axes = pd->grid.zplane_axes; | ||||
| float grid_steps[SI_GRID_STEPS_LEN] = { | float grid_steps[SI_GRID_STEPS_LEN] = { | ||||
| 0.001f, 0.01f, 0.1f, 1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f}; | 0.001f, 0.01f, 0.1f, 1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f}; | ||||
| OVERLAY_GridBits grid_flag = 0, zneg_flag = 0, zpos_flag = 0; | OVERLAY_GridBits grid_flag = OVERLAY_GridBits(0), zneg_flag = OVERLAY_GridBits(0), | ||||
| zpos_flag = OVERLAY_GridBits(0); | |||||
| grid->line_size = max_ff(0.0f, U.pixelsize - 1.0f) * 0.5f; | grid->line_size = max_ff(0.0f, U.pixelsize - 1.0f) * 0.5f; | ||||
| /* Default, nothing is drawn. */ | /* Default, nothing is drawn. */ | ||||
| pd->grid.grid_flag = pd->grid.zneg_flag = pd->grid.zpos_flag = 0; | pd->grid.grid_flag = pd->grid.zneg_flag = pd->grid.zpos_flag = OVERLAY_GridBits(0); | ||||
| if (pd->space_type == SPACE_IMAGE) { | if (pd->space_type == SPACE_IMAGE) { | ||||
| SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; | SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; | ||||
| View2D *v2d = &draw_ctx->region->v2d; | View2D *v2d = &draw_ctx->region->v2d; | ||||
| /* Only UV Edit mode has the various Overlay options for now. */ | /* Only UV Edit mode has the various Overlay options for now. */ | ||||
| const bool is_uv_edit = sima->mode == SI_MODE_UV; | const bool is_uv_edit = sima->mode == SI_MODE_UV; | ||||
| Show All 37 Lines | else { | ||||
| if (pd->hide_overlays || !(pd->v3d_gridflag & (V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z | | if (pd->hide_overlays || !(pd->v3d_gridflag & (V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z | | ||||
| V3D_SHOW_FLOOR | V3D_SHOW_ORTHO_GRID))) { | V3D_SHOW_FLOOR | V3D_SHOW_ORTHO_GRID))) { | ||||
| return; | return; | ||||
| } | } | ||||
| float viewinv[4][4], wininv[4][4]; | float viewinv[4][4], wininv[4][4]; | ||||
| float viewmat[4][4], winmat[4][4]; | float viewmat[4][4], winmat[4][4]; | ||||
| DRW_view_winmat_get(NULL, winmat, false); | DRW_view_winmat_get(nullptr, winmat, false); | ||||
| DRW_view_winmat_get(NULL, wininv, true); | DRW_view_winmat_get(nullptr, wininv, true); | ||||
| DRW_view_viewmat_get(NULL, viewmat, false); | DRW_view_viewmat_get(nullptr, viewmat, false); | ||||
| DRW_view_viewmat_get(NULL, viewinv, true); | DRW_view_viewmat_get(nullptr, viewinv, true); | ||||
| /* If perspective view or non-axis aligned view. */ | /* If perspective view or non-axis aligned view. */ | ||||
| if (winmat[3][3] == 0.0f || rv3d->view == RV3D_VIEW_USER) { | if (winmat[3][3] == 0.0f || rv3d->view == RV3D_VIEW_USER) { | ||||
| if (show_axis_x) { | if (show_axis_x) { | ||||
| grid_flag |= PLANE_XY | SHOW_AXIS_X; | grid_flag |= PLANE_XY | SHOW_AXIS_X; | ||||
| } | } | ||||
| if (show_axis_y) { | if (show_axis_y) { | ||||
| grid_flag |= PLANE_XY | SHOW_AXIS_Y; | grid_flag |= PLANE_XY | SHOW_AXIS_Y; | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| OVERLAY_StorageList *stl = ved->stl; | OVERLAY_StorageList *stl = ved->stl; | ||||
| OVERLAY_PrivateData *pd = stl->pd; | OVERLAY_PrivateData *pd = stl->pd; | ||||
| OVERLAY_GridData *grid = &pd->grid_data; | OVERLAY_GridData *grid = &pd->grid_data; | ||||
| OVERLAY_PassList *psl = ved->psl; | OVERLAY_PassList *psl = ved->psl; | ||||
| DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | ||||
| psl->grid_ps = NULL; | psl->grid_ps = nullptr; | ||||
| if ((pd->grid.grid_flag == 0 && pd->grid.zpos_flag == 0) || !DRW_state_is_fbo()) { | if ((pd->grid.grid_flag == 0 && pd->grid.zpos_flag == 0) || !DRW_state_is_fbo()) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (ved->instance->grid_ubo == NULL) { | if (ved->instance->grid_ubo == nullptr) { | ||||
| ved->instance->grid_ubo = GPU_uniformbuf_create(sizeof(OVERLAY_GridData)); | ved->instance->grid_ubo = GPU_uniformbuf_create(sizeof(OVERLAY_GridData)); | ||||
| } | } | ||||
| GPU_uniformbuf_update(ved->instance->grid_ubo, &pd->grid_data); | GPU_uniformbuf_update(ved->instance->grid_ubo, &pd->grid_data); | ||||
| DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA; | DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA; | ||||
| DRW_PASS_CREATE(psl->grid_ps, state); | DRW_PASS_CREATE(psl->grid_ps, state); | ||||
| if (pd->space_type == SPACE_IMAGE) { | if (pd->space_type == SPACE_IMAGE) { | ||||
| Show All 23 Lines | if (pd->space_type == SPACE_IMAGE) { | ||||
| grp = DRW_shgroup_create(sh, psl->grid_ps); | grp = DRW_shgroup_create(sh, psl->grid_ps); | ||||
| DRW_shgroup_uniform_block(grp, "grid_buf", ved->instance->grid_ubo); | DRW_shgroup_uniform_block(grp, "grid_buf", ved->instance->grid_ubo); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "depth_tx", &dtxl->depth); | DRW_shgroup_uniform_texture_ref(grp, "depth_tx", &dtxl->depth); | ||||
| DRW_shgroup_uniform_int_copy(grp, "grid_flag", pd->grid.zneg_flag); | DRW_shgroup_uniform_int_copy(grp, "grid_flag", pd->grid.zneg_flag); | ||||
| DRW_shgroup_uniform_vec3_copy(grp, "plane_axes", pd->grid.zplane_axes); | DRW_shgroup_uniform_vec3_copy(grp, "plane_axes", pd->grid.zplane_axes); | ||||
| if (pd->grid.zneg_flag & SHOW_AXIS_Z) { | if (pd->grid.zneg_flag & SHOW_AXIS_Z) { | ||||
| DRW_shgroup_call(grp, geom, NULL); | DRW_shgroup_call(grp, geom, nullptr); | ||||
| } | } | ||||
| grp = DRW_shgroup_create_sub(grp); | grp = DRW_shgroup_create_sub(grp); | ||||
| DRW_shgroup_uniform_int_copy(grp, "grid_flag", pd->grid.grid_flag); | DRW_shgroup_uniform_int_copy(grp, "grid_flag", pd->grid.grid_flag); | ||||
| DRW_shgroup_uniform_vec3_copy(grp, "plane_axes", pd->grid.grid_axes); | DRW_shgroup_uniform_vec3_copy(grp, "plane_axes", pd->grid.grid_axes); | ||||
| if (pd->grid.grid_flag) { | if (pd->grid.grid_flag) { | ||||
| DRW_shgroup_call(grp, geom, NULL); | DRW_shgroup_call(grp, geom, nullptr); | ||||
| } | } | ||||
| grp = DRW_shgroup_create_sub(grp); | grp = DRW_shgroup_create_sub(grp); | ||||
| DRW_shgroup_uniform_int_copy(grp, "grid_flag", pd->grid.zpos_flag); | DRW_shgroup_uniform_int_copy(grp, "grid_flag", pd->grid.zpos_flag); | ||||
| DRW_shgroup_uniform_vec3_copy(grp, "plane_axes", pd->grid.zplane_axes); | DRW_shgroup_uniform_vec3_copy(grp, "plane_axes", pd->grid.zplane_axes); | ||||
| if (pd->grid.zpos_flag & SHOW_AXIS_Z) { | if (pd->grid.zpos_flag & SHOW_AXIS_Z) { | ||||
| DRW_shgroup_call(grp, geom, NULL); | DRW_shgroup_call(grp, geom, nullptr); | ||||
| } | } | ||||
| } | } | ||||
| if (pd->space_type == SPACE_IMAGE) { | if (pd->space_type == SPACE_IMAGE) { | ||||
| float theme_color[4]; | float theme_color[4]; | ||||
| UI_GetThemeColorShade4fv(TH_BACK, 60, theme_color); | UI_GetThemeColorShade4fv(TH_BACK, 60, theme_color); | ||||
| srgb_to_linearrgb_v4(theme_color, theme_color); | srgb_to_linearrgb_v4(theme_color, theme_color); | ||||
| Show All 24 Lines | |||||