Blender V5.0
draw_debug.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
15
16#pragma once
17
19#include "BLI_mutex.hh"
20
21#include "DNA_object_types.h"
22
23#include "draw_shader_shared.hh"
24
25#include "DRW_gpu_wrapper.hh"
26
27namespace blender::draw {
28
29class View;
30
37void drw_debug_clear();
38
39/* Used for virtually infinite lifetime.
40 * Useful for debugging render or baking jobs, or non-modal operators. */
42
64
65void drw_debug_line(float3 v1, float3 v2, float4 color = {1, 0, 0, 1}, uint lifetime = 1);
66
67void drw_debug_polygon(Span<float3> face_verts, float4 color = {1, 0, 0, 1}, uint lifetime = 1);
68
69void drw_debug_bbox(const BoundBox &bbox, float4 color = {1, 0, 0, 1}, uint lifetime = 1);
70
71void drw_debug_sphere(float3 center, float radius, float4 color = {1, 0, 0, 1}, uint lifetime = 1);
73void drw_debug_point(float3 pos, float rad = 0.01f, float4 col = {1, 0, 0, 1}, uint lifetime = 1);
75void drw_debug_matrix(const float4x4 &m4, uint lifetime = 1);
77void drw_debug_matrix_as_bbox(const float4x4 &mat, float4 color = {1, 0, 0, 1}, uint lifetime = 1);
78
79class DebugDraw {
80 private:
81 using DebugDrawBuf = StorageBuffer<DRWDebugDrawBuffer>;
82
87 std::atomic<int> vertex_len_;
89 SwapChain<DebugDrawBuf *, 2> cpu_draw_buf_ = {};
90 SwapChain<DebugDrawBuf *, 2> gpu_draw_buf_ = {};
92 bool gpu_draw_buf_used = false;
93
94 /* Reference counter used by GPUContext to allow freeing of DebugDrawBuf before the last
95 * context is destroyed. */
96 int ref_count_ = 0;
97 Mutex ref_count_mutex_;
98
99 public:
100 void reset();
101
107
110
111 void acquire()
112 {
113 std::scoped_lock lock(ref_count_mutex_);
114 ref_count_++;
115 if (ref_count_ == 1) {
116 reset();
117 }
118 }
119
120 void release()
121 {
122 std::scoped_lock lock(ref_count_mutex_);
123 ref_count_--;
124 if (ref_count_ == 0) {
125 clear_gpu_data();
126 }
127 }
128
129 static DebugDraw &get()
130 {
131 static DebugDraw module;
132 return module;
133 }
134
135 void draw_line(float3 v1, float3 v2, uint color, uint lifetime = 1);
136
138
139 private:
140 void display_lines(View &view);
141
142 void clear_gpu_data();
143};
144
145} // namespace blender::draw
unsigned int uint
Object is a sort of wrapper for general info.
static AppView * view
volatile int lock
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static uint color_pack(float4 color)
void display_to_view(View &view)
static DebugDraw & get()
gpu::StorageBuf * gpu_draw_buf_get()
Definition draw_debug.cc:57
void draw_line(float3 v1, float3 v2, uint color, uint lifetime=1)
uint pos
uint col
constexpr uint drw_debug_persistent_lifetime
Definition draw_debug.hh:41
void drw_debug_bbox(const BoundBox &bbox, const float4 color, const uint lifetime)
void drw_debug_matrix_as_bbox(const float4x4 &mat, const float4 color, const uint lifetime)
void drw_debug_sphere(const float3 center, float radius, const float4 color, const uint lifetime)
void drw_debug_matrix(const float4x4 &m4, const uint lifetime)
void drw_debug_line(const float3 v1, const float3 v2, const float4 color, const uint lifetime)
Definition draw_debug.cc:89
void drw_debug_polygon(Span< float3 > face_verts, const float4 color, const uint lifetime)
Definition draw_debug.cc:95
void drw_debug_clear()
Definition draw_debug.cc:78
void drw_debug_point(const float3 pos, float rad, const float4 col, const uint lifetime)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
std::mutex Mutex
Definition BLI_mutex.hh:47
VecBase< float, 3 > float3
static struct PyModuleDef module
Definition python.cpp:796