DRW: Guard debug lib using defines

This allows adding debug calls to library
sources and not trigger an error for
all shaders that reference the lib.
The particular shader that need to use
it can set `drw_debug_print_enable` and
`drw_debug_draw_enable` in their main file
and it will trigger the injection of the
debug functions.
This commit is contained in:
Clément Foucault
2023-08-20 16:48:46 +02:00
parent 39a40d6f84
commit b4b5977aed
3 changed files with 14 additions and 5 deletions

View File

@@ -6,6 +6,8 @@
* will be rendered in the default view. No additional setup required.
*/
#ifdef DRW_DEBUG_DRAW
/** Global switch option. */
bool drw_debug_draw_enable = true;
const vec4 drw_debug_default_color = vec4(1.0, 0.0, 0.0, 1.0);
@@ -212,4 +214,6 @@ void drw_debug_matrix_as_bbox(mat4 mat)
drw_debug_matrix_as_bbox(mat, drw_debug_default_color);
}
#endif
/** \} */

View File

@@ -30,6 +30,8 @@
* in sync to write the same data.
*/
#ifdef DRW_DEBUG_PRINT
/** Global switch option when you want to silence all prints from all shaders at once. */
bool drw_debug_print_enable = true;
@@ -202,7 +204,7 @@ void drw_print_value(int value)
drw_print_value_uint(uint(abs(value)), false, (value < 0), false);
}
#ifndef GPU_METAL
# ifndef GPU_METAL
void drw_print_value(bool value)
{
@@ -214,7 +216,7 @@ void drw_print_value(bool value)
}
}
#endif
# endif
/* NOTE(@fclem): This is homebrew and might not be 100% accurate (accuracy has
* not been tested and might dependent on compiler implementation). If unsure,
@@ -290,8 +292,7 @@ void drw_print_value(float val)
}
/* Decimal part. */
value = uint(abs(dec_part));
#if 0 /* We don't do that because it makes unstable values really hard to \
read. */
# if 0 /* We don't do that because it makes unstable values really hard to read. */
/* Trim trailing zeros. */
while ((value % base) == 0u) {
value /= base;
@@ -299,7 +300,7 @@ void drw_print_value(float val)
break;
}
}
#endif
# endif
if (value != 0u) {
for (int i = 0; value != 0u || i == 0; i++, value /= base) {
drw_print_append_digit(value % base, digits[digit / 4u]);
@@ -409,3 +410,5 @@ void drw_print_value(mat3 value)
drw_print(" ", value[2]);
drw_print(")");
}
#endif

View File

@@ -12,6 +12,7 @@
* \{ */
GPU_SHADER_CREATE_INFO(draw_debug_print)
.define("DRW_DEBUG_PRINT")
.typedef_source("draw_shader_shared.h")
.storage_buf(DRW_DEBUG_PRINT_SLOT, Qualifier::READ_WRITE, "uint", "drw_debug_print_buf[]");
@@ -37,6 +38,7 @@ GPU_SHADER_CREATE_INFO(draw_debug_print_display)
* \{ */
GPU_SHADER_CREATE_INFO(draw_debug_draw)
.define("DRW_DEBUG_DRAW")
.typedef_source("draw_shader_shared.h")
.storage_buf(DRW_DEBUG_DRAW_SLOT,
Qualifier::READ_WRITE,