Blender V4.5
overlay_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
8
9#pragma once
10
11#include "DNA_world_types.h"
12
13#include "draw_cache.hh"
14
15#include "overlay_base.hh"
16
17namespace blender::draw::overlay {
18
23 private:
24 PassSimple bg_ps_ = {"Background"};
25
26 GPUFrameBuffer *framebuffer_ref_ = nullptr;
27
28 public:
29 void begin_sync(Resources &res, const State &state) final
30 {
32 float4 color_override(0.0f, 0.0f, 0.0f, 0.0f);
33 int background_type;
34
35 if (state.is_viewport_image_render && !state.draw_background) {
36 background_type = BG_SOLID;
37 color_override[3] = 1.0f;
38 }
39 else if (state.is_space_image()) {
40 background_type = BG_SOLID_CHECKER;
41 }
42 else if (state.is_space_node()) {
43 background_type = BG_MASK;
45 }
46 else if (!state.draw_background) {
47 background_type = BG_CHECKER;
48 }
49 else if (state.v3d->shading.background_type == V3D_SHADING_BACKGROUND_WORLD &&
50 state.scene->world)
51 {
52 background_type = BG_SOLID;
53 /* TODO(fclem): this is a scene referred linear color. we should convert
54 * it to display linear here. */
55 color_override = float4(UNPACK3(&state.scene->world->horr), 1.0f);
56 }
57 else if (state.v3d->shading.background_type == V3D_SHADING_BACKGROUND_VIEWPORT &&
58 state.v3d->shading.type <= OB_SOLID)
59 {
60 background_type = BG_SOLID;
61 color_override = float4(UNPACK3(state.v3d->shading.background_color), 1.0f);
62 }
63 else {
66 background_type = BG_GRADIENT;
67 break;
69 background_type = BG_RADIAL;
70 break;
71 default:
73 background_type = BG_SOLID;
74 break;
75 }
76 }
77
78 bg_ps_.init();
79 bg_ps_.framebuffer_set(&framebuffer_ref_);
80
81 if ((state.clipping_plane_count != 0) && (state.rv3d) && (state.rv3d->clipbb)) {
82 Span<float3> bbox(reinterpret_cast<float3 *>(state.rv3d->clipbb->vec[0]), 8);
83
85 bg_ps_.shader_set(res.shaders->background_clip_bound.get());
86 bg_ps_.push_constant("ucolor", res.theme.colors.clipping_border);
87 bg_ps_.push_constant("boundbox", bbox.data(), 8);
88 bg_ps_.draw(res.shapes.cube_solid.get());
89 }
90
91 bg_ps_.state_set(pass_state);
92 bg_ps_.shader_set(res.shaders->background_fill.get());
93 bg_ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
94 bg_ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
95 bg_ps_.bind_texture("color_buffer", &res.color_render_tx);
96 bg_ps_.bind_texture("depth_buffer", &res.depth_tx);
97 bg_ps_.push_constant("color_override", color_override);
98 bg_ps_.push_constant("bg_type", background_type);
99 bg_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
100 }
101
102 void draw_output(Framebuffer &framebuffer, Manager &manager, View &view) final
103 {
104 framebuffer_ref_ = framebuffer;
105 manager.submit(bg_ps_, view);
106 }
107};
108
109} // namespace blender::draw::overlay
#define UNPACK3(a)
@ OB_SOLID
@ TH_BACKGROUND_GRADIENT_RADIAL
@ TH_BACKGROUND_SINGLE_COLOR
@ TH_BACKGROUND_GRADIENT_LINEAR
@ V3D_SHADING_BACKGROUND_VIEWPORT
@ V3D_SHADING_BACKGROUND_WORLD
static AppView * view
@ GPU_PRIM_TRIS
@ TH_BACKGROUND_TYPE
int UI_GetThemeValue(int colorid)
constexpr const T * data() const
Definition BLI_span.hh:215
void draw_output(Framebuffer &framebuffer, Manager &manager, View &view) final
void begin_sync(Resources &res, const State &state) final
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
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]
detail::Pass< command::DrawCommandBuf > PassSimple
VecBase< float, 4 > float4
VecBase< float, 3 > float3
@ BG_SOLID_CHECKER