Blender V5.0
overlay_facing.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 "BKE_paint.hh"
12
13#include "draw_sculpt.hh"
14
15#include "overlay_base.hh"
16
17namespace blender::draw::overlay {
18
23class Facing : Overlay {
24
25 private:
26 PassMain ps_ = {"Facing"};
27
28 public:
29 void begin_sync(Resources &res, const State &state) final
30 {
31 enabled_ = state.v3d && state.show_face_orientation() && !state.xray_enabled &&
32 !res.is_selection() && !state.is_depth_only_drawing;
33 if (!enabled_) {
34 /* Not used. But release the data. */
35 ps_.init();
36 return;
37 }
38
39 const View3DShading &shading = state.v3d->shading;
40 const bool is_solid_viewport = shading.type == OB_SOLID;
41 bool use_cull = (is_solid_viewport && (shading.flag & V3D_SHADING_BACKFACE_CULLING));
42 DRWState backface_cull_state = use_cull ? DRW_STATE_CULL_BACK : DRWState(0);
43
44 /* Use the Depth Equal test in solid mode to ensure transparent textures display correctly.
45 * (See #128113). And the Depth-Less test in other modes (E.g. EEVEE) to ensure the overlay
46 * displays correctly (See # 114000). */
47 DRWState depth_compare_state = is_solid_viewport ? DRW_STATE_DEPTH_EQUAL :
49
50 ps_.init();
51 ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | depth_compare_state |
52 backface_cull_state,
53 state.clipping_plane_count);
54 ps_.shader_set(res.shaders->facing.get());
55 ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
56 ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
57 }
58
59 void object_sync(Manager &manager,
60 const ObjectRef &ob_ref,
61 Resources & /*res*/,
62 const State &state) final
63 {
64 if (!enabled_) {
65 return;
66 }
67 const bool renderable = DRW_object_is_renderable(ob_ref.object);
68 const bool draw_surface = (ob_ref.object->dt >= OB_WIRE) &&
69 (renderable || (ob_ref.object->dt == OB_WIRE));
70 const bool draw_facing = draw_surface && (ob_ref.object->dt >= OB_SOLID);
71 if (!draw_facing) {
72 return;
73 }
74 const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob_ref.object, state.rv3d) &&
75 !state.is_image_render;
76
77 if (use_sculpt_pbvh) {
78 ResourceHandleRange handle = manager.unique_handle_for_sculpt(ob_ref);
79
81 ps_.draw(batch.batch, handle);
82 }
83 }
84 else {
85 blender::gpu::Batch *geom = DRW_cache_object_surface_get(ob_ref.object);
86 if (geom) {
87 ps_.draw(geom, manager.unique_handle(ob_ref));
88 }
89 }
90 }
91
92 void pre_draw(Manager &manager, View &view) final
93 {
94 if (!enabled_) {
95 return;
96 }
97
98 manager.generate_commands(ps_, view);
99 }
100
101 void draw(Framebuffer &framebuffer, Manager &manager, View &view) final
102 {
103 if (!enabled_) {
104 return;
105 }
106
107 GPU_framebuffer_bind(framebuffer);
108 manager.submit_only(ps_, view);
109 }
110};
111
112} // namespace blender::draw::overlay
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:3068
@ OB_WIRE
@ OB_SOLID
@ V3D_SHADING_BACKFACE_CULLING
static AppView * view
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
void draw(Framebuffer &framebuffer, Manager &manager, View &view) final
void pre_draw(Manager &manager, View &view) final
void begin_sync(Resources &res, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
bool DRW_object_is_renderable(const Object *ob)
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
DRWState
Definition draw_state.hh:25
@ DRW_STATE_DEPTH_EQUAL
Definition draw_state.hh:39
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:29
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
@ DRW_STATE_CULL_BACK
Definition draw_state.hh:43
struct @021025263243242147216143265077100330027142264337::@225245033123204053237120173316075113304004012000 batch
static ulong state[N]
detail::Pass< command::DrawMultiBuf > PassMain
Vector< SculptBatch > sculpt_batches_get(const Object *ob, SculptBatchFeature features)
gpu::Batch * DRW_cache_object_surface_get(Object *ob)