1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 *
16 * Copyright 2020, Blender Foundation.
17 */
18
19 /** \file
20 * \ingroup draw_engine
21 */
22
23 #include "BKE_paint.h"
24 #include "DRW_render.h"
25
26 #include "ED_view3d.h"
27
28 #include "overlay_private.h"
29
OVERLAY_fade_init(OVERLAY_Data * UNUSED (vedata))30 void OVERLAY_fade_init(OVERLAY_Data *UNUSED(vedata))
31 {
32 }
33
OVERLAY_fade_cache_init(OVERLAY_Data * vedata)34 void OVERLAY_fade_cache_init(OVERLAY_Data *vedata)
35 {
36 OVERLAY_PassList *psl = vedata->psl;
37 OVERLAY_PrivateData *pd = vedata->stl->pd;
38
39 for (int i = 0; i < 2; i++) {
40 /* Non Meshes Pass (Camera, empties, lights ...) */
41 DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA;
42 DRW_PASS_CREATE(psl->fade_ps[i], state | pd->clipping_state);
43
44 GPUShader *sh = OVERLAY_shader_uniform_color();
45 pd->fade_grp[i] = DRW_shgroup_create(sh, psl->fade_ps[i]);
46 DRW_shgroup_uniform_block(pd->fade_grp[i], "globalsBlock", G_draw.block_ubo);
47
48 const DRWContextState *draw_ctx = DRW_context_state_get();
49 float color[4];
50 ED_view3d_background_color_get(draw_ctx->scene, draw_ctx->v3d, color);
51 color[3] = pd->overlay.fade_alpha;
52 if (draw_ctx->v3d->shading.background_type == V3D_SHADING_BACKGROUND_THEME) {
53 srgb_to_linearrgb_v4(color, color);
54 }
55 DRW_shgroup_uniform_vec4_copy(pd->fade_grp[i], "color", color);
56 }
57
58 if (!pd->use_in_front) {
59 pd->fade_grp[IN_FRONT] = pd->fade_grp[NOT_IN_FRONT];
60 }
61 }
62
OVERLAY_fade_cache_populate(OVERLAY_Data * vedata,Object * ob)63 void OVERLAY_fade_cache_populate(OVERLAY_Data *vedata, Object *ob)
64 {
65 OVERLAY_PrivateData *pd = vedata->stl->pd;
66
67 if (pd->xray_enabled) {
68 return;
69 }
70
71 const DRWContextState *draw_ctx = DRW_context_state_get();
72 const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) &&
73 !DRW_state_is_image_render();
74 const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
75
76 if (use_sculpt_pbvh) {
77 DRW_shgroup_call_sculpt(pd->fade_grp[is_xray], ob, false, false);
78 }
79 else {
80 struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
81 if (geom) {
82 DRW_shgroup_call(pd->fade_grp[is_xray], geom, ob);
83 }
84 }
85 }
86
OVERLAY_fade_draw(OVERLAY_Data * vedata)87 void OVERLAY_fade_draw(OVERLAY_Data *vedata)
88 {
89 OVERLAY_PassList *psl = vedata->psl;
90
91 DRW_draw_pass(psl->fade_ps[NOT_IN_FRONT]);
92 }
93
OVERLAY_fade_infront_draw(OVERLAY_Data * vedata)94 void OVERLAY_fade_infront_draw(OVERLAY_Data *vedata)
95 {
96 OVERLAY_PassList *psl = vedata->psl;
97
98 DRW_draw_pass(psl->fade_ps[IN_FRONT]);
99 }
100