Blender V4.3
overlay_next_background.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
12
13namespace blender::draw::overlay {
14
16 private:
17 PassSimple bg_ps_ = {"Background"};
18
19 GPUFrameBuffer *framebuffer_ref_ = nullptr;
20
21 public:
22 void begin_sync(Resources &res, const State &state)
23 {
25 float4 color_override(0.0f, 0.0f, 0.0f, 0.0f);
26 int background_type;
27
29 background_type = BG_SOLID;
30 color_override[3] = 1.0f;
31 }
32 else if (state.space_type == SPACE_IMAGE) {
33 background_type = BG_SOLID_CHECKER;
34 }
35 else if (state.space_type == SPACE_NODE) {
36 background_type = BG_MASK;
38 }
39 else if (!DRW_state_draw_background()) {
40 background_type = BG_CHECKER;
41 }
42 else if (state.v3d->shading.background_type == V3D_SHADING_BACKGROUND_WORLD &&
43 state.scene->world)
44 {
45 background_type = BG_SOLID;
46 /* TODO(fclem): this is a scene referred linear color. we should convert
47 * it to display linear here. */
48 color_override = float4(UNPACK3(&state.scene->world->horr), 1.0f);
49 }
50 else if (state.v3d->shading.background_type == V3D_SHADING_BACKGROUND_VIEWPORT &&
51 state.v3d->shading.type <= OB_SOLID)
52 {
53 background_type = BG_SOLID;
54 color_override = float4(UNPACK3(state.v3d->shading.background_color), 1.0f);
55 }
56 else {
59 background_type = BG_GRADIENT;
60 break;
62 background_type = BG_RADIAL;
63 break;
64 default:
66 background_type = BG_SOLID;
67 break;
68 }
69 }
70
71 bg_ps_.init();
72 bg_ps_.framebuffer_set(&framebuffer_ref_);
73 /* Don't clear background for the node editor. The node editor draws the background and we
74 * need to mask out the image from the already drawn overlay color buffer. */
75 if (state.space_type != SPACE_NODE) {
76 bg_ps_.clear_color(float4(0.0f));
77 }
78
79 if ((state.clipping_plane_count != 0) && (state.rv3d) && (state.rv3d->clipbb)) {
83 bg_ps_.push_constant("boundbox", &state.rv3d->clipbb->vec[0][0], 8);
84 bg_ps_.draw(DRW_cache_cube_get());
85 }
86
87 bg_ps_.state_set(pass_state);
88 bg_ps_.shader_set(res.shaders.background_fill.get());
89 bg_ps_.bind_ubo("globalsBlock", &res.globals_buf);
90 bg_ps_.bind_texture("colorBuffer", &res.color_render_tx);
91 bg_ps_.bind_texture("depthBuffer", &res.depth_tx);
92 bg_ps_.push_constant("colorOverride", color_override);
93 bg_ps_.push_constant("bgType", background_type);
94 bg_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
95 }
96
97 void draw(Framebuffer &framebuffer, Manager &manager, View & /*view*/)
98 {
99 framebuffer_ref_ = framebuffer;
100 manager.submit(bg_ps_);
101 }
102};
103
104} // namespace blender::draw::overlay
#define UNPACK3(a)
@ 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
@ GPU_PRIM_TRIS
@ TH_BACKGROUND_TYPE
int UI_GetThemeValue(int colorid)
void submit(PassSimple &pass, View &view)
void bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state=sampler_auto)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
Definition draw_pass.hh:760
void clear_color(float4 color)
Definition draw_pass.hh:911
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
Definition draw_pass.hh:833
void state_set(DRWState state, int clip_plane_count=0)
Definition draw_pass.hh:954
void bind_ubo(const char *name, GPUUniformBuf *buffer)
void framebuffer_set(GPUFrameBuffer **framebuffer)
Definition draw_pass.hh:977
void push_constant(const char *name, const float &data)
void shader_set(GPUShader *shader)
Definition draw_pass.hh:971
void begin_sync(Resources &res, const State &state)
void draw(Framebuffer &framebuffer, Manager &manager, View &)
blender::gpu::Batch * DRW_cache_cube_get()
bool DRW_state_draw_background()
bool DRW_state_is_viewport_image_render()
DRWState
Definition draw_state.hh:25
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:55
@ DRW_STATE_BLEND_BACKGROUND
Definition draw_state.hh:58
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_CULL_BACK
Definition draw_state.hh:43
@ DRW_STATE_BLEND_MUL
Definition draw_state.hh:60
static ulong state[N]
VecBase< float, 4 > float4
#define BG_MASK
#define BG_SOLID_CHECKER
#define BG_GRADIENT
#define BG_RADIAL
#define BG_CHECKER
#define BG_SOLID