X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=logicsignal.cpp;h=584be441acfad737330ea0ac87d1bda99b7ab029;hp=09a65afca5a32188186f9352f77e328ff00f979f;hb=7cd5faf8cfed1871195aed7a4c325342172944b3;hpb=3b18c57d8f224791481e0b768065bd4d11a3d79e diff --git a/logicsignal.cpp b/logicsignal.cpp index 09a65afc..584be441 100644 --- a/logicsignal.cpp +++ b/logicsignal.cpp @@ -18,11 +18,25 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#define GL_GLEXT_PROTOTYPES +#include +#include + +#include + +#include "logicdata.h" +#include "logicdatasnapshot.h" #include "logicsignal.h" -LogicSignal::LogicSignal(QString name, boost::shared_ptr data, +using namespace boost; +using namespace std; + +const float Log2 = logf(2.0f); + +LogicSignal::LogicSignal(QString name, shared_ptr data, int probe_index) : - Signal(name, data), + Signal(name), + _data(data), _probe_index(probe_index) { assert(_probe_index >= 0); @@ -31,10 +45,98 @@ LogicSignal::LogicSignal(QString name, boost::shared_ptr data, void LogicSignal::paint(QGLWidget &widget, const QRect &rect, uint64_t scale, int64_t offset) { - glColor3f(1,0,0); - glBegin(GL_POLYGON); - glVertex2f(rect.left(), rect.top()); - glVertex2f(rect.right(), rect.top()); - glVertex2f(rect.right(), rect.bottom()); - glEnd(); + Point2F *vertex; + + vector< pair > edges; + + assert(_data); + + const queue< shared_ptr > &snapshots = + _data->get_snapshots(); + if(snapshots.empty()) + return; + + const shared_ptr &snapshot = snapshots.front(); + + const uint64_t samplerate = _data->get_samplerate(); + const int64_t start_time = _data->get_start_time(); + const float samples_per_pixel = samplerate * scale / 1e15f; + const int64_t start = samplerate * (offset - start_time) / + 1000000000000000ULL; + const int64_t end = start + samples_per_pixel * rect.width(); + const int64_t quantization_length = 1LL << (int64_t)floorf( + max(logf(samples_per_pixel / Log2), 0.0f)); + + snapshot->get_subsampled_edges(edges, start, end, + quantization_length, _probe_index); + + // Paint the edges + const unsigned int edge_point_count = (edges.size() - 2) * 2; + Point2F *const edge_points = new Point2F[edge_point_count]; + vertex = edge_points; + + for(vector::const_iterator i = edges.begin() + 1; + i != edges.end() - 1; i++) + { + const int x = (int)((*i).first / samples_per_pixel) + + rect.left(); + + vertex->x = x, vertex->y = 10 + rect.top() - 1; + vertex++; + vertex->x = x, vertex->y = 40 + rect.top(); + vertex++; + } + + glColor3f(0,0,1); + paint_lines(edge_points, edge_point_count); + delete[] edge_points; + + // Paint the caps + const unsigned int cap_point_count = (edges.size() - 1) * 2; + Point2F *const cap_points = new Point2F[cap_point_count]; + vertex = cap_points; + + for(vector::const_iterator i = edges.begin(); + i != (edges.end() - 1); i++) + { + const int y = ((*i).second ? 10 : 40) + rect.top(); + + vertex->x = (int)((*i).first / samples_per_pixel) + + rect.left() - 1; + vertex->y = y; + vertex++; + + vertex->x = (int)((*(i+1)).first / samples_per_pixel) + + rect.left(); + vertex->y = y; + vertex++; + } + + glColor3f(0,0,1); + paint_lines(cap_points, cap_point_count); + delete[] cap_points; +} + +void LogicSignal::paint_lines(Point2F *points, int count) +{ + GLuint vbo_id; + + assert(points); + + glGenBuffers(1, &vbo_id); + glBindBuffer(GL_ARRAY_BUFFER, vbo_id); + + const unsigned int vbo_length = count * sizeof(Point2F); + glBufferData(GL_ARRAY_BUFFER, vbo_length, NULL, GL_STATIC_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, vbo_length, points); + + glBindBuffer(GL_ARRAY_BUFFER, vbo_id); + + glVertexPointer(2, GL_FLOAT, sizeof(Point2F), 0); + + glEnableClientState(GL_VERTEX_ARRAY); + glDrawArrays(GL_LINES, 0, count); + glDisableClientState(GL_VERTEX_ARRAY); + + glDeleteBuffers(1, &vbo_id); }