Project

General

Profile

Plot and opengl » History » Version 5

Anonymous, 19/07/2016 10:20 AM

1 1 Anonymous
h1. Plot and OpenGL in QtCharts
2
3
The following test has been used to test the limits of OpenGL :
4
5 5 Anonymous
<pre><code class="cpp">
6 1 Anonymous
 typedef struct __attribute__((packed)) dbl_str{
7
    uint64_t mant:52;
8
    uint64_t exp:11;
9
    uint64_t sign:1;
10
}dbl_str;
11
12
typedef union dbl{
13
    double dblval;
14
    uint64_t intval;
15
    dbl_str strval;
16
}dbl;
17
18
QT_CHARTS_USE_NAMESPACE
19
20
int main(int argc, char *argv[])
21
{
22
    QApplication a(argc, argv);
23
    
24
    QVector<double> timeVector;
25
    dbl offset;
26
    offset.strval.sign=0;
27
    offset.strval.exp=0b01111111111;
28
    offset.strval.mant=0b10000000000000000000000000000000000000000000000000000;
29
    for(int i = 0; i<(1<<20);i++)
30
    {
31
        timeVector.append(offset.dblval);
32
        offset.strval.mant+=1<<(52-24);
33
    }
34
35
    QLineSeries *seriesOGL = new QLineSeries();
36
    seriesOGL->setUseOpenGL(true);
37
38
    for(int i=0;i<timeVector.count();i++)
39
    {
40
        double LUT[]={0.0,1.0,-1.0,2.0,-2.0,3.0};
41
        seriesOGL->append(timeVector.at(i), LUT[i%6]);
42
    }
43
44
    Chart *chart = new Chart();
45
    chart->legend()->hide();
46
47
    chart->addSeries(seriesOGL);
48
49
    chart->createDefaultAxes();
50
    chart->setTitle("Simple line chart example");
51
52
    ChartView *chartView = new ChartView(chart);
53
    chartView->setRenderHint(QPainter::Antialiasing);
54
55
    QMainWindow window;
56
    window.setCentralWidget(chartView);
57
    window.resize(1400, 1300);
58
    window.show();
59
    return a.exec();
60
}
61 2 Anonymous
</code></pre>
62 1 Anonymous
63
By changing this line :
64
    offset.strval.mant+=1<<(52-23); 
65
to offset.strval.mant+=1<<(52-24);
66
we observed that the plot did not take into account any changes in the double mantissa after 28 bits (52-24), 
67
i.e. some points are stacked because the plot cannot make the difference between two different abscissa values.
68
69
This corresponds to the size of the float mantissa.
70
We can then assume that the OpenGL plot uses floats.
71
72
We found the lines where the doubles are casted to floats in the QtCharts code.
73 2 Anonymous
This takes place in glxyseriesdata.cpp in GLXYSeriesDataManager::setPoints : each x and y of the points are casted to floats.
74 1 Anonymous
75
The new float vector is then used by glwidget.cpp  in vertex and fragment source code called by GLWidget::paintGL