Blender  V2.93
overlay_background.c
Go to the documentation of this file.
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 
23 #include "DRW_render.h"
24 
25 #include "UI_resources.h"
26 
27 #include "draw_manager_text.h"
28 #include "overlay_private.h"
29 
30 #define BG_SOLID 0
31 #define BG_GRADIENT 1
32 #define BG_CHECKER 2
33 #define BG_RADIAL 3
34 #define BG_SOLID_CHECKER 4
35 #define BG_MASK 5
36 
38 {
39  OVERLAY_PassList *psl = vedata->psl;
40  OVERLAY_PrivateData *pd = vedata->stl->pd;
42  const DRWContextState *draw_ctx = DRW_context_state_get();
43  const Scene *scene = draw_ctx->scene;
44  const RegionView3D *rv3d = draw_ctx->rv3d;
45  const BoundBox *bb = rv3d ? rv3d->clipbb : NULL;
46  const View3D *v3d = draw_ctx->v3d;
47  bool draw_clipping_bounds = (pd->clipping_state != 0);
48 
49  {
51  float color_override[4] = {0.0f, 0.0f, 0.0f, 0.0f};
52  int background_type;
53 
55  background_type = BG_SOLID;
56  color_override[3] = 1.0f;
57  }
58  else if (pd->space_type == SPACE_IMAGE) {
59  background_type = BG_SOLID_CHECKER;
60  }
61  else if (pd->space_type == SPACE_NODE) {
62  background_type = BG_MASK;
64  }
65  else if (!DRW_state_draw_background()) {
66  background_type = BG_CHECKER;
67  }
69  background_type = BG_SOLID;
70  /* TODO(fclem): this is a scene referred linear color. we should convert
71  * it to display linear here. */
72  copy_v3_v3(color_override, &scene->world->horr);
73  color_override[3] = 1.0f;
74  }
76  v3d->shading.type <= OB_SOLID) {
77  background_type = BG_SOLID;
78  copy_v3_v3(color_override, v3d->shading.background_color);
79  color_override[3] = 1.0f;
80  }
81  else {
84  background_type = BG_GRADIENT;
85  break;
87  background_type = BG_RADIAL;
88  break;
89  default:
91  background_type = BG_SOLID;
92  break;
93  }
94  }
95 
97 
100  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
101  DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &dtxl->color);
102  DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
103  DRW_shgroup_uniform_vec4_copy(grp, "colorOverride", color_override);
104  DRW_shgroup_uniform_int_copy(grp, "bgType", background_type);
106  }
107 
108  if (draw_clipping_bounds) {
111 
115  DRW_shgroup_uniform_vec3(grp, "boundbox", &bb->vec[0][0], 8);
116 
117  struct GPUBatch *cube = DRW_cache_cube_get();
118  DRW_shgroup_call(grp, cube, NULL);
119  }
120  else {
121  psl->clipping_frustum_ps = NULL;
122  }
123 }
124 
126 {
127  OVERLAY_PassList *psl = vedata->psl;
128 
129  if (DRW_state_is_fbo()) {
130  if (psl->clipping_frustum_ps) {
132  }
133 
135  }
136 }
MINLINE void copy_v3_v3(float r[3], const float a[3])
@ OB_SOLID
@ SPACE_NODE
@ SPACE_IMAGE
@ TH_BACKGROUND_GRADIENT_RADIAL
@ TH_BACKGROUND_SINGLE_COLOR
@ TH_BACKGROUND_GRADIENT_LINEAR
@ V3D_SHADING_BACKGROUND_VIEWPORT
@ V3D_SHADING_BACKGROUND_WORLD
DRWState
Definition: DRW_render.h:312
@ DRW_STATE_BLEND_ALPHA
Definition: DRW_render.h:340
@ DRW_STATE_BLEND_BACKGROUND
Definition: DRW_render.h:343
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:315
@ DRW_STATE_CULL_BACK
Definition: DRW_render.h:328
@ DRW_STATE_BLEND_MUL
Definition: DRW_render.h:345
#define DRW_PASS_CREATE(pass, state)
Definition: DRW_render.h:593
#define DRW_shgroup_call(shgroup, geom, ob)
Definition: DRW_render.h:420
GPUBatch
Definition: GPU_batch.h:93
struct GPUShader GPUShader
Definition: GPU_shader.h:33
@ TH_BACKGROUND_TYPE
Definition: UI_resources.h:327
int UI_GetThemeValue(int colorid)
Definition: resources.c:1171
Scene scene
GPUBatch * DRW_cache_cube_get(void)
Definition: draw_cache.c:700
struct DRW_Global G_draw
Definition: draw_common.c:45
bool DRW_state_is_opengl_render(void)
bool DRW_state_is_fbo(void)
const DRWContextState * DRW_context_state_get(void)
bool DRW_state_draw_background(void)
DefaultTextureList * DRW_viewport_texture_list_get(void)
Definition: draw_manager.c:702
void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const GPUUniformBuf *ubo)
void DRW_shgroup_uniform_vec3(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *shgroup, Object *ob, uint tri_count)
void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
void DRW_draw_pass(DRWPass *pass)
static ulong state[N]
#define BG_MASK
#define BG_SOLID_CHECKER
#define BG_GRADIENT
void OVERLAY_background_cache_init(OVERLAY_Data *vedata)
#define BG_RADIAL
#define BG_CHECKER
#define BG_SOLID
void OVERLAY_background_draw(OVERLAY_Data *vedata)
GPUShader * OVERLAY_shader_background(void)
GPUShader * OVERLAY_shader_clipbound(void)
float vec[8][3]
struct Scene * scene
Definition: DRW_render.h:745
struct View3D * v3d
Definition: DRW_render.h:742
struct RegionView3D * rv3d
Definition: DRW_render.h:741
GlobalsUboStorage block
Definition: draw_common.h:208
struct GPUUniformBuf * block_ubo
Definition: draw_common.h:210
struct GPUTexture * depth
struct GPUTexture * color
float colorClippingBorder[4]
Definition: draw_common.h:86
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
DRWPass * clipping_frustum_ps
DRWPass * background_ps
struct OVERLAY_PrivateData * pd
struct BoundBox * clipbb
struct World * world
float background_color[3]
View3DShading shading
float horr