3 This file is part of NetVis
4 Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
5 Distributed unter the GPL
8 #include <msp/gl/extension.h>
9 #include <msp/gl/immediate.h>
10 #include <msp/gl/matrix.h>
11 #include <msp/gl/meshbuilder.h>
12 #include <msp/gl/misc.h>
13 #include <msp/strings/format.h>
14 #include <msp/time/units.h>
21 History::History(NetVis &n, unsigned w, unsigned h):
27 mesh((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2))
29 unsigned texw = height;
30 unsigned texh = width;
31 if(!GL::is_supported("ARB_texture_non_power_of_two"))
33 for(texw=1; texw<height; texw<<=1) ;
34 for(texh=1; texh<width; texh<<=1) ;
36 texture.storage(GL::RGBA, texw, texh);
37 texture.image(0, GL::RGBA, GL::UNSIGNED_BYTE, 0);
38 texture.set_min_filter(GL::LINEAR);
39 float wf = static_cast<float>(height)/texw;
40 float hf = static_cast<float>(width)/texh;
41 GL::MeshBuilder bld(mesh);
42 bld.color(1.0f, 1.0f, 1.0f);
49 bld.vertex(width, height);
51 bld.vertex(0, height);
55 void History::activity(unsigned down, unsigned up)
61 void History::tick(const Time::TimeStamp &t)
67 next_push += Time::sec;
69 next_push = t+Time::sec;
72 for(unsigned i=0; i<width; ++i)
74 const Bandwidth &bw = buffer.get(i);
75 m = max(m, max(bw.down, bw.up));
91 void History::render() const
97 unsigned value = scale;
108 GL::MatrixStack::Push push_(GL::MatrixStack::modelview());
109 GL::MatrixStack::modelview() *= GL::Matrix::translation(width+5, height-10, 0);
110 GL::MatrixStack::modelview() *= GL::Matrix::scaling(10);
111 netvis.get_font().draw_string(format("%d%c", value, suffix));
112 GL::MatrixStack::modelview() *= GL::Matrix::translation(0, (height-12)*-0.05, 0);
113 netvis.get_font().draw_string(format("%g%c", value*0.5, suffix));
114 GL::MatrixStack::modelview() *= GL::Matrix::translation(0, (height-12)*-0.05, 0);
115 netvis.get_font().draw_string(format("0%c", suffix));
116 GL::Texture::unbind();
119 void History::create_texture()
121 vector<unsigned> data(width*height);
122 for(unsigned y=0; y<width; ++y)
124 const Bandwidth &bw = buffer.get(y);
125 unsigned down = bw.down*height/scale;
126 unsigned up = bw.up*height/scale;
127 unsigned up_min = up;
128 unsigned up_max = up;
131 unsigned value = (up+buffer.get(y-1).up*height/scale)/2;
132 up_min = min(value+1, up_min);
133 up_max = max(value, up_max);
137 unsigned value = (up+buffer.get(y+1).up*height/scale)/2;
138 up_min = min(value+1, up_min);
139 up_max = max(value, up_max);
141 unsigned *row = &data[y*height];
142 for(unsigned x=0; x<height; ++x)
144 if(x>=up_min && x<=up_max)
148 else if((x*4+4)%height==0 || y%60==0)
154 texture.sub_image(0, 0, 0, height, width, GL::RGBA, GL::UNSIGNED_BYTE, data.data());
158 History::Bandwidth::Bandwidth():