10#include "qwt_plot_opengl_canvas.h"
12#include "qwt_painter.h"
15#include <qpainterpath.h>
16#include <qcoreevent.h>
17#include <qopenglframebufferobject.h>
18#include <qopenglpaintdevice.h>
20class QwtPlotOpenGLCanvas::PrivateData
40 QOpenGLFramebufferObject* fbo;
50 : QOpenGLWidget( plot )
64 : QOpenGLWidget( plot )
67 if ( numSamples < -1 )
70 QSurfaceFormat fmt = format();
71 if ( numSamples != fmt.samples() )
73 fmt.setSamples( numSamples );
80void QwtPlotOpenGLCanvas::init()
82 m_data =
new PrivateData;
85 setAttribute( Qt::WA_OpaquePaintEvent,
true );
107 if ( m_data->isPolished )
108 QOpenGLWidget::paintEvent(
event );
118 if (
event->type() == QEvent::Resize )
120 if ( m_data->numFBOSamples < 0 )
127 m_data->numFBOSamples = qMax( format().samples(), 0 );
131 const bool ok = QOpenGLWidget::event(
event );
133 if (
event->type() == QEvent::PolishRequest )
139 m_data->isPolished =
true;
142 if (
event->type() == QEvent::PolishRequest ||
143 event->type() == QEvent::StyleChange )
148 setAttribute( Qt::WA_StyledBackground,
149 testAttribute( Qt::WA_StyleSheet ) );
167 m_data->fboDirty =
true;
170void QwtPlotOpenGLCanvas::clearBackingStore()
198 const bool hasFocusIndicator =
204 QOpenGLFramebufferObject::hasOpenGLFramebufferBlit() )
207 const QSize fboSize = size() * pixelRatio;
209 if ( hasFocusIndicator )
210 painter.begin(
this );
224 if ( m_data->fbo->size() != fboSize )
231 if ( m_data->fbo == NULL )
233 QOpenGLFramebufferObjectFormat fboFormat;
234 fboFormat.setAttachment( QOpenGLFramebufferObject::CombinedDepthStencil );
236 if ( m_data->numFBOSamples > 0 )
237 fboFormat.setSamples( m_data->numFBOSamples );
239 m_data->fbo =
new QOpenGLFramebufferObject( fboSize, fboFormat );
240 m_data->fboDirty =
true;
243 if ( m_data->fboDirty )
247 QOpenGLPaintDevice pd( fboSize );
249 QPainter fboPainter( &pd );
250 fboPainter.scale( pixelRatio, pixelRatio );
254 m_data->fboDirty =
false;
257 QOpenGLFramebufferObject::blitFramebuffer( NULL, m_data->fbo );
261 painter.begin(
this );
265 if ( hasFocusIndicator )
275#include "moc_qwt_plot_opengl_canvas.cpp"
static qreal devicePixelRatio(const QPaintDevice *)
FocusIndicator focusIndicator() const
QPainterPath canvasBorderPath(const QRect &rect) const
virtual void drawFocusIndicator(QPainter *)
Base class of QwtPlotOpenGLCanvas and QwtPlotGLCanvas.
bool testPaintAttribute(PaintAttribute) const
@ BackingStore
Paint double buffered reusing the content of the pixmap buffer when possible.
void setFrameShape(QFrame::Shape)
void setFrameShadow(QFrame::Shadow)
void draw(QPainter *)
Helper function for the derived plot canvas.
virtual void paintEvent(QPaintEvent *) override
virtual void initializeGL() override
No operation - reserved for some potential use in the future.
virtual ~QwtPlotOpenGLCanvas()
Destructor.
Q_INVOKABLE QPainterPath borderPath(const QRect &) const
QwtPlotOpenGLCanvas(QwtPlot *=NULL)
Constructor.
virtual void paintGL() override
Paint the plot.
virtual void resizeGL(int width, int height) override
No operation - reserved for some potential use in the future.
virtual bool event(QEvent *) override
virtual Q_INVOKABLE void invalidateBackingStore() override
Invalidate the internal backing store.