Qt 4.8
Public Functions | Private Functions | List of all members
QOpenGLPaintEngine Class Reference

#include <qpaintengine_opengl_p.h>

Inheritance diagram for QOpenGLPaintEngine:
QPaintEngineEx QPaintEngine

Public Functions

bool begin (QPaintDevice *pdev)
 Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. More...
 
void brushChanged ()
 
void brushOriginChanged ()
 
void clip (const QVectorPath &path, Qt::ClipOperation op)
 
void clipEnabledChanged ()
 
void compositionModeChanged ()
 
QPainterStatecreateState (QPainterState *orig) const
 
void drawEllipse (const QRectF &rect)
 Reimplement this function to draw the largest ellipse that can be contained within rectangle rect. More...
 
void drawImage (const QRectF &r, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags conversionFlags)
 Reimplement this function to draw the part of the image specified by the sr rectangle in the given rectangle using the given conversion flags flags, to convert it to a pixmap. More...
 
void drawLines (const QLineF *lines, int lineCount)
 The default implementation splits the list of lines in lines into lineCount separate calls to drawPath() or drawPolygon() depending on the feature set of the paint engine. More...
 
void drawLines (const QLine *lines, int lineCount)
 The default implementation converts the first lineCount lines in lines to a QLineF and calls the floating point version of this function. More...
 
void drawPath (const QPainterPath &path)
 The default implementation ignores the path and does nothing. More...
 
void drawPixmap (const QRectF &r, const QPixmap &pm, const QRectF &sr)
 Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r. More...
 
void drawPoints (const QPointF *p, int pointCount)
 Draws the first pointCount points in the buffer points. More...
 
void drawPoints (const QPoint *p, int pointCount)
 Draws the first pointCount points in the buffer points. More...
 
void drawPolygon (const QPointF *points, int pointCount, PolygonDrawMode mode)
 Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode. More...
 
void drawPolygon (const QPoint *points, int pointCount, PolygonDrawMode mode)
 Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode. More...
 
void drawRects (const QRectF *r, int rectCount)
 Draws the first rectCount rectangles in the buffer rects. More...
 
void drawRects (const QRect *r, int rectCount)
 The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF and calls the floating point version of this function. More...
 
void drawStaticTextItem (QStaticTextItem *staticTextItem)
 
void drawTextItem (const QPointF &p, const QTextItem &ti)
 This function draws the text item textItem at position p. More...
 
void drawTiledPixmap (const QRectF &r, const QPixmap &pixmap, const QPointF &s)
 Reimplement this function to draw the pixmap in the given rect, starting at the given p. More...
 
bool end ()
 Reimplement this function to finish painting on the current paint device. More...
 
void fill (const QVectorPath &path, const QBrush &brush)
 
HDC handle () const
 
void opacityChanged ()
 
void penChanged ()
 
 QOpenGLPaintEngine ()
 
void renderHintsChanged ()
 
void setState (QPainterState *s)
 
QOpenGLPaintEngineStatestate ()
 
const QOpenGLPaintEngineStatestate () const
 
bool supportsTransformations (qreal, const QTransform &) const
 
void transformChanged ()
 
Type type () const
 Reimplement this function to return the paint engine Type. More...
 
void updateBrush (const QBrush &brush, const QPointF &pt)
 
void updateClipRegion (const QRegion &region, Qt::ClipOperation op)
 
void updateCompositionMode (QPainter::CompositionMode composition_mode)
 
void updateFont (const QFont &font)
 
void updateMatrix (const QTransform &matrix)
 
void updatePen (const QPen &pen)
 
void updateRenderHints (QPainter::RenderHints hints)
 
void updateState (const QPaintEngineState &state)
 Reimplement this function to update the state of a paint engine. More...
 
 ~QOpenGLPaintEngine ()
 
- Public Functions inherited from QPaintEngineEx
virtual void beginNativePainting ()
 
virtual void clip (const QRect &rect, Qt::ClipOperation op)
 
virtual void clip (const QRegion &region, Qt::ClipOperation op)
 
virtual void clip (const QPainterPath &path, Qt::ClipOperation op)
 
virtual void draw (const QVectorPath &path)
 
virtual void drawEllipse (const QRect &r)
 The default implementation of this function calls the floating point version of this function. More...
 
virtual void drawImage (const QPointF &pos, const QImage &image)
 
virtual void drawPixmap (const QPointF &pos, const QPixmap &pm)
 
virtual void drawPixmapFragments (const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, QPainter::PixmapFragmentHints hints)
 
virtual void drawPixmapFragments (const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount, const QPixmap &pixmap, QPainter::PixmapFragmentHints hints)
 
virtual void drawRoundedRect (const QRectF &rect, qreal xrad, qreal yrad, Qt::SizeMode mode)
 
virtual void endNativePainting ()
 
virtual void fillRect (const QRectF &rect, const QBrush &brush)
 
virtual void fillRect (const QRectF &rect, const QColor &color)
 
virtual uint flags () const
 
virtual QPixmapFilterpixmapFilter (int, const QPixmapFilter *)
 
 QPaintEngineEx ()
 
QPainterStatestate ()
 
const QPainterStatestate () const
 
virtual void stroke (const QVectorPath &path, const QPen &pen)
 
virtual void sync ()
 
- Public Functions inherited from QPaintEngine
void clearDirty (DirtyFlags df)
 
virtual QPoint coordinateOffset () const
 Returns the offset from the painters origo to the engines origo. More...
 
void fix_neg_rect (int *x, int *y, int *w, int *h)
 
virtual HDC getDC () const
 Empty default implementation. More...
 
bool hasFeature (PaintEngineFeatures feature) const
 Returns true if the paint engine supports the specified feature; otherwise returns false. More...
 
bool isActive () const
 Returns true if the paint engine is actively drawing; otherwise returns false. More...
 
bool isExtended () const
 Returns true if the paint engine is a QPaintEngineEx derivative. More...
 
QPaintDevicepaintDevice () const
 Returns the device that this engine is painting on, if painting is active; otherwise returns 0. More...
 
QPainterpainter () const
 Returns the paint engine's painter. More...
 
 QPaintEngine (PaintEngineFeatures features=0)
 Creates a paint engine with the featureset specified by caps. More...
 
virtual void releaseDC (HDC hdc) const
 Empty default implementation. More...
 
void setActive (bool newState)
 Sets the active state of the paint engine to state. More...
 
void setDirty (DirtyFlags df)
 
void setPaintDevice (QPaintDevice *device)
 
void setSystemClip (const QRegion &baseClip)
 Sets the system clip for this engine. More...
 
void setSystemRect (const QRect &rect)
 Sets the target rect for drawing within the backing store. More...
 
void syncState ()
 Updates all dirty states in this engine. More...
 
QRegion systemClip () const
 Returns the system clip. More...
 
QRect systemRect () const
 Retrieves the rect for drawing within the backing store. More...
 
bool testDirty (DirtyFlags df)
 
virtual ~QPaintEngine ()
 Destroys the paint engine. More...
 

Private Functions

void drawPolyInternal (const QPolygonF &pa, bool close=true)
 
void drawTextureRect (int tx_width, int tx_height, const QRectF &r, const QRectF &sr, GLenum target, QGLTexture *tex)
 

Additional Inherited Members

- Public Types inherited from QPaintEngineEx
enum  Flags { DoNotEmulate = 0x01, IsEmulationEngine = 0x02 }
 
- Public Types inherited from QPaintEngine
enum  DirtyFlag {
  DirtyPen = 0x0001, DirtyBrush = 0x0002, DirtyBrushOrigin = 0x0004, DirtyFont = 0x0008,
  DirtyBackground = 0x0010, DirtyBackgroundMode = 0x0020, DirtyTransform = 0x0040, DirtyClipRegion = 0x0080,
  DirtyClipPath = 0x0100, DirtyHints = 0x0200, DirtyCompositionMode = 0x0400, DirtyClipEnabled = 0x0800,
  DirtyOpacity = 0x1000, AllDirty = 0xffff
}
 QPaintEngine::updateState(). More...
 
enum  PaintEngineFeature {
  PrimitiveTransform = 0x00000001, PatternTransform = 0x00000002, PixmapTransform = 0x00000004, PatternBrush = 0x00000008,
  LinearGradientFill = 0x00000010, RadialGradientFill = 0x00000020, ConicalGradientFill = 0x00000040, AlphaBlend = 0x00000080,
  PorterDuff = 0x00000100, PainterPaths = 0x00000200, Antialiasing = 0x00000400, BrushStroke = 0x00000800,
  ConstantOpacity = 0x00001000, MaskedBrush = 0x00002000, PerspectiveTransform = 0x00004000, BlendModes = 0x00008000,
  ObjectBoundingModeGradients = 0x00010000, RasterOpModes = 0x00020000, PaintOutsidePaintEvent = 0x20000000, AllFeatures = 0xffffffff
}
 This enum is used to describe the features or capabilities that the paint engine has. More...
 
enum  PolygonDrawMode { OddEvenMode, WindingMode, ConvexMode, PolylineMode }
 
enum  Type {
  X11, Windows, QuickDraw, CoreGraphics,
  MacPrinter, QWindowSystem, PostScript, OpenGL,
  Picture, SVG, Raster, Direct3D,
  Pdf, OpenVG, OpenGL2, PaintBuffer,
  Blitter, User = 50, MaxUser = 100
}
 
- Protected Functions inherited from QPaintEngineEx
 QPaintEngineEx (QPaintEngineExPrivate &data)
 
- Protected Functions inherited from QPaintEngine
 QPaintEngine (QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0)
 
- Protected Variables inherited from QPaintEngine
uint active: 1
 
QScopedPointer< QPaintEnginePrivated_ptr
 
uint extended: 1
 
PaintEngineFeatures gccaps
 
uint selfDestruct: 1
 
QPaintEngineStatestate
 

Detailed Description

Definition at line 76 of file qpaintengine_opengl_p.h.

Constructors and Destructors

◆ QOpenGLPaintEngine()

QOpenGLPaintEngine::QOpenGLPaintEngine ( )

◆ ~QOpenGLPaintEngine()

QOpenGLPaintEngine::~QOpenGLPaintEngine ( )

Definition at line 1240 of file qpaintengine_opengl.cpp.

1241 {
1242 }

Functions

◆ begin()

bool QOpenGLPaintEngine::begin ( QPaintDevice pdev)
virtual

Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev.

Return true if the initialization was successful; otherwise return false.

See also
end() isActive()

Implements QPaintEngine.

Definition at line 1244 of file qpaintengine_opengl.cpp.

1245 {
1247 
1248  if (pdev->devType() == QInternal::OpenGL)
1249  d->device = static_cast<QGLPaintDevice*>(pdev);
1250  else
1251  d->device = QGLPaintDevice::getDevice(pdev);
1252 
1253  if (!d->device)
1254  return false;
1255 
1256  d->offscreen.setDevice(pdev);
1257  d->has_fast_pen = false;
1258  d->inverseScale = 1;
1259  d->opacity = 1;
1260  d->device->beginPaint();
1261  d->matrix = QTransform();
1262  d->has_antialiasing = false;
1263  d->high_quality_antialiasing = false;
1264 
1265  QSize sz(d->device->size());
1266  d->dirty_stencil = QRect(0, 0, sz.width(), sz.height());
1267 
1268  d->use_emulation = false;
1269 
1270  for (int i = 0; i < 4; ++i)
1271  for (int j = 0; j < 4; ++j)
1272  d->mv_matrix[i][j] = (i == j ? qreal(1) : qreal(0));
1273 
1274  bool has_frag_program = (QGLExtensions::glExtensions() & QGLExtensions::FragmentProgram)
1275  && (pdev->devType() != QInternal::Pixmap);
1276 
1277  QGLContext *ctx = const_cast<QGLContext *>(d->device->context());
1278  if (!ctx) {
1279  qWarning() << "QOpenGLPaintEngine: paint device doesn't have a valid GL context.";
1280  return false;
1281  }
1282 
1283  if (has_frag_program)
1285 
1286  d->use_stencil_method = d->device->format().stencil()
1288  if (d->device->format().directRendering()
1289  && (d->use_stencil_method && QGLExtensions::glExtensions() & QGLExtensions::StencilTwoSide))
1290  d->has_stencil_face_ext = qt_resolve_stencil_face_extension(ctx);
1291 
1292 #ifdef Q_WS_X11
1293  static bool nvidia_workaround_needs_init = true;
1294  if (nvidia_workaround_needs_init) {
1295  // nvidia 9x.xx unix drivers contain a bug which requires us to
1296  // call glFinish before releasing an fbo to avoid painting
1297  // artifacts
1298  const QByteArray versionString(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
1299  const int pos = versionString.indexOf("NVIDIA");
1300  if (pos >= 0) {
1301  const float nvidiaDriverVersion = versionString.mid(pos + strlen("NVIDIA")).toFloat();
1302  qt_nvidiaFboNeedsFinish = nvidiaDriverVersion >= 90.0 && nvidiaDriverVersion < 100.0;
1303  }
1304  nvidia_workaround_needs_init = false;
1305  }
1306 #endif
1307 
1308 #ifndef QT_OPENGL_ES
1309  if (!ctx->d_ptr->internal_context) {
1310  glGetDoublev(GL_PROJECTION_MATRIX, &d->projection_matrix[0][0]);
1311  glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
1312  glPushAttrib(GL_ALL_ATTRIB_BITS);
1313 
1314  glDisableClientState(GL_EDGE_FLAG_ARRAY);
1315  glDisableClientState(GL_INDEX_ARRAY);
1316  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1317  glDisable(GL_TEXTURE_1D);
1318  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1319  glPixelTransferi(GL_MAP_COLOR, false);
1320  glPixelTransferi(GL_MAP_STENCIL, false);
1321  glDisable(GL_TEXTURE_GEN_S);
1322 
1323  glPixelStorei(GL_PACK_SWAP_BYTES, false);
1324  glPixelStorei(GL_PACK_LSB_FIRST, false);
1325  glPixelStorei(GL_PACK_ROW_LENGTH, 0);
1326  glPixelStorei(GL_PACK_SKIP_ROWS, 0);
1327  glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
1328  glPixelStorei(GL_PACK_ALIGNMENT, 4);
1329 
1330  glPixelStorei(GL_UNPACK_SWAP_BYTES, false);
1331  glPixelStorei(GL_UNPACK_LSB_FIRST, false);
1332  glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1333  glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1334  glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1335  glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1336 
1338  glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
1339  glPixelStorei(GL_PACK_SKIP_IMAGES, 0);
1340  glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
1341  glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
1342  }
1343  }
1344 #endif
1345 
1346  if (!ctx->d_ptr->internal_context) {
1347  glMatrixMode(GL_MODELVIEW);
1348  glPushMatrix();
1349  glMatrixMode(GL_TEXTURE);
1350  glPushMatrix();
1351  glLoadIdentity();
1352  glDisableClientState(GL_COLOR_ARRAY);
1353  glDisableClientState(GL_NORMAL_ARRAY);
1354  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1355  glDisableClientState(GL_VERTEX_ARRAY);
1356 
1358  glDisable(GL_MULTISAMPLE);
1359  glDisable(GL_TEXTURE_2D);
1361  glDisable(GL_TEXTURE_RECTANGLE_NV);
1362  glDisable(GL_STENCIL_TEST);
1363  glDisable(GL_CULL_FACE);
1364  glDisable(GL_LIGHTING);
1365  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1366  }
1367 
1368  d->offscreen.begin();
1369 
1370  glViewport(0, 0, sz.width(), sz.height()); // XXX (Embedded): We need a solution for GLWidgets that draw in a part or a bigger surface...
1371  glMatrixMode(GL_PROJECTION);
1372  glLoadIdentity();
1373 #ifdef QT_OPENGL_ES
1374  glOrthof(0, sz.width(), sz.height(), 0, -999999, 999999);
1375 #else
1376  glOrtho(0, sz.width(), sz.height(), 0, -999999, 999999);
1377 #endif
1378  glMatrixMode(GL_MODELVIEW);
1379  glLoadIdentity();
1380  glEnable(GL_BLEND);
1381  d->composition_mode = QPainter::CompositionMode_SourceOver;
1382 
1383 #ifdef QT_OPENGL_ES
1384  d->max_texture_size = ctx->d_func()->maxTextureSize();
1385 #else
1386  bool shared_ctx = QGLContext::areSharing(d->device->context(), d->shader_ctx);
1387 
1388  if (shared_ctx) {
1389  d->max_texture_size = d->shader_ctx->d_func()->maxTextureSize();
1390  } else {
1391  d->max_texture_size = ctx->d_func()->maxTextureSize();
1392 
1393  if (d->shader_ctx) {
1394  d->shader_ctx->makeCurrent();
1395  glBindTexture(GL_TEXTURE_1D, 0);
1396  glDeleteTextures(1, &d->grad_palette);
1397 
1398  if (has_frag_program && d->use_fragment_programs)
1399  glDeleteTextures(1, &d->drawable_texture);
1400  ctx->makeCurrent();
1401  }
1402  d->shader_ctx = d->device->context();
1403  glGenTextures(1, &d->grad_palette);
1404 
1405  qt_mask_texture_cache()->clearCache();
1406  d->use_fragment_programs = has_frag_program;
1407  }
1408 
1409  if (d->use_fragment_programs && (!shared_ctx || sz.width() > d->drawable_texture_size.width()
1410  || sz.height() > d->drawable_texture_size.height()))
1411  {
1412  // delete old texture if size has increased, otherwise it was deleted earlier
1413  if (shared_ctx)
1414  glDeleteTextures(1, &d->drawable_texture);
1415 
1416  d->dirty_drawable_texture = true;
1417  d->drawable_texture_size = QSize(qt_next_power_of_two(sz.width()),
1418  qt_next_power_of_two(sz.height()));
1419  }
1420 #endif
1421 
1423  penChanged();
1424  brushChanged();
1425  opacityChanged();
1428  transformChanged();
1429  return true;
1430 }
bool qt_resolve_version_1_3_functions(QGLContext *ctx)
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
double qreal
Definition: qglobal.h:1193
static OpenGLVersionFlags openGLVersionFlags()
#define GL_TRUE
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define GL_UNPACK_IMAGE_HEIGHT
#define GL_PACK_ALIGNMENT
int qt_next_power_of_two(int v)
Definition: qgl.cpp:1886
#define GL_STENCIL_TEST
#define Q_D(Class)
Definition: qglobal.h:2482
uint internal_context
Definition: qgl_p.h:426
virtual int devType() const
Definition: qpaintdevice.h:167
#define GL_TEXTURE_2D
#define GL_TEXTURE
void updateClipRegion(const QRegion &region, Qt::ClipOperation op)
static bool areSharing(const QGLContext *context1, const QGLContext *context2)
Returns true if context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.
Definition: qgl.cpp:3319
#define GL_VERSION
#define GL_MULTISAMPLE
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define GL_PACK_SKIP_IMAGES
Q_CORE_EXPORT void qWarning(const char *,...)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
#define GL_UNPACK_ALIGNMENT
#define GL_BLEND
static bool qt_nvidiaFboNeedsFinish
#define ctx
Definition: qgl.cpp:6094
#define GL_TEXTURE_RECTANGLE_NV
#define GL_CULL_FACE
#define GL_UNPACK_SKIP_IMAGES
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual void makeCurrent()
Makes this context the current OpenGL rendering context.
Definition: qgl_egl.cpp:213
static Extensions glExtensions()
Definition: qgl.cpp:5781
#define GL_FRONT_AND_BACK
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QGLPaintDevice * getDevice(QPaintDevice *)
bool qt_resolve_frag_program_extensions(QGLContext *ctx)
#define GL_PACK_IMAGE_HEIGHT
bool qt_resolve_stencil_face_extension(QGLContext *ctx)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ brushChanged()

void QOpenGLPaintEngine::brushChanged ( )
virtual

Implements QPaintEngineEx.

Definition at line 5419 of file qpaintengine_opengl.cpp.

Referenced by begin().

5420 {
5421  updateBrush(state()->brush, state()->brushOrigin);
5422 }
QOpenGLPaintEngineState * state()
void updateBrush(const QBrush &brush, const QPointF &pt)

◆ brushOriginChanged()

void QOpenGLPaintEngine::brushOriginChanged ( )
virtual

Implements QPaintEngineEx.

Definition at line 5424 of file qpaintengine_opengl.cpp.

5425 {
5426  updateBrush(state()->brush, state()->brushOrigin);
5427 }
QOpenGLPaintEngineState * state()
void updateBrush(const QBrush &brush, const QPointF &pt)

◆ clip()

void QOpenGLPaintEngine::clip ( const QVectorPath path,
Qt::ClipOperation  op 
)
virtual

Implements QPaintEngineEx.

Definition at line 5501 of file qpaintengine_opengl.cpp.

5502 {
5503  const qreal *points = path.points();
5504  const QPainterPath::ElementType *types = path.elements();
5505  if (!types && path.shape() == QVectorPath::RectangleHint) {
5506  QRectF r(points[0], points[1], points[4]-points[0], points[5]-points[1]);
5507  updateClipRegion(QRegion(r.toRect()), op);
5508  return;
5509  }
5510 
5511  QPainterPath p;
5512  if (types) {
5513  int id = 0;
5514  for (int i=0; i<path.elementCount(); ++i) {
5515  switch(types[i]) {
5517  p.moveTo(QPointF(points[id], points[id+1]));
5518  id+=2;
5519  break;
5521  p.lineTo(QPointF(points[id], points[id+1]));
5522  id+=2;
5523  break;
5525  QPointF p1(points[id], points[id+1]);
5526  QPointF p2(points[id+2], points[id+3]);
5527  QPointF p3(points[id+4], points[id+5]);
5528  p.cubicTo(p1, p2, p3);
5529  id+=6;
5530  break;
5531  }
5533  ;
5534  break;
5535  }
5536  }
5537  } else if (!path.isEmpty()) {
5538  p.moveTo(QPointF(points[0], points[1]));
5539  int id = 2;
5540  for (int i=1; i<path.elementCount(); ++i) {
5541  p.lineTo(QPointF(points[id], points[id+1]));
5542  id+=2;
5543  }
5544  }
5545  if (path.hints() & QVectorPath::WindingFill)
5547 
5549  return;
5550 }
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
double qreal
Definition: qglobal.h:1193
int elementCount() const
bool isEmpty() const
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPolygon toPolygon() const
Creates and returns a QPolygon by converting each QPointF to a QPoint.
Definition: qpolygon.cpp:772
const QPainterPath::ElementType * elements() const
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
void updateClipRegion(const QRegion &region, Qt::ClipOperation op)
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPolygonF toFillPolygon(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
Qt::FillRule fillRule() const
Returns the painter path&#39;s currently set fill rule.
uint hints() const
static const struct @32 types[]
const qreal * points() const
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...
Hint shape() const

◆ clipEnabledChanged()

void QOpenGLPaintEngine::clipEnabledChanged ( )
virtual

Implements QPaintEngineEx.

Definition at line 5407 of file qpaintengine_opengl.cpp.

5408 {
5410 
5411  d->updateDepthClip();
5412 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ compositionModeChanged()

void QOpenGLPaintEngine::compositionModeChanged ( )
virtual

Implements QPaintEngineEx.

Definition at line 5438 of file qpaintengine_opengl.cpp.

Referenced by begin().

5439 {
5440  updateCompositionMode(state()->composition_mode);
5441 }
QOpenGLPaintEngineState * state()
void updateCompositionMode(QPainter::CompositionMode composition_mode)

◆ createState()

QPainterState * QOpenGLPaintEngine::createState ( QPainterState orig) const
virtual

Reimplemented from QPaintEngineEx.

Definition at line 5578 of file qpaintengine_opengl.cpp.

5579 {
5580  const Q_D(QOpenGLPaintEngine);
5581 
5583  if (!orig)
5584  s = new QOpenGLPaintEngineState();
5585  else
5586  s = new QOpenGLPaintEngineState(*static_cast<QOpenGLPaintEngineState *>(orig));
5587 
5588  d->last_created_state = s;
5589  return s;
5590 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawEllipse()

void QOpenGLPaintEngine::drawEllipse ( const QRectF rect)
virtual

Reimplement this function to draw the largest ellipse that can be contained within rectangle rect.

The default implementation calls drawPolygon().

Reimplemented from QPaintEngineEx.

Definition at line 5025 of file qpaintengine_opengl.cpp.

5026 {
5027 #ifndef Q_WS_QWS
5029 
5030  if (d->use_emulation) {
5032  return;
5033  }
5034 
5035  if (d->high_quality_antialiasing) {
5036  if (d->has_brush) {
5037  d->disableClipping();
5038 
5039  glMatrixMode(GL_MODELVIEW);
5040  glPushMatrix();
5041  glLoadIdentity();
5042 
5043  GLuint program = qt_gl_program_cache()->getProgram(d->device->context(),
5045  QGLEllipseMaskGenerator maskGenerator(rect,
5046  d->matrix,
5047  d->offscreen,
5048  program,
5050 
5051  d->addItem(qt_mask_texture_cache()->getMask(maskGenerator, d));
5052 
5053  d->enableClipping();
5054 
5055  glMatrixMode(GL_MODELVIEW);
5056  glPopMatrix();
5057  }
5058 
5059  if (d->has_pen) {
5060  QPainterPath path;
5061  path.addEllipse(rect);
5062 
5063  d->strokePath(path, false);
5064  }
5065  } else {
5066  DEBUG_ONCE_STR("QOpenGLPaintEngine::drawEllipse(): falling back to drawPath()");
5067 
5068  QPainterPath path;
5069  path.addEllipse(rect);
5070  drawPath(path);
5071  }
5072 #else
5074 #endif
5075 }
double d
Definition: qnumeric_p.h:62
#define DEBUG_ONCE_STR(str)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.
#define Q_D(Class)
Definition: qglobal.h:2482
static int mask_variable_locations[num_fragment_masks][num_fragment_variables]
virtual void drawEllipse(const QRectF &r)
Reimplement this function to draw the largest ellipse that can be contained within rectangle rect...
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...

◆ drawImage()

void QOpenGLPaintEngine::drawImage ( const QRectF r,
const QImage pm,
const QRectF sr,
Qt::ImageConversionFlags  flags 
)
virtual

Reimplement this function to draw the part of the image specified by the sr rectangle in the given rectangle using the given conversion flags flags, to convert it to a pixmap.

Implements QPaintEngineEx.

Definition at line 4427 of file qpaintengine_opengl.cpp.

4429 {
4431 
4432  const int sz = d->max_texture_size;
4433  if (image.width() > sz || image.height() > sz) {
4434  QRectF subsr;
4435  const QImage sub = qSubImage(image, sr, &subsr);
4436 
4437  if (sub.width() <= sz && sub.height() <= sz) {
4438  drawImage(r, sub, subsr, 0);
4439  } else {
4440  const QImage scaled = sub.scaled(sz, sz, Qt::KeepAspectRatio);
4441  const qreal sx = scaled.width() / qreal(sub.width());
4442  const qreal sy = scaled.height() / qreal(sub.height());
4443 
4444  drawImage(r, scaled, scaleRect(subsr, sx, sy), 0);
4445  }
4446  return;
4447  }
4448 
4449  if (d->composition_mode > QPainter::CompositionMode_Plus || (d->high_quality_antialiasing && !d->isFastRect(r)))
4450  d->drawImageAsPath(r, image, sr);
4451  else {
4453  d->flushDrawQueue();
4454  QGLTexture *tex =
4455  d->device->context()->d_func()->bindTexture(image, target, GL_RGBA,
4457  drawTextureRect(image.width(), image.height(), r, sr, target, tex);
4458  }
4459 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
#define Q_D(Class)
Definition: qglobal.h:2482
GLenum qt_gl_preferredTextureTarget()
Definition: qgl_p.h:715
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void drawImage(const QRectF &r, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags conversionFlags)
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
unsigned int GLenum
Definition: main.cpp:50
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
#define GL_RGBA
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qimage.h:232
void drawTextureRect(int tx_width, int tx_height, const QRectF &r, const QRectF &sr, GLenum target, QGLTexture *tex)
static const QRectF scaleRect(const QRectF &r, qreal sx, qreal sy)
static const T qSubImage(const T &image, const QRectF &src, QRectF *srcNew)

◆ drawLines() [1/2]

void QOpenGLPaintEngine::drawLines ( const QLineF lines,
int  lineCount 
)
virtual

The default implementation splits the list of lines in lines into lineCount separate calls to drawPath() or drawPolygon() depending on the feature set of the paint engine.

Reimplemented from QPaintEngineEx.

Definition at line 3697 of file qpaintengine_opengl.cpp.

3698 {
3700 
3701  if (d->use_emulation) {
3702  QPaintEngineEx::drawLines(lines, lineCount);
3703  return;
3704  }
3705 
3706  if (d->has_pen) {
3707  QOpenGLCoordinateOffset offset(d);
3708  if (d->has_fast_pen && !d->high_quality_antialiasing) {
3709  //### gradient resolving on lines isn't correct
3710  d->setGradientOps(d->cpen.brush(), QRectF());
3711 
3712  bool useRects = false;
3713  // scale or 90 degree rotation?
3714  if (d->matrix.type() <= QTransform::TxTranslate
3715  || (!d->cpen.isCosmetic()
3716  && (d->matrix.type() <= QTransform::TxScale
3717  || (d->matrix.type() == QTransform::TxRotate
3718  && d->matrix.m11() == 0 && d->matrix.m22() == 0)))) {
3719  useRects = true;
3720  for (int i = 0; i < lineCount; ++i) {
3721  if (lines[i].p1().x() != lines[i].p2().x()
3722  && lines[i].p1().y() != lines[i].p2().y()) {
3723  useRects = false;
3724  break;
3725  }
3726  }
3727  }
3728 
3729  GLfloat endCap = d->cpen.capStyle() == Qt::FlatCap ? 0.0f : 0.5f;
3730  if (useRects) {
3731  QVarLengthArray<GLfloat> vertexArray(12 * lineCount);
3732 
3733  GLfloat quad[8];
3734  for (int i = 0; i < lineCount; ++i) {
3735  GLfloat x1 = lines[i].x1();
3736  GLfloat x2 = lines[i].x2();
3737  GLfloat y1 = lines[i].y1();
3738  GLfloat y2 = lines[i].y2();
3739 
3740  if (x1 == x2) {
3741  if (y1 > y2)
3742  qSwap(y1, y2);
3743 
3744  quad[0] = x1 - 0.5f;
3745  quad[1] = y1 - endCap;
3746 
3747  quad[2] = x1 + 0.5f;
3748  quad[3] = y1 - endCap;
3749 
3750  quad[4] = x1 + 0.5f;
3751  quad[5] = y2 + endCap;
3752 
3753  quad[6] = x1 - 0.5f;
3754  quad[7] = y2 + endCap;
3755  } else {
3756  if (x1 > x2)
3757  qSwap(x1, x2);
3758 
3759  quad[0] = x1 - endCap;
3760  quad[1] = y1 + 0.5f;
3761 
3762  quad[2] = x1 - endCap;
3763  quad[3] = y1 - 0.5f;
3764 
3765  quad[4] = x2 + endCap;
3766  quad[5] = y1 - 0.5f;
3767 
3768  quad[6] = x2 + endCap;
3769  quad[7] = y1 + 0.5f;
3770  }
3771 
3772  addQuadAsTriangle(quad, &vertexArray[12*i]);
3773  }
3774 
3775  glEnableClientState(GL_VERTEX_ARRAY);
3776 
3777  glVertexPointer(2, GL_FLOAT, 0, vertexArray.constData());
3778  glDrawArrays(GL_TRIANGLES, 0, lineCount*6);
3779 
3780  glDisableClientState(GL_VERTEX_ARRAY);
3781  } else {
3782  QVarLengthArray<GLfloat> vertexArray(4 * lineCount);
3783  for (int i = 0; i < lineCount; ++i) {
3784  vertexArray[4*i] = lines[i].x1();
3785  vertexArray[4*i+1] = lines[i].y1();
3786  vertexArray[4*i+2] = lines[i].x2();
3787  vertexArray[4*i+3] = lines[i].y2();
3788  }
3789 
3790  glEnableClientState(GL_VERTEX_ARRAY);
3791 
3792  glVertexPointer(2, GL_FLOAT, 0, vertexArray.constData());
3793  glDrawArrays(GL_LINES, 0, lineCount*2);
3794 
3795  glVertexPointer(2, GL_FLOAT, 4*sizeof(GLfloat), vertexArray.constData() + 2);
3796  glDrawArrays(GL_POINTS, 0, lineCount);
3797 
3798  glDisableClientState(GL_VERTEX_ARRAY);
3799  }
3800  } else {
3801  QPainterPath path;
3803  for (int i=0; i<lineCount; ++i) {
3804  const QLineF &l = lines[i];
3805 
3806  if (l.p1() == l.p2()) {
3807  if (d->cpen.capStyle() != Qt::FlatCap) {
3808  QPointF p = l.p1();
3809  drawPoints(&p, 1);
3810  }
3811  continue;
3812  }
3813 
3814  path.moveTo(l.x1(), l.y1());
3815  path.lineTo(l.x2(), l.y2());
3816  }
3817 
3818  if (d->has_fast_pen && d->high_quality_antialiasing)
3819  d->strokeLines(path);
3820  else
3821  d->strokePath(path, false);
3822  }
3823  }
3824 }
double d
Definition: qnumeric_p.h:62
#define GL_LINES
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define GL_POINTS
qreal x2() const
Returns the x-coordinate of the line&#39;s end point.
Definition: qline.h:304
QPointF p1() const
Returns the line&#39;s start point.
Definition: qline.h:314
qreal y2() const
Returns the y-coordinate of the line&#39;s end point.
Definition: qline.h:309
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_D(Class)
Definition: qglobal.h:2482
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal y1() const
Returns the y-coordinate of the line&#39;s start point.
Definition: qline.h:299
#define GL_FLOAT
void drawPoints(const QPointF *p, int pointCount)
Draws the first pointCount points in the buffer points.
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
virtual void drawLines(const QLine *lines, int lineCount)
The default implementation converts the first lineCount lines in lines to a QLineF and calls the floa...
static void addQuadAsTriangle(GLfloat *quad, GLfloat *triangle)
#define GL_TRIANGLES
QPointF p2() const
Returns the line&#39;s end point.
Definition: qline.h:319
QFactoryLoader * l
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal x1() const
Returns the x-coordinate of the line&#39;s start point.
Definition: qline.h:294

◆ drawLines() [2/2]

void QOpenGLPaintEngine::drawLines ( const QLine lines,
int  lineCount 
)
virtual

The default implementation converts the first lineCount lines in lines to a QLineF and calls the floating point version of this function.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented from QPaintEngineEx.

Definition at line 3669 of file qpaintengine_opengl.cpp.

3670 {
3671  struct PointF {
3672  qreal x;
3673  qreal y;
3674  };
3675  struct LineF {
3676  PointF p1;
3677  PointF p2;
3678  };
3679  Q_ASSERT(sizeof(PointF) == sizeof(QPointF));
3680  Q_ASSERT(sizeof(LineF) == sizeof(QLineF));
3681  LineF fl[256];
3682  while (lineCount) {
3683  int i = 0;
3684  while (i < lineCount && i < 256) {
3685  fl[i].p1.x = lines[i].x1();
3686  fl[i].p1.y = lines[i].y1();
3687  fl[i].p2.x = lines[i].x2();
3688  fl[i].p2.y = lines[i].y2();
3689  ++i;
3690  }
3691  drawLines((QLineF *)(void *)fl, i);
3692  lines += i;
3693  lineCount -= i;
3694  }
3695 }
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int y1() const
Returns the y-coordinate of the line&#39;s start point.
Definition: qline.h:117
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void drawLines(const QLineF *lines, int lineCount)
The default implementation splits the list of lines in lines into lineCount separate calls to drawPat...
int x2() const
Returns the x-coordinate of the line&#39;s end point.
Definition: qline.h:122
int y2() const
Returns the y-coordinate of the line&#39;s end point.
Definition: qline.h:127
int x1() const
Returns the x-coordinate of the line&#39;s start point.
Definition: qline.h:112

◆ drawPath()

void QOpenGLPaintEngine::drawPath ( const QPainterPath path)
virtual

The default implementation ignores the path and does nothing.

Reimplemented from QPaintEngineEx.

Definition at line 4166 of file qpaintengine_opengl.cpp.

4167 {
4169 
4170  if (path.isEmpty())
4171  return;
4172 
4173  if (d->use_emulation) {
4175  return;
4176  }
4177 
4178  QOpenGLCoordinateOffset offset(d);
4179 
4180  if (d->has_brush) {
4181  bool path_closed = pathClosed(path);
4182 
4183  bool has_thick_pen =
4184  path_closed
4185  && d->has_pen
4186  && d->cpen.style() == Qt::SolidLine
4187  && d->cpen.isSolid()
4188  && d->cpen.color().alpha() == 255
4189  && d->txop < QTransform::TxProject
4190  && d->cpen.widthF() >= 2 / qSqrt(qMin(d->matrix.m11() * d->matrix.m11()
4191  + d->matrix.m21() * d->matrix.m21(),
4192  d->matrix.m12() * d->matrix.m12()
4193  + d->matrix.m22() * d->matrix.m22()));
4194 
4195  if (has_thick_pen) {
4196  DEBUG_ONCE qDebug() << "QOpenGLPaintEngine::drawPath(): Using thick pen optimization, style:" << d->cbrush.style();
4197 
4198  d->flushDrawQueue();
4199 
4200  bool temp = d->high_quality_antialiasing;
4201  d->high_quality_antialiasing = false;
4202 
4203  updateCompositionMode(d->composition_mode);
4204 
4205  d->fillPath(path);
4206 
4207  d->high_quality_antialiasing = temp;
4208  updateCompositionMode(d->composition_mode);
4209  } else {
4210  d->fillPath(path);
4211  }
4212  }
4213 
4214  if (d->has_pen) {
4215  if (d->has_fast_pen && !d->high_quality_antialiasing)
4216  d->strokePathFastPen(path, state()->penNeedsResolving());
4217  else
4218  d->strokePath(path, true);
4219  }
4220 }
double d
Definition: qnumeric_p.h:62
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.
static bool pathClosed(const QPainterPath &path)
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
QOpenGLPaintEngineState * state()
void updateCompositionMode(QPainter::CompositionMode composition_mode)
#define DEBUG_ONCE
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ drawPixmap()

void QOpenGLPaintEngine::drawPixmap ( const QRectF r,
const QPixmap pm,
const QRectF sr 
)
virtual

Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.

Implements QPaintEngineEx.

Definition at line 4289 of file qpaintengine_opengl.cpp.

4290 {
4292  if (pm.depth() == 1) {
4293  QPixmap tpx(pm.size());
4294  tpx.fill(Qt::transparent);
4295  QPainter p(&tpx);
4296  p.setPen(d->cpen);
4297  p.drawPixmap(0, 0, pm);
4298  p.end();
4299  drawPixmap(r, tpx, sr);
4300  return;
4301  }
4302 
4303  const int sz = d->max_texture_size;
4304  if (pm.width() > sz || pm.height() > sz) {
4305  QRectF subsr;
4306  const QPixmap sub = qSubImage(pm, sr, &subsr);
4307 
4308  if (sub.width() <= sz && sub.height() <= sz) {
4309  drawPixmap(r, sub, subsr);
4310  } else {
4311  const QPixmap scaled = sub.scaled(sz, sz, Qt::KeepAspectRatio);
4312  const qreal sx = scaled.width() / qreal(sub.width());
4313  const qreal sy = scaled.height() / qreal(sub.height());
4314 
4315  drawPixmap(r, scaled, scaleRect(subsr, sx, sy));
4316  }
4317  return;
4318  }
4319 
4320 
4321  if (d->composition_mode > QPainter::CompositionMode_Plus || (d->high_quality_antialiasing && !d->isFastRect(r)))
4322  d->drawImageAsPath(r, pm.toImage(), sr);
4323  else {
4325  d->flushDrawQueue();
4326  QGLTexture *tex =
4327  d->device->context()->d_func()->bindTexture(pm, target, GL_RGBA,
4329  drawTextureRect(pm.width(), pm.height(), r, sr, target, tex);
4330  }
4331 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
double qreal
Definition: qglobal.h:1193
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qpixmap.h:132
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
#define Q_D(Class)
Definition: qglobal.h:2482
GLenum qt_gl_preferredTextureTarget()
Definition: qgl_p.h:715
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
unsigned int GLenum
Definition: main.cpp:50
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
#define GL_RGBA
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
void drawTextureRect(int tx_width, int tx_height, const QRectF &r, const QRectF &sr, GLenum target, QGLTexture *tex)
static const QRectF scaleRect(const QRectF &r, qreal sx, qreal sy)
static const T qSubImage(const T &image, const QRectF &src, QRectF *srcNew)

◆ drawPoints() [1/2]

void QOpenGLPaintEngine::drawPoints ( const QPointF points,
int  pointCount 
)
virtual

Draws the first pointCount points in the buffer points.

Reimplemented from QPaintEngineEx.

Definition at line 3596 of file qpaintengine_opengl.cpp.

3597 {
3599 
3600  if (d->use_emulation) {
3601  QPaintEngineEx::drawPoints(points, pointCount);
3602  return;
3603  }
3604 
3605  d->setGradientOps(d->cpen.brush(), QRectF());
3606 
3607  if (!d->cpen.isCosmetic() || d->high_quality_antialiasing) {
3608  Qt::PenCapStyle capStyle = d->cpen.capStyle();
3609  if (capStyle == Qt::FlatCap)
3610  d->cpen.setCapStyle(Qt::SquareCap);
3611  QPaintEngine::drawPoints(points, pointCount);
3612  d->cpen.setCapStyle(capStyle);
3613  return;
3614  }
3615 
3616  d->flushDrawQueue();
3617 
3618  if (d->has_fast_pen) {
3619  QVarLengthArray<GLfloat> vertexArray(6 * pointCount);
3620 
3621  glMatrixMode(GL_MODELVIEW);
3622  glPushMatrix();
3623  glLoadIdentity();
3624 
3625  int j = 0;
3626  for (int i = 0; i < pointCount; ++i) {
3627  QPointF mapped = d->matrix.map(points[i]);
3628 
3629  GLfloat x = GLfloat(qRound(mapped.x()));
3630  GLfloat y = GLfloat(qRound(mapped.y()));
3631 
3632  vertexArray[j++] = x;
3633  vertexArray[j++] = y - 0.5f;
3634 
3635  vertexArray[j++] = x + 1.5f;
3636  vertexArray[j++] = y + 1.0f;
3637 
3638  vertexArray[j++] = x;
3639  vertexArray[j++] = y + 1.0f;
3640  }
3641 
3642  glEnableClientState(GL_VERTEX_ARRAY);
3643 
3644  glVertexPointer(2, GL_FLOAT, 0, vertexArray.constData());
3645  glDrawArrays(GL_TRIANGLES, 0, pointCount*3);
3646 
3647  glDisableClientState(GL_VERTEX_ARRAY);
3648 
3649  glPopMatrix();
3650  return;
3651  }
3652 
3653  const qreal *vertexArray = reinterpret_cast<const qreal*>(&points[0]);
3654 
3655  if (sizeof(qreal) == sizeof(double)) {
3656  Q_ASSERT(sizeof(QPointF) == 16);
3657  glVertexPointer(2, GL_DOUBLE, 0, vertexArray);
3658  }
3659  else {
3660  Q_ASSERT(sizeof(QPointF) == 8);
3661  glVertexPointer(2, GL_FLOAT, 0, vertexArray);
3662  }
3663 
3664  glEnableClientState(GL_VERTEX_ARRAY);
3665  glDrawArrays(GL_POINTS, 0, pointCount);
3666  glDisableClientState(GL_VERTEX_ARRAY);
3667 }
virtual void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the buffer points.
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
#define GL_POINTS
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the buffer points.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
PenCapStyle
Definition: qnamespace.h:1147
QFuture< T > mapped(const Sequence &sequence, MapFunction function)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define GL_FLOAT
#define GL_TRIANGLES
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ drawPoints() [2/2]

void QOpenGLPaintEngine::drawPoints ( const QPoint points,
int  pointCount 
)
virtual

Draws the first pointCount points in the buffer points.

The default implementation converts the first pointCount QPoints in points to QPointFs and calls the floating point version of drawPoints.

Reimplemented from QPaintEngineEx.

Definition at line 3579 of file qpaintengine_opengl.cpp.

3580 {
3581  Q_ASSERT(sizeof(QT_PointF) == sizeof(QPointF));
3582  QT_PointF fp[256];
3583  while (pointCount) {
3584  int i = 0;
3585  while (i < pointCount && i < 256) {
3586  fp[i].x = points[i].x();
3587  fp[i].y = points[i].y();
3588  ++i;
3589  }
3590  drawPoints((QPointF *)(void *)fp, i);
3591  points += i;
3592  pointCount -= i;
3593  }
3594 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void drawPoints(const QPointF *p, int pointCount)
Draws the first pointCount points in the buffer points.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ drawPolygon() [1/2]

void QOpenGLPaintEngine::drawPolygon ( const QPointF points,
int  pointCount,
PolygonDrawMode  mode 
)
virtual

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

Note
At least one of the drawPolygon() functions must be reimplemented.

Reimplemented from QPaintEngineEx.

Definition at line 3837 of file qpaintengine_opengl.cpp.

3838 {
3840  if(pointCount < 2)
3841  return;
3842 
3843  if (d->use_emulation) {
3844  QPaintEngineEx::drawPolygon(points, pointCount, mode);
3845  return;
3846  }
3847 
3848  QRectF bounds;
3849  if ((mode == ConvexMode && !d->high_quality_antialiasing && state()->brushNeedsResolving()) ||
3850  ((d->has_fast_pen && !d->high_quality_antialiasing) && state()->penNeedsResolving())) {
3851  qreal minx = points[0].x(), miny = points[0].y(),
3852  maxx = points[0].x(), maxy = points[0].y();
3853  for (int i = 1; i < pointCount; ++i) {
3854  const QPointF &pt = points[i];
3855  if (minx > pt.x())
3856  minx = pt.x();
3857  if (miny > pt.y())
3858  miny = pt.y();
3859  if (maxx < pt.x())
3860  maxx = pt.x();
3861  if (maxy < pt.y())
3862  maxy = pt.y();
3863  }
3864  bounds = QRectF(minx, maxx, maxx-minx, maxy-miny);
3865  }
3866 
3867  QOpenGLCoordinateOffset offset(d);
3868 
3869  if (d->has_brush && mode != PolylineMode) {
3870  if (mode == ConvexMode && !d->high_quality_antialiasing) {
3871  //### resolving on polygon from points isn't correct
3872  d->setGradientOps(d->cbrush, bounds);
3873 
3874  const qreal *vertexArray = reinterpret_cast<const qreal*>(&points[0]);
3875 
3876  if (sizeof(qreal) == sizeof(double)) {
3877  Q_ASSERT(sizeof(QPointF) == 16);
3878  glVertexPointer(2, GL_DOUBLE, 0, vertexArray);
3879  }
3880  else {
3881  Q_ASSERT(sizeof(QPointF) == 8);
3882  glVertexPointer(2, GL_FLOAT, 0, vertexArray);
3883  }
3884 
3885  glEnableClientState(GL_VERTEX_ARRAY);
3886  glDrawArrays(GL_TRIANGLE_FAN, 0, pointCount);
3887  glDisableClientState(GL_VERTEX_ARRAY);
3888  } else {
3889  QPainterPath path;
3891  path.moveTo(points[0]);
3892  for (int i=1; i<pointCount; ++i)
3893  path.lineTo(points[i]);
3894  d->fillPath(path);
3895  }
3896  }
3897 
3898  if (d->has_pen) {
3899  if (d->has_fast_pen && !d->high_quality_antialiasing) {
3900  d->setGradientOps(d->cpen.brush(), bounds);
3901  QVarLengthArray<GLfloat> vertexArray(pointCount*2 + 2);
3902  glVertexPointer(2, GL_FLOAT, 0, vertexArray.constData());
3903  int i;
3904  for (i=0; i<pointCount; ++i) {
3905  vertexArray[i*2] = points[i].x();
3906  vertexArray[i*2+1] = points[i].y();
3907  }
3908 
3909  glEnableClientState(GL_VERTEX_ARRAY);
3910  if (mode != PolylineMode) {
3911  vertexArray[i*2] = vertexArray[0];
3912  vertexArray[i*2+1] = vertexArray[1];
3913  glDrawArrays(GL_LINE_STRIP, 0, pointCount+1);
3914  } else {
3915  glDrawArrays(GL_LINE_STRIP, 0, pointCount);
3916  glDrawArrays(GL_POINTS, pointCount-1, 1);
3917  }
3918  glDisableClientState(GL_VERTEX_ARRAY);
3919  } else {
3920  QPainterPath path(points[0]);
3921  for (int i = 1; i < pointCount; ++i)
3922  path.lineTo(points[i]);
3923  if (mode != PolylineMode)
3924  path.lineTo(points[0]);
3925 
3926  if (d->has_fast_pen)
3927  d->strokeLines(path);
3928  else
3929  d->strokePath(path, true);
3930  }
3931  }
3932 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define GL_POINTS
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QOpenGLPaintEngineState * state()
#define GL_TRIANGLE_FAN
#define GL_FLOAT
#define GL_LINE_STRIP
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ drawPolygon() [2/2]

void QOpenGLPaintEngine::drawPolygon ( const QPoint points,
int  pointCount,
PolygonDrawMode  mode 
)
virtual

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note
At least one of the drawPolygon() functions must be reimplemented.

Reimplemented from QPaintEngineEx.

Definition at line 3826 of file qpaintengine_opengl.cpp.

3827 {
3828  Q_ASSERT(sizeof(QT_PointF) == sizeof(QPointF));
3829  QVarLengthArray<QT_PointF> p(pointCount);
3830  for (int i=0; i<pointCount; ++i) {
3831  p[i].x = points[i].x();
3832  p[i].y = points[i].y();
3833  }
3834  drawPolygon((QPointF *)p.data(), pointCount, mode);
3835 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ drawPolyInternal()

void QOpenGLPaintEngine::drawPolyInternal ( const QPolygonF pa,
bool  close = true 
)
private

◆ drawRects() [1/2]

void QOpenGLPaintEngine::drawRects ( const QRectF rects,
int  rectCount 
)
virtual

Draws the first rectCount rectangles in the buffer rects.

The default implementation of this function calls drawPath() or drawPolygon() depending on the feature set of the paint engine.

Reimplemented from QPaintEngineEx.

Definition at line 3513 of file qpaintengine_opengl.cpp.

3514 {
3516 
3517  if (d->use_emulation) {
3518  QPaintEngineEx::drawRects(rects, rectCount);
3519  return;
3520  }
3521 
3522  for (int i=0; i<rectCount; ++i) {
3523  const QRectF &r = rects[i];
3524 
3525  // optimization for rects which can be drawn aliased
3526  if (!d->high_quality_antialiasing || d->isFastRect(r)) {
3527  d->drawFastRect(r);
3528  } else {
3529  QPainterPath path;
3530  path.addRect(r);
3531 
3532  if (d->has_brush) {
3533  d->disableClipping();
3534  GLuint program = qt_gl_program_cache()->getProgram(d->device->context(),
3536 
3537  if (d->matrix.type() >= QTransform::TxProject) {
3538  QGLPathMaskGenerator maskGenerator(path, d->matrix, d->offscreen, program);
3539  d->addItem(qt_mask_texture_cache()->getMask(maskGenerator, d));
3540  } else {
3541  QGLRectMaskGenerator maskGenerator(path, d->matrix, d->offscreen, program);
3542  d->addItem(qt_mask_texture_cache()->getMask(maskGenerator, d));
3543  }
3544 
3545  d->enableClipping();
3546  }
3547 
3548  if (d->has_pen) {
3549  if (d->has_fast_pen)
3550  d->strokeLines(path);
3551  else
3552  d->strokePath(path, false);
3553  }
3554  }
3555  }
3556 }
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
virtual void drawRects(const QRect *rects, int rectCount)
The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF an...

◆ drawRects() [2/2]

void QOpenGLPaintEngine::drawRects ( const QRect rects,
int  rectCount 
)
virtual

The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF and calls the floating point version of this function.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented from QPaintEngineEx.

Definition at line 3488 of file qpaintengine_opengl.cpp.

3489 {
3490  struct RectF {
3491  qreal x;
3492  qreal y;
3493  qreal w;
3494  qreal h;
3495  };
3496  Q_ASSERT(sizeof(RectF) == sizeof(QRectF));
3497  RectF fr[256];
3498  while (rectCount) {
3499  int i = 0;
3500  while (i < rectCount && i < 256) {
3501  fr[i].x = rects[i].x();
3502  fr[i].y = rects[i].y();
3503  fr[i].w = rects[i].width();
3504  fr[i].h = rects[i].height();
3505  ++i;
3506  }
3507  drawRects((QRectF *)(void *)fr, i);
3508  rects += i;
3509  rectCount -= i;
3510  }
3511 }
double qreal
Definition: qglobal.h:1193
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawRects(const QRectF *r, int rectCount)
Draws the first rectCount rectangles in the buffer rects.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252

◆ drawStaticTextItem()

void QOpenGLPaintEngine::drawStaticTextItem ( QStaticTextItem staticTextItem)
virtual

Reimplemented from QPaintEngineEx.

Definition at line 4922 of file qpaintengine_opengl.cpp.

4923 {
4925 
4926  d->flushDrawQueue();
4927 
4928  // make sure the glyphs we want to draw are in the cache
4929  qt_glyph_cache()->cacheGlyphs(d->device->context(), textItem->fontEngine(), textItem->glyphs,
4930  textItem->numGlyphs);
4931 
4932  d->setGradientOps(Qt::SolidPattern, QRectF()); // turns off gradient ops
4933  qt_glColor4ubv(d->pen_color);
4934  glEnable(GL_TEXTURE_2D);
4935 
4936 #ifdef Q_WS_QWS
4937  // XXX: it is necessary to disable alpha writes on GLES/embedded because we don't want
4938  // text rendering to update the alpha in the window surface.
4939  // XXX: This may not be needed as this behavior does seem to be caused by driver bug
4940  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
4941 #endif
4942 
4943  // do the actual drawing
4944  GLfloat vertexArray[4*2];
4945  GLfloat texCoordArray[4*2];
4946 
4947  glVertexPointer(2, GL_FLOAT, 0, vertexArray);
4948  glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray);
4949 
4950  glEnableClientState(GL_VERTEX_ARRAY);
4951  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
4952  bool antialias = !(textItem->fontEngine()->fontDef.styleStrategy & QFont::NoAntialias)
4953  && (d->matrix.type() > QTransform::TxTranslate);
4954  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, antialias ? GL_LINEAR : GL_NEAREST);
4955  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, antialias ? GL_LINEAR : GL_NEAREST);
4956 
4957  for (int i=0; i< textItem->numGlyphs; ++i) {
4958  QGLGlyphCoord *g = qt_glyph_cache()->lookup(textItem->fontEngine(), textItem->glyphs[i]);
4959 
4960  // we don't cache glyphs with no width/height
4961  if (!g)
4962  continue;
4963 
4964  qreal x1, x2, y1, y2;
4965  x1 = g->x;
4966  y1 = g->y;
4967  x2 = x1 + g->width;
4968  y2 = y1 + g->height;
4969 
4970  QPointF logical_pos((textItem->glyphPositions[i].x - g->x_offset).toReal(),
4971  (textItem->glyphPositions[i].y + g->y_offset).toReal());
4972 
4973  qt_add_rect_to_array(QRectF(logical_pos, QSizeF(g->log_width, g->log_height)), vertexArray);
4974  qt_add_texcoords_to_array(x1, y1, x2, y2, texCoordArray);
4975 
4976  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
4977  }
4978 
4979  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
4980  glDisableClientState(GL_VERTEX_ARRAY);
4981 
4982  glDisable(GL_TEXTURE_2D);
4983 
4984 #ifdef Q_WS_QWS
4985  // XXX: This may not be needed as this behavior does seem to be caused by driver bug
4986  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
4987 #endif
4988 
4989 }
double d
Definition: qnumeric_p.h:62
#define GL_TEXTURE_MIN_FILTER
double qreal
Definition: qglobal.h:1193
#define GL_TRUE
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static void qt_glColor4ubv(unsigned char *col)
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
#define GL_TEXTURE_2D
void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array)
Definition: qgl.cpp:2989
#define GL_FALSE
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define GL_TRIANGLE_FAN
#define GL_FLOAT
#define GL_LINEAR
#define GL_TEXTURE_MAG_FILTER
void qt_add_rect_to_array(const QRectF &r, GLfloat *array)
Definition: qgl.cpp:2972
static qreal toReal(Register *reg, int type, bool *ok=0)
#define GL_NEAREST

◆ drawTextItem()

void QOpenGLPaintEngine::drawTextItem ( const QPointF p,
const QTextItem textItem 
)
virtual

This function draws the text item textItem at position p.

The default implementation of this function converts the text to a QPainterPath and paints the resulting path.

Reimplemented from QPaintEngine.

Definition at line 4991 of file qpaintengine_opengl.cpp.

4992 {
4994 
4995  const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
4996 
4997  // fall back to drawing a polygon if the scale factor is large, or
4998  // we use a gradient pen
4999  if ((d->matrix.det() > 1) || (d->pen_brush_style >= Qt::LinearGradientPattern
5000  && d->pen_brush_style <= Qt::ConicalGradientPattern)) {
5001  QPaintEngine::drawTextItem(p, textItem);
5002  return;
5003  }
5004 
5005  // add the glyphs used to the glyph texture cache
5007  QVarLengthArray<glyph_t> glyphs;
5008  QTransform matrix = QTransform::fromTranslate(qRound(p.x()), qRound(p.y()));
5009  ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
5010 
5011  {
5012  QStaticTextItem staticTextItem;
5013  staticTextItem.chars = const_cast<QChar *>(ti.chars);
5014  staticTextItem.setFontEngine(ti.fontEngine);
5015  staticTextItem.glyphs = glyphs.data();
5016  staticTextItem.numChars = ti.num_chars;
5017  staticTextItem.numGlyphs = glyphs.size();
5018  staticTextItem.glyphPositions = positions.data();
5019  drawStaticTextItem(&staticTextItem);
5020  }
5021 
5022 }
double d
Definition: qnumeric_p.h:62
QFontEngine * fontEngine
void drawStaticTextItem(QStaticTextItem *staticTextItem)
const QChar * chars
QFixedPoint * glyphPositions
RenderFlags flags
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void setFontEngine(QFontEngine *fe)
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QGlyphLayout glyphs
static const QCssKnownValue positions[NumKnownPositionModes - 1]
Definition: qcssparser.cpp:329
void getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags, QVarLengthArray< glyph_t > &glyphs_out, QVarLengthArray< QFixedPoint > &positions)
Internal QTextItem.
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
int size() const
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
glyph_t * glyphs
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.

◆ drawTextureRect()

void QOpenGLPaintEngine::drawTextureRect ( int  tx_width,
int  tx_height,
const QRectF r,
const QRectF sr,
GLenum  target,
QGLTexture tex 
)
private

Definition at line 4461 of file qpaintengine_opengl.cpp.

4463 {
4465 #ifndef QT_OPENGL_ES
4466  glPushAttrib(GL_CURRENT_BIT);
4467  glDisable(GL_TEXTURE_GEN_S);
4468 #endif
4469  glColor4f(d->opacity, d->opacity, d->opacity, d->opacity);
4470  glEnable(target);
4471  updateTextureFilter(target, GL_CLAMP_TO_EDGE, d->use_smooth_pixmap_transform);
4472 
4473  qreal x1, x2, y1, y2;
4474  if (target == GL_TEXTURE_2D) {
4475  x1 = sr.x() / tx_width;
4476  x2 = x1 + sr.width() / tx_width;
4478  y1 = 1 - (sr.bottom() / tx_height);
4479  y2 = 1 - (sr.y() / tx_height);
4480  } else {
4481  y1 = sr.bottom() / tx_height;
4482  y2 = sr.y() / tx_height;
4483  }
4484  } else {
4485  x1 = sr.x();
4486  x2 = sr.right();
4487  y1 = sr.bottom();
4488  y2 = sr.y();
4489  }
4490 
4491  GLfloat vertexArray[4*2];
4492  GLfloat texCoordArray[4*2];
4493 
4494  qt_add_rect_to_array(r, vertexArray);
4495  qt_add_texcoords_to_array(x1, y2, x2, y1, texCoordArray);
4496 
4497  glVertexPointer(2, GL_FLOAT, 0, vertexArray);
4498  glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray);
4499 
4500  glEnableClientState(GL_VERTEX_ARRAY);
4501  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
4502  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
4503  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
4504  glDisableClientState(GL_VERTEX_ARRAY);
4505 
4506  glDisable(target);
4507 #ifndef QT_OPENGL_ES
4508  glPopAttrib();
4509 #endif
4510 }
double d
Definition: qnumeric_p.h:62
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
#define GL_CLAMP_TO_EDGE
Definition: glfunctions.h:62
double qreal
Definition: qglobal.h:1193
#define Q_D(Class)
Definition: qglobal.h:2482
QGLContext::BindOptions options
Definition: qgl_p.h:611
#define GL_TEXTURE_2D
void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array)
Definition: qgl.cpp:2989
#define GL_TRIANGLE_FAN
#define GL_FLOAT
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
static void updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform)
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
void qt_add_rect_to_array(const QRectF &r, GLfloat *array)
Definition: qgl.cpp:2972

◆ drawTiledPixmap()

void QOpenGLPaintEngine::drawTiledPixmap ( const QRectF rect,
const QPixmap pixmap,
const QPointF p 
)
virtual

Reimplement this function to draw the pixmap in the given rect, starting at the given p.

The pixmap will be drawn repeatedly until the rect is filled.

Reimplemented from QPaintEngineEx.

Definition at line 4333 of file qpaintengine_opengl.cpp.

4334 {
4336  if (pm.depth() == 1) {
4337  QPixmap tpx(pm.size());
4338  tpx.fill(Qt::transparent);
4339  QPainter p(&tpx);
4340  p.setPen(d->cpen);
4341  p.drawPixmap(0, 0, pm);
4342  p.end();
4343  drawTiledPixmap(r, tpx, offset);
4344  return;
4345  }
4346 
4347  QImage scaled;
4348  const int sz = d->max_texture_size;
4349  if (pm.width() > sz || pm.height() > sz) {
4350  int rw = qCeil(r.width());
4351  int rh = qCeil(r.height());
4352  if (rw < pm.width() && rh < pm.height()) {
4353  drawTiledPixmap(r, pm.copy(0, 0, rw, rh), offset);
4354  return;
4355  }
4356 
4357  scaled = pm.toImage().scaled(sz, sz, Qt::KeepAspectRatio);
4358  }
4359 
4360  if (d->composition_mode > QPainter::CompositionMode_Plus || (d->high_quality_antialiasing && !d->isFastRect(r))) {
4361  if (scaled.isNull())
4362  d->drawTiledImageAsPath(r, pm.toImage(), 1, 1, offset);
4363  else {
4364  const qreal sx = pm.width() / qreal(scaled.width());
4365  const qreal sy = pm.height() / qreal(scaled.height());
4366  d->drawTiledImageAsPath(r, scaled, sx, sy, offset);
4367  }
4368  } else {
4369  d->flushDrawQueue();
4370 
4371  QGLTexture *tex;
4372  if (scaled.isNull())
4373  tex = d->device->context()->d_func()->bindTexture(pm, GL_TEXTURE_2D, GL_RGBA,
4375  else
4376  tex = d->device->context()->d_func()->bindTexture(scaled, GL_TEXTURE_2D, GL_RGBA,
4378  updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, d->use_smooth_pixmap_transform);
4379 
4380 #ifndef QT_OPENGL_ES
4381  glPushAttrib(GL_CURRENT_BIT);
4382  glDisable(GL_TEXTURE_GEN_S);
4383 #endif
4384  glColor4f(d->opacity, d->opacity, d->opacity, d->opacity);
4385  glEnable(GL_TEXTURE_2D);
4386 
4387  GLdouble tc_w = r.width()/pm.width();
4388  GLdouble tc_h = r.height()/pm.height();
4389 
4390  // Rotate the texture so that it is aligned correctly and the
4391  // wrapping is done correctly
4393  glMatrixMode(GL_TEXTURE);
4394  glPushMatrix();
4395  glRotatef(180.0, 0.0, 1.0, 0.0);
4396  glRotatef(180.0, 0.0, 0.0, 1.0);
4397  }
4398 
4399  GLfloat vertexArray[4*2];
4400  GLfloat texCoordArray[4*2];
4401 
4402  double offset_x = offset.x() / pm.width();
4403  double offset_y = offset.y() / pm.height();
4404 
4405  qt_add_rect_to_array(r, vertexArray);
4406  qt_add_texcoords_to_array(offset_x, offset_y,
4407  tc_w + offset_x, tc_h + offset_y, texCoordArray);
4408 
4409  glVertexPointer(2, GL_FLOAT, 0, vertexArray);
4410  glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray);
4411 
4412  glEnableClientState(GL_VERTEX_ARRAY);
4413  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
4414  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
4415  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
4416  glDisableClientState(GL_VERTEX_ARRAY);
4418  glPopMatrix();
4419 
4420  glDisable(GL_TEXTURE_2D);
4421 #ifndef QT_OPENGL_ES
4422  glPopAttrib();
4423 #endif
4424  }
4425 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
int qCeil(qreal v)
Definition: qmath.h:63
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
#define Q_D(Class)
Definition: qglobal.h:2482
QGLContext::BindOptions options
Definition: qgl_p.h:611
#define GL_TEXTURE_2D
#define GL_TEXTURE
#define GL_REPEAT
void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array)
Definition: qgl.cpp:2989
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
#define GL_TRIANGLE_FAN
#define GL_FLOAT
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
static void updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform)
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
#define GL_RGBA
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qimage.h:232
void qt_add_rect_to_array(const QRectF &r, GLfloat *array)
Definition: qgl.cpp:2972

◆ end()

bool QOpenGLPaintEngine::end ( )
virtual

Reimplement this function to finish painting on the current paint device.

Return true if painting was finished successfully; otherwise return false.

See also
begin() isActive()

Implements QPaintEngine.

Definition at line 1432 of file qpaintengine_opengl.cpp.

Referenced by QGLMaskTextureCache::maintainCache().

1433 {
1435  d->flushDrawQueue();
1436  d->offscreen.end();
1437  QGLContext *ctx = const_cast<QGLContext *>(d->device->context());
1438  if (!ctx->d_ptr->internal_context) {
1439  glMatrixMode(GL_TEXTURE);
1440  glPopMatrix();
1441  glMatrixMode(GL_MODELVIEW);
1442  glPopMatrix();
1443  }
1444 #ifndef QT_OPENGL_ES
1445  if (ctx->d_ptr->internal_context) {
1446  glDisable(GL_SCISSOR_TEST);
1447  } else {
1448  glMatrixMode(GL_PROJECTION);
1449  glLoadMatrixd(&d->projection_matrix[0][0]);
1450  glPopAttrib();
1451  glPopClientAttrib();
1452  }
1453 #endif
1454  d->device->endPaint();
1455  qt_mask_texture_cache()->maintainCache();
1456 
1457 #if defined(Q_WS_X11)
1458  // clear out the references we hold for textures bound with the
1459  // texture_from_pixmap extension
1460  ctx->d_func()->boundPixmaps.clear();
1461 #endif
1462  return true;
1463 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
#define Q_D(Class)
Definition: qglobal.h:2482
uint internal_context
Definition: qgl_p.h:426
#define GL_TEXTURE
#define GL_SCISSOR_TEST
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define ctx
Definition: qgl.cpp:6094

◆ fill()

void QOpenGLPaintEngine::fill ( const QVectorPath path,
const QBrush brush 
)
virtual

Implements QPaintEngineEx.

Definition at line 5455 of file qpaintengine_opengl.cpp.

5456 {
5458 
5459  if (brush.style() == Qt::NoBrush)
5460  return;
5461 
5462  if ((!d->use_fragment_programs && needsEmulation(brush.style())) || qt_isExtendedRadialGradient(brush)) {
5463  QPainter *p = painter();
5464  QBrush oldBrush = p->brush();
5465  p->setBrush(brush);
5467  p->setBrush(oldBrush);
5468  return;
5469  }
5470 
5471  QBrush old_brush = state()->brush;
5472  updateBrush(brush, state()->brushOrigin);
5473 
5474  const qreal *points = path.points();
5475  const QPainterPath::ElementType *types = path.elements();
5476  if (!types && path.shape() == QVectorPath::RectangleHint) {
5477  QRectF r(points[0], points[1], points[4]-points[0], points[5]-points[1]);
5478  QPen old_pen = state()->pen;
5480  drawRects(&r, 1);
5481  updatePen(old_pen);
5482  } else {
5483  d->fillPath(qt_painterPathFromVectorPath(path));
5484  }
5485 
5486  updateBrush(old_brush, state()->brushOrigin);
5487 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
double qreal
Definition: qglobal.h:1193
T * data() const
Returns the value of the pointer referenced by this object.
Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush)
Definition: qbrush.cpp:881
void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation)
Definition: qpainter.cpp:9937
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
const QPainterPath::ElementType * elements() const
QPainter * painter() const
Returns the paint engine&#39;s painter.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QOpenGLPaintEngineState * state()
void drawRects(const QRectF *r, int rectCount)
Draws the first rectCount rectangles in the buffer rects.
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void updateBrush(const QBrush &brush, const QPointF &pt)
static const struct @32 types[]
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
const qreal * points() const
QBrush brush
Definition: qpainter_p.h:153
static bool needsEmulation(Qt::BrushStyle style)
void updatePen(const QPen &pen)
Q_GUI_EXPORT QPainterPath qt_painterPathFromVectorPath(const QVectorPath &path)
QScopedPointer< QPainterPrivate > d_ptr
Definition: qpainter.h:546
Hint shape() const

◆ handle()

HDC QOpenGLPaintEngine::handle ( ) const

Definition at line 4517 of file qpaintengine_opengl.cpp.

4518 {
4519  return 0;
4520 }

◆ opacityChanged()

void QOpenGLPaintEngine::opacityChanged ( )
virtual

Implements QPaintEngineEx.

Definition at line 5429 of file qpaintengine_opengl.cpp.

Referenced by begin().

5430 {
5432  QPainterState *s = state();
5433  d->opacity = s->opacity;
5434  updateBrush(s->brush, s->brushOrigin);
5435  updatePen(s->pen);
5436 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QOpenGLPaintEngineState * state()
void updateBrush(const QBrush &brush, const QPointF &pt)
QPointF brushOrigin
Definition: qpainter_p.h:149
QBrush brush
Definition: qpainter_p.h:153
void updatePen(const QPen &pen)

◆ penChanged()

void QOpenGLPaintEngine::penChanged ( )
virtual

Implements QPaintEngineEx.

Definition at line 5414 of file qpaintengine_opengl.cpp.

Referenced by begin().

5415 {
5416  updatePen(state()->pen);
5417 }
QOpenGLPaintEngineState * state()
void updatePen(const QPen &pen)

◆ renderHintsChanged()

void QOpenGLPaintEngine::renderHintsChanged ( )
virtual

Implements QPaintEngineEx.

Definition at line 5443 of file qpaintengine_opengl.cpp.

Referenced by begin().

5444 {
5445  updateRenderHints(state()->renderHints);
5446 }
QOpenGLPaintEngineState * state()
void updateRenderHints(QPainter::RenderHints hints)

◆ setState()

void QOpenGLPaintEngine::setState ( QPainterState s)
virtual

Reimplemented from QPaintEngineEx.

Definition at line 5552 of file qpaintengine_opengl.cpp.

5553 {
5555  QOpenGLPaintEngineState *new_state = static_cast<QOpenGLPaintEngineState *>(s);
5556  QOpenGLPaintEngineState *old_state = state();
5557 
5559 
5560  // are we in a save() ?
5561  if (s == d->last_created_state) {
5562  d->last_created_state = 0;
5563  return;
5564  }
5565 
5566  if (isActive()) {
5567  if (old_state->depthClipId != new_state->depthClipId)
5568  d->updateDepthClip();
5569  penChanged();
5570  brushChanged();
5571  opacityChanged();
5574  transformChanged();
5575  }
5576 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
QOpenGLPaintEngineState * state()
virtual void setState(QPainterState *s)

◆ state() [1/2]

QOpenGLPaintEngineState* QOpenGLPaintEngine::state ( )
inline

Definition at line 101 of file qpaintengine_opengl_p.h.

Referenced by updateClipRegion().

101  {
102  return static_cast<QOpenGLPaintEngineState *>(QPaintEngineEx::state());
103  }
QPainterState * state()

◆ state() [2/2]

const QOpenGLPaintEngineState* QOpenGLPaintEngine::state ( ) const
inline

Definition at line 104 of file qpaintengine_opengl_p.h.

104  {
105  return static_cast<const QOpenGLPaintEngineState *>(QPaintEngineEx::state());
106  }
QPainterState * state()

◆ supportsTransformations()

bool QOpenGLPaintEngine::supportsTransformations ( qreal  ,
const QTransform  
) const
inlinevirtual

Reimplemented from QPaintEngineEx.

Definition at line 146 of file qpaintengine_opengl_p.h.

146 { return true; }

◆ transformChanged()

void QOpenGLPaintEngine::transformChanged ( )
virtual

Implements QPaintEngineEx.

Definition at line 5448 of file qpaintengine_opengl.cpp.

Referenced by begin().

5449 {
5450  updateMatrix(state()->matrix);
5451 }
void updateMatrix(const QTransform &matrix)
QOpenGLPaintEngineState * state()

◆ type()

Type QOpenGLPaintEngine::type ( ) const
inlinevirtual

Reimplement this function to return the paint engine Type.

Implements QPaintEngine.

Definition at line 145 of file qpaintengine_opengl_p.h.

◆ updateBrush()

void QOpenGLPaintEngine::updateBrush ( const QBrush brush,
const QPointF pt 
)

Definition at line 2166 of file qpaintengine_opengl.cpp.

Referenced by updateState().

2167 {
2169  d->cbrush = brush;
2170  d->brush_style = brush.style();
2171  d->brush_origin = origin;
2172  d->has_brush = (d->brush_style != Qt::NoBrush);
2173  d->updateUseEmulation();
2174 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182

◆ updateClipRegion()

void QOpenGLPaintEngine::updateClipRegion ( const QRegion region,
Qt::ClipOperation  op 
)

Definition at line 2347 of file qpaintengine_opengl.cpp.

Referenced by begin(), and updateState().

2348 {
2350 
2351  // clipping is only supported when a stencil or depth buffer is
2352  // available
2353  if (!d->device->format().depth())
2354  return;
2355 
2356  d->use_system_clip = false;
2357  QRegion sysClip = systemClip();
2358  if (!sysClip.isEmpty()) {
2359  if (d->pdev->devType() != QInternal::Widget) {
2360  d->use_system_clip = true;
2361  } else {
2362 #ifndef Q_WS_QWS
2363  // Only use the system clip if we're currently rendering a widget with a GL painter.
2364  if (d->currentClipWidget) {
2365  QWidgetPrivate *widgetPrivate = qt_widget_private(d->currentClipWidget->window());
2366  d->use_system_clip = widgetPrivate->extra && widgetPrivate->extra->inRenderWithPainter;
2367  }
2368 #endif
2369  }
2370  }
2371 
2372  d->flushDrawQueue();
2373 
2374  if (op == Qt::NoClip && !d->use_system_clip) {
2375  state()->hasClipping = false;
2376  state()->clipRegion = QRegion();
2377  d->updateDepthClip();
2378  return;
2379  }
2380 
2381  bool isScreenClip = false;
2382  if (!d->use_system_clip) {
2383  QVector<QRect> untransformedRects = clipRegion.rects();
2384 
2385  if (untransformedRects.size() == 1) {
2386  QPainterPath path;
2387  path.addRect(untransformedRects[0]);
2388  path = d->matrix.map(path);
2389 
2390  if (path.contains(QRectF(QPointF(), d->device->size())))
2391  isScreenClip = true;
2392  }
2393  }
2394 
2395  QRegion region = isScreenClip ? QRegion() : clipRegion * d->matrix;
2396  switch (op) {
2397  case Qt::NoClip:
2398  if (!d->use_system_clip)
2399  break;
2400  state()->clipRegion = sysClip;
2401  break;
2402  case Qt::IntersectClip:
2403  if (isScreenClip)
2404  return;
2405  if (state()->hasClipping) {
2406  state()->clipRegion &= region;
2407  break;
2408  }
2409  // fall through
2410  case Qt::ReplaceClip:
2411  if (d->use_system_clip)
2412  state()->clipRegion = region & sysClip;
2413  else
2414  state()->clipRegion = region;
2415  break;
2416  case Qt::UniteClip:
2417  state()->clipRegion |= region;
2418  if (d->use_system_clip)
2419  state()->clipRegion &= sysClip;
2420  break;
2421  default:
2422  break;
2423  }
2424 
2425  if (isScreenClip) {
2426  state()->hasClipping = false;
2427  state()->clipRegion = QRegion();
2428  } else {
2429  state()->hasClipping = op != Qt::NoClip || d->use_system_clip;
2430  }
2431 
2432  if (state()->hasClipping && state()->clipRegion.rects().size() == 1)
2433  state()->fastClip = state()->clipRegion.rects().at(0);
2434  else
2435  state()->fastClip = QRect();
2436 
2437  d->updateDepthClip();
2438 }
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QOpenGLPaintEngineState * state()
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
uint inRenderWithPainter
Definition: qwidget_p.h:277
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QWExtra * extra
Definition: qwidget_p.h:700
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
QRegion systemClip() const
Returns the system clip.
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ updateCompositionMode()

void QOpenGLPaintEngine::updateCompositionMode ( QPainter::CompositionMode  composition_mode)

Definition at line 2489 of file qpaintengine_opengl.cpp.

Referenced by updateState().

2490 {
2492 
2493  if (!d->use_fragment_programs && composition_mode > QPainter::CompositionMode_Plus)
2494  composition_mode = QPainter::CompositionMode_SourceOver;
2495 
2496  d->composition_mode = composition_mode;
2497 
2498  d->has_fast_composition_mode = (!d->high_quality_antialiasing && composition_mode <= QPainter::CompositionMode_Plus)
2499  || composition_mode == QPainter::CompositionMode_SourceOver
2500  || composition_mode == QPainter::CompositionMode_Destination
2501  || composition_mode == QPainter::CompositionMode_DestinationOver
2502  || composition_mode == QPainter::CompositionMode_DestinationOut
2503  || composition_mode == QPainter::CompositionMode_SourceAtop
2504  || composition_mode == QPainter::CompositionMode_Xor
2505  || composition_mode == QPainter::CompositionMode_Plus;
2506 
2507  if (d->has_fast_composition_mode)
2508  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODE_BLEND_MODE_MASK : COMPOSITION_MODE_BLEND_MODE_NOMASK;
2509  else if (composition_mode <= QPainter::CompositionMode_Plus)
2510  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_SIMPLE_PORTER_DUFF : COMPOSITION_MODES_SIMPLE_PORTER_DUFF_NOMASK;
2511  else
2512  switch (composition_mode) {
2514  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_MULTIPLY : COMPOSITION_MODES_MULTIPLY_NOMASK;
2515  break;
2517  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_SCREEN : COMPOSITION_MODES_SCREEN_NOMASK;
2518  break;
2520  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_OVERLAY : COMPOSITION_MODES_OVERLAY_NOMASK;
2521  break;
2523  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_DARKEN : COMPOSITION_MODES_DARKEN_NOMASK;
2524  break;
2526  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_LIGHTEN : COMPOSITION_MODES_LIGHTEN_NOMASK;
2527  break;
2529  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_COLORDODGE : COMPOSITION_MODES_COLORDODGE_NOMASK;
2530  break;
2532  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_COLORBURN : COMPOSITION_MODES_COLORBURN_NOMASK;
2533  break;
2535  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_HARDLIGHT : COMPOSITION_MODES_HARDLIGHT_NOMASK;
2536  break;
2538  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_SOFTLIGHT : COMPOSITION_MODES_SOFTLIGHT_NOMASK;
2539  break;
2541  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_DIFFERENCE : COMPOSITION_MODES_DIFFERENCE_NOMASK;
2542  break;
2544  d->fragment_composition_mode = d->high_quality_antialiasing ? COMPOSITION_MODES_EXCLUSION : COMPOSITION_MODES_EXCLUSION_NOMASK;
2545  break;
2546  default:
2547  Q_ASSERT(false);
2548  }
2549 
2550  switch(composition_mode) {
2552  glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
2553  d->setPorterDuffData(0, 1, 1, 1, 1);
2554  break;
2556  glBlendFunc(GL_ZERO, GL_ZERO);
2557  d->setPorterDuffData(0, 0, 0, 0, 0);
2558  break;
2560  glBlendFunc(GL_ONE, GL_ZERO);
2561  d->setPorterDuffData(1, 0, 1, 1, 0);
2562  break;
2564  glBlendFunc(GL_ZERO, GL_ONE);
2565  d->setPorterDuffData(0, 1, 1, 0, 1);
2566  break;
2568  glBlendFunc(GL_DST_ALPHA, GL_ZERO);
2569  d->setPorterDuffData(1, 0, 1, 0, 0);
2570  break;
2572  glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
2573  d->setPorterDuffData(0, 1, 1, 0, 0);
2574  break;
2576  glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO);
2577  d->setPorterDuffData(0, 0, 0, 1, 0);
2578  break;
2580  glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
2581  d->setPorterDuffData(0, 0, 0, 0, 1);
2582  break;
2584  glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2585  d->setPorterDuffData(1, 0, 1, 0, 1);
2586  break;
2588  glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA);
2589  d->setPorterDuffData(0, 1, 1, 1, 0);
2590  break;
2593  d->setPorterDuffData(0, 0, 0, 1, 1);
2594  break;
2596  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2597  d->setPorterDuffData(1, 0, 1, 1, 1);
2598  break;
2600  glBlendFunc(GL_ONE, GL_ONE);
2601  d->setPorterDuffData(1, 1, 1, 1, 1);
2602  break;
2603  default:
2604  break;
2605  }
2606 }
#define GL_ONE_MINUS_SRC_ALPHA
double d
Definition: qnumeric_p.h:62
#define GL_SRC_ALPHA
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
#define GL_ONE_MINUS_DST_ALPHA
#define GL_ZERO
#define GL_DST_ALPHA
#define GL_ONE

◆ updateFont()

void QOpenGLPaintEngine::updateFont ( const QFont font)

Definition at line 2176 of file qpaintengine_opengl.cpp.

Referenced by updateState().

2177 {
2178 }

◆ updateMatrix()

void QOpenGLPaintEngine::updateMatrix ( const QTransform matrix)

Definition at line 2180 of file qpaintengine_opengl.cpp.

Referenced by updateState().

2181 {
2183 
2184  d->matrix = mtx;
2185 
2186  d->mv_matrix[0][0] = mtx.m11();
2187  d->mv_matrix[0][1] = mtx.m12();
2188  d->mv_matrix[0][2] = 0;
2189  d->mv_matrix[0][3] = mtx.m13();
2190 
2191  d->mv_matrix[1][0] = mtx.m21();
2192  d->mv_matrix[1][1] = mtx.m22();
2193  d->mv_matrix[1][2] = 0;
2194  d->mv_matrix[1][3] = mtx.m23();
2195 
2196  d->mv_matrix[2][0] = 0;
2197  d->mv_matrix[2][1] = 0;
2198  d->mv_matrix[2][2] = 1;
2199  d->mv_matrix[2][3] = 0;
2200 
2201  d->mv_matrix[3][0] = mtx.dx();
2202  d->mv_matrix[3][1] = mtx.dy();
2203  d->mv_matrix[3][2] = 0;
2204  d->mv_matrix[3][3] = mtx.m33();
2205 
2206  d->txop = mtx.type();
2207 
2208  // 1/10000 == 0.0001, so we have good enough res to cover curves
2209  // that span the entire widget...
2210  d->inverseScale = qMax(1 / qMax( qMax(qAbs(mtx.m11()), qAbs(mtx.m22())),
2211  qMax(qAbs(mtx.m12()), qAbs(mtx.m21())) ),
2212  qreal(0.0001));
2213 
2214  d->updateGLMatrix();
2215  d->updateFastPen();
2216 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

◆ updatePen()

void QOpenGLPaintEngine::updatePen ( const QPen pen)

Definition at line 2140 of file qpaintengine_opengl.cpp.

Referenced by updateState().

2141 {
2143  Qt::PenStyle pen_style = pen.style();
2144  d->pen_brush_style = pen.brush().style();
2145  d->cpen = pen;
2146  d->has_pen = (pen_style != Qt::NoPen) && (d->pen_brush_style != Qt::NoBrush);
2147  d->updateUseEmulation();
2148 
2149  if (pen.isCosmetic()) {
2150  GLfloat width = pen.widthF() == 0.0f ? 1.0f : pen.widthF();
2151  glLineWidth(width);
2152  glPointSize(width);
2153  }
2154 
2155  if (d->pen_brush_style >= Qt::LinearGradientPattern
2156  && d->pen_brush_style <= Qt::ConicalGradientPattern)
2157  {
2158  d->setGLPen(Qt::white);
2159  } else {
2160  d->setGLPen(pen.color());
2161  }
2162 
2163  d->updateFastPen();
2164 }
double d
Definition: qnumeric_p.h:62
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
#define Q_D(Class)
Definition: qglobal.h:2482
PenStyle
Definition: qnamespace.h:1134
bool isCosmetic() const
Returns true if the pen is cosmetic; otherwise returns false.
Definition: qpen.cpp:840
QBrush brush() const
Returns the brush used to fill strokes generated with this pen.
Definition: qpen.cpp:797
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645

◆ updateRenderHints()

void QOpenGLPaintEngine::updateRenderHints ( QPainter::RenderHints  hints)

Definition at line 2440 of file qpaintengine_opengl.cpp.

Referenced by updateState().

2441 {
2443 
2444  d->flushDrawQueue();
2445  d->use_smooth_pixmap_transform = bool(hints & QPainter::SmoothPixmapTransform);
2446  if ((hints & QPainter::Antialiasing) || (hints & QPainter::HighQualityAntialiasing)) {
2447  if (d->use_fragment_programs && QGLOffscreen::isSupported()
2448  && (hints & QPainter::HighQualityAntialiasing)) {
2449  d->high_quality_antialiasing = true;
2450  } else {
2451  d->high_quality_antialiasing = false;
2453  glEnable(GL_MULTISAMPLE);
2454  }
2455  } else {
2456  d->high_quality_antialiasing = false;
2458  glDisable(GL_MULTISAMPLE);
2459  }
2460 
2461  if (d->high_quality_antialiasing) {
2462  d->offscreen.initialize();
2463 
2464  if (!d->offscreen.isValid()) {
2465  DEBUG_ONCE_STR("Unable to initialize offscreen, disabling high quality antialiasing");
2466  d->high_quality_antialiasing = false;
2468  glEnable(GL_MULTISAMPLE);
2469  }
2470  }
2471 
2472  d->has_antialiasing = d->high_quality_antialiasing
2473  || ((hints & QPainter::Antialiasing)
2475 }
double d
Definition: qnumeric_p.h:62
#define DEBUG_ONCE_STR(str)
static bool isSupported()
#define Q_D(Class)
Definition: qglobal.h:2482
#define GL_MULTISAMPLE
static Extensions glExtensions()
Definition: qgl.cpp:5781

◆ updateState()

void QOpenGLPaintEngine::updateState ( const QPaintEngineState state)
virtual

Reimplement this function to update the state of a paint engine.

When implemented, this function is responsible for checking the paint engine's current state and update the properties that are changed. Use the QPaintEngineState::state() function to find out which properties that must be updated, then use the corresponding GetFunction{get function} to retrieve the current values for the given properties.

See also
QPaintEngineState

Reimplemented from QPaintEngineEx.

Definition at line 1465 of file qpaintengine_opengl.cpp.

1466 {
1468  QPaintEngine::DirtyFlags flags = state.state();
1469 
1470  bool update_fast_pen = false;
1471 
1472  if (flags & DirtyOpacity) {
1473  update_fast_pen = true;
1474  d->opacity = state.opacity();
1475  if (d->opacity > 1.0f)
1476  d->opacity = 1.0f;
1477  if (d->opacity < 0.f)
1478  d->opacity = 0.f;
1479  // force update
1480  flags |= DirtyPen;
1481  flags |= DirtyBrush;
1482  }
1483 
1484  if (flags & DirtyTransform) {
1485  update_fast_pen = true;
1486  updateMatrix(state.transform());
1487  // brush setup depends on transform state
1488  if (state.brush().style() != Qt::NoBrush)
1489  flags |= DirtyBrush;
1490  }
1491 
1492  if (flags & DirtyPen) {
1493  update_fast_pen = true;
1494  updatePen(state.pen());
1495  }
1496 
1497  if (flags & (DirtyBrush | DirtyBrushOrigin)) {
1498  updateBrush(state.brush(), state.brushOrigin());
1499  }
1500 
1501  if (flags & DirtyFont) {
1502  updateFont(state.font());
1503  }
1504 
1505  if (state.state() & DirtyClipEnabled) {
1506  if (state.isClipEnabled())
1508  else
1510  }
1511 
1512  if (flags & DirtyClipPath) {
1514  state.clipPath().fillRule()),
1515  state.clipOperation());
1516  }
1517 
1518  if (flags & DirtyClipRegion) {
1519  updateClipRegion(state.clipRegion(), state.clipOperation());
1520  }
1521 
1522  if (flags & DirtyHints) {
1523  updateRenderHints(state.renderHints());
1524  }
1525 
1526  if (flags & DirtyCompositionMode) {
1528  }
1529 
1530  if (update_fast_pen) {
1532  qreal pen_width = d->cpen.widthF();
1533  d->has_fast_pen =
1534  ((pen_width == 0 || (pen_width <= 1 && d->txop <= QTransform::TxTranslate))
1535  || d->cpen.isCosmetic())
1536  && d->cpen.style() == Qt::SolidLine
1537  && d->cpen.isSolid();
1538  }
1539 }
double d
Definition: qnumeric_p.h:62
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
Definition: qpaintengine.h:292
double qreal
Definition: qglobal.h:1193
qreal opacity() const
Returns the opacity in the current paint engine state.
Definition: qpainter.cpp:9529
void updateMatrix(const QTransform &matrix)
QTransform transform() const
Returns the matrix in the current paint engine state.
Definition: qpainter.cpp:9377
virtual uint flags() const
bool isClipEnabled() const
Returns whether clipping is enabled or not in the current paint engine state.
Definition: qpainter.cpp:9473
#define Q_D(Class)
Definition: qglobal.h:2482
QPolygon toPolygon() const
Creates and returns a QPolygon by converting each QPointF to a QPoint.
Definition: qpolygon.cpp:772
void updateClipRegion(const QRegion &region, Qt::ClipOperation op)
QRegion clipRegion() const
Returns the currently set clip region.
Definition: qpainter.cpp:2562
QPainter * painter() const
Returns the paint engine&#39;s painter.
QBrush brush() const
Returns the brush in the current paint engine state.
Definition: qpainter.cpp:9273
QPolygonF toFillPolygon(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Qt::ClipOperation clipOperation() const
Returns the clip operation in the current paint engine state.
Definition: qpainter.cpp:9396
QPointF brushOrigin() const
Returns the brush origin in the current paint engine state.
Definition: qpainter.cpp:9287
void updateFont(const QFont &font)
QFont font() const
Returns the font in the current paint engine state.
Definition: qpainter.cpp:9331
QPainter::CompositionMode compositionMode() const
Returns the composition mode in the current paint engine state.
Definition: qpainter.cpp:9503
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QPainterPath clipPath() const
Returns the clip path in the current paint engine state.
Definition: qpainter.cpp:9457
Qt::FillRule fillRule() const
Returns the painter path&#39;s currently set fill rule.
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void updateCompositionMode(QPainter::CompositionMode composition_mode)
QPainter::RenderHints renderHints() const
Returns the render hints in the current paint engine state.
Definition: qpainter.cpp:9488
void updateBrush(const QBrush &brush, const QPointF &pt)
QRegion clipRegion() const
Returns the clip region in the current paint engine state.
Definition: qpainter.cpp:9443
QPen pen() const
Returns the pen in the current paint engine state.
Definition: qpainter.cpp:9259
void updateRenderHints(QPainter::RenderHints hints)
void updatePen(const QPen &pen)

The documentation for this class was generated from the following files: