Blender V4.3
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
16#pragma once
17
19#include "BLI_string_ref.hh"
20#include "BLI_vector.hh"
21#include "DNA_object_types.h"
22#include "DRW_gpu_wrapper.hh"
23
24namespace blender::draw {
25
26/* Shortcuts to avoid boilerplate code and match shader API. */
27#define drw_debug_line(...) DRW_debug_get()->draw_line(__VA_ARGS__)
28#define drw_debug_polygon(...) DRW_debug_get()->draw_polygon(__VA_ARGS__)
29#define drw_debug_bbox(...) DRW_debug_get()->draw_bbox(__VA_ARGS__)
30#define drw_debug_sphere(...) DRW_debug_get()->draw_sphere(__VA_ARGS__)
31#define drw_debug_point(...) DRW_debug_get()->draw_point(__VA_ARGS__)
32#define drw_debug_matrix(...) DRW_debug_get()->draw_matrix(__VA_ARGS__)
33#define drw_debug_matrix_as_bbox(...) DRW_debug_get()->draw_matrix_as_bbox(__VA_ARGS__)
34#define drw_print(...) DRW_debug_get()->print(__VA_ARGS__)
35#define drw_print_hex(...) DRW_debug_get()->print_hex(__VA_ARGS__)
36#define drw_print_binary(...) DRW_debug_get()->print_binary(__VA_ARGS__)
37#define drw_print_no_endl(...) DRW_debug_get()->print_no_endl(__VA_ARGS__)
38
39/* Will log variable along with its name, like the shader version of print(). */
40#define drw_print_id(v_) DRW_debug_get()->print(#v_, "= ", v_)
41#define drw_print_id_no_endl(v_) DRW_debug_get()->print_no_endl(#v_, "= ", v_)
42
43class DebugDraw {
44 private:
47
49 DebugDrawBuf cpu_draw_buf_ = {"DebugDrawBuf-CPU"};
50 DebugDrawBuf gpu_draw_buf_ = {"DebugDrawBuf-GPU"};
51 DebugPrintBuf cpu_print_buf_ = {"DebugPrintBuf-CPU"};
52 DebugPrintBuf gpu_print_buf_ = {"DebugPrintBuf-GPU"};
54 bool gpu_print_buf_used = false;
55 bool gpu_draw_buf_used = false;
57 float4x4 model_mat_;
59 Vector<float3> sphere_verts_;
60 Vector<float3> point_verts_;
62 uint print_col_ = 0;
63 uint print_row_ = 0;
64
65 public:
66 DebugDraw();
68
73 void init();
74
78 void modelmat_reset();
82 void modelmat_set(const float modelmat[4][4]);
83
87 void draw_line(float3 v1, float3 v2, float4 color = {1, 0, 0, 1});
88 void draw_polygon(Span<float3> face_verts, float4 color = {1, 0, 0, 1});
89 void draw_bbox(const BoundBox &bbox, const float4 color = {1, 0, 0, 1});
90 void draw_sphere(const float3 center, float radius, const float4 color = {1, 0, 0, 1});
91 void draw_point(const float3 center, float radius = 0.01f, const float4 color = {1, 0, 0, 1});
95 void draw_matrix(const float4x4 &m4);
99 void draw_matrix_as_bbox(const float4x4 &mat, const float4 color = {1, 0, 0, 1});
100
105 void display_to_view();
106
112 template<typename... Ts> void print(StringRefNull str, Ts... args)
113 {
114 print_no_endl(str, args...);
115 print_newline();
116 }
117 template<typename T> void print(const T &value)
118 {
119 print_value(value);
120 print_newline();
121 }
122 template<typename T> void print_hex(const T &value)
123 {
124 print_value_hex(value);
125 print_newline();
126 }
127 template<typename T> void print_binary(const T &value)
128 {
129 print_value_binary(value);
130 print_newline();
131 }
132
136 void print_no_endl(std::string arg)
137 {
138 print_string(arg);
139 }
141 {
142 print_string(arg);
143 }
145 {
146 print_string(arg);
147 }
148 void print_no_endl(char const *arg)
149 {
150 print_string(StringRefNull(arg));
151 }
152 template<typename T> void print_no_endl(T arg)
153 {
154 print_value(arg);
155 }
156 template<typename T, typename... Ts> void print_no_endl(T arg, Ts... args)
157 {
158 print_no_endl(arg);
159 print_no_endl(args...);
160 }
161
165 GPUStorageBuf *gpu_draw_buf_get();
166 GPUStorageBuf *gpu_print_buf_get();
167
168 private:
169 uint color_pack(float4 color);
170 DRWDebugVert vert_pack(float3 pos, uint color);
171
172 void draw_line(float3 v1, float3 v2, uint color);
173
174 void print_newline();
175 void print_string_start(uint len);
176 void print_string(std::string str);
177 void print_char4(uint data);
178 void print_append_char(uint char1, uint &char4);
179 void print_append_digit(uint digit, uint &char4);
180 void print_append_space(uint &char4);
181 void print_value_binary(uint value);
182 void print_value_uint(uint value, const bool hex, bool is_negative, const bool is_unsigned);
183
184 template<typename T> void print_value(const T &value);
185 template<typename T> void print_value_hex(const T &value);
186 template<typename T> void print_value_binary(const T &value);
187
188 void display_lines();
189 void display_prints();
190};
191
192} // namespace blender::draw
193
unsigned int uint
Object is a sort of wrapper for general info.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void print_no_endl(T arg, Ts... args)
void modelmat_set(const float modelmat[4][4])
void print_no_endl(std::string arg)
void draw_matrix(const float4x4 &m4)
void print_hex(const T &value)
void print(const T &value)
void draw_polygon(Span< float3 > face_verts, float4 color={1, 0, 0, 1})
void print_binary(const T &value)
void print(StringRefNull str, Ts... args)
void draw_matrix_as_bbox(const float4x4 &mat, const float4 color={1, 0, 0, 1})
void print_no_endl(StringRef arg)
void draw_sphere(const float3 center, float radius, const float4 color={1, 0, 0, 1})
void draw_bbox(const BoundBox &bbox, const float4 color={1, 0, 0, 1})
void print_no_endl(char const *arg)
GPUStorageBuf * gpu_print_buf_get()
GPUStorageBuf * gpu_draw_buf_get()
void draw_line(float3 v1, float3 v2, float4 color={1, 0, 0, 1})
void print_no_endl(StringRefNull arg)
void draw_point(const float3 center, float radius=0.01f, const float4 color={1, 0, 0, 1})
blender::draw::DebugDraw * DRW_debug_get()
int len
#define str(s)
#define T
bool is_negative(const MatBase< T, Size, Size > &mat)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
static const char hex[17]
Definition thumbs.cc:159