source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.cpp @ 2834

Revision 2834, 2.3 KB checked in by mattausch, 16 years ago (diff)

research version: implemented temporal smoothing and color bleeding

Line 
1#include "PerformanceGraph.h"
2#include "glInterface.h"
3
4
5PerformanceGraph::PerformanceGraph(int maxData):
6mMaxData(maxData), mCurrentIdx(0)
7{
8        mGraphColor[0] = 1.0f;
9        mGraphColor[1] = 0.0f;
10        mGraphColor[2] = 0.0f;
11}
12
13       
14void PerformanceGraph::DrawBackGround()
15{
16        glEnable(GL_BLEND);
17        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
18
19        glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
20
21        // show a grid
22        glBegin(GL_QUADS);
23        glVertex3f(0, 0, 0.0f);
24        glVertex3f(1, 0, 0.0f);
25        glVertex3f(1, 1, 0.0f);
26        glVertex3f(0, 1, 0.0f);
27        glEnd();
28
29        glDisable(GL_BLEND);
30}
31
32
33void PerformanceGraph::DrawGrid()
34{
35        glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
36
37        // show a grid
38        glBegin(GL_LINE_LOOP);
39        glVertex3f(0, 0, 0.0f);
40        glVertex3f(1, 0, 0.0f);
41        glVertex3f(1, 1, 0.0f);
42        glVertex3f(0, 1, 0.0f);
43        glEnd();
44}
45
46
47void PerformanceGraph::Draw()
48{
49        glPushAttrib(GL_ALL_ATTRIB_BITS);
50
51        glLineWidth(2);
52        glDisable(GL_DEPTH_TEST);
53
54        glDisable(GL_LIGHTING);
55        glDisable(GL_TEXTURE_2D);
56
57        // init ortographic projection
58        glMatrixMode(GL_PROJECTION);
59        glPushMatrix();
60        glLoadIdentity();
61
62        gluOrtho2D(0, 1.0f, 0, 1.0f);
63
64        glMatrixMode(GL_MODELVIEW);
65        glPushMatrix();
66        glLoadIdentity();
67       
68        glTranslatef(0.668f, 0.668f, 0.0f);
69        glScalef(0.33f, 0.33f, 1.0f);
70
71        DrawBackGround();
72        DrawCurve();
73        DrawGrid();
74
75        // restore the projection matrix
76        glMatrixMode(GL_PROJECTION);
77        glPopMatrix();
78
79        glMatrixMode(GL_MODELVIEW);
80        glPopMatrix();
81
82        glPopAttrib();
83}
84
85
86void PerformanceGraph::DrawCurve()
87{
88        const float scalex = 1.0f / mMaxData;
89        const float scaley = 1.0f / 50.0f;
90
91        glColor3fv(mGraphColor);
92
93        glBegin(GL_LINE_STRIP);
94
95        for (size_t i = 0; i < mData.size(); ++ i)
96        {
97                const float x = i * scalex;
98                const float y = mData[i] * scaley;
99
100                glVertex3f(x, y, 0.0f);
101        }
102
103        glEnd();
104
105        // show a grid
106        glBegin(GL_LINES);
107        glVertex3f(mCurrentIdx * scalex, 0, 0.0f);
108        glVertex3f(mCurrentIdx * scalex, 1, 0.0f);
109        glEnd();
110}
111
112
113void PerformanceGraph::AddData(float data)
114{
115        if ((int)mData.size() < mMaxData)
116                mData.push_back(data);
117        else
118                mData[mCurrentIdx]= data;
119
120        mCurrentIdx = (mCurrentIdx + 1) % mMaxData;
121}
122
123
124void PerformanceGraph::Reset()
125{
126        mCurrentIdx = 0;
127        mData.clear();
128}
129
130
131void PerformanceGraph::SetGraphColor(float *col)
132{
133        mGraphColor[0] = col[0];
134        mGraphColor[1] = col[1];
135        mGraphColor[2] = col[2];
136}
Note: See TracBrowser for help on using the repository browser.