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 
17 /** \file
18  * \ingroup draw_engine
19  */
20 
21 #include "DNA_volume_types.h"
22 
23 #include "DRW_render.h"
24 #include "GPU_shader.h"
25 
26 #include "overlay_private.h"
27 
OVERLAY_volume_cache_init(OVERLAY_Data * vedata)28 void OVERLAY_volume_cache_init(OVERLAY_Data *vedata)
29 {
30   OVERLAY_PassList *psl = vedata->psl;
31   OVERLAY_PrivateData *pd = vedata->stl->pd;
32   const bool is_select = DRW_state_is_select();
33 
34   if (is_select) {
35     DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
36     DRW_PASS_CREATE(psl->volume_ps, state | pd->clipping_state);
37     GPUShader *sh = OVERLAY_shader_depth_only();
38     DRWShadingGroup *grp = DRW_shgroup_create(sh, psl->volume_ps);
39     pd->volume_selection_surface_grp = grp;
40     DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
41   }
42   else {
43     psl->volume_ps = NULL;
44     pd->volume_selection_surface_grp = NULL;
45   }
46 }
47 
OVERLAY_volume_cache_populate(OVERLAY_Data * vedata,Object * ob)48 void OVERLAY_volume_cache_populate(OVERLAY_Data *vedata, Object *ob)
49 {
50   OVERLAY_PrivateData *pd = vedata->stl->pd;
51   const bool is_select = DRW_state_is_select();
52 
53   if (is_select) {
54     struct GPUBatch *geom = DRW_cache_volume_selection_surface_get(ob);
55     if (geom != NULL) {
56       DRW_shgroup_call(pd->volume_selection_surface_grp, geom, ob);
57     }
58   }
59 }
60 
OVERLAY_volume_draw(OVERLAY_Data * vedata)61 void OVERLAY_volume_draw(OVERLAY_Data *vedata)
62 {
63   OVERLAY_PassList *psl = vedata->psl;
64 
65   if (psl->volume_ps) {
66     DRW_draw_pass(psl->volume_ps);
67   }
68 }
69