Blender V4.3
overlay_next_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
9#pragma once
10
11#include "BKE_paint.hh"
12
14
15namespace blender::draw::overlay {
16
17class Facing {
18
19 private:
20 const SelectionType selection_type_;
21
22 PassMain ps_ = {"Facing"};
23
24 bool enabled = false;
25
26 public:
27 Facing(const SelectionType selection_type_) : selection_type_(selection_type_) {}
28
29 void begin_sync(Resources &res, const State &state)
30 {
31 enabled = state.v3d && (state.overlay.flag & V3D_OVERLAY_FACE_ORIENTATION) &&
32 !state.xray_enabled && (selection_type_ == SelectionType::DISABLED);
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 bool use_cull = ((shading.type == OB_SOLID) && (shading.flag & V3D_SHADING_BACKFACE_CULLING));
41 DRWState backface_cull_state = use_cull ? DRW_STATE_CULL_BACK : DRWState(0);
42
43 ps_.init();
45 backface_cull_state,
46 state.clipping_plane_count);
47 ps_.shader_set(res.shaders.facing.get());
48 ps_.bind_ubo("globalsBlock", &res.globals_buf);
49 }
50
51 void object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state)
52 {
53 if (!enabled) {
54 return;
55 }
56 const bool renderable = DRW_object_is_renderable(ob_ref.object);
57 const bool draw_surface = (ob_ref.object->dt >= OB_WIRE) &&
58 (renderable || (ob_ref.object->dt == OB_WIRE));
59 const bool draw_facing = draw_surface && (ob_ref.object->dt >= OB_SOLID);
60 if (!draw_facing) {
61 return;
62 }
63 const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob_ref.object, state.rv3d) &&
65
66 if (use_sculpt_pbvh) {
67 ResourceHandle handle = manager.resource_handle_for_sculpt(ob_ref);
68
70 ps_.draw(batch.batch, handle);
71 }
72 }
73 else {
74 blender::gpu::Batch *geom = DRW_cache_object_surface_get(ob_ref.object);
75 if (geom) {
76 ps_.draw(geom, manager.unique_handle(ob_ref));
77 }
78 }
79 }
80
81 void draw(Framebuffer &framebuffer, Manager &manager, View &view)
82 {
83 if (!enabled) {
84 return;
85 }
86 GPU_framebuffer_bind(framebuffer);
87 manager.submit(ps_, view);
88 }
89};
90
91} // namespace blender::draw::overlay
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:2862
@ OB_WIRE
@ OB_SOLID
@ V3D_OVERLAY_FACE_ORIENTATION
@ V3D_SHADING_BACKFACE_CULLING
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
ResourceHandle unique_handle(const ObjectRef &ref)
ResourceHandle resource_handle_for_sculpt(const ObjectRef &ref)
void submit(PassSimple &pass, View &view)
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 state_set(DRWState state, int clip_plane_count=0)
Definition draw_pass.hh:954
void bind_ubo(const char *name, GPUUniformBuf *buffer)
void shader_set(GPUShader *shader)
Definition draw_pass.hh:971
Facing(const SelectionType selection_type_)
void draw(Framebuffer &framebuffer, Manager &manager, View &view)
void object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state)
void begin_sync(Resources &res, const State &state)
blender::gpu::Batch * DRW_cache_object_surface_get(Object *ob)
bool DRW_object_is_renderable(const Object *ob)
bool DRW_state_is_image_render()
DRWState
Definition draw_state.hh:25
@ 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 @620::@622 batch
static ulong state[N]
Vector< SculptBatch > sculpt_batches_get(const Object *ob, SculptBatchFeature features)