Blender V5.3
overlay_armature.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_userdef_types.h"
12
13#include "ED_view3d.hh"
14
15#include "DRW_render.hh"
16
17#include "overlay_base.hh"
19
20namespace blender::draw::overlay {
26
32 using EmptyInstanceBuf = ShapeInstanceBuf<ExtraInstanceData>;
33 using BoneInstanceBuf = ShapeInstanceBuf<BoneInstanceData>;
34 using BoneEnvelopeBuf = ShapeInstanceBuf<BoneEnvelopeData>;
35 using BoneStickBuf = ShapeInstanceBuf<BoneStickData>;
36 using DegreesOfFreedomBuf = ShapeInstanceBuf<ExtraInstanceData>;
37
38 private:
39 const SelectionType selection_type_;
40
41 PassSimple armature_ps_ = {"Armature"};
42
43 /* Force transparent drawing in X-ray mode. */
44 bool draw_transparent = false;
45 /* Force disable drawing relation is relations are off in viewport. */
46 bool show_relations = false;
47 /* Show selection state. */
48 bool show_outline = false;
49
50 struct BoneBuffers {
51 const SelectionType selection_type_;
52
53 /* Bone end points (joints). */
54 PassSimple::Sub *sphere_fill = nullptr;
55 PassSimple::Sub *sphere_outline = nullptr;
56 /* Bone shapes. */
57 PassSimple::Sub *shape_fill = nullptr;
58 PassSimple::Sub *shape_outline = nullptr;
59 /* Custom bone wire-frame. */
60 PassSimple::Sub *shape_wire = nullptr;
61 PassSimple::Sub *shape_wire_strip = nullptr;
62 /* Envelopes. */
63 PassSimple::Sub *envelope_fill = nullptr;
64 PassSimple::Sub *envelope_outline = nullptr;
65 PassSimple::Sub *envelope_distance = nullptr;
66 /* Stick bones. */
67 PassSimple::Sub *stick = nullptr;
68 /* Wire bones. */
69 PassSimple::Sub *wire = nullptr;
70
71 /* Bone axes. */
72 PassSimple::Sub *arrows = nullptr;
73 /* Degrees of freedom. */
74 PassSimple::Sub *degrees_of_freedom_fill = nullptr;
75 PassSimple::Sub *degrees_of_freedom_wire = nullptr;
76 /* Relations. */
77 PassSimple::Sub *relations = nullptr;
78
79 BoneInstanceBuf bbones_fill_buf = {selection_type_, "bbones_fill_buf"};
80 BoneInstanceBuf bbones_outline_buf = {selection_type_, "bbones_outline_buf"};
81
82 BoneInstanceBuf octahedral_fill_buf = {selection_type_, "octahedral_fill_buf"};
83 BoneInstanceBuf octahedral_outline_buf = {selection_type_, "octahedral_outline_buf"};
84
85 BoneInstanceBuf sphere_fill_buf = {selection_type_, "sphere_fill_buf"};
86 BoneInstanceBuf sphere_outline_buf = {selection_type_, "sphere_outline_buf"};
87
88 BoneEnvelopeBuf envelope_fill_buf = {selection_type_, "envelope_fill_buf"};
89 BoneEnvelopeBuf envelope_outline_buf = {selection_type_, "envelope_outline_buf"};
90 BoneEnvelopeBuf envelope_distance_buf = {selection_type_, "envelope_distance_buf"};
91
92 BoneStickBuf stick_buf = {selection_type_, "stick_buf"};
93
94 LinePrimitiveBuf wire_buf = {selection_type_, "wire_buf"};
95
96 EmptyInstanceBuf arrows_buf = {selection_type_, "arrows_buf"};
97
98 DegreesOfFreedomBuf degrees_of_freedom_fill_buf = {SelectionType::DISABLED,
99 "degrees_of_freedom_buf"};
100 DegreesOfFreedomBuf degrees_of_freedom_wire_buf = {SelectionType::DISABLED,
101 "degrees_of_freedom_buf"};
102
103 LinePrimitiveBuf relations_buf = {SelectionType::DISABLED, "relations_buf"};
104
109
110 BoneInstanceBuf &custom_shape_fill_get_buffer(gpu::Batch *geom)
111 {
112 return *custom_shape_fill.lookup_or_add_cb(geom, [this]() {
113 return std::make_unique<BoneInstanceBuf>(this->selection_type_, "CustomBoneSolid");
114 });
115 }
116
117 BoneInstanceBuf &custom_shape_outline_get_buffer(gpu::Batch *geom)
118 {
119 return *custom_shape_outline.lookup_or_add_cb(geom, [this]() {
120 return std::make_unique<BoneInstanceBuf>(this->selection_type_, "CustomBoneOutline");
121 });
122 }
123
124 BoneInstanceBuf &custom_shape_wire_get_buffer(gpu::Batch *geom)
125 {
126 if (geom->prim_type == GPU_PRIM_LINE_STRIP) {
127 return *custom_shape_wire_strip.lookup_or_add_cb(geom, [this]() {
128 return std::make_unique<BoneInstanceBuf>(this->selection_type_, "CustomBoneWireStrip");
129 });
130 }
131 return *custom_shape_wire.lookup_or_add_cb(geom, [this]() {
132 return std::make_unique<BoneInstanceBuf>(this->selection_type_, "CustomBoneWire");
133 });
134 }
135
136 BoneBuffers(const SelectionType selection_type) : selection_type_(selection_type) {};
137 };
138
139 BoneBuffers opaque_ = {selection_type_};
140 BoneBuffers transparent_ = {selection_type_};
141
142 public:
143 Armatures(const SelectionType selection_type) : selection_type_(selection_type) {};
144
145 void begin_sync(Resources &res, const State &state) final
146 {
147 enabled_ = state.is_space_v3d() && state.show_bones();
148
149 if (!enabled_) {
150 return;
151 }
152
153 draw_transparent = (state.v3d->shading.type == OB_WIRE) || XRAY_FLAG_ENABLED(state.v3d);
154 show_relations = !((state.v3d->flag & V3D_HIDE_HELPLINES) || res.is_selection());
155 show_outline = (state.v3d->flag & V3D_SELECT_OUTLINE);
156
157 const bool do_smooth_wire = U.gpu_flag & USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE;
158 const float wire_alpha = state.ctx_mode == CTX_MODE_PAINT_WEIGHT ?
159 state.overlay.bone_wire_alpha :
160 1.0f;
161 /* Draw bone outlines and custom shape wire with a specific alpha. */
162 const bool use_wire_alpha = (wire_alpha < 1.0f);
163
164 gpu::Texture **depth_tex = (state.xray_enabled) ? &res.depth_tx : &res.dummy_depth_tx;
165
166 armature_ps_.init();
167 armature_ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
168 armature_ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
169 res.select_bind(armature_ps_);
170
171 /* Envelope distances and degrees of freedom need to be drawn first as they use additive
172 * transparent blending. */
173 {
176 {
177 auto &sub = armature_ps_.sub("opaque.envelope_distance");
178 sub.state_set(transparent_state | DRW_STATE_CULL_FRONT, state.clipping_plane_count);
179 sub.shader_set(res.shaders->armature_envelope_fill.get());
180 sub.push_constant("alpha", 1.0f);
181 sub.push_constant("is_distance", true);
182 opaque_.envelope_distance = &sub;
183 }
184 if (use_wire_alpha) {
185 auto &sub = armature_ps_.sub("transparent.envelope_distance");
186 sub.state_set(transparent_state | DRW_STATE_CULL_FRONT, state.clipping_plane_count);
187 sub.shader_set(res.shaders->armature_envelope_fill.get());
188 sub.push_constant("alpha", wire_alpha);
189 sub.push_constant("is_distance", true);
190 transparent_.envelope_distance = &sub;
191 }
192 else {
193 transparent_.envelope_distance = opaque_.envelope_distance;
194 }
195
196 {
197 auto &sub = armature_ps_.sub("opaque.degrees_of_freedom_fill");
198 sub.state_set(transparent_state, state.clipping_plane_count);
199 sub.shader_set(res.shaders->armature_degrees_of_freedom.get());
200 sub.push_constant("alpha", 1.0f);
201 opaque_.degrees_of_freedom_fill = &sub;
202 }
203 if (use_wire_alpha) {
204 auto &sub = armature_ps_.sub("transparent.degrees_of_freedom_fill");
205 sub.state_set(transparent_state, state.clipping_plane_count);
206 sub.shader_set(res.shaders->armature_degrees_of_freedom.get());
207 sub.push_constant("alpha", wire_alpha);
208 transparent_.degrees_of_freedom_fill = &sub;
209 }
210 else {
211 transparent_.degrees_of_freedom_fill = opaque_.degrees_of_freedom_fill;
212 }
213 }
214
217
218 /* Bone Shapes (Octahedral, Box, Custom Shapes, Spheres). */
219 {
220 {
221 auto &sub = armature_ps_.sub("opaque.sphere_fill");
222 sub.state_set(default_state, state.clipping_plane_count);
223 sub.shader_set(res.shaders->armature_sphere_fill.get());
224 sub.push_constant("alpha", 1.0f);
225 opaque_.sphere_fill = &sub;
226 }
227 {
228 auto &sub = armature_ps_.sub("transparent.sphere_fill");
229 sub.state_set((default_state & ~DRW_STATE_WRITE_DEPTH) | DRW_STATE_BLEND_ALPHA,
230 state.clipping_plane_count);
231 sub.shader_set(res.shaders->armature_sphere_fill.get());
232 sub.push_constant("alpha", wire_alpha * 0.4f);
233 transparent_.sphere_fill = &sub;
234 }
235
236 {
237 auto &sub = armature_ps_.sub("opaque.shape_fill");
238 sub.state_set(default_state, state.clipping_plane_count);
239 sub.shader_set(res.shaders->armature_shape_fill.get());
240 sub.push_constant("alpha", 1.0f);
241 opaque_.shape_fill = &sub;
242 }
243 {
244 auto &sub = armature_ps_.sub("transparent.shape_fill");
245 sub.state_set((default_state & ~DRW_STATE_WRITE_DEPTH) | DRW_STATE_BLEND_ALPHA,
246 state.clipping_plane_count);
247 sub.shader_set(res.shaders->armature_shape_fill.get());
248 sub.push_constant("alpha", wire_alpha * 0.6f);
249 transparent_.shape_fill = &sub;
250 }
251
252 {
253 auto &sub = armature_ps_.sub("opaque.sphere_outline");
254 sub.state_set(default_state, state.clipping_plane_count);
255 sub.shader_set(res.shaders->armature_sphere_outline.get());
256 sub.push_constant("alpha", 1.0f);
257 opaque_.sphere_outline = &sub;
258 }
259 if (use_wire_alpha) {
260 auto &sub = armature_ps_.sub("transparent.sphere_outline");
261 sub.state_set(default_state | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
262 sub.shader_set(res.shaders->armature_sphere_outline.get());
263 sub.push_constant("alpha", wire_alpha);
264 transparent_.sphere_outline = &sub;
265 }
266 else {
267 transparent_.sphere_outline = opaque_.sphere_outline;
268 }
269
270 {
271 auto &sub = armature_ps_.sub("opaque.shape_outline");
272 sub.state_set(default_state, state.clipping_plane_count);
273 sub.shader_set(res.shaders->armature_shape_outline.get());
274 sub.push_constant("alpha", 1.0f);
275 opaque_.shape_outline = &sub;
276 }
277 if (use_wire_alpha) {
278 auto &sub = armature_ps_.sub("transparent.shape_outline");
279 sub.state_set(default_state | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
280 sub.shader_set(res.shaders->armature_shape_outline.get());
281 sub.bind_texture("depth_tx", depth_tex);
282 sub.push_constant("alpha", wire_alpha * 0.6f);
283 sub.push_constant("do_smooth_wire", do_smooth_wire);
284 transparent_.shape_outline = &sub;
285 }
286 else {
287 transparent_.shape_outline = opaque_.shape_outline;
288 }
289
290 {
291 auto &sub = armature_ps_.sub("opaque.shape_wire");
292 sub.state_set(default_state | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
293 sub.shader_set(res.shaders->armature_shape_wire.get());
294 sub.push_constant("alpha", 1.0f);
295 sub.push_constant("do_smooth_wire", do_smooth_wire);
296 sub.push_constant("use_arrow_drawing", false);
297 opaque_.shape_wire = &sub;
298 }
299 if (use_wire_alpha) {
300 auto &sub = armature_ps_.sub("transparent.shape_wire");
301 sub.state_set(default_state | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
302 sub.shader_set(res.shaders->armature_shape_wire.get());
303 sub.bind_texture("depth_tx", depth_tex);
304 sub.push_constant("alpha", wire_alpha * 0.6f);
305 sub.push_constant("do_smooth_wire", do_smooth_wire);
306 sub.push_constant("use_arrow_drawing", false);
307 transparent_.shape_wire = &sub;
308 }
309 else {
310 transparent_.shape_wire = opaque_.shape_wire;
311 }
312
313 {
314 auto &sub = armature_ps_.sub("opaque.shape_wire_strip");
315 sub.state_set(default_state | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
316 sub.shader_set(res.shaders->armature_shape_wire_strip.get());
317 sub.push_constant("alpha", 1.0f);
318 sub.push_constant("do_smooth_wire", do_smooth_wire);
319 sub.push_constant("use_arrow_drawing", false);
320 opaque_.shape_wire_strip = &sub;
321 }
322 if (use_wire_alpha) {
323 auto &sub = armature_ps_.sub("transparent.shape_wire_strip");
324 sub.state_set(default_state | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
325 sub.shader_set(res.shaders->armature_shape_wire_strip.get());
326 sub.bind_texture("depth_tx", depth_tex);
327 sub.push_constant("alpha", wire_alpha * 0.6f);
328 sub.push_constant("do_smooth_wire", do_smooth_wire);
329 sub.push_constant("use_arrow_drawing", false);
330 transparent_.shape_wire_strip = &sub;
331 }
332 else {
333 transparent_.shape_wire_strip = opaque_.shape_wire_strip;
334 }
335 }
336 /* Degrees of freedom. */
337 {
338 {
339 auto &sub = armature_ps_.sub("opaque.degrees_of_freedom_wire");
340 sub.shader_set(res.shaders->armature_degrees_of_freedom.get());
341 sub.push_constant("alpha", 1.0f);
342 opaque_.degrees_of_freedom_wire = &sub;
343 }
344 if (use_wire_alpha) {
345 auto &sub = armature_ps_.sub("transparent.degrees_of_freedom_wire");
346 sub.shader_set(res.shaders->armature_degrees_of_freedom.get());
347 sub.push_constant("alpha", wire_alpha);
348 transparent_.degrees_of_freedom_wire = &sub;
349 }
350 else {
351 transparent_.degrees_of_freedom_wire = opaque_.degrees_of_freedom_wire;
352 }
353 }
354 /* Stick bones. */
355 {
356 {
357 auto &sub = armature_ps_.sub("opaque.stick");
358 sub.shader_set(res.shaders->armature_stick.get());
359 sub.push_constant("alpha", 1.0f);
360 opaque_.stick = &sub;
361 }
362 if (use_wire_alpha) {
363 auto &sub = armature_ps_.sub("transparent.stick");
364 sub.state_set(default_state | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
365 sub.shader_set(res.shaders->armature_stick.get());
366 sub.push_constant("alpha", wire_alpha);
367 transparent_.stick = &sub;
368 }
369 else {
370 transparent_.stick = opaque_.stick;
371 }
372 }
373 /* Envelopes. */
374 {
375 {
376 auto &sub = armature_ps_.sub("opaque.envelope_fill");
377 sub.state_set(default_state | DRW_STATE_CULL_BACK, state.clipping_plane_count);
378 sub.shader_set(res.shaders->armature_envelope_fill.get());
379 sub.push_constant("is_distance", false);
380 sub.push_constant("alpha", 1.0f);
381 opaque_.envelope_fill = &sub;
382 }
383 {
384 auto &sub = armature_ps_.sub("transparent.envelope_fill");
385 sub.state_set((default_state & ~DRW_STATE_WRITE_DEPTH) |
387 state.clipping_plane_count);
388 sub.shader_set(res.shaders->armature_envelope_fill.get());
389 sub.push_constant("alpha", wire_alpha * 0.6f);
390 transparent_.envelope_fill = &sub;
391 }
392
393 {
394 auto &sub = armature_ps_.sub("opaque.envelope_outline");
395 sub.state_set(default_state | DRW_STATE_CULL_BACK, state.clipping_plane_count);
396 sub.shader_set(res.shaders->armature_envelope_outline.get());
397 sub.push_constant("alpha", 1.0f);
398 opaque_.envelope_outline = &sub;
399 }
400 if (use_wire_alpha) {
401 auto &sub = armature_ps_.sub("transparent.envelope_outline");
402 sub.state_set((default_state & ~DRW_STATE_WRITE_DEPTH) |
404 state.clipping_plane_count);
405 sub.shader_set(res.shaders->armature_envelope_outline.get());
406 sub.push_constant("alpha", wire_alpha);
407 transparent_.envelope_outline = &sub;
408 }
409 else {
410 transparent_.envelope_outline = opaque_.envelope_outline;
411 }
412 }
413 {
414 {
415 auto &sub = armature_ps_.sub("opaque.wire");
416 sub.shader_set(res.shaders->armature_wire.get());
417 sub.push_constant("alpha", 1.0f);
418 opaque_.wire = &sub;
419 }
420 if (use_wire_alpha) {
421 auto &sub = armature_ps_.sub("transparent.wire");
422 sub.state_set(default_state | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
423 sub.shader_set(res.shaders->armature_wire.get());
424 sub.push_constant("alpha", wire_alpha);
425 transparent_.wire = &sub;
426 }
427 else {
428 transparent_.wire = opaque_.wire;
429 }
430 }
431
432 {
433 auto &sub = armature_ps_.sub("opaque.arrow");
434 sub.shader_set(res.shaders->extra_shape.get());
435 opaque_.arrows = &sub;
436 transparent_.arrows = opaque_.arrows;
437 }
438
439 {
440 auto &sub = armature_ps_.sub("opaque.relations");
441 sub.shader_set(res.shaders->extra_wire.get());
442 opaque_.relations = &sub;
443 transparent_.relations = opaque_.relations;
444 }
445
446 auto shape_instance_bufs_begin_sync = [](BoneBuffers &bb) {
447 bb.envelope_fill_buf.clear();
448 bb.envelope_outline_buf.clear();
449 bb.envelope_distance_buf.clear();
450 bb.bbones_fill_buf.clear();
451 bb.bbones_outline_buf.clear();
452 bb.octahedral_fill_buf.clear();
453 bb.octahedral_outline_buf.clear();
454 bb.sphere_fill_buf.clear();
455 bb.sphere_outline_buf.clear();
456 bb.stick_buf.clear();
457 bb.wire_buf.clear();
458 bb.arrows_buf.clear();
459 bb.degrees_of_freedom_fill_buf.clear();
460 bb.degrees_of_freedom_wire_buf.clear();
461 bb.relations_buf.clear();
462 /* TODO(fclem): Potentially expensive operation recreating a lot of gpu buffers.
463 * Prefer a pruning strategy. */
464 bb.custom_shape_fill.clear();
465 bb.custom_shape_outline.clear();
466 bb.custom_shape_wire.clear();
467 bb.custom_shape_wire_strip.clear();
468 };
469
470 shape_instance_bufs_begin_sync(transparent_);
471 shape_instance_bufs_begin_sync(opaque_);
472 }
473
474 struct DrawContext {
475 /* Current armature object */
476 Object *ob = nullptr;
477 const ObjectRef *ob_ref = nullptr;
478 bArmature *armature = nullptr;
479
480 /* Note: can be mutated inside `draw_armature_pose()`. */
483
484 Armatures::BoneBuffers *bone_buf = nullptr;
485 Resources *res = nullptr;
486 DRWTextStore *dt = nullptr;
487
488 /* Not a theme, this is an override. */
489 const float *const_color = nullptr;
490 /* Wire thickness. */
491 float const_wire = 0.0f;
492
493 bool do_relations = false;
494 bool transparent = false;
495 bool show_relations = false;
498 bool show_text = false;
499 /* Draw the inner part of the bones, otherwise render just outlines. */
500 bool is_filled = false;
501
502 const ThemeWireColor *bcolor = nullptr; /* Pose-channel color. */
503
504 DrawContext() = default;
505 };
506
508 Resources &res,
509 const State &state,
510 eArmatureDrawMode draw_mode)
511 {
513
514 DrawContext ctx;
515 ctx.ob = ob_ref.object;
516 ctx.ob_ref = &ob_ref;
517 ctx.armature = &arm;
518 ctx.res = &res;
519 ctx.dt = state.dt;
520 ctx.draw_mode = draw_mode;
522
523 const bool is_edit_or_pose_mode = draw_mode != ARM_DRAW_MODE_OBJECT;
524 const bool draw_as_wire = (ctx.ob->dt < OB_SOLID);
525 const bool is_transparent = draw_transparent || (draw_as_wire && is_edit_or_pose_mode);
526
527 ctx.bone_buf = is_transparent ? &transparent_ : &opaque_;
528
529 ctx.is_filled = (!draw_transparent && !draw_as_wire) || is_edit_or_pose_mode;
530 ctx.show_relations = show_relations;
531 ctx.do_relations = show_relations && is_edit_or_pose_mode;
532 ctx.draw_envelope_distance = is_edit_or_pose_mode;
534 ctx.show_text = state.show_text;
535 ctx.const_color = is_edit_or_pose_mode ? nullptr : &res.object_wire_color(ob_ref, state)[0];
536 ctx.const_wire = (!ctx.is_filled || is_transparent) ? 1.0f : 0.0f;
537 if ((ctx.ob->base_flag & BASE_SELECTED) && show_outline) {
538 ctx.const_wire = 1.5f;
539 }
540 return ctx;
541 }
542
543 void edit_object_sync(Manager & /*manager*/,
544 const ObjectRef &ob_ref,
545 Resources &res,
546 const State &state) final
547 {
548 if (!enabled_) {
549 return;
550 }
551
553 draw_armature_edit(&ctx);
554 }
555
556 void object_sync(Manager & /*manager*/,
557 const ObjectRef &ob_ref,
558 Resources &res,
559 const State &state) final
560 {
561 if (!enabled_ || ob_ref.object->dt == OB_BOUNDBOX) {
562 return;
563 }
564
565 eArmatureDrawMode draw_mode = is_pose_mode(ob_ref.object, state) ? ARM_DRAW_MODE_POSE :
567
568 DrawContext ctx = create_draw_context(ob_ref, res, state, draw_mode);
569 draw_armature_pose(&ctx);
570 }
571
572 void end_sync(Resources &res, const State & /*state*/) final
573 {
574 if (!enabled_) {
575 return;
576 }
577
578 auto end_sync = [&](BoneBuffers &bb) {
579 bb.sphere_fill_buf.end_sync(*bb.sphere_fill, res.shapes.bone_sphere.get());
580 bb.sphere_outline_buf.end_sync(*bb.sphere_outline, res.shapes.bone_sphere_wire.get());
581
582 bb.octahedral_fill_buf.end_sync(*bb.shape_fill, res.shapes.bone_octahedron.get());
583 bb.octahedral_outline_buf.end_sync(
584 *bb.shape_outline, res.shapes.bone_octahedron_wire.get(), GPU_PRIM_LINES, 1);
585
586 bb.bbones_fill_buf.end_sync(*bb.shape_fill, res.shapes.bone_box.get());
587 bb.bbones_outline_buf.end_sync(
588 *bb.shape_outline, res.shapes.bone_box_wire.get(), GPU_PRIM_LINES, 1);
589
590 bb.envelope_fill_buf.end_sync(*bb.envelope_fill, res.shapes.bone_envelope.get());
591 bb.envelope_outline_buf.end_sync(*bb.envelope_outline, res.shapes.bone_envelope_wire.get());
592 bb.envelope_distance_buf.end_sync(*bb.envelope_distance, res.shapes.bone_envelope.get());
593
594 bb.stick_buf.end_sync(*bb.stick, res.shapes.bone_stick.get());
595
596 bb.wire_buf.end_sync(*bb.wire);
597
598 bb.arrows_buf.end_sync(*bb.arrows, res.shapes.arrows.get());
599
600 bb.degrees_of_freedom_fill_buf.end_sync(*bb.degrees_of_freedom_fill,
601 res.shapes.bone_degrees_of_freedom.get());
602 bb.degrees_of_freedom_wire_buf.end_sync(*bb.degrees_of_freedom_wire,
603 res.shapes.bone_degrees_of_freedom_wire.get());
604
605 bb.relations_buf.end_sync(*bb.relations);
606
608
609 gpu::Batch *arrow_batch = res.shapes.arrows.get();
610 for (CustomShapeBuf item : bb.custom_shape_fill.items()) {
611 item.value->end_sync(*bb.shape_fill, item.key);
612 }
613 for (CustomShapeBuf item : bb.custom_shape_outline.items()) {
614 item.value->end_sync(*bb.shape_outline, item.key, GPU_PRIM_LINES, 1);
615 }
616 for (CustomShapeBuf item : bb.custom_shape_wire.items()) {
617 /* WORKAROUND: This shape needs a special vertex shader path that should be triggered by
618 * its `vclass` attribute. However, to avoid many changes in the primitive expansion API,
619 * we create a specific path inside the shader only for this shape batch and infer the
620 * value of the `vclass` attribute based on the vertex index. */
621 if (item.key == arrow_batch) {
622 bb.shape_wire->push_constant("use_arrow_drawing", true);
623 }
624
625 item.value->end_sync(*bb.shape_wire, item.key, GPU_PRIM_TRIS, 2);
626
627 if (item.key == arrow_batch) {
628 bb.shape_wire->push_constant("use_arrow_drawing", false);
629 }
630 }
631 for (CustomShapeBuf item : bb.custom_shape_wire_strip.items()) {
632 item.value->end_sync(*bb.shape_wire_strip, item.key, GPU_PRIM_TRIS, 2);
633 }
634 };
635
636 end_sync(transparent_);
637 end_sync(opaque_);
638 }
639
640 void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
641 {
642 if (!enabled_) {
643 return;
644 }
645
646 GPU_framebuffer_bind(framebuffer);
647 manager.submit(armature_ps_, view);
648 }
649
650 /* Public for the time of the Overlay Next port to avoid duplicated logic. */
653
654 static bool is_pose_mode(const Object *armature_ob, const State &state)
655 {
656 const Object *active_ob = state.object_active;
657
658 /* Armature is in pose mode. */
659 if (((armature_ob == active_ob) || (armature_ob->mode & OB_MODE_POSE)) &&
660 ((state.object_mode & OB_MODE_POSE) != 0))
661 {
662 return true;
663 }
664
665 /* Active object is in weight paint and the associated armature is in pose mode. */
666 if ((active_ob != nullptr) && (state.object_mode & OB_MODE_ALL_WEIGHT_PAINT)) {
667 if (armature_ob == BKE_object_pose_armature_get(const_cast<Object *>(active_ob))) {
668 return true;
669 }
670 }
671
672 return false;
673 }
674};
675
676} // namespace blender::draw::overlay
#define OB_MODE_ALL_WEIGHT_PAINT
#define XRAY_FLAG_ENABLED(v3d)
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
Definition BLI_map.hh:620
detail::PassBase< command::DrawCommandBuf > Sub
Definition draw_pass.hh:509
static bool is_pose_mode(const Object *armature_ob, const State &state)
static void draw_armature_pose(Armatures::DrawContext *ctx)
DrawContext create_draw_context(const ObjectRef &ob_ref, Resources &res, const State &state, eArmatureDrawMode draw_mode)
void begin_sync(Resources &res, const State &state) final
Armatures(const SelectionType selection_type)
void edit_object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
static void draw_armature_edit(Armatures::DrawContext *ctx)
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
void end_sync(Resources &res, const State &) final
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
const int state
select::SelectionType SelectionType
detail::Pass< command::DrawCommandBuf > PassSimple
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
UserDef U
Definition blender.cc:58
@ GPU_PRIM_LINE_STRIP
@ ARM_DRAW_RELATION_FROM_HEAD
@ CTX_MODE_PAINT_WEIGHT
T & DRW_object_get_data_for_drawing(const Object &object)
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
@ USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE
@ DRW_STATE_CULL_BACK
Definition draw_state.hh:45
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:32
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:57
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:31
@ DRW_STATE_BLEND_ADD
Definition draw_state.hh:53
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:40
@ DRW_STATE_CULL_FRONT
Definition draw_state.hh:46
eArmature_Drawtype drawtype
const float4 & object_wire_color(const ObjectRef &ob_ref, ThemeColorID theme_id) const