CopperSpice API  1.9.2
QOpenGLPaintDevice Class Reference

The QOpenGLPaintDevice class enables painting to an OpenGL context using QPainter. More...

Inheritance diagram for QOpenGLPaintDevice:
QPaintDevice

Public Methods

 QOpenGLPaintDevice ()
 
 QOpenGLPaintDevice (const QSize &size)
 
 QOpenGLPaintDevice (int width, int height)
 
virtual ~QOpenGLPaintDevice ()
 
QOpenGLContextcontext () const
 
qreal dotsPerMeterX () const
 
qreal dotsPerMeterY () const
 
virtual void ensureActiveTarget ()
 
QPaintEnginepaintEngine () const override
 
bool paintFlipped () const
 
void setDevicePixelRatio (qreal devicePixelRatio)
 
void setDotsPerMeterX (qreal dpmx)
 
void setDotsPerMeterY (qreal dpmy)
 
void setPaintFlipped (bool flipped)
 
void setSize (const QSize &size)
 
QSize size () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

int metric (QPaintDevice::PaintDeviceMetric metric) const override
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Additional Inherited Members

- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Detailed Description

The QOpenGLPaintDevice uses the current QOpenGL context to render QPainter draw commands. The context is captured upon construction. It requires support for OpenGL (ES) 2.0 or higher.

Performance

The QOpenGLPaintDevice is almost always hardware accelerated and has the potential of being much faster than software rasterization. However, it is more sensitive to state changes and requires the drawing commands to be carefully ordered to achieve optimal performance.

Antialiasing and Quality

Antialiasing in the OpenGL paint engine is done using multisampling. Most hardware require significantly more memory to do multisampling and the resulting quality is not on par with the quality of the software paint engine. The OpenGL paint engine's strength lies in its performance, not its visual rendering quality.

State Changes

When painting to a QOpenGLPaintDevice using QPainter, the state of the current OpenGL context will be altered by the paint engine to reflect its needs. Applications should not rely upon the OpenGL state being reset to its original conditions, particularly the current shader program, OpenGL viewport, texture units, and drawing modes.

Mixing QPainter and OpenGL

When intermixing QPainter and OpenGL, it is important to notify QPainter that the OpenGL state may have been cluttered so it can restore its internal state. This is achieved by calling QPainter::beginNativePainting() before starting the OpenGL rendering and calling QPainter::endNativePainting() after finishing.

Constructor & Destructor Documentation

QOpenGLPaintDevice::QOpenGLPaintDevice ( )

Constructs a QOpenGLPaintDevice. The QOpenGLPaintDevice is only valid for the current context.

See also
QOpenGLContext::currentContext()
QOpenGLPaintDevice::QOpenGLPaintDevice ( const QSize size)
explicit

Constructs a QOpenGLPaintDevice with the given size. The QOpenGLPaintDevice is only valid for the current context.

See also
QOpenGLContext::currentContext()
QOpenGLPaintDevice::QOpenGLPaintDevice ( int  width,
int  height 
)

Constructs a QOpenGLPaintDevice with the given width and height. The QOpenGLPaintDevice is only valid for the current context.

See also
QOpenGLContext::currentContext()
QOpenGLPaintDevice::~QOpenGLPaintDevice ( )
virtual

Destroys the QOpenGLPaintDevice.

Method Documentation

QOpenGLContext * QOpenGLPaintDevice::context ( ) const

Returns the OpenGL context associated with the paint device.

qreal QOpenGLPaintDevice::dotsPerMeterX ( ) const

Returns the number of pixels per meter horizontally.

See also
setDotsPerMeterX()
qreal QOpenGLPaintDevice::dotsPerMeterY ( ) const

Returns the number of pixels per meter vertically.

See also
setDotsPerMeterY()
void QOpenGLPaintDevice::ensureActiveTarget ( )
virtual

The default implementation does nothing. Override this method to rebind a target frame buffer object or context when different QOpenGLPaintDevice instances are issuing draw calls alternately.

The method beginNativePainting() will invoke this method.

int QOpenGLPaintDevice::metric ( QPaintDevice::PaintDeviceMetric  metric) const
overrideprotectedvirtual

Returns the metric information for the given paint device metric.

See also
PaintDeviceMetric

Reimplemented from QPaintDevice::metric()

QPaintEngine* QOpenGLPaintDevice::paintEngine ( ) const
overridevirtual

Returns a pointer to the paint engine used for drawing on the device.

Implements QPaintDevice::paintEngine()

bool QOpenGLPaintDevice::paintFlipped ( ) const

Returns true if painting is flipped around the Y-axis.

See also
setPaintFlipped()
void QOpenGLPaintDevice::setDevicePixelRatio ( qreal  devicePixelRatio)

Sets the device pixel ratio for the paint device to devicePixelRatio.

void QOpenGLPaintDevice::setDotsPerMeterX ( qreal  dpmx)

Sets the number of pixels per meter horizontally to dpmx.

See also
dotsPerMeterX()
void QOpenGLPaintDevice::setDotsPerMeterY ( qreal  dpmy)

Sets the number of pixels per meter vertically to dpmy.

See also
dotsPerMeterY()
void QOpenGLPaintDevice::setPaintFlipped ( bool  flipped)

Sets whether painting should be flipped around the Y-axis.

See also
paintFlipped()
void QOpenGLPaintDevice::setSize ( const QSize size)

Sets the pixel size of the paint device to size.

See also
size()
QSize QOpenGLPaintDevice::size ( ) const

Returns the pixel size of the paint device.

See also
setSize()