String drawing function for the "simdebug" utilities.
Simple string drawing API for debug drawing, in addition to basic primitives.
This commit is contained in:
@@ -172,6 +172,7 @@ typedef struct SimDebugElement {
|
|||||||
float color[3];
|
float color[3];
|
||||||
|
|
||||||
float v1[3], v2[3];
|
float v1[3], v2[3];
|
||||||
|
char str[64];
|
||||||
} SimDebugElement;
|
} SimDebugElement;
|
||||||
|
|
||||||
typedef enum eSimDebugElement_Type {
|
typedef enum eSimDebugElement_Type {
|
||||||
@@ -179,6 +180,7 @@ typedef enum eSimDebugElement_Type {
|
|||||||
SIM_DEBUG_ELEM_CIRCLE,
|
SIM_DEBUG_ELEM_CIRCLE,
|
||||||
SIM_DEBUG_ELEM_LINE,
|
SIM_DEBUG_ELEM_LINE,
|
||||||
SIM_DEBUG_ELEM_VECTOR,
|
SIM_DEBUG_ELEM_VECTOR,
|
||||||
|
SIM_DEBUG_ELEM_STRING,
|
||||||
} eSimDebugElement_Type;
|
} eSimDebugElement_Type;
|
||||||
|
|
||||||
typedef struct SimDebugData {
|
typedef struct SimDebugData {
|
||||||
@@ -191,26 +193,30 @@ void BKE_sim_debug_data_set_enabled(bool enable);
|
|||||||
bool BKE_sim_debug_data_get_enabled(void);
|
bool BKE_sim_debug_data_get_enabled(void);
|
||||||
void BKE_sim_debug_data_free(void);
|
void BKE_sim_debug_data_free(void);
|
||||||
|
|
||||||
void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3],
|
void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], const char *str,
|
||||||
float r, float g, float b, const char *category, unsigned int hash);
|
float r, float g, float b, const char *category, unsigned int hash);
|
||||||
void BKE_sim_debug_data_remove_element(unsigned int hash);
|
void BKE_sim_debug_data_remove_element(unsigned int hash);
|
||||||
|
|
||||||
#define BKE_sim_debug_data_add_dot(p, r, g, b, category, ...) { \
|
#define BKE_sim_debug_data_add_dot(p, r, g, b, category, ...) { \
|
||||||
const float v2[3] = { 0.0f, 0.0f, 0.0f }; \
|
const float v2[3] = { 0.0f, 0.0f, 0.0f }; \
|
||||||
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_DOT, p, v2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_DOT, p, v2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BKE_sim_debug_data_add_circle(p, radius, r, g, b, category, ...) { \
|
#define BKE_sim_debug_data_add_circle(p, radius, r, g, b, category, ...) { \
|
||||||
const float v2[3] = { radius, 0.0f, 0.0f }; \
|
const float v2[3] = { radius, 0.0f, 0.0f }; \
|
||||||
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_CIRCLE, p, v2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_CIRCLE, p, v2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BKE_sim_debug_data_add_line(p1, p2, r, g, b, category, ...) { \
|
#define BKE_sim_debug_data_add_line(p1, p2, r, g, b, category, ...) { \
|
||||||
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_LINE, p1, p2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_LINE, p1, p2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BKE_sim_debug_data_add_vector(p, d, r, g, b, category, ...) { \
|
#define BKE_sim_debug_data_add_vector(p, d, r, g, b, category, ...) { \
|
||||||
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_VECTOR, p, d, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_VECTOR, p, d, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BKE_sim_debug_data_add_string(p, str, r, g, b, category, ...) { \
|
||||||
|
BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_STRING, p, NULL, str, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BKE_sim_debug_data_remove(...) \
|
#define BKE_sim_debug_data_remove(...) \
|
||||||
|
@@ -1130,7 +1130,7 @@ static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem)
|
|||||||
BLI_ghash_insert(debug_data->gh, elem, elem);
|
BLI_ghash_insert(debug_data->gh, elem, elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], float r, float g, float b, const char *category, unsigned int hash)
|
void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], const char *str, float r, float g, float b, const char *category, unsigned int hash)
|
||||||
{
|
{
|
||||||
unsigned int category_hash = BLI_ghashutil_strhash_p(category);
|
unsigned int category_hash = BLI_ghashutil_strhash_p(category);
|
||||||
SimDebugElement *elem;
|
SimDebugElement *elem;
|
||||||
@@ -1149,8 +1149,18 @@ void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[
|
|||||||
elem->color[0] = r;
|
elem->color[0] = r;
|
||||||
elem->color[1] = g;
|
elem->color[1] = g;
|
||||||
elem->color[2] = b;
|
elem->color[2] = b;
|
||||||
copy_v3_v3(elem->v1, v1);
|
if (v1)
|
||||||
copy_v3_v3(elem->v2, v2);
|
copy_v3_v3(elem->v1, v1);
|
||||||
|
else
|
||||||
|
zero_v3(elem->v1);
|
||||||
|
if (v2)
|
||||||
|
copy_v3_v3(elem->v2, v2);
|
||||||
|
else
|
||||||
|
zero_v3(elem->v2);
|
||||||
|
if (str)
|
||||||
|
BLI_strncpy(elem->str, str, sizeof(elem->str));
|
||||||
|
else
|
||||||
|
elem->str[0] = '\0';
|
||||||
|
|
||||||
debug_data_insert(_sim_debug_data, elem);
|
debug_data_insert(_sim_debug_data, elem);
|
||||||
}
|
}
|
||||||
|
@@ -136,9 +136,23 @@ static void draw_sim_debug_elements(SimDebugData *debug_data, float imat[4][4])
|
|||||||
glVertex3f(t[0], t[1], t[2]);
|
glVertex3f(t[0], t[1], t[2]);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
|
/**** strings ****/
|
||||||
|
|
||||||
|
for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
|
||||||
|
SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
|
||||||
|
if (elem->type != SIM_DEBUG_ELEM_STRING)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
unsigned char col[4];
|
||||||
|
rgb_float_to_uchar(col, elem->color);
|
||||||
|
col[3] = 255;
|
||||||
|
view3d_cached_text_draw_add(elem->v1, elem->str, strlen(elem->str),
|
||||||
|
0, V3D_CACHE_TEXT_GLOBALSPACE, col);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_sim_debug_data(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar)
|
void draw_sim_debug_data(Scene *UNUSED(scene), View3D *v3d, ARegion *ar)
|
||||||
{
|
{
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
/*Object *ob = base->object;*/
|
/*Object *ob = base->object;*/
|
||||||
@@ -153,9 +167,11 @@ void draw_sim_debug_data(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar)
|
|||||||
// glEnable(GL_BLEND);
|
// glEnable(GL_BLEND);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glLoadMatrixf(rv3d->viewmat);
|
glLoadMatrixf(rv3d->viewmat);
|
||||||
|
|
||||||
|
view3d_cached_text_draw_begin();
|
||||||
draw_sim_debug_elements(_sim_debug_data, imat);
|
draw_sim_debug_elements(_sim_debug_data, imat);
|
||||||
|
view3d_cached_text_draw_end(v3d, ar, false, NULL);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user