27#if defined(_DEBUG) || defined(WITH_DRAW_DEBUG)
42 constexpr int circle_resolution = 16;
44 for (
auto edge :
IndexRange(circle_resolution)) {
46 const float angle = (2 *
M_PI) * (edge + vert) /
float(circle_resolution);
47 const float point[3] = {
cosf(angle),
sinf(angle), 0.0f};
49 float3(point[(0 + axis) % 3], point[(1 + axis) % 3], point[(2 + axis) % 3]));
54 constexpr int point_resolution = 4;
56 for (
auto edge :
IndexRange(point_resolution)) {
58 const float angle = (2 *
M_PI) * (edge + vert) /
float(point_resolution);
59 const float point[3] = {
cosf(angle),
sinf(angle), 0.0f};
61 float3(point[(0 + axis) % 3], point[(1 + axis) % 3], point[(2 + axis) % 3]));
83 gpu_print_buf_used =
false;
89 gpu_draw_buf_used =
false;
109 if (!gpu_draw_buf_used) {
110 gpu_draw_buf_used =
true;
113 return gpu_draw_buf_;
118 if (!gpu_print_buf_used) {
119 gpu_print_buf_used =
true;
122 return gpu_print_buf_;
142 for (
auto vert : face_verts) {
188 const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {1.0f, 1.0f, 1.0f};
199 for (
auto i :
IndexRange(sphere_verts_.size() / 2)) {
200 float3 v0 = sphere_verts_[i * 2] * radius + center;
201 float3 v1 = sphere_verts_[i * 2 + 1] * radius + center;
209 for (
auto i :
IndexRange(point_verts_.size() / 2)) {
210 float3 v0 = point_verts_[i * 2] * radius + center;
211 float3 v1 = point_verts_[i * 2 + 1] * radius + center;
222template<>
void DebugDraw::print_value<uint>(
const uint &value)
224 print_value_uint(value,
false,
false,
true);
226template<>
void DebugDraw::print_value<int>(
const int &value)
228 print_value_uint(
uint(
abs(value)),
false, (value < 0),
false);
230template<>
void DebugDraw::print_value<bool>(
const bool &value)
232 print_string(value ?
"true " :
"false");
234template<>
void DebugDraw::print_value<float>(
const float &val)
236 std::stringstream ss;
237 ss << std::setw(12) << std::to_string(val);
238 print_string(ss.str());
240template<>
void DebugDraw::print_value<double>(
const double &val)
242 print_value(
float(val));
245template<>
void DebugDraw::print_value_hex<uint>(
const uint &value)
247 print_value_uint(value,
true,
false,
false);
249template<>
void DebugDraw::print_value_hex<int>(
const int &value)
251 print_value_uint(
uint(value),
true,
false,
false);
253template<>
void DebugDraw::print_value_hex<float>(
const float &value)
255 print_value_uint(*
reinterpret_cast<const uint *
>(&value),
true,
false,
false);
257template<>
void DebugDraw::print_value_hex<double>(
const double &val)
259 print_value_hex(
float(val));
262template<>
void DebugDraw::print_value_binary<uint>(
const uint &value)
264 print_value_binary(value);
266template<>
void DebugDraw::print_value_binary<int>(
const int &value)
268 print_value_binary(
uint(value));
270template<>
void DebugDraw::print_value_binary<float>(
const float &value)
272 print_value_binary(*
reinterpret_cast<const uint *
>(&value));
274template<>
void DebugDraw::print_value_binary<double>(
const double &val)
276 print_value_binary(
float(val));
279template<>
void DebugDraw::print_value<float2>(
const float2 &value)
283template<>
void DebugDraw::print_value<float3>(
const float3 &value)
285 print_no_endl(
"float3(", value[0],
", ", value[1],
", ", value[1],
")");
287template<>
void DebugDraw::print_value<float4>(
const float4 &value)
289 print_no_endl(
"float4(", value[0],
", ", value[1],
", ", value[2],
", ", value[3],
")");
292template<>
void DebugDraw::print_value<int2>(
const int2 &value)
296template<>
void DebugDraw::print_value<int3>(
const int3 &value)
298 print_no_endl(
"int3(", value[0],
", ", value[1],
", ", value[1],
")");
300template<>
void DebugDraw::print_value<int4>(
const int4 &value)
302 print_no_endl(
"int4(", value[0],
", ", value[1],
", ", value[2],
", ", value[3],
")");
305template<>
void DebugDraw::print_value<uint2>(
const uint2 &value)
309template<>
void DebugDraw::print_value<uint3>(
const uint3 &value)
311 print_no_endl(
"uint3(", value[0],
", ", value[1],
", ", value[1],
")");
313template<>
void DebugDraw::print_value<uint4>(
const uint4 &value)
315 print_no_endl(
"uint4(", value[0],
", ", value[1],
", ", value[2],
", ", value[3],
")");
329 DebugDrawBuf &buf = cpu_draw_buf_;
334 buf.command.vertex_len += 2;
344 result |=
uint(color.x * 255.0f) << 0u;
345 result |=
uint(color.y * 255.0f) << 8u;
346 result |=
uint(color.z * 255.0f) << 16u;
347 result |=
uint(color.w * 255.0f) << 24u;
361void DebugDraw::print_newline()
367void DebugDraw::print_string_start(
uint len)
376void DebugDraw::print_string(std::string
str)
378 size_t len_before_pad =
str.length();
380 while (
str.length() % 4 != 0) {
384 print_string_start(len_before_pad);
385 for (
size_t i = 0; i < len_before_pad; i += 4) {
391 chars[0] = *(
reinterpret_cast<const uint8_t *
>(
str.c_str()) + i + 0);
392 chars[1] = *(
reinterpret_cast<const uint8_t *
>(
str.c_str()) + i + 1);
393 chars[2] = *(
reinterpret_cast<const uint8_t *
>(
str.c_str()) + i + 2);
394 chars[3] = *(
reinterpret_cast<const uint8_t *
>(
str.c_str()) + i + 3);
396 if (i + 4 > len_before_pad) {
397 chars[len_before_pad - i] =
'\0';
404void DebugDraw::print_char4(
uint data)
407 for (; data != 0u; data >>= 8u) {
408 uint char1 = data & 0xFFu;
419 uint print_header = (flags << 24u) | (print_row_ << 16u) | (
col << 8u);
420 cpu_print_buf_.
char_array[cursor] = print_header | char1;
436 const uint char_A = 0x41u;
437 const uint char_0 = 0x30u;
438 bool is_hexadecimal = digit > 9u;
439 char4 = (
char4 << 8u) | (is_hexadecimal ? (char_A + digit - 10u) : (char_0 + digit));
442void DebugDraw::print_append_space(
uint &
char4)
447void DebugDraw::print_value_binary(
uint value)
450 print_string_start(10u * 4u);
451 uint digits[10] = {0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
453 for (
uint i = 0u; i < 32u; i++) {
454 print_append_digit(((value >> i) & 1u), digits[digit / 4u]);
456 if ((i % 4u) == 3u) {
457 print_append_space(digits[digit / 4u]);
462 for (
int j = 9; j >= 0; j--) {
463 print_char4(digits[j]);
467void DebugDraw::print_value_uint(
uint value,
470 const bool is_unsigned)
472 print_string_start(3u * 4u);
473 const uint blank_value =
hex ? 0x30303030u : 0x20202020u;
474 const uint prefix =
hex ? 0x78302020u : 0x20202020u;
475 uint digits[3] = {blank_value, blank_value, prefix};
476 const uint base =
hex ? 16u : 10u;
480 print_append_char(
'u', digits[digit / 4u]);
484 for (; value != 0u || digit ==
uint(is_unsigned); value /= base) {
485 print_append_digit(value % base, digits[digit / 4u]);
490 print_append_char(
'-', digits[digit / 4u]);
494 for (
uint i = digit % 4u; i < 4u && i > 0u; i++) {
495 print_append_space(digits[digit / 4u]);
499 for (
int j = 2; j >= 0; j--) {
500 print_char4(digits[j]);
510void DebugDraw::display_lines()
529 if (gpu_draw_buf_used) {
546void DebugDraw::display_prints()
563 if (gpu_print_buf_used) {
General operations, lookup, etc. for blender objects.
void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float max[3])
Single link-list utility macros. (header only api).
void mul_project_m4_v3(const float mat[4][4], float vec[3])
void GPU_batch_draw_indirect(blender::gpu::Batch *batch, GPUStorageBuf *indirect_buf, intptr_t offset)
void GPU_batch_set_shader(blender::gpu::Batch *batch, GPUShader *shader)
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
void GPU_viewport_size_get_f(float coords[4])
void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot)
void GPU_storagebuf_unbind(GPUStorageBuf *ssbo)
struct GPUShader GPUShader
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
constexpr const T & last(const int64_t n=0) const
constexpr bool is_empty() const
void modelmat_set(const float modelmat[4][4])
void print_no_endl(std::string arg)
void draw_matrix(const float4x4 &m4)
void draw_polygon(Span< float3 > face_verts, float4 color={1, 0, 0, 1})
void draw_matrix_as_bbox(const float4x4 &mat, const float4 color={1, 0, 0, 1})
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})
GPUStorageBuf * gpu_print_buf_get()
GPUStorageBuf * gpu_draw_buf_get()
void draw_line(float3 v1, float3 v2, float4 color={1, 0, 0, 1})
void draw_point(const float3 center, float radius=0.01f, const float4 color={1, 0, 0, 1})
blender::gpu::Batch * drw_cache_procedural_lines_get()
blender::gpu::Batch * drw_cache_procedural_points_get()
GPUStorageBuf * drw_debug_gpu_print_buf_get()
void DRW_debug_modelmat(const float modelmat[4][4])
blender::draw::DebugDraw * DRW_debug_get()
void DRW_debug_sphere(const float center[3], float radius, const float color[4])
void DRW_debug_m4(const float m[4][4])
void drw_debug_module_free(DRWDebugModule *module)
void DRW_debug_line_v3v3(const float v1[3], const float v2[3], const float color[4])
void DRW_debug_modelmat_reset()
void DRW_debug_bbox(const BoundBox *bbox, const float color[4])
GPUStorageBuf * drw_debug_gpu_draw_buf_get()
void DRW_debug_polygon_v3(const float(*v)[3], int vert_len, const float color[4])
void DRW_debug_m4_as_bbox(const float m[4][4], bool invert, const float color[4])
Simple API to draw debug shapes and log in the viewport.
Simple API to draw debug shapes in the viewport. IMPORTANT: This is the legacy API for C....
#define DRW_DEBUG_DRAW_SLOT
#define DRW_DEBUG_PRINT_SLOT
void drw_state_set(DRWState state)
void DRW_view_persmat_get(const DRWView *view, float mat[4][4], bool inverse)
const DRWView * DRW_view_get_active()
GPUShader * DRW_shader_debug_draw_display_get()
GPUShader * DRW_shader_debug_print_display_get()
#define DRW_DEBUG_PRINT_WORD_WRAP_COLUMN
#define DRW_DEBUG_PRINT_MAX
#define DRW_DEBUG_DRAW_VERT_MAX
@ DRW_STATE_PROGRAM_POINT_SIZE
draw_view in_light_buf[] float
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
T clamp(const T &a, const T &min, const T &max)
bool is_negative(const MatBase< T, Size, Size > &mat)
CartesianBasis invert(const CartesianBasis &basis)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
blender::VecBase< int8_t, 4 > char4
MatView< float, 4, 4, 4, 4, 0, 0, alignof(float)> float4x4_view
VecBase< float, 3 > float3
static struct PyModuleDef module
uint char_array[DRW_DEBUG_PRINT_MAX]
uint instance_first_array
const c_style_mat & ptr() const
static MatBase identity()
static const char hex[17]