Qt 4.8
Public Functions | Properties | List of all members
QGLEllipseMaskGenerator Class Reference
Inheritance diagram for QGLEllipseMaskGenerator:
QGLMaskGenerator

Public Functions

void drawMask (const QRect &rect)
 
 QGLEllipseMaskGenerator (const QRectF &rect, const QTransform &matrix, QGLOffscreen &offscreen, GLuint maskFragmentProgram, int *maskVariableLocations)
 
QRect screenRect ()
 
- Public Functions inherited from QGLMaskGenerator
QTransform matrix () const
 
QPainterPath path () const
 
 QGLMaskGenerator (const QPainterPath &path, const QTransform &matrix, qreal stroke_width=-1)
 
qreal strokeWidth () const
 
virtual ~QGLMaskGenerator ()
 

Properties

QRectF ellipseRect
 
GLuint maskFragmentProgram
 
int * maskVariableLocations
 
QGLOffscreenoffscreen
 
QRect screen_rect
 
float vertexArray [4 *2]
 

Detailed Description

Definition at line 3088 of file qpaintengine_opengl.cpp.

Constructors and Destructors

◆ QGLEllipseMaskGenerator()

QGLEllipseMaskGenerator::QGLEllipseMaskGenerator ( const QRectF rect,
const QTransform matrix,
QGLOffscreen offscreen,
GLuint  maskFragmentProgram,
int *  maskVariableLocations 
)

Definition at line 3287 of file qpaintengine_opengl.cpp.

3288  : QGLMaskGenerator(ellipseRectToPath(rect), matrix),
3289  ellipseRect(rect),
3290  offscreen(&offs),
3291  maskFragmentProgram(program),
3292  maskVariableLocations(locations)
3293 {
3294 }
static QPainterPath ellipseRectToPath(const QRectF &rect)
QGLMaskGenerator(const QPainterPath &path, const QTransform &matrix, qreal stroke_width=-1)

Functions

◆ drawMask()

void QGLEllipseMaskGenerator::drawMask ( const QRect rect)
virtual

Implements QGLMaskGenerator.

Definition at line 3338 of file qpaintengine_opengl.cpp.

3339 {
3340 #ifdef QT_OPENGL_ES
3341  Q_UNUSED(rect);
3342 #else
3344  offscreen->bind();
3345 
3346  glDisable(GL_TEXTURE_GEN_S);
3347  glDisable(GL_TEXTURE_1D);
3348 
3349  // fragment program needs the inverse radii of the ellipse
3350  glTexCoord2f(1.0f / (ellipseRect.width() * 0.5f),
3351  1.0f / (ellipseRect.height() * 0.5f));
3352 
3353  QTransform translate(1, 0, 0, 1, -ellipseRect.center().x(), -ellipseRect.center().y());
3354  QTransform gl_to_qt(1, 0, 0, -1, 0, offscreen->drawableSize().height());
3355  QTransform inv_matrix = gl_to_qt * matrix().inverted() * translate;
3356 
3357  float m[3][4] = { { float(inv_matrix.m11()), float(inv_matrix.m12()), float(inv_matrix.m13()) },
3358  { float(inv_matrix.m21()), float(inv_matrix.m22()), float(inv_matrix.m23()) },
3359  { float(inv_matrix.m31()), float(inv_matrix.m32()), float(inv_matrix.m33()) } };
3360 
3361  QPoint offs(screen_rect.left() - rect.left(), (offscreen->drawableSize().height() - screen_rect.top())
3362  - (offscreen->offscreenSize().height() - rect.top()));
3363 
3364  // last component needs to be 1.0f to avoid Nvidia bug on linux
3365  float ellipse_offset[4] = { float(offs.x()), float(offs.y()), 0.0f, 1.0f };
3366 
3367  GLfloat vertexArray[4 * 2];
3368  qt_add_rect_to_array(rect, vertexArray);
3369 
3370  glBlendFunc(GL_ONE, GL_ZERO); // set mask
3371  glEnable(GL_FRAGMENT_PROGRAM_ARB);
3373 
3377 
3379 
3380  glEnableClientState(GL_VERTEX_ARRAY);
3381  glVertexPointer(2, GL_FLOAT, 0, vertexArray);
3382  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
3383  glDisableClientState(GL_VERTEX_ARRAY);
3384  glDisable(GL_FRAGMENT_PROGRAM_ARB);
3385 #endif
3386 }
int left() const
Returns the x-coordinate of the rectangle's left edge.
Definition: qrect.h:240
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QSize drawableSize() const
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
#define GL_TRIANGLE_FAN
#define GL_FLOAT
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
#define GL_ZERO
#define glProgramLocalParameter4fvARB
int top() const
Returns the y-coordinate of the rectangle's top edge.
Definition: qrect.h:243
#define ctx
Definition: qgl.cpp:6094
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int height() const
Returns the height.
Definition: qsize.h:129
QTransform matrix() const
#define GL_FRAGMENT_PROGRAM_ARB
QSize offscreenSize() const
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QGLContext * context() const
void qt_add_rect_to_array(const QRectF &r, GLfloat *array)
Definition: qgl.cpp:2972
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define glBindProgramARB
#define GL_ONE
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ screenRect()

QRect QGLEllipseMaskGenerator::screenRect ( )
virtual

Implements QGLMaskGenerator.

Definition at line 3296 of file qpaintengine_opengl.cpp.

3297 {
3299 
3300  QPointF points[] = {
3301  QPointF(ellipseRect.left(), center.y()),
3302  QPointF(ellipseRect.right(), center.y()),
3303  QPointF(center.x(), ellipseRect.top()),
3304  QPointF(center.x(), ellipseRect.bottom())
3305  };
3306 
3307  qreal min_screen_delta_len = QREAL_MAX;
3308 
3309  for (int i = 0; i < 4; ++i) {
3310  QPointF delta = points[i] - center;
3311 
3312  // normalize
3313  delta /= qSqrt(delta.x() * delta.x() + delta.y() * delta.y());
3314 
3315  QPointF screen_delta(matrix().m11() * delta.x() + matrix().m21() * delta.y(),
3316  matrix().m12() * delta.x() + matrix().m22() * delta.y());
3317 
3318  min_screen_delta_len = qMin(min_screen_delta_len,
3319  qreal(qSqrt(screen_delta.x() * screen_delta.x() + screen_delta.y() * screen_delta.y())));
3320  }
3321 
3322  const qreal padding = 2.0f;
3323 
3324  qreal grow = padding / min_screen_delta_len;
3325 
3326  QRectF boundingRect = ellipseRect.adjusted(-grow, -grow, grow, grow);
3327 
3328  boundingRect = matrix().mapRect(boundingRect);
3329 
3330  QPointF p(0.5, 0.5);
3331 
3332  screen_rect = QRect((boundingRect.topLeft() - p).toPoint(),
3333  (boundingRect.bottomRight() + p).toPoint());
3334 
3335  return screen_rect;
3336 }
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static const QRectF boundingRect(const QPointF *points, int pointCount)
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define QREAL_MAX
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QTransform matrix() const
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
static int grow(int size)
Definition: qlist.cpp:62
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
qreal qSqrt(qreal v)
Definition: qmath.h:205

Properties

◆ ellipseRect

QRectF QGLEllipseMaskGenerator::ellipseRect
private

Definition at line 3099 of file qpaintengine_opengl.cpp.

Referenced by drawMask(), and screenRect().

◆ maskFragmentProgram

GLuint QGLEllipseMaskGenerator::maskFragmentProgram
private

Definition at line 3103 of file qpaintengine_opengl.cpp.

Referenced by drawMask().

◆ maskVariableLocations

int* QGLEllipseMaskGenerator::maskVariableLocations
private

Definition at line 3105 of file qpaintengine_opengl.cpp.

Referenced by drawMask().

◆ offscreen

QGLOffscreen* QGLEllipseMaskGenerator::offscreen
private

Definition at line 3101 of file qpaintengine_opengl.cpp.

◆ screen_rect

QRect QGLEllipseMaskGenerator::screen_rect
private

◆ vertexArray

float QGLEllipseMaskGenerator::vertexArray[4 *2]
private

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