Qt 4.8
Public Types | Public Functions | Static Public Variables | Private Slots | Private Functions | Properties | List of all members
QGLWindowSurface Class Reference

#include <qwindowsurface_gl_p.h>

Inheritance diagram for QGLWindowSurface:
QObject QWindowSurface

Public Types

enum  SwapMode { AutomaticSwap, AlwaysFullSwap, AlwaysPartialSwap, KillSwap }
 
- Public Types inherited from QWindowSurface
enum  WindowSurfaceFeature { PartialUpdates = 0x00000001, PreservedContents = 0x00000002, StaticContents = 0x00000004, AllFeatures = 0xffffffff }
 

Public Functions

void beginPaint (const QRegion &region)
 This function is called before painting onto the surface begins, with the region in which the painting will occur. More...
 
QImagebuffer (const QWidget *widget)
 Returns a QImage pointer which represents the actual buffer the widget is drawn into or 0 if this is unavailable. More...
 
QGLContextcontext () const
 
void endPaint (const QRegion &region)
 This function is called after painting onto the surface has ended, with the region in which the painting was performed. More...
 
WindowSurfaceFeatures features () const
 
void flush (QWidget *widget, const QRegion &region, const QPoint &offset)
 Flushes the given region from the specified widget onto the screen. More...
 
QPaintDevicepaintDevice ()
 Implement this function to return the appropriate paint device. More...
 
 QGLWindowSurface (QWidget *window)
 
bool scroll (const QRegion &area, int dx, int dy)
 Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative. More...
 
void setGeometry (const QRect &rect)
 Sets the currently allocated area to be the given rect. More...
 
void updateGeometry ()
 
 ~QGLWindowSurface ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QWindowSurface
QRect geometry () const
 Returns the currently allocated area on the screen. More...
 
virtual QPixmap grabWidget (const QWidget *widget, const QRect &rectangle=QRect()) const
 Returns a QPixmap generated from the part of the backing store corresponding to widget. More...
 
bool hasFeature (WindowSurfaceFeature feature) const
 
virtual QPoint offset (const QWidget *widget) const
 Returns the offset of widget in the coordinates of this window surface. More...
 
 QWindowSurface (QWidget *window, bool setDefaultSurface=true)
 Constructs an empty surface for the given top-level window. More...
 
QRect rect (const QWidget *widget) const
 Returns the rectangle for widget in the coordinates of this window surface. More...
 
void setStaticContents (const QRegion &region)
 
QRegion staticContents () const
 
QWidgetwindow () const
 Returns a pointer to the top-level window associated with this surface. More...
 
virtual ~QWindowSurface ()
 Destroys this surface. More...
 

Static Public Variables

static QGLFormat surfaceFormat
 
static SwapMode swapBehavior = QGLWindowSurface::AutomaticSwap
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 

Private Slots

void deleted (QObject *object)
 

Private Functions

void hijackWindow (QWidget *widget)
 
bool initializeOffscreenTexture (const QSize &size)
 

Properties

QGLWindowSurfacePrivated_ptr
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QWindowSurface
bool hasStaticContents () const
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 83 of file qwindowsurface_gl_p.h.

Enumerations

◆ SwapMode

Constructors and Destructors

◆ QGLWindowSurface()

QGLWindowSurface::QGLWindowSurface ( QWidget window)

Definition at line 345 of file qwindowsurface_gl.cpp.

347 {
348 // Q_ASSERT(window->isTopLevel());
349  d_ptr->pb = 0;
350  d_ptr->fbo = 0;
351  d_ptr->ctx = 0;
352  d_ptr->tex_id = 0;
353 #if defined (QT_OPENGL_ES_2)
354  d_ptr->tried_fbo = true;
355  d_ptr->tried_pb = true;
356 #else
357  d_ptr->tried_fbo = false;
358  d_ptr->tried_pb = false;
359 #endif
360  d_ptr->destructive_swap_buffers = qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull();
361  d_ptr->glDevice.d = d_ptr;
362  d_ptr->q_ptr = this;
363  d_ptr->geometry_updated = false;
364  d_ptr->did_paint = false;
365  d_ptr->swap_region_support = false;
366 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
QWindowSurface(QWidget *window, bool setDefaultSurface=true)
Constructs an empty surface for the given top-level window.
QGLFramebufferObject * fbo
QGLWindowSurfacePrivate * d
QGLWindowSurfacePrivate * d_ptr
QGLWindowSurfaceGLPaintDevice glDevice

◆ ~QGLWindowSurface()

QGLWindowSurface::~QGLWindowSurface ( )

Definition at line 368 of file qwindowsurface_gl.cpp.

369 {
370  if (d_ptr->ctx)
371  glDeleteTextures(1, &d_ptr->tex_id);
372 #ifndef Q_WS_QPA // Don't delete the contexts. Destroying the window does that for us
373  foreach(QGLContext **ctx, d_ptr->contexts) {
374  delete *ctx;
375  *ctx = 0;
376  }
377 #endif
378  delete d_ptr->pb;
379  delete d_ptr->fbo;
380  delete d_ptr;
381 
383  return;
384 
385 #ifdef Q_OS_SYMBIAN
386  // Destroy the context if necessary.
387  if (qt_gl_share_widget() && !qt_gl_share_context()->isSharing())
389 #endif
390 }
const QGLContext * qt_gl_share_context()
QList< QGLContext ** > contexts
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
void qt_destroy_gl_share_widget()
#define ctx
Definition: qgl.cpp:6094
QGLFramebufferObject * fbo
QGLWidget * qt_gl_share_widget()
QGLWindowSurfacePrivate * d_ptr

Functions

◆ beginPaint()

void QGLWindowSurface::beginPaint ( const QRegion region)
virtual

This function is called before painting onto the surface begins, with the region in which the painting will occur.

See also
endPaint(), paintDevice()

Reimplemented from QWindowSurface.

Definition at line 511 of file qwindowsurface_gl.cpp.

512 {
513  d_ptr->did_paint = true;
514  updateGeometry();
515 
516  int clearFlags = 0;
517 
518  QGLContext *ctx = reinterpret_cast<QGLContext *>(window()->d_func()->extraData()->glContext);
519 
520  if (!ctx)
521  return;
522 
523  if (ctx->d_func()->workaround_needsFullClearOnEveryFrame)
525  else if (ctx->format().alpha())
526  clearFlags = GL_COLOR_BUFFER_BIT;
527 
528  if (clearFlags) {
529  if (d_ptr->fbo)
530  d_ptr->fbo->bind();
531 
532  glClearColor(0.0, 0.0, 0.0, 0.0);
533  glClear(clearFlags);
534 
535  if (d_ptr->fbo)
536  d_ptr->fbo->release();
537  }
538 }
#define GL_STENCIL_BUFFER_BIT
QGLFormat format() const
Returns the frame buffer format that was obtained (this may be a subset of what was requested)...
Definition: qgl.cpp:3495
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define GL_COLOR_BUFFER_BIT
#define GL_DEPTH_BUFFER_BIT
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
#define ctx
Definition: qgl.cpp:6094
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
Definition: qgl.h:628
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
QGLFramebufferObject * fbo
QGLWindowSurfacePrivate * d_ptr
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.

◆ buffer()

QImage * QGLWindowSurface::buffer ( const QWidget widget)
virtual

Returns a QImage pointer which represents the actual buffer the widget is drawn into or 0 if this is unavailable.

You must call beginPaint() before you call this function and the returned pointer is only valid until endPaint() is called.

Reimplemented from QWindowSurface.

Definition at line 1153 of file qwindowsurface_gl.cpp.

1154 {
1155  QImage image;
1156 
1157  if (d_ptr->pb)
1158  image = d_ptr->pb->toImage();
1159  else if (d_ptr->fbo)
1160  image = d_ptr->fbo->toImage();
1161 
1162  if (image.isNull())
1163  return 0;
1164 
1165  QRect rect = widget->rect();
1166  rect.translate(widget->mapTo(widget->window(), QPoint()));
1167 
1168  QImage subImage = image.copy(rect);
1169  d_ptr->buffers << subImage;
1170  return &d_ptr->buffers.last();
1171 }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
QRect rect(const QWidget *widget) const
Returns the rectangle for widget in the coordinates of this window surface.
QImage toImage() const
Returns the contents of this framebuffer object as a QImage.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage toImage() const
Returns the contents of the pbuffer as a QImage.
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QGLFramebufferObject * fbo
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
QGLWindowSurfacePrivate * d_ptr

◆ context()

QGLContext * QGLWindowSurface::context ( ) const

Definition at line 482 of file qwindowsurface_gl.cpp.

Referenced by endPaint(), and flush().

483 {
484  return d_ptr->ctx;
485 }
QGLWindowSurfacePrivate * d_ptr

◆ deleted

void QGLWindowSurface::deleted ( QObject object)
privateslot

Definition at line 392 of file qwindowsurface_gl.cpp.

Referenced by hijackWindow().

393 {
394  QWidget *widget = qobject_cast<QWidget *>(object);
395  if (widget) {
396  if (widget == window()) {
397  // Make sure that the fbo is destroyed before destroying its context.
398  delete d_ptr->fbo;
399  d_ptr->fbo = 0;
400  }
401 
402 #ifndef Q_WS_QPA //no need to specifically delete the QGLContext as it will be deleted by QWidget
403  QWidgetPrivate *widgetPrivate = widget->d_func();
404  if (widgetPrivate->extraData()) {
405  union { QGLContext **ctxPtrPtr; void **voidPtrPtr; };
406  voidPtrPtr = &widgetPrivate->extraData()->glContext;
407  int index = d_ptr->contexts.indexOf(ctxPtrPtr);
408  if (index != -1) {
409  delete *ctxPtrPtr;
410  *ctxPtrPtr = 0;
411  d_ptr->contexts.removeAt(index);
412  }
413  }
414 #endif
415  }
416 }
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QList< QGLContext ** > contexts
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
void * glContext
Definition: qwidget_p.h:248
QGLFramebufferObject * fbo
quint16 index
QWExtra * extraData() const
Definition: qwidget_p.h:999
QGLWindowSurfacePrivate * d_ptr
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ endPaint()

void QGLWindowSurface::endPaint ( const QRegion region)
virtual

This function is called after painting onto the surface has ended, with the region in which the painting was performed.

See also
beginPaint(), paintDevice()

Reimplemented from QWindowSurface.

Definition at line 540 of file qwindowsurface_gl.cpp.

541 {
542  if (context())
543  d_ptr->paintedRegion |= rgn;
544 
545  d_ptr->buffers.clear();
546 }
void clear()
Removes all items from the list.
Definition: qlist.h:764
QGLContext * context() const
QGLWindowSurfacePrivate * d_ptr

◆ features()

QWindowSurface::WindowSurfaceFeatures QGLWindowSurface::features ( ) const
virtual

Reimplemented from QWindowSurface.

Definition at line 1173 of file qwindowsurface_gl.cpp.

1174 {
1175  WindowSurfaceFeatures features = 0;
1177  features |= PartialUpdates;
1179  features |= PreservedContents;
1180  return features;
1181 }
WindowSurfaceFeatures features() const
QGLWindowSurfacePrivate * d_ptr

◆ flush()

void QGLWindowSurface::flush ( QWidget widget,
const QRegion region,
const QPoint offset 
)
virtual

Flushes the given region from the specified widget onto the screen.

Note that the offset parameter is currently unused.

Implements QWindowSurface.

Definition at line 582 of file qwindowsurface_gl.cpp.

583 {
584  //### Find out why d_ptr->geometry_updated isn't always false.
585  // flush() should not be called when d_ptr->geometry_updated is true. It assumes that either
586  // d_ptr->fbo or d_ptr->pb is allocated and has the correct size.
587  if (d_ptr->geometry_updated)
588  return;
589 
590  // did_paint is set to true in ::beginPaint. ::beginPaint means that we
591  // at least cleared the background (= painted something). In EGL API it's a
592  // mistake to call swapBuffers if nothing was painted unless
593  // EGL_BUFFER_PRESERVED is set. This check protects the flush func from
594  // being executed if it's for nothing.
596  return;
597 
598 #ifdef Q_OS_SYMBIAN
599  if (window() != widget) {
600  // For performance reasons we don't support
601  // flushing native child widgets on Symbian.
602  // It breaks overlapping native child widget
603  // rendering in some cases but we prefer performance.
604  return;
605  }
606 #endif
607 
608 
609  QWidget *parent = widget->internalWinId() ? widget : widget->nativeParentWidget();
610  Q_ASSERT(parent);
611 
612 #if !defined(Q_WS_QPA)
613  if (!geometry().isValid())
614  return;
615 #else
616  if (!size().isValid())
617  return;
618 #endif
619 
620  // Needed to support native child-widgets...
621  hijackWindow(parent);
622 
623  QRect br = rgn.boundingRect().translated(offset);
624  br = br.intersected(window()->rect());
625  QPoint wOffset = qt_qwidget_data(parent)->wrect.topLeft();
626  QRect rect = br.translated(-offset - wOffset);
627 
628  const GLenum target = GL_TEXTURE_2D;
629  Q_UNUSED(target);
630 
632  return;
633 
634  if (context()) {
635  context()->makeCurrent();
636 
637  if (context()->format().doubleBuffer()) {
638 #if !defined(QT_OPENGL_ES_2)
640  glBindTexture(target, d_ptr->tex_id);
641 
643  for (int i = 0; i < rects.size(); ++i) {
644  QRect br = rects.at(i);
645  if (br.isEmpty())
646  continue;
647 
648  const uint bottom = window()->height() - (br.y() + br.height());
649  glCopyTexSubImage2D(target, 0, br.x(), bottom, br.x(), bottom, br.width(), br.height());
650  }
651 
652  glBindTexture(target, 0);
653 
654  QRegion dirtyRegion = QRegion(window()->rect()) - d_ptr->paintedRegion;
655 
656  if (!dirtyRegion.isEmpty()) {
657  glMatrixMode(GL_MODELVIEW);
658  glLoadIdentity();
659 
660  glMatrixMode(GL_PROJECTION);
661  glLoadIdentity();
662 #ifndef QT_OPENGL_ES
663  glOrtho(0, window()->width(), window()->height(), 0, -999999, 999999);
664 #else
665  glOrthof(0, window()->width(), window()->height(), 0, -999999, 999999);
666 #endif
667  glViewport(0, 0, window()->width(), window()->height());
668 
669  QVector<QRect> rects = dirtyRegion.rects();
670  glColor4f(1, 1, 1, 1);
671  for (int i = 0; i < rects.size(); ++i) {
672  QRect rect = rects.at(i);
673  if (rect.isEmpty())
674  continue;
675 
676  drawTexture(rect, d_ptr->tex_id, window()->size(), rect);
677  }
678  }
679  }
680 #endif
681  bool doingPartialUpdate = false;
682  if (d_ptr->swap_region_support) {
684  doingPartialUpdate = br.width() * br.height() < parent->geometry().width() * parent->geometry().height() * 0.2;
686  doingPartialUpdate = true;
687  }
688 
689  QGLContext *ctx = reinterpret_cast<QGLContext *>(parent->d_func()->extraData()->glContext);
690 #ifdef Q_OS_SYMBIAN
691  if (!ctx)
692  return;
693 #endif
694 
695  if (widget != window()) {
696  if (initializeOffscreenTexture(window()->size()))
697  qWarning() << "QGLWindowSurface: Flushing to native child widget, may lead to significant performance loss";
698  glBindTexture(target, d_ptr->tex_id);
699 
700  const uint bottom = window()->height() - (br.y() + br.height());
701  glCopyTexSubImage2D(target, 0, br.x(), bottom, br.x(), bottom, br.width(), br.height());
702 
703  glBindTexture(target, 0);
704 
705  ctx->makeCurrent();
706  if (doingPartialUpdate)
707  blitTexture(ctx, d_ptr->tex_id, parent->size(), window()->size(), rect, br);
708  else
709  blitTexture(ctx, d_ptr->tex_id, parent->size(), window()->size(), parent->rect(), parent->rect().translated(offset + wOffset));
710  }
711 
712  if (doingPartialUpdate)
713  ctx->d_func()->swapRegion(br);
714  else
715  ctx->swapBuffers();
716 
718  } else {
719  glFlush();
720  }
721  return;
722  }
723 
724  QGLContext *previous_ctx = const_cast<QGLContext *>(QGLContext::currentContext());
725  QGLContext *ctx = reinterpret_cast<QGLContext *>(parent->d_func()->extraData()->glContext);
726 #ifdef Q_OS_SYMBIAN
727  if (!ctx)
728  return;
729 #endif
730 
731  // QPainter::end() should have unbound the fbo, otherwise something is very wrong...
732  Q_ASSERT(!d_ptr->fbo || !d_ptr->fbo->isBound());
733 
734  if (ctx != previous_ctx) {
735  ctx->makeCurrent();
736  }
737 
738  QSize size = widget->rect().size();
740  rect = parent->rect();
741  br = rect.translated(wOffset + offset);
742  size = parent->size();
743  }
744 
745  glDisable(GL_SCISSOR_TEST);
746 
748  const int h = d_ptr->fbo->height();
749 
750  const int sx0 = br.left();
751  const int sx1 = br.left() + br.width();
752  const int sy0 = h - (br.top() + br.height());
753  const int sy1 = h - br.top();
754 
755  const int tx0 = rect.left();
756  const int tx1 = rect.left() + rect.width();
757  const int ty0 = parent->height() - (rect.top() + rect.height());
758  const int ty1 = parent->height() - rect.top();
759 
760  if (window() == parent || d_ptr->fbo->format().samples() <= 1) {
761  if (ctx->d_ptr->current_fbo != 0)
763 
765 
766  glBlitFramebufferEXT(sx0, sy0, sx1, sy1,
767  tx0, ty0, tx1, ty1,
769  GL_NEAREST);
770 
772  } else {
773 #ifndef Q_OS_SYMBIAN // We don't have FBO pool on Symbian
774  // can't do sub-region blits with multisample FBOs
776 
779 
781  0, 0, d_ptr->fbo->width(), d_ptr->fbo->height(),
783  GL_NEAREST);
784 
787 
788  glBlitFramebufferEXT(sx0, sy0, sx1, sy1,
789  tx0, ty0, tx1, ty1,
791  GL_NEAREST);
792 
794 
795  qgl_fbo_pool()->release(temp);
796 #endif // Q_OS_SYMBIAN
797  }
798 
799  ctx->d_ptr->current_fbo = 0;
800  }
801 #if !defined(QT_OPENGL_ES_2)
802  else {
803  GLuint texture;
804  if (d_ptr->fbo) {
805  texture = d_ptr->fbo->texture();
806  } else {
807  d_ptr->pb->makeCurrent();
808  glBindTexture(target, d_ptr->pb_tex_id);
809  const uint bottom = window()->height() - (br.y() + br.height());
810  glCopyTexSubImage2D(target, 0, br.x(), bottom, br.x(), bottom, br.width(), br.height());
811  texture = d_ptr->pb_tex_id;
812  glBindTexture(target, 0);
813  }
814 
815  glDisable(GL_DEPTH_TEST);
816 
817  if (d_ptr->fbo) {
818  d_ptr->fbo->release();
819  } else {
820  ctx->makeCurrent();
821  }
822 
823  glMatrixMode(GL_MODELVIEW);
824  glLoadIdentity();
825 
826  glMatrixMode(GL_PROJECTION);
827  glLoadIdentity();
828 #ifndef QT_OPENGL_ES
829  glOrtho(0, size.width(), size.height(), 0, -999999, 999999);
830 #else
831  glOrthof(0, size.width(), size.height(), 0, -999999, 999999);
832 #endif
833  glViewport(0, 0, size.width(), size.height());
834 
835  glColor4f(1, 1, 1, 1);
836  drawTexture(rect, texture, window()->size(), br);
837 
838  if (d_ptr->fbo)
839  d_ptr->fbo->bind();
840  }
841 #else
842  // OpenGL/ES 2.0 version of the fbo blit.
843  else if (d_ptr->fbo) {
844  Q_UNUSED(target);
845 
846  if (d_ptr->fbo->isBound())
847  d_ptr->fbo->release();
848 
849  blitTexture(ctx, d_ptr->fbo->texture(), size, window()->size(), rect, br);
850  }
851 #endif
852 
853  if (ctx->format().doubleBuffer())
854  ctx->swapBuffers();
855  else
856  glFlush();
857 
858  d_ptr->did_paint = false;
859 }
virtual void swapBuffers() const
Swaps the screen contents with an off-screen buffer.
Definition: qgl_egl.cpp:287
QSize size() const
Returns the size of the texture attached to this framebuffer object.
QRect geometry() const
Returns the currently allocated area on the screen.
bool initializeOffscreenTexture(const QSize &size)
QGLFramebufferObjectPool * qgl_fbo_pool()
GLuint texture() const
Returns the texture id for the texture attached as the default rendering target in this framebuffer o...
int samples() const
Returns the number of samples per pixel if a framebuffer object is a multisample framebuffer object...
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
QPointer< QWidget > widget
#define GL_DEPTH_TEST
QRect rect(const QWidget *widget) const
Returns the rectangle for widget in the coordinates of this window surface.
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
int height() const
Definition: qpaintdevice.h:92
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:481
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define glBindFramebuffer
#define GL_TEXTURE_2D
bool makeCurrent()
Makes this pbuffer the current OpenGL rendering context.
#define GL_SCISSOR_TEST
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
QGLFramebufferObject * acquire(const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize=false)
#define glBlitFramebufferEXT
int width() const
Returns the width.
Definition: qsize.h:126
QWidget * nativeParentWidget() const
Returns the native parent for this widget, i.
Definition: qwidget.cpp:4514
int width() const
Definition: qpaintdevice.h:91
static SwapMode swapBehavior
QGLFormat format() const
Returns the frame buffer format that was obtained (this may be a subset of what was requested)...
Definition: qgl.cpp:3495
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
QGLFramebufferObjectFormat format() const
Returns the format of this framebuffer object.
void release(QGLFramebufferObject *fbo)
Q_CORE_EXPORT void qWarning(const char *,...)
#define GL_COLOR_BUFFER_BIT
unsigned int uint
Definition: qglobal.h:996
static void blitTexture(QGLContext *ctx, GLuint texture, const QSize &viewport, const QSize &texSize, const QRect &targetRect, const QRect &sourceRect)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
QRect wrect
Definition: qwidget.h:145
GLuint handle() const
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffe...
#define GL_DRAW_FRAMEBUFFER_EXT
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src=QRectF())
#define GL_READ_FRAMEBUFFER_EXT
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
GLuint current_fbo
Definition: qgl_p.h:456
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
unsigned int GLenum
Definition: main.cpp:50
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void hijackWindow(QWidget *widget)
QGLContext * context() const
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
#define ctx
Definition: qgl.cpp:6094
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
QGLFramebufferObject * fbo
virtual void makeCurrent()
Makes this context the current OpenGL rendering context.
Definition: qgl_egl.cpp:213
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
bool doubleBuffer() const
Returns true if double buffering is enabled; otherwise returns false.
Definition: qgl.h:613
static Extensions glExtensions()
Definition: qgl.cpp:5781
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isBound() const
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned...
The QGLFramebufferObjectFormat class specifies the format of an OpenGL framebuffer object...
Q_GUI_EXPORT QWidgetData * qt_qwidget_data(QWidget *widget)
Definition: qwidget.cpp:12915
QGLWindowSurfacePrivate * d_ptr
#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
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
#define GL_NEAREST

◆ hijackWindow()

void QGLWindowSurface::hijackWindow ( QWidget widget)
private

Definition at line 418 of file qwindowsurface_gl.cpp.

Referenced by flush(), and updateGeometry().

419 {
420  QWidgetPrivate *widgetPrivate = widget->d_func();
421  widgetPrivate->createExtra();
422  if (widgetPrivate->extraData()->glContext)
423  return;
424 
425  QGLContext *ctx = NULL;
426 
427  // For translucent top-level widgets we need alpha in the format.
429  QGLFormat modFormat(surfaceFormat);
430  modFormat.setSampleBuffers(false);
431  modFormat.setSamples(0);
432  modFormat.setAlpha(true);
433  ctx = new QGLContext(modFormat, widget);
434  } else
435  ctx = new QGLContext(surfaceFormat, widget);
436 
437  ctx->create(qt_gl_share_context());
438 #ifdef Q_OS_SYMBIAN
439  if (!ctx->isValid()) {
440  delete ctx;
441  return;
442  }
443 #endif
444 #ifndef QT_NO_EGL
445  static bool checkedForNOKSwapRegion = false;
446  static bool haveNOKSwapRegion = false;
447 
448  if (!checkedForNOKSwapRegion) {
449  haveNOKSwapRegion = QEgl::hasExtension("EGL_NOK_swap_region2");
450  checkedForNOKSwapRegion = true;
451 
452  if (haveNOKSwapRegion)
453  qDebug() << "Found EGL_NOK_swap_region2 extension. Using partial updates.";
454  }
455 
457  if (ctx->d_func()->eglContext->configAttrib(EGL_SURFACE_TYPE)&EGL_SWAP_BEHAVIOR_PRESERVED_BIT) {
458  EGLint swapBehavior;
459  if (eglQuerySurface(ctx->d_func()->eglContext->display(), ctx->d_func()->eglSurface
460  , EGL_SWAP_BEHAVIOR, &swapBehavior)) {
461  d_ptr->destructive_swap_buffers = (swapBehavior != EGL_BUFFER_PRESERVED);
462  }
463  }
464 
465  d_ptr->swap_region_support = haveNOKSwapRegion;
466 #endif
467 
468  widgetPrivate->extraData()->glContext = ctx;
469 
470  union { QGLContext **ctxPtrPtr; void **voidPtrPtr; };
471 
472  connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(deleted(QObject*)));
473 
474  voidPtrPtr = &widgetPrivate->extraData()->glContext;
475  d_ptr->contexts << ctxPtrPtr;
476 
477 #ifndef Q_OS_SYMBIAN
478  qDebug() << "hijackWindow() context created for" << widget << d_ptr->contexts.size();
479 #endif
480 }
const QGLContext * qt_gl_share_context()
void deleted(QObject *object)
#define SLOT(a)
Definition: qobjectdefs.h:226
QList< QGLContext ** > contexts
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void createExtra()
Creates the widget extra data.
Definition: qwidget.cpp:1802
static SwapMode swapBehavior
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
The QGLFormat class specifies the display format of an OpenGL rendering context.
Definition: qgl.h:175
virtual bool create(const QGLContext *shareContext=0)
Creates the GL context.
Definition: qgl.cpp:3454
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static QGLFormat surfaceFormat
Q_GUI_EXPORT bool hasExtension(const char *extensionName)
Definition: qegl.cpp:791
bool isValid() const
Returns true if a GL rendering context has been successfully created; otherwise returns false...
Definition: qgl.cpp:3477
#define ctx
Definition: qgl.cpp:6094
void * glContext
Definition: qwidget_p.h:248
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QWExtra * extraData() const
Definition: qwidget_p.h:999
QGLWindowSurfacePrivate * d_ptr

◆ initializeOffscreenTexture()

bool QGLWindowSurface::initializeOffscreenTexture ( const QSize size)
private

Definition at line 1041 of file qwindowsurface_gl.cpp.

Referenced by flush(), and updateGeometry().

1042 {
1043  if (size == d_ptr->textureSize)
1044  return false;
1045 
1046  glGenTextures(1, &d_ptr->tex_id);
1047  glBindTexture(GL_TEXTURE_2D, d_ptr->tex_id);
1048  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
1049 
1050  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1051  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1052  glBindTexture(GL_TEXTURE_2D, 0);
1053 
1054  d_ptr->textureSize = size;
1055  return true;
1056 }
#define GL_RGB
#define GL_TEXTURE_MIN_FILTER
#define GL_TEXTURE_2D
int width() const
Returns the width.
Definition: qsize.h:126
#define GL_UNSIGNED_BYTE
int height() const
Returns the height.
Definition: qsize.h:129
#define GL_TEXTURE_MAG_FILTER
QGLWindowSurfacePrivate * d_ptr
#define GL_NEAREST

◆ paintDevice()

QPaintDevice * QGLWindowSurface::paintDevice ( )
virtual

Implement this function to return the appropriate paint device.

Implements QWindowSurface.

Definition at line 487 of file qwindowsurface_gl.cpp.

488 {
489  updateGeometry();
490 
491 #ifdef Q_OS_SYMBIAN
492  // On symbian we always return glDevice, even if it's invalid
493  return &d_ptr->glDevice;
494 #else
495  if (d_ptr->pb)
496  return d_ptr->pb;
497 
498  if (d_ptr->ctx)
499  return &d_ptr->glDevice;
500 
501  QGLContext *ctx = reinterpret_cast<QGLContext *>(window()->d_func()->extraData()->glContext);
502  ctx->makeCurrent();
503 
504  Q_ASSERT(d_ptr->fbo);
505  return d_ptr->fbo;
506 #endif
507 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define ctx
Definition: qgl.cpp:6094
QGLFramebufferObject * fbo
virtual void makeCurrent()
Makes this context the current OpenGL rendering context.
Definition: qgl_egl.cpp:213
QGLWindowSurfacePrivate * d_ptr
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
QGLWindowSurfaceGLPaintDevice glDevice

◆ scroll()

bool QGLWindowSurface::scroll ( const QRegion area,
int  dx,
int  dy 
)
virtual

Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative.

Returns true if the area was scrolled successfully; false otherwise.

Reimplemented from QWindowSurface.

Definition at line 1058 of file qwindowsurface_gl.cpp.

1059 {
1060  // this code randomly fails currently for unknown reasons
1061  return false;
1062 
1063  if (!d_ptr->pb)
1064  return false;
1065 
1066  d_ptr->pb->makeCurrent();
1067 
1068  QRect br = area.boundingRect();
1069 
1070 #if 0
1071  // ## workaround driver issue (scrolling by these deltas is unbearably slow for some reason)
1072  // ## maybe we should use glCopyTexSubImage insteadk
1073  if (dx == 1 || dx == -1 || dy == 1 || dy == -1 || dy == 2)
1074  return false;
1075 
1076  glRasterPos2i(br.x() + dx, br.y() + br.height() + dy);
1077  glCopyPixels(br.x(), d_ptr->pb->height() - (br.y() + br.height()), br.width(), br.height(), GL_COLOR);
1078  return true;
1079 #endif
1080 
1081  const GLenum target = GL_TEXTURE_2D;
1082 
1083  glBindTexture(target, d_ptr->tex_id);
1084  glCopyTexImage2D(target, 0, GL_RGBA, br.x(), d_ptr->pb->height() - (br.y() + br.height()), br.width(), br.height(), 0);
1085  glBindTexture(target, 0);
1086 
1087  drawTexture(br.translated(dx, dy), d_ptr->tex_id, window()->size());
1088 
1089  return true;
1090 }
int height() const
Definition: qpaintdevice.h:92
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define GL_TEXTURE_2D
bool makeCurrent()
Makes this pbuffer the current OpenGL rendering context.
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src=QRectF())
unsigned int GLenum
Definition: main.cpp:50
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
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
#define GL_RGBA
QGLWindowSurfacePrivate * d_ptr
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.

◆ setGeometry()

void QGLWindowSurface::setGeometry ( const QRect rect)
virtual

Sets the currently allocated area to be the given rect.

This function is called whenever area covered by the top-level window changes.

See also
geometry()

Reimplemented from QWindowSurface.

Definition at line 863 of file qwindowsurface_gl.cpp.

864 {
866  d_ptr->geometry_updated = true;
867 }
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
QGLWindowSurfacePrivate * d_ptr

◆ updateGeometry()

void QGLWindowSurface::updateGeometry ( )

Definition at line 876 of file qwindowsurface_gl.cpp.

Referenced by beginPaint(), and paintDevice().

876  {
877  if (!d_ptr->geometry_updated)
878  return;
879  d_ptr->geometry_updated = false;
880 
881  bool hijack(true);
882  QWidgetPrivate *wd = window()->d_func();
883  if (wd->extraData() && wd->extraData()->glContext) {
884 #ifdef Q_OS_SYMBIAN // Symbian needs to recreate the context when native window size changes
885  if (d_ptr->size != geometry().size()) {
886  QGLContext *ctx = reinterpret_cast<QGLContext *>(wd->extraData()->glContext);
887 
888  if (ctx == QGLContext::currentContext())
889  ctx->doneCurrent();
890 
891  ctx->d_func()->destroyEglSurfaceForDevice();
892 
893  // Delete other contexts (shouldn't happen too often, if at all)
894  while (d_ptr->contexts.size()) {
895  QGLContext **ctxPtrPtr = d_ptr->contexts.takeFirst();
896  if ((*ctxPtrPtr) != ctx)
897  delete *ctxPtrPtr;
898  }
899  union { QGLContext **ctxPtrPtr; void **voidPtrPtr; };
900  voidPtrPtr = &wd->extraData()->glContext;
901  d_ptr->contexts << ctxPtrPtr;
902 
903  ctx->d_func()->eglSurface = ctx->d_func()->eglContext->createSurface(window());
904 
905  // Swap behaviour has been checked already in previous hijackWindow call.
906  // Reset swap behaviour based on that flag.
908  eglSurfaceAttrib(QEgl::display(), ctx->d_func()->eglSurfaceForDevice(),
909  EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED);
910 
911  if (eglGetError() != EGL_SUCCESS)
912  qWarning("QGLWindowSurface::updateGeometry() - could not re-enable destroyed swap behaviour");
913  } else {
914  eglSurfaceAttrib(QEgl::display(), ctx->d_func()->eglSurfaceForDevice(),
915  EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
916 
917  if (eglGetError() != EGL_SUCCESS)
918  qWarning("QGLWindowSurface::updateGeometry() - could not re-enable preserved swap behaviour");
919  }
920  }
921 #endif
922  hijack = false; // we already have gl context for widget
923  }
924 
925  if (hijack)
926  hijackWindow(window());
927 
928  QGLContext *ctx = reinterpret_cast<QGLContext *>(wd->extraData()->glContext);
929 #ifdef Q_OS_SYMBIAN
930  if (!ctx)
931  return;
932 #endif
933 #ifdef Q_WS_MAC
934  ctx->updatePaintDevice();
935 #endif
936 
937  QSize surfSize = geometry().size();
938 
939  if (surfSize.width() <= 0 || surfSize.height() <= 0)
940  return;
941 
942  if (d_ptr->size == surfSize)
943  return;
944 
945  d_ptr->size = surfSize;
946 
947  if (d_ptr->ctx) {
948 #ifndef QT_OPENGL_ES_2
950  initializeOffscreenTexture(surfSize);
951 #endif
952  return;
953  }
954 
955  const GLenum target = GL_TEXTURE_2D;
958  && (d_ptr->fbo || !d_ptr->tried_fbo)
960  {
961  d_ptr->tried_fbo = true;
962  ctx->d_ptr->internal_context = true;
963  ctx->makeCurrent();
964  delete d_ptr->fbo;
965 
969  format.setTextureTarget(target);
970 
972  format.setSamples(8);
973 
974  d_ptr->fbo = new QGLFramebufferObject(surfSize, format);
975 
976  if (d_ptr->fbo->isValid()) {
977  qDebug() << "Created Window Surface FBO" << surfSize
978  << "with samples" << d_ptr->fbo->format().samples();
979  return;
980  } else {
981  qDebug() << "QGLWindowSurface: Failed to create valid FBO, falling back";
982  delete d_ptr->fbo;
983  d_ptr->fbo = 0;
984  }
985  }
986 
987 #if !defined(QT_OPENGL_ES_2) && !defined(Q_WS_QPA) //QPA doesn't support pixelbuffers
989  d_ptr->tried_pb = true;
990 
991  if (d_ptr->pb) {
992  d_ptr->pb->makeCurrent();
993  glDeleteTextures(1, &d_ptr->pb_tex_id);
994  }
995 
996  delete d_ptr->pb;
997 
998  d_ptr->pb = new QGLPixelBuffer(surfSize.width(), surfSize.height(),
1000  qt_gl_share_widget());
1001 
1002  if (d_ptr->pb->isValid()) {
1003  qDebug() << "Created Window Surface Pixelbuffer, Sample buffers:" << d_ptr->pb->format().sampleBuffers();
1004  d_ptr->pb->makeCurrent();
1005 
1006  glGenTextures(1, &d_ptr->pb_tex_id);
1007  glBindTexture(target, d_ptr->pb_tex_id);
1008  glTexImage2D(target, 0, GL_RGBA, surfSize.width(), surfSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
1009 
1010  glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1011  glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1012  glBindTexture(target, 0);
1013 
1014  glMatrixMode(GL_PROJECTION);
1015  glLoadIdentity();
1016  glOrtho(0, d_ptr->pb->width(), d_ptr->pb->height(), 0, -999999, 999999);
1017 
1018  d_ptr->pb->d_ptr->qctx->d_func()->internal_context = true;
1019  return;
1020  } else {
1021  qDebug() << "QGLWindowSurface: Failed to create valid pixelbuffer, falling back";
1022  delete d_ptr->pb;
1023  d_ptr->pb = 0;
1024  }
1025  }
1026 #endif // !defined(QT_OPENGL_ES_2) !defined(Q_WS_QPA)
1027 
1028  ctx->makeCurrent();
1029 
1030 #ifndef QT_OPENGL_ES_2
1032  initializeOffscreenTexture(surfSize);
1033 #endif
1034 #ifndef Q_OS_SYMBIAN
1035  qDebug() << "QGLWindowSurface: Using plain widget as window surface" << this;
1036 #endif
1037  d_ptr->ctx = ctx;
1038  d_ptr->ctx->d_ptr->internal_context = true;
1039 }
QGLFormat format() const
Returns the format of the pbuffer.
QRect geometry() const
Returns the currently allocated area on the screen.
bool initializeOffscreenTexture(const QSize &size)
int samples() const
Returns the number of samples per pixel if a framebuffer object is a multisample framebuffer object...
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
void setAttachment(QGLFramebufferObject::Attachment attachment)
Sets the attachment configuration of a framebuffer object to attachment.
#define GL_TEXTURE_MIN_FILTER
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isValid() const
Returns true if the framebuffer object is valid.
int height() const
Definition: qpaintdevice.h:92
void setInternalTextureFormat(GLenum internalTextureFormat)
Sets the internal format of a framebuffer object&#39;s texture or multisample framebuffer object&#39;s color ...
QList< QGLContext ** > contexts
void updatePaintDevice()
Definition: qgl_mac.mm:583
uint internal_context
Definition: qgl_p.h:426
#define GL_TEXTURE_2D
bool makeCurrent()
Makes this pbuffer the current OpenGL rendering context.
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
Q_CORE_EXPORT void qDebug(const char *,...)
bool sampleBuffers() const
Returns true if multisample buffer support is enabled; otherwise returns false.
Definition: qgl.h:658
int width() const
Returns the width.
Definition: qsize.h:126
int width() const
Definition: qpaintdevice.h:91
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
The QGLFormat class specifies the display format of an OpenGL rendering context.
Definition: qgl.h:175
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void setSamples(int samples)
Sets the number of samples per pixel for a multisample framebuffer object to samples.
QGLFramebufferObjectFormat format() const
Returns the format of this framebuffer object.
Q_CORE_EXPORT void qWarning(const char *,...)
bool isValid() const
Returns true if this pbuffer is valid; otherwise returns false.
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
bool qt_gl_preferGL2Engine()
Definition: qgl.cpp:218
QScopedPointer< QGLPixelBufferPrivate > d_ptr
void setTextureTarget(GLenum target)
Sets the texture target of the texture attached to a framebuffer object to target.
unsigned int GLenum
Definition: main.cpp:50
void hijackWindow(QWidget *widget)
#define GL_UNSIGNED_BYTE
#define ctx
Definition: qgl.cpp:6094
virtual void doneCurrent()
Makes no GL context the current context.
Definition: qgl_egl.cpp:277
void * glContext
Definition: qwidget_p.h:248
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int height() const
Returns the height.
Definition: qsize.h:129
QGLFramebufferObject * fbo
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_RGBA
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QWExtra * extraData() const
Definition: qwidget_p.h:999
#define GL_TEXTURE_MAG_FILTER
QGLWidget * qt_gl_share_widget()
The QGLFramebufferObjectFormat class specifies the format of an OpenGL framebuffer object...
QGLWindowSurfacePrivate * d_ptr
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
#define GL_NEAREST

Properties

◆ d_ptr

QGLWindowSurfacePrivate* QGLWindowSurface::d_ptr
private

◆ surfaceFormat

QGLFormat QGLWindowSurface::surfaceFormat
static

◆ swapBehavior

QGLWindowSurface::SwapMode QGLWindowSurface::swapBehavior = QGLWindowSurface::AutomaticSwap
static

Definition at line 114 of file qwindowsurface_gl_p.h.

Referenced by hijackWindow().


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