Welcome to mirror list, hosted at ThFree Co, Russian Federation.

overlay_background.hh « overlay « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ec212c108cfcbf1ed74951e5bccafb1ff8cd931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup overlay
 */

#pragma once

#include "DEG_depsgraph_query.h"
#include "DNA_camera_types.h"
#include "DNA_space_types.h"
#include "ED_view3d.h"
#include "UI_resources.h"

#include "draw_cache.h"
#include "draw_pass.hh"
#include "overlay_private.hh"
#include "overlay_shader_shared.h"

namespace blender::draw::overlay {

class Background {
 private:
  PassSimple bg_ps_ = {"Background"};

 public:
  void begin_sync(Resources &res, const State &state)
  {
    DRWState pass_state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_BACKGROUND;
    float4 color_override(0.0f, 0.0f, 0.0f, 0.0f);
    int background_type;

    if (DRW_state_is_opengl_render() && !DRW_state_draw_background()) {
      background_type = BG_SOLID;
      color_override[3] = 1.0f;
    }
    /*
    else if (pd->space_type == SPACE_IMAGE) {
      background_type = BG_SOLID_CHECKER;
    }
    else if (pd->space_type == SPACE_NODE) {
      background_type = BG_MASK;
      pass_state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_MUL;
    }
    */
    else if (!DRW_state_draw_background()) {
      background_type = BG_CHECKER;
    }
    else if (state.v3d->shading.background_type == V3D_SHADING_BACKGROUND_WORLD &&
             state.scene->world) {
      background_type = BG_SOLID;
      /* TODO(fclem): this is a scene referred linear color. we should convert
       * it to display linear here. */
      color_override = float4(UNPACK3(&state.scene->world->horr), 1.0f);
    }
    else if (state.v3d->shading.background_type == V3D_SHADING_BACKGROUND_VIEWPORT &&
             state.v3d->shading.type <= OB_SOLID) {
      background_type = BG_SOLID;
      color_override = float4(UNPACK3(state.v3d->shading.background_color), 1.0f);
    }
    else {
      switch (UI_GetThemeValue(TH_BACKGROUND_TYPE)) {
        case TH_BACKGROUND_GRADIENT_LINEAR:
          background_type = BG_GRADIENT;
          break;
        case TH_BACKGROUND_GRADIENT_RADIAL:
          background_type = BG_RADIAL;
          break;
        default:
        case TH_BACKGROUND_SINGLE_COLOR:
          background_type = BG_SOLID;
          break;
      }
    }

    bg_ps_.init();
    bg_ps_.state_set(pass_state);
    bg_ps_.shader_set(OVERLAY_shader_background());
    bg_ps_.bind_ubo("globalsBlock", &res.globals_buf);
    bg_ps_.bind_texture("colorBuffer", &res.color_render_tx);
    bg_ps_.bind_texture("depthBuffer", &res.depth_tx);
    bg_ps_.push_constant("colorOverride", color_override);
    bg_ps_.push_constant("bgType", background_type);
    bg_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);

    if (state.clipping_state != 0 && state.rv3d != nullptr && state.rv3d->clipbb != nullptr) {
      bg_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA | DRW_STATE_CULL_BACK);
      bg_ps_.shader_set(OVERLAY_shader_clipbound());
      bg_ps_.push_constant("ucolor", res.theme_settings.color_clipping_border);
      bg_ps_.push_constant("boundbox", &state.rv3d->clipbb->vec[0][0], 8);
      bg_ps_.draw(DRW_cache_cube_get());
    }
  }

  void draw(Resources &res, Manager &manager)
  {
    GPU_framebuffer_bind(res.overlay_color_only_fb);
    manager.submit(bg_ps_);
  }
};

}  // namespace blender::draw::overlay