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/formatter.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, 0);
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::PushMatrix push_;
109 GL::translate(width+5, height-10, 0);
110 GL::scale_uniform(10);
111 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
112 imm.color(1.0f, 1.0f, 1.0f);
113 netvis.get_font().draw_string(format("%d%c", value, suffix), imm);
114 GL::translate(0, (height-12)*-0.05, 0);
115 netvis.get_font().draw_string(format("%g%c", value*0.5, suffix), imm);
116 GL::translate(0, (height-12)*-0.05, 0);
117 netvis.get_font().draw_string(format("0%c", suffix), imm);
118 GL::Texture::unbind();
121 void History::create_texture()
123 vector<unsigned> data(width*height);
124 for(unsigned y=0; y<width; ++y)
126 const Bandwidth &bw = buffer.get(y);
127 unsigned down = bw.down*height/scale;
128 unsigned up = bw.up*height/scale;
129 unsigned up_min = up;
130 unsigned up_max = up;
133 unsigned value = (up+buffer.get(y-1).up*height/scale)/2;
134 up_min = min(value+1, up_min);
135 up_max = max(value, up_max);
139 unsigned value = (up+buffer.get(y+1).up*height/scale)/2;
140 up_min = min(value+1, up_min);
141 up_max = max(value, up_max);
143 unsigned *row = &data[y*height];
144 for(unsigned x=0; x<height; ++x)
146 if(x>=up_min && x<=up_max)
150 else if((x*4+4)%height==0 || y%60==0)
156 texture.sub_image(0, 0, 0, height, width, GL::RGBA, GL::UNSIGNED_BYTE, data.data());
160 History::Bandwidth::Bandwidth():