Blender
V5.0
source
blender
draw
engines
overlay
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
17
namespace
blender::draw::overlay
{
18
23
class
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
:
48
DRW_STATE_DEPTH_LESS_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
80
for
(
SculptBatch
&
batch
:
sculpt_batches_get
(ob_ref.object,
SCULPT_BATCH_DEFAULT
)) {
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
BKE_paint.hh
BKE_sculptsession_use_pbvh_draw
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition
paint.cc:3068
OB_WIRE
@ OB_WIRE
Definition
DNA_object_enums.h:34
OB_SOLID
@ OB_SOLID
Definition
DNA_object_enums.h:35
V3D_SHADING_BACKFACE_CULLING
@ V3D_SHADING_BACKFACE_CULLING
Definition
DNA_view3d_types.h:592
view
static AppView * view
Definition
FRS_freestyle.cpp:59
GPU_framebuffer_bind
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
Definition
gpu_framebuffer.cc:239
blender::draw::Framebuffer
Definition
DRW_gpu_wrapper.hh:1202
blender::draw::Manager
Definition
draw_manager.hh:45
blender::draw::ObjectRef
Definition
draw_handle.hh:207
blender::draw::ResourceHandleRange
Definition
draw_handle.hh:152
blender::draw::View
Definition
draw_view.hh:37
blender::draw::overlay::Facing
Definition
overlay_facing.hh:23
blender::draw::overlay::Facing::draw
void draw(Framebuffer &framebuffer, Manager &manager, View &view) final
Definition
overlay_facing.hh:101
blender::draw::overlay::Facing::pre_draw
void pre_draw(Manager &manager, View &view) final
Definition
overlay_facing.hh:92
blender::draw::overlay::Facing::begin_sync
void begin_sync(Resources &res, const State &state) final
Definition
overlay_facing.hh:29
blender::draw::overlay::Facing::object_sync
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
Definition
overlay_facing.hh:59
DRW_object_is_renderable
bool DRW_object_is_renderable(const Object *ob)
Definition
draw_context.cc:286
DRW_CLIPPING_UBO_SLOT
#define DRW_CLIPPING_UBO_SLOT
Definition
draw_defines.hh:23
OVERLAY_GLOBALS_SLOT
#define OVERLAY_GLOBALS_SLOT
Definition
draw_defines.hh:48
draw_sculpt.hh
DRWState
DRWState
Definition
draw_state.hh:25
DRW_STATE_DEPTH_EQUAL
@ DRW_STATE_DEPTH_EQUAL
Definition
draw_state.hh:39
DRW_STATE_WRITE_DEPTH
@ DRW_STATE_WRITE_DEPTH
Definition
draw_state.hh:29
DRW_STATE_WRITE_COLOR
@ DRW_STATE_WRITE_COLOR
Definition
draw_state.hh:30
DRW_STATE_DEPTH_LESS_EQUAL
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition
draw_state.hh:38
DRW_STATE_CULL_BACK
@ DRW_STATE_CULL_BACK
Definition
draw_state.hh:43
batch
struct @021025263243242147216143265077100330027142264337::@225245033123204053237120173316075113304004012000 batch
state
static ulong state[N]
Definition
mathutils_noise.cc:56
blender::draw::overlay
Definition
overlay_antialiasing.hh:49
blender::draw::PassMain
detail::Pass< command::DrawMultiBuf > PassMain
Definition
draw_manager.hh:42
blender::draw::sculpt_batches_get
Vector< SculptBatch > sculpt_batches_get(const Object *ob, SculptBatchFeature features)
Definition
draw_sculpt.cc:156
blender::draw::DRW_cache_object_surface_get
gpu::Batch * DRW_cache_object_surface_get(Object *ob)
Definition
draw_cache.cc:138
blender::draw::SCULPT_BATCH_DEFAULT
@ SCULPT_BATCH_DEFAULT
Definition
draw_sculpt.hh:32
overlay_base.hh
View3DShading
Definition
DNA_view3d_types.h:160
View3DShading::type
char type
Definition
DNA_view3d_types.h:162
View3DShading::flag
short flag
Definition
DNA_view3d_types.h:168
blender::draw::SculptBatch
Definition
draw_sculpt.hh:24
blender::draw::overlay::Overlay
Definition
overlay_base.hh:22
blender::draw::overlay::Overlay::enabled_
bool enabled_
Definition
overlay_base.hh:29
blender::draw::overlay::Resources
Definition
overlay_private.hh:588
blender::draw::overlay::State
Definition
overlay_private.hh:125
Generated on
for Blender by
doxygen
1.16.1