cgv
Loading...
Searching...
No Matches
gl_performance_monitor.cxx
1#include "gl_performance_monitor.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv/render/attribute_array_binding.h>
4#include <cgv/render/shader_program.h>
5
6namespace cgv {
7 namespace render {
8 namespace gl {
9
13void gl_performance_monitor::draw_computed_bars(cgv::render::context& ctx, cgv::render::shader_program& prog)
14{
15 if (positions.empty())
16 return;
17 std::vector<vec2> P;
18 P.clear();
19 for (const auto& p : positions)
20 P.push_back(vec2(p));
23 glDrawArrays(GL_LINES, 0, (GLsizei)positions.size());
24}
25
26void gl_performance_monitor::draw_bars(cgv::render::context& ctx, cgv::render::shader_program& prog)
27{
29
30 float xmin = (float)placement.get_min_pnt()(0);
31 float ymin = (float)placement.get_min_pnt()(1);
32 float xmax = (float)placement.get_max_pnt()(0);
33 float ymax = (float)placement.get_max_pnt()(1);
34 float w = xmax - xmin + 1;
35 float h = ymax - ymin + 1;
36 int dy = (int)(h / nr_display_cycles);
37
38 std::swap(ymin, ymax);
39 ymin = ctx.get_height() - 1 - ymin;
40 ymax = ctx.get_height() - 1 - ymax;
41
42 if (data.empty())
43 return;
44 // draw history of frames and determine local frame index of min and max
45 int min_i = -1, max_i = -1;
46 if (data.size() > 1) {
47 // go through all but current frame
48 int x = placement.get_min_pnt()(0);
49 for (unsigned i = 0; i < data.size() - 1; ++i, ++x) {
50 const frame_data& fdata = data[i];
51 compute_colors(fdata);
52 compute_positions(x, int(ymin), 0, dy, fdata);
53 draw_computed_bars(ctx, prog);
54 // check for min
55 if (min_i == -1 || data[i][data[i].size() - 2].time < data[min_i][data[min_i].size() - 2].time)
56 min_i = i;
57 // check for max
58 if (max_i == -1 || data[i][data[i].size() - 2].time > data[max_i][data[max_i].size() - 2].time)
59 max_i = i;
60 }
61 if (!bar_config.empty()) {
62 int y = int(ymin - (bar_line_width + 4) / 2 - 4);
63 glLineWidth((float)bar_line_width);
64 for (int c = 0; c < (int)bar_config.size(); ++c) {
65 switch (bar_config[c]) {
66 case PMB_MIN:
67 if (min_i != -1)
68 draw_bar(ctx, prog, y, data[min_i]);
69 break;
70 case PMB_MAX:
71 if (max_i != -1)
72 draw_bar(ctx, prog, y, data[max_i]);
73 break;
74 case PMB_CUR:
75 draw_bar(ctx, prog, y, data.back());
76 break;
77 case PMB_AVG:
78 std::cerr << "avg not yet supported" << std::endl;
79 break;
80 }
81 y -= bar_line_width + 1;
82 }
83 }
84 }
86 glLineWidth(1.0f);
87}
88void gl_performance_monitor::draw_bar(cgv::render::context& ctx, cgv::render::shader_program& prog, int y, const frame_data& fdata)
89{
90 compute_colors(fdata);
91 compute_positions(placement.get_min_pnt()(0),y,placement.get_extent()(0)/nr_display_cycles, 0, fdata);
92 draw_computed_bars(ctx, prog);
93}
94
95void checkClientState()
96{
97 GLint at;
98 glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &at);
99 std::cout << "AT="
100 << at << " ";
101 std::cout << (glIsEnabled(GL_VERTEX_ARRAY)?"V":"v")
102 << (glIsEnabled(GL_NORMAL_ARRAY)?"N":"n")
103 << (glIsEnabled(GL_COLOR_ARRAY)?"C":"c");
104
105 for (int i=0; i<8; ++i) {
106 glClientActiveTexture(GL_TEXTURE0+i);
107 std::cout << (glIsEnabled(GL_TEXTURE_COORD_ARRAY)?("0"+std::to_string(i)):".");
108 }
109 std::cout << std::endl;
110}
111void gl_performance_monitor::draw_lines(cgv::render::context& ctx, cgv::render::shader_program& prog)
112{
113 // collect lines first
114 std::vector<vec2> lines;
115 float xmin = (float)placement.get_min_pnt()(0);
116 float ymin = (float)placement.get_min_pnt()(1);
117 float xmax = (float)placement.get_max_pnt()(0);
118 float ymax = (float)placement.get_max_pnt()(1);
119 float w = xmax - xmin + 1;
120 float h = ymax - ymin + 1;
121 float dy = h / nr_display_cycles;
122
123 std::swap(ymin, ymax);
124 ymin = ctx.get_height() - 1 - ymin;
125 ymax = ctx.get_height() - 1 - ymax;
126
127 lines.push_back(vec2(xmin - 1, ymax + 1));
128 lines.push_back(vec2(xmax + 1, ymax + 1));
129 lines.push_back(vec2(xmax + 1, ymax + 1));
130 lines.push_back(vec2(xmax + 1, ymin - 1));
131 lines.push_back(vec2(xmax + 1, ymin - 1));
132 lines.push_back(vec2(xmin - 1, ymin - 1));
133 lines.push_back(vec2(xmin - 1, ymin - 1));
134 lines.push_back(vec2(xmin - 1, ymax + 1));
135
136 if (nr_display_cycles > 1) {
137 float y = ymax - dy;
138 for (int i = 1; i < nr_display_cycles; ++i) {
139 lines.push_back(vec2(xmin, y));
140 lines.push_back(vec2(xmax, y));
141 y -= dy;
142 }
143 }
144
145 ctx.set_color(plot_color);
146 cgv::render::attribute_array_binding::set_global_attribute_array(ctx, prog.get_position_index(), lines);
147 glDrawArrays(GL_LINES, 0, (GLsizei) lines.size());
148}
149
151{
152 //int xmin = placement.get_min_pnt()(0);
153 //int ymin = placement.get_min_pnt()(1);
154 //int xmax = placement.get_max_pnt()(0);
155 //int ymax = placement.get_max_pnt()(1);
156 //int w = xmax - xmin + 1;
157 //int h = ymax - ymin + 1;
158 //int dy = h/nr_display_cycles;
159
160 GLboolean is_depth = glIsEnabled(GL_DEPTH_TEST);
161 glDisable(GL_DEPTH_TEST);
162 ctx.push_pixel_coords();
163 GLfloat lw;
164 glGetFloatv(GL_LINE_WIDTH, &lw);
165 glLineWidth(1.0f);
167 cgv::render::attribute_array_binding::enable_global_array(ctx, prog.get_position_index());
168 prog.enable(ctx);
169 draw_bars(ctx, prog);
170 draw_lines(ctx, prog);
171 prog.disable(ctx);
173 glLineWidth(lw);
174 ctx.pop_pixel_coords();
175 if (is_depth)
176 glEnable(GL_DEPTH_TEST);
177}
178
179 }
180 }
181}
fvec_type get_extent() const
return a vector with the extents in the different dimensions
const fpnt_type & get_max_pnt() const
return a const reference to corner 7
const fpnt_type & get_min_pnt() const
return a const reference to corner 0
static bool enable_global_array(const context &ctx, int loc)
enable attribute array of given location
static bool set_global_attribute_array(const context &ctx, int loc, const vertex_buffer &vbo, type_descriptor td, size_t size, size_t offset, unsigned stride=0)
point array of vertex attribute at location loc to vertex buffer array array stored in CPU memory; in...
static bool disable_global_array(const context &ctx, int loc)
disable attribute array of given location
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
virtual void set_color(const rgba &clr)
set the current color
Definition context.cxx:1617
virtual shader_program & ref_default_shader_program(bool texture_support=false)=0
return a reference to a shader program used to render without illumination
virtual unsigned int get_height() const =0
return the height of the window
virtual void push_pixel_coords()=0
use this to push new modelview and new projection matrices onto the transformation stacks such that x...
virtual void pop_pixel_coords()=0
pop previously pushed transformation matrices from modelview and projection stacks
gl_performance_monitor()
construct performance monitor with standard configuration
void draw(cgv::render::context &ctx)
draw with OpenGL
a shader program combines several shader code fragments to a complete definition of the shading pipel...
bool enable(context &ctx)
enable the shader program
bool disable(context &ctx)
disable shader program and restore fixed functionality
the cgv namespace
Definition print.h:11
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:667