/
paintbuffer.h
138 lines (112 loc) · 5.01 KB
/
paintbuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***************************************************************************
** **
** QCustomPlot, an easy to use, modern plotting widget for Qt **
** Copyright (C) 2011-2016 Emanuel Eichhammer **
** **
** This program is free software: you can redistribute it and/or modify **
** it under the terms of the GNU General Public License as published by **
** the Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see http://www.gnu.org/licenses/. **
** **
****************************************************************************
** Author: Emanuel Eichhammer **
** Website/Contact: http://www.qcustomplot.com/ **
** Date: 13.09.16 **
** Version: 2.0.0-beta **
****************************************************************************/
#ifndef QCP_PAINTBUFFER_H
#define QCP_PAINTBUFFER_H
#include "global.h"
class QCPPainter;
class QCP_LIB_DECL QCPAbstractPaintBuffer
{
public:
explicit QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio);
virtual ~QCPAbstractPaintBuffer();
// getters:
QSize size() const { return mSize; }
bool invalidated() const { return mInvalidated; }
double devicePixelRatio() const { return mDevicePixelRatio; }
// setters:
void setSize(const QSize &size);
void setInvalidated(bool invalidated=true);
void setDevicePixelRatio(double ratio);
// introduced virtual methods:
virtual QCPPainter *startPainting() = 0;
virtual void donePainting() {}
virtual void draw(QCPPainter *painter) const = 0;
virtual void draw(QPainter *painter) const = 0;
virtual void clear(const QColor &color) = 0;
protected:
// property members:
QSize mSize;
double mDevicePixelRatio;
// non-property members:
bool mInvalidated;
// introduced virtual methods:
virtual void reallocateBuffer() = 0;
};
class QCP_LIB_DECL QCPPaintBufferPixmap : public QCPAbstractPaintBuffer
{
public:
explicit QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio);
virtual ~QCPPaintBufferPixmap();
// reimplemented virtual methods:
virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
virtual void draw(QPainter *painter) const Q_DECL_OVERRIDE;
void clear(const QColor &color) Q_DECL_OVERRIDE;
protected:
// non-property members:
QPixmap mBuffer;
// reimplemented virtual methods:
virtual void reallocateBuffer() Q_DECL_OVERRIDE;
};
#ifdef QCP_OPENGL_PBUFFER
class QCP_LIB_DECL QCPPaintBufferGlPbuffer : public QCPAbstractPaintBuffer
{
public:
explicit QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples);
virtual ~QCPPaintBufferGlPbuffer();
// reimplemented virtual methods:
virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
void clear(const QColor &color) Q_DECL_OVERRIDE;
protected:
// non-property members:
QGLPixelBuffer *mGlPBuffer;
int mMultisamples;
// reimplemented virtual methods:
virtual void reallocateBuffer() Q_DECL_OVERRIDE;
};
#endif // QCP_OPENGL_PBUFFER
#ifdef QCP_OPENGL_FBO
class QCP_LIB_DECL QCPPaintBufferGlFbo : public QCPAbstractPaintBuffer
{
public:
explicit QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer<QOpenGLContext> glContext, QWeakPointer<QOpenGLPaintDevice> glPaintDevice);
virtual ~QCPPaintBufferGlFbo();
// reimplemented virtual methods:
virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
virtual void donePainting() Q_DECL_OVERRIDE;
virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
virtual void draw(QPainter *painter) const Q_DECL_OVERRIDE;
void clear(const QColor &color) Q_DECL_OVERRIDE;
protected:
// non-property members:
QWeakPointer<QOpenGLContext> mGlContext;
QWeakPointer<QOpenGLPaintDevice> mGlPaintDevice;
QOpenGLFramebufferObject *mGlFrameBuffer;
// reimplemented virtual methods:
virtual void reallocateBuffer() Q_DECL_OVERRIDE;
};
#endif // QCP_OPENGL_FBO
#endif // QCP_PAINTBUFFER_H