Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_debug.cc
| Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | for (auto edge : IndexRange(point_resolution)) { | ||||
| float3(point[(0 + axis) % 3], point[(1 + axis) % 3], point[(2 + axis) % 3])); | float3(point[(0 + axis) % 3], point[(1 + axis) % 3], point[(2 + axis) % 3])); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| void DebugDraw::init() | void DebugDraw::init() | ||||
| { | { | ||||
| cpu_print_buf_.command.v_count = 0; | cpu_print_buf_.command.vertex_len = 0; | ||||
| cpu_print_buf_.command.v_first = 0; | cpu_print_buf_.command.vertex_first = 0; | ||||
| cpu_print_buf_.command.i_count = 1; | cpu_print_buf_.command.instance_len = 1; | ||||
| cpu_print_buf_.command.i_first = 0; | cpu_print_buf_.command.instance_first_array = 0; | ||||
| cpu_draw_buf_.command.v_count = 0; | cpu_draw_buf_.command.vertex_len = 0; | ||||
| cpu_draw_buf_.command.v_first = 0; | cpu_draw_buf_.command.vertex_first = 0; | ||||
| cpu_draw_buf_.command.i_count = 1; | cpu_draw_buf_.command.instance_len = 1; | ||||
| cpu_draw_buf_.command.i_first = 0; | cpu_draw_buf_.command.instance_first_array = 0; | ||||
| gpu_print_buf_.command.v_count = 0; | gpu_print_buf_.command.vertex_len = 0; | ||||
| gpu_print_buf_.command.v_first = 0; | gpu_print_buf_.command.vertex_first = 0; | ||||
| gpu_print_buf_.command.i_count = 1; | gpu_print_buf_.command.instance_len = 1; | ||||
| gpu_print_buf_.command.i_first = 0; | gpu_print_buf_.command.instance_first_array = 0; | ||||
| gpu_print_buf_used = false; | gpu_print_buf_used = false; | ||||
| gpu_draw_buf_.command.v_count = 0; | gpu_draw_buf_.command.vertex_len = 0; | ||||
| gpu_draw_buf_.command.v_first = 0; | gpu_draw_buf_.command.vertex_first = 0; | ||||
| gpu_draw_buf_.command.i_count = 1; | gpu_draw_buf_.command.instance_len = 1; | ||||
| gpu_draw_buf_.command.i_first = 0; | gpu_draw_buf_.command.instance_first_array = 0; | ||||
| gpu_draw_buf_used = false; | gpu_draw_buf_used = false; | ||||
| modelmat_reset(); | modelmat_reset(); | ||||
| } | } | ||||
| void DebugDraw::modelmat_reset() | void DebugDraw::modelmat_reset() | ||||
| { | { | ||||
| model_mat_ = float4x4::identity(); | model_mat_ = float4x4::identity(); | ||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | |||||
| * | * | ||||
| * IMPORTANT: All of these are copied from the shader libs (common_debug_draw_lib.glsl & | * IMPORTANT: All of these are copied from the shader libs (common_debug_draw_lib.glsl & | ||||
| * common_debug_print_lib.glsl). They need to be kept in sync to write the same data. | * common_debug_print_lib.glsl). They need to be kept in sync to write the same data. | ||||
| * \{ */ | * \{ */ | ||||
| void DebugDraw::draw_line(float3 v1, float3 v2, uint color) | void DebugDraw::draw_line(float3 v1, float3 v2, uint color) | ||||
| { | { | ||||
| DebugDrawBuf &buf = cpu_draw_buf_; | DebugDrawBuf &buf = cpu_draw_buf_; | ||||
| uint index = buf.command.v_count; | uint index = buf.command.vertex_len; | ||||
| if (index + 2 < DRW_DEBUG_DRAW_VERT_MAX) { | if (index + 2 < DRW_DEBUG_DRAW_VERT_MAX) { | ||||
| buf.verts[index + 0] = vert_pack(model_mat_ * v1, color); | buf.verts[index + 0] = vert_pack(model_mat_ * v1, color); | ||||
| buf.verts[index + 1] = vert_pack(model_mat_ * v2, color); | buf.verts[index + 1] = vert_pack(model_mat_ * v2, color); | ||||
| buf.command.v_count += 2; | buf.command.vertex_len += 2; | ||||
| } | } | ||||
| } | } | ||||
| /* Keep in sync with drw_debug_color_pack(). */ | /* Keep in sync with drw_debug_color_pack(). */ | ||||
| uint DebugDraw::color_pack(float4 color) | uint DebugDraw::color_pack(float4 color) | ||||
| { | { | ||||
| color = math::clamp(color, 0.0f, 1.0f); | color = math::clamp(color, 0.0f, 1.0f); | ||||
| uint result = 0; | uint result = 0; | ||||
| Show All 12 Lines | DRWDebugVert DebugDraw::vert_pack(float3 pos, uint color) | ||||
| vert.pos2 = *reinterpret_cast<uint32_t *>(&pos.z); | vert.pos2 = *reinterpret_cast<uint32_t *>(&pos.z); | ||||
| vert.color = color; | vert.color = color; | ||||
| return vert; | return vert; | ||||
| } | } | ||||
| void DebugDraw::print_newline() | void DebugDraw::print_newline() | ||||
| { | { | ||||
| print_col_ = 0u; | print_col_ = 0u; | ||||
| print_row_ = ++cpu_print_buf_.command.i_first; | print_row_ = ++cpu_print_buf_.command.instance_first_array; | ||||
| } | } | ||||
| void DebugDraw::print_string_start(uint len) | void DebugDraw::print_string_start(uint len) | ||||
| { | { | ||||
| /* Break before word. */ | /* Break before word. */ | ||||
| if (print_col_ + len > DRW_DEBUG_PRINT_WORD_WRAP_COLUMN) { | if (print_col_ + len > DRW_DEBUG_PRINT_WORD_WRAP_COLUMN) { | ||||
| print_newline(); | print_newline(); | ||||
| } | } | ||||
| Show All 33 Lines | void DebugDraw::print_char4(uint data) | ||||
| /* Convert into char stream. */ | /* Convert into char stream. */ | ||||
| for (; data != 0u; data >>= 8u) { | for (; data != 0u; data >>= 8u) { | ||||
| uint char1 = data & 0xFFu; | uint char1 = data & 0xFFu; | ||||
| /* Check for null terminator. */ | /* Check for null terminator. */ | ||||
| if (char1 == 0x00) { | if (char1 == 0x00) { | ||||
| break; | break; | ||||
| } | } | ||||
| /* NOTE: Do not skip the header manually like in GPU. */ | /* NOTE: Do not skip the header manually like in GPU. */ | ||||
| uint cursor = cpu_print_buf_.command.v_count++; | uint cursor = cpu_print_buf_.command.vertex_len++; | ||||
| if (cursor < DRW_DEBUG_PRINT_MAX) { | if (cursor < DRW_DEBUG_PRINT_MAX) { | ||||
| /* For future usage. (i.e: Color) */ | /* For future usage. (i.e: Color) */ | ||||
| uint flags = 0u; | uint flags = 0u; | ||||
| uint col = print_col_++; | uint col = print_col_++; | ||||
| uint print_header = (flags << 24u) | (print_row_ << 16u) | (col << 8u); | uint print_header = (flags << 24u) | (print_row_ << 16u) | (col << 8u); | ||||
| cpu_print_buf_.char_array[cursor] = print_header | char1; | cpu_print_buf_.char_array[cursor] = print_header | char1; | ||||
| /* Break word. */ | /* Break word. */ | ||||
| if (print_col_ > DRW_DEBUG_PRINT_WORD_WRAP_COLUMN) { | if (print_col_ > DRW_DEBUG_PRINT_WORD_WRAP_COLUMN) { | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Display | /** \name Display | ||||
| * \{ */ | * \{ */ | ||||
| void DebugDraw::display_lines() | void DebugDraw::display_lines() | ||||
| { | { | ||||
| if (cpu_draw_buf_.command.v_count == 0 && gpu_draw_buf_used == false) { | if (cpu_draw_buf_.command.vertex_len == 0 && gpu_draw_buf_used == false) { | ||||
| return; | return; | ||||
| } | } | ||||
| GPU_debug_group_begin("Lines"); | GPU_debug_group_begin("Lines"); | ||||
| cpu_draw_buf_.push_update(); | cpu_draw_buf_.push_update(); | ||||
| float4x4 persmat; | float4x4 persmat; | ||||
| const DRWView *view = DRW_view_get_active(); | const DRWView *view = DRW_view_get_active(); | ||||
| DRW_view_persmat_get(view, persmat.ptr(), false); | DRW_view_persmat_get(view, persmat.ptr(), false); | ||||
| Show All 20 Lines | void DebugDraw::display_lines() | ||||
| GPU_storagebuf_unbind(cpu_draw_buf_); | GPU_storagebuf_unbind(cpu_draw_buf_); | ||||
| GPU_debug_group_end(); | GPU_debug_group_end(); | ||||
| GPU_debug_group_end(); | GPU_debug_group_end(); | ||||
| } | } | ||||
| void DebugDraw::display_prints() | void DebugDraw::display_prints() | ||||
| { | { | ||||
| if (cpu_print_buf_.command.v_count == 0 && gpu_print_buf_used == false) { | if (cpu_print_buf_.command.vertex_len == 0 && gpu_print_buf_used == false) { | ||||
| return; | return; | ||||
| } | } | ||||
| GPU_debug_group_begin("Prints"); | GPU_debug_group_begin("Prints"); | ||||
| cpu_print_buf_.push_update(); | cpu_print_buf_.push_update(); | ||||
| drw_state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_PROGRAM_POINT_SIZE); | drw_state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_PROGRAM_POINT_SIZE); | ||||
| GPUBatch *batch = drw_cache_procedural_points_get(); | GPUBatch *batch = drw_cache_procedural_points_get(); | ||||
| ▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines | |||||