summaryrefslogtreecommitdiff
path: root/retrace/daemon/bargraph
diff options
context:
space:
mode:
authorMark Janes <mark.a.janes@intel.com>2015-09-30 11:34:07 -0700
committerMark Janes <mark.a.janes@intel.com>2017-06-19 14:04:45 -0700
commite4bfff8f86c2197a8fb4b09e280e8651218bf955 (patch)
tree1152f22af572b19e95ac8273ad19a5419ea4f88f /retrace/daemon/bargraph
parent6361bc19646e953e6383be78bcc88461de612716 (diff)
add support for drawing a mouse area
the bargraph accepts mouse coordinates in the 0.0-1.0 range, and paints a transparent yellow box over the graph.
Diffstat (limited to 'retrace/daemon/bargraph')
-rw-r--r--retrace/daemon/bargraph/glframe_bargraph.cpp48
-rw-r--r--retrace/daemon/bargraph/glframe_bargraph.hpp5
-rw-r--r--retrace/daemon/bargraph/glframe_glhelper.cpp9
-rw-r--r--retrace/daemon/bargraph/glframe_glhelper.hpp1
-rw-r--r--retrace/daemon/bargraph/glframe_qbargraph.cpp1
-rw-r--r--retrace/daemon/bargraph/test/test_bargraph.cpp57
6 files changed, 119 insertions, 2 deletions
diff --git a/retrace/daemon/bargraph/glframe_bargraph.cpp b/retrace/daemon/bargraph/glframe_bargraph.cpp
index a902e40d..37aca994 100644
--- a/retrace/daemon/bargraph/glframe_bargraph.cpp
+++ b/retrace/daemon/bargraph/glframe_bargraph.cpp
@@ -59,7 +59,9 @@ BarGraphRenderer::fshader =
"}";
BarGraphRenderer::BarGraphRenderer(bool invert)
- : invert_y(invert ? -1 : 1) {
+ : mouse_vertices(4),
+ mouse_area(2),
+ invert_y(invert ? -1 : 1) {
// generate vbo
GL::GenBuffers(1, &vbo);
GL_CHECK();
@@ -151,6 +153,24 @@ BarGraphRenderer::setBars(const std::vector<BarMetrics> &bars) {
void
BarGraphRenderer::setMouseArea(float x1, float y1, float x2, float y2) {
+ mouse_area[0].x = x1;
+ mouse_area[0].y = y1;
+ mouse_area[1].x = x2;
+ mouse_area[1].y = y2;
+
+ // calculate mouse_vertices based on b
+ mouse_vertices[0].x = x1;
+ mouse_vertices[0].y = y1;
+ mouse_vertices[1].x = x1;
+ mouse_vertices[1].y = y2;
+ mouse_vertices[2].x = x2;
+ mouse_vertices[2].y = y1;
+ mouse_vertices[3].x = x2;
+ mouse_vertices[3].y = y2;
+ for (auto &vertex : mouse_vertices) {
+ vertex.x *= total_x;
+ vertex.y *= max_y;
+ }
}
// solely for debugging: allows gdb to print vertices[n]
@@ -222,7 +242,31 @@ BarGraphRenderer::render() {
for (auto &i : outline_indices) {
i += 4;
}
-}
+ }
+
+ if ((mouse_area[0].x > 0) ||
+ (mouse_area[0].y > 0) ||
+ (mouse_area[1].x > 0) ||
+ (mouse_area[1].y > 0)) {
+ // mouse selection is active, draw a selection rectangle
+
+ GL::Enable(GL_BLEND);
+ GL_CHECK();
+ GL::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ GL_CHECK();
+
+ // buffer data to vbo
+ GL::BufferData(GL_ARRAY_BUFFER, mouse_vertices.size() * sizeof(Vertex),
+ mouse_vertices.data(), GL_STATIC_DRAW);
+ GL_CHECK();
+
+ // yellow selection box
+ const float color[4] = { 1.0, 1.0, 0.0, 0.5 };
+ GL::Uniform4f(uni_bar_color, color[0], color[1], color[2], color[3]);
+ GL_CHECK();
+ GL::DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ GL_CHECK();
+ }
// disable vbo
GL::DisableVertexAttribArray(att_coord);
diff --git a/retrace/daemon/bargraph/glframe_bargraph.hpp b/retrace/daemon/bargraph/glframe_bargraph.hpp
index 2a089cec..d4175264 100644
--- a/retrace/daemon/bargraph/glframe_bargraph.hpp
+++ b/retrace/daemon/bargraph/glframe_bargraph.hpp
@@ -68,6 +68,11 @@ class BarGraphRenderer {
};
std::vector<Vertex> vertices;
+ std::vector<Vertex> mouse_vertices;
+
+ // selection box. coordinates are in the 0.0 - 1.0 range
+ std::vector<Vertex> mouse_area;
+
float max_y, total_x, invert_y;
};
diff --git a/retrace/daemon/bargraph/glframe_glhelper.cpp b/retrace/daemon/bargraph/glframe_glhelper.cpp
index fd8ca1a6..b36c1dc9 100644
--- a/retrace/daemon/bargraph/glframe_glhelper.cpp
+++ b/retrace/daemon/bargraph/glframe_glhelper.cpp
@@ -61,6 +61,7 @@ static void *pDisableVertexAttribArray = NULL;
static void *pEnable = NULL;
static void *pReadPixels = NULL;
static void *pDrawElements = NULL;
+static void *pBlendFunc = NULL;
} // namespace
void
@@ -129,6 +130,8 @@ GlFunctions::Init(void *lookup_fn) {
assert(pReadPixels);
pDrawElements = GetProcAddress("glDrawElements");
assert(pDrawElements);
+ pBlendFunc = GetProcAddress("glBlendFunc");
+ assert(pBlendFunc);
}
GLuint
@@ -315,3 +318,9 @@ GlFunctions::DrawElements(GLenum mode, GLsizei count,
GLenum type, const GLvoid *indices);
((DRAWELEMENTS) pDrawElements)(mode, count, type, indices);
}
+
+void
+GlFunctions::BlendFunc(GLenum sfactor, GLenum dfactor) {
+ typedef void (*BLENDFUNC)(GLenum sfactor, GLenum dfactor);
+ ((BLENDFUNC) pBlendFunc)(sfactor, dfactor);
+}
diff --git a/retrace/daemon/bargraph/glframe_glhelper.hpp b/retrace/daemon/bargraph/glframe_glhelper.hpp
index da992a56..342e2042 100644
--- a/retrace/daemon/bargraph/glframe_glhelper.hpp
+++ b/retrace/daemon/bargraph/glframe_glhelper.hpp
@@ -80,6 +80,7 @@ class GlFunctions {
GLvoid *pixels);
static void DrawElements(GLenum mode, GLsizei count,
GLenum type, const GLvoid *indices);
+ static void BlendFunc(GLenum sfactor, GLenum dfactor);
private:
GlFunctions();
diff --git a/retrace/daemon/bargraph/glframe_qbargraph.cpp b/retrace/daemon/bargraph/glframe_qbargraph.cpp
index 9e952083..1d391fb1 100644
--- a/retrace/daemon/bargraph/glframe_qbargraph.cpp
+++ b/retrace/daemon/bargraph/glframe_qbargraph.cpp
@@ -45,6 +45,7 @@ QBarGraphRenderer::QBarGraphRenderer() : m_graph(true) {
metrics[3].metric1 = 2;
metrics[3].metric2 = 2;
m_graph.setBars(metrics);
+ m_graph.setMouseArea(.25, .25, .75, .75);
}
void
diff --git a/retrace/daemon/bargraph/test/test_bargraph.cpp b/retrace/daemon/bargraph/test/test_bargraph.cpp
index f67dbba3..b9eef55f 100644
--- a/retrace/daemon/bargraph/test/test_bargraph.cpp
+++ b/retrace/daemon/bargraph/test/test_bargraph.cpp
@@ -103,3 +103,60 @@ TEST(BarGraph, MultiBar) {
EXPECT_EQ(data.red, 255);
}
+TEST(BarGraph, BarSpacing) {
+ GlFunctions::Init();
+ TestContext c;
+ BarGraphRenderer r;
+ std::vector<BarMetrics> bars(2);
+ bars[0].metric1 = 25;
+ bars[0].metric2 = 0;
+ bars[1].metric1 = 50;
+ bars[1].metric2 = 0;
+ r.setBars(bars);
+ r.render();
+
+ Pixel data;
+
+ // whitespace should be at center
+ GlFunctions::ReadPixels(500, 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data);
+ EXPECT_EQ(data.red, 255);
+ EXPECT_EQ(data.blue, 255);
+ EXPECT_EQ(data.green, 255);
+}
+
+TEST(BarGraph, MouseSelect) {
+ GlFunctions::Init();
+ TestContext c;
+ BarGraphRenderer r;
+ std::vector<BarMetrics> bars(2);
+ bars[0].metric1 = 25;
+ bars[0].metric2 = 0;
+ bars[1].metric1 = 50;
+ bars[1].metric2 = 0;
+ r.setBars(bars);
+ r.setMouseArea(0.25, 0.25, 0.75, 0.75);
+ r.render();
+
+ Pixel data;
+
+ // yellow blended on white should be at center
+ GlFunctions::ReadPixels(500, 500, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data);
+ EXPECT_EQ(data.red, 255);
+ EXPECT_EQ(data.blue, 255);
+ EXPECT_EQ(data.green, 128);
+ EXPECT_EQ(data.alpha, 255);
+
+ // white should be at the bottom
+ GlFunctions::ReadPixels(500, 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data);
+ EXPECT_EQ(data.red, 255);
+ EXPECT_EQ(data.blue, 255);
+ EXPECT_EQ(data.green, 255);
+ EXPECT_EQ(data.alpha, 255);
+
+ // blend should be on the bar
+ GlFunctions::ReadPixels(300, 300, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data);
+ EXPECT_EQ(data.red, 128);
+ EXPECT_EQ(data.blue, 128);
+ EXPECT_EQ(data.green, 128);
+ EXPECT_EQ(data.alpha, 255);
+}