Browse Source

added new graph style

shared-context
Moritz Kassner 10 years ago
parent
commit
b112ce00b7
2 changed files with 18 additions and 1 deletions
  1. +17
    -1
      example/perf.c
  2. +1
    -0
      example/perf.h

+ 17
- 1
example/perf.c View File

@@ -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);


+ 1
- 0
example/perf.h View File

@@ -10,6 +10,7 @@ extern "C" {
enum GraphrenderStyle {
GRAPH_RENDER_FPS,
GRAPH_RENDER_MS,
GRAPH_RENDER_PERCENT,
};

#define GRAPH_HISTORY_COUNT 100


Loading…
Cancel
Save