diff --git a/example/perf.c b/example/perf.c index 27ef417..a74dc3c 100644 --- a/example/perf.c +++ b/example/perf.c @@ -125,6 +125,15 @@ void renderGraph(NVGcontext* vg, float x, float y, PerfGraph* fps) vy = y + h - ((v / 80.0f) * h); nvgLineTo(vg, vx, vy); } + } else if (fps->style == GRAPH_RENDER_PERCENT) { + for (i = 0; i < GRAPH_HISTORY_COUNT; i++) { + float v = fps->values[(fps->head+i) % GRAPH_HISTORY_COUNT] * 1.0f; + float vx, vy; + if (v > 100.0f) v = 100.0f; + vx = x + ((float)i/(GRAPH_HISTORY_COUNT-1)) * w; + vy = y + h - ((v / 100.0f) * h); + nvgLineTo(vg, vx, vy); + } } else { for (i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = fps->values[(fps->head+i) % GRAPH_HISTORY_COUNT] * 1000.0f; @@ -154,12 +163,19 @@ void renderGraph(NVGcontext* vg, float x, float y, PerfGraph* fps) nvgFillColor(vg, nvgRGBA(240,240,240,255)); sprintf(str, "%.2f FPS", 1.0f / avg); nvgText(vg, x+w-3,y+1, str, NULL); - + nvgFontSize(vg, 15.0f); nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_BOTTOM); nvgFillColor(vg, nvgRGBA(240,240,240,160)); sprintf(str, "%.2f ms", avg * 1000.0f); nvgText(vg, x+w-3,y+h-1, str, NULL); + } + else if (fps->style == GRAPH_RENDER_PERCENT) { + nvgFontSize(vg, 18.0f); + nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_TOP); + nvgFillColor(vg, nvgRGBA(240,240,240,255)); + sprintf(str, "%.1f %%", avg * 1.0f); + nvgText(vg, x+w-3,y+1, str, NULL); } else { nvgFontSize(vg, 18.0f); nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_TOP); diff --git a/example/perf.h b/example/perf.h index 25e3284..3ca67b2 100644 --- a/example/perf.h +++ b/example/perf.h @@ -10,6 +10,7 @@ extern "C" { enum GraphrenderStyle { GRAPH_RENDER_FPS, GRAPH_RENDER_MS, + GRAPH_RENDER_PERCENT, }; #define GRAPH_HISTORY_COUNT 100