Qt 4.8
Public Slots | Public Functions | Static Public Functions | Properties | List of all members
QGLOffscreen Class Reference
Inheritance diagram for QGLOffscreen:
QObject

Public Slots

void cleanupGLContextRefs (const QGLContext *context)
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Public Functions

void begin ()
 
void bind ()
 
QGLContextcontext () const
 
QSize drawableSize () const
 
void end ()
 
void initialize ()
 
bool isBound () const
 
bool isValid () const
 
QSize offscreenSize () const
 
GLuint offscreenTexture () const
 
 QGLOffscreen ()
 
void release ()
 
void setDevice (QPaintDevice *pdev)
 
- 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...
 

Static Public Functions

static bool isSupported ()
 
- 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)
 

Properties

bool activated
 
bool bound
 
QGLContextctx
 
QGLPaintDevicedevice
 
bool drawable_fbo
 
bool initialized
 
QSize last_failed_size
 
int mask_dim
 
QGLFramebufferObjectoffscreen
 

Additional Inherited Members

- 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 Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- 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 Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 235 of file qpaintengine_opengl.cpp.

Constructors and Destructors

◆ QGLOffscreen()

QGLOffscreen::QGLOffscreen ( )
inline

Definition at line 239 of file qpaintengine_opengl.cpp.

240  : QObject(),
241  offscreen(0),
242  ctx(0),
243  mask_dim(0),
244  activated(false),
245  bound(false)
246  {
248  SIGNAL(aboutToDestroyContext(const QGLContext*)),
250  }
#define SLOT(a)
Definition: qobjectdefs.h:226
static QGLSignalProxy * instance()
Definition: qgl.cpp:148
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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
void cleanupGLContextRefs(const QGLContext *context)
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QGLFramebufferObject * offscreen

Functions

◆ begin()

void QGLOffscreen::begin ( )

Definition at line 316 of file qpaintengine_opengl.cpp.

317 {
318 #ifndef QT_OPENGL_ES
319  initialized = false;
320 
321  if (activated)
322  initialize();
323 #endif
324 }

◆ bind()

void QGLOffscreen::bind ( )
inline

Definition at line 397 of file qpaintengine_opengl.cpp.

Referenced by QGLTrapezoidMaskGenerator::drawMask(), and QGLEllipseMaskGenerator::drawMask().

398 {
399 #ifndef QT_OPENGL_ES
401 
402  if (!offscreen || bound)
403  return;
404 
405  DEBUG_ONCE qDebug() << "QGLOffscreen: binding offscreen";
406  offscreen->bind();
407 
408  bound = true;
409 
410  glViewport(0, 0, offscreenSize().width(), offscreenSize().height());
411 
412  glMatrixMode(GL_PROJECTION);
413  glLoadIdentity();
414  glOrtho(0, offscreenSize().width(), offscreenSize().height(), 0, -999999, 999999);
415  glMatrixMode(GL_MODELVIEW);
416 #endif
417 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
#define DEBUG_ONCE
QSize offscreenSize() const
QGLFramebufferObject * offscreen

◆ cleanupGLContextRefs

void QGLOffscreen::cleanupGLContextRefs ( const QGLContext context)
inlineslot

Definition at line 276 of file qpaintengine_opengl.cpp.

276  {
277  if (context == ctx) {
278  delete offscreen;
279  ctx = 0;
280  offscreen = 0;
281  mask_dim = 0;
282  }
283  }
QGLFramebufferObject * offscreen

◆ context()

QGLContext * QGLOffscreen::context ( ) const
inline

Definition at line 474 of file qpaintengine_opengl.cpp.

Referenced by QGLTrapezoidMaskGenerator::drawMask(), and QGLEllipseMaskGenerator::drawMask().

475 {
476  return ctx;
477 }

◆ drawableSize()

QSize QGLOffscreen::drawableSize ( ) const
inline

Definition at line 459 of file qpaintengine_opengl.cpp.

Referenced by QGLEllipseMaskGenerator::drawMask(), and QGLTrapezoidMaskGenerator::screenRect().

460 {
461  return device->size();
462 }
virtual QSize size() const =0
QGLPaintDevice * device

◆ end()

void QGLOffscreen::end ( )

Definition at line 369 of file qpaintengine_opengl.cpp.

370 {
371  if (bound)
372  release();
373 #ifdef DEBUG_DISPLAY_MASK_TEXTURE
374  glReadBuffer(GL_BACK);
375  glDrawBuffer(GL_BACK);
376  glMatrixMode(GL_MODELVIEW);
377  glLoadIdentity();
378  glColor4f(1, 1, 1, 1);
379  glDisable(GL_DEPTH_TEST);
380  glBlendFunc(GL_ONE, GL_ZERO);
381  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
382  glEnable(GL_TEXTURE_2D);
383  glBindTexture(GL_TEXTURE_2D, offscreen->texture());
384 
385  glBegin(GL_QUADS);
386  glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 0.0);
387  glTexCoord2f(1.0, 1.0); glVertex2f(drawable.size().width(), 0.0);
388  glTexCoord2f(1.0, 0.0); glVertex2f(drawable.size().width(), drawable.size().height());
389  glTexCoord2f(0.0, 0.0); glVertex2f(0.0, drawable.size().height());
390  glEnd();
391 
392  glBindTexture(GL_TEXTURE_2D, 0);
393  glDisable(GL_TEXTURE_2D);
394 #endif
395 }
GLuint texture() const
Returns the texture id for the texture attached as the default rendering target in this framebuffer o...
#define GL_TRUE
#define GL_DEPTH_TEST
#define GL_TEXTURE_2D
#define GL_ZERO
#define GL_BACK
QGLFramebufferObject * offscreen
#define GL_ONE

◆ initialize()

void QGLOffscreen::initialize ( )
inline

Definition at line 326 of file qpaintengine_opengl.cpp.

327 {
328 #ifndef QT_OPENGL_ES
329  if (initialized)
330  return;
331 
332  activated = true;
333  initialized = true;
334 
335  int dim = qMax(2048, static_cast<int>(qt_next_power_of_two(qMax(device->size().width(), device->size().height()))));
336 
337  bool shared_context = QGLContext::areSharing(device->context(), ctx);
338  bool would_fail = last_failed_size.isValid() &&
339  (device->size().width() >= last_failed_size.width() ||
341  bool needs_refresh = dim > mask_dim || !shared_context;
342 
343  if (needs_refresh && !would_fail) {
344  DEBUG_ONCE qDebug() << "QGLOffscreen::initialize(): creating offscreen of size" << dim;
345  delete offscreen;
347  mask_dim = dim;
348 
349  if (!offscreen->isValid()) {
350  qWarning("QGLOffscreen: Invalid offscreen fbo (size %dx%d)", mask_dim, mask_dim);
351  delete offscreen;
352  offscreen = 0;
353  mask_dim = 0;
355  }
356  }
357 
358  qt_mask_texture_cache()->setOffscreenSize(offscreenSize());
359  qt_mask_texture_cache()->setDrawableSize(device->size());
360  ctx = device->context();
361 #endif
362 }
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isValid() const
Returns true if the framebuffer object is valid.
virtual QSize size() const =0
int qt_next_power_of_two(int v)
Definition: qgl.cpp:1886
#define GL_TEXTURE_2D
virtual QGLContext * context() const =0
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
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
Q_CORE_EXPORT void qDebug(const char *,...)
int width() const
Returns the width.
Definition: qsize.h:126
Q_CORE_EXPORT void qWarning(const char *,...)
QGLPaintDevice * device
unsigned int GLenum
Definition: main.cpp:50
#define DEBUG_ONCE
int height() const
Returns the height.
Definition: qsize.h:129
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
QSize offscreenSize() const
QGLFramebufferObject * offscreen

◆ isBound()

bool QGLOffscreen::isBound ( ) const
inline

Definition at line 454 of file qpaintengine_opengl.cpp.

455 {
456  return bound;
457 }

◆ isSupported()

bool QGLOffscreen::isSupported ( )
static

Definition at line 479 of file qpaintengine_opengl.cpp.

Referenced by QOpenGLPaintEngine::updateRenderHints().

480 {
482 }
static Extensions glExtensions()
Definition: qgl.cpp:5781

◆ isValid()

bool QGLOffscreen::isValid ( ) const
inline

Definition at line 364 of file qpaintengine_opengl.cpp.

365 {
366  return offscreen;
367 }
QGLFramebufferObject * offscreen

◆ offscreenSize()

QSize QGLOffscreen::offscreenSize ( ) const
inline

Definition at line 464 of file qpaintengine_opengl.cpp.

Referenced by QOpenGLPaintEnginePrivate::drawItem(), QGLTrapezoidMaskGenerator::drawMask(), QGLEllipseMaskGenerator::drawMask(), and QOpenGLPaintEnginePrivate::updateFragmentProgramData().

465 {
466  return QSize(mask_dim, mask_dim);
467 }
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ offscreenTexture()

GLuint QGLOffscreen::offscreenTexture ( ) const
inline

Definition at line 469 of file qpaintengine_opengl.cpp.

Referenced by QOpenGLPaintEnginePrivate::composite().

470 {
471  return offscreen ? offscreen->texture() : 0;
472 }
GLuint texture() const
Returns the texture id for the texture attached as the default rendering target in this framebuffer o...
QGLFramebufferObject * offscreen

◆ release()

void QGLOffscreen::release ( )
inline

Definition at line 419 of file qpaintengine_opengl.cpp.

Referenced by QOpenGLPaintEnginePrivate::flushDrawQueue().

420 {
421 #ifndef QT_OPENGL_ES
422  if (!offscreen || !bound)
423  return;
424 
425 #ifdef Q_WS_X11
426  // workaround for bug in nvidia driver versions 9x.xx
428  glFinish();
429 #endif
430 
431  DEBUG_ONCE_STR("QGLOffscreen: releasing offscreen");
432 
433  if (drawable_fbo)
434  device->ensureActiveTarget(); //###
435  else
436  offscreen->release();
437 
438  QSize sz(device->size());
439  glViewport(0, 0, sz.width(), sz.height());
440 
441  glMatrixMode(GL_PROJECTION);
442  glLoadIdentity();
443 #ifndef QT_OPENGL_ES
444  glOrtho(0, sz.width(), sz.height(), 0, -999999, 999999);
445 #else
446  glOrthof(0, sz.width(), sz.height(), 0, -999999, 999999);
447 #endif
448  glMatrixMode(GL_MODELVIEW);
449 
450  bound = false;
451 #endif
452 }
#define DEBUG_ONCE_STR(str)
virtual QSize size() const =0
virtual void ensureActiveTarget()
QGLPaintDevice * device
static bool qt_nvidiaFboNeedsFinish
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QGLFramebufferObject * offscreen

◆ setDevice()

void QGLOffscreen::setDevice ( QPaintDevice pdev)
inline

Definition at line 303 of file qpaintengine_opengl.cpp.

304 {
305  if (pdev->devType() == QInternal::OpenGL)
306  device = static_cast<QGLPaintDevice*>(pdev);
307  else
309 
310  if (!device)
311  return;
312 
314 }
virtual int devType() const
Definition: qpaintdevice.h:167
QGLPaintDevice * device
static QGLPaintDevice * getDevice(QPaintDevice *)

Properties

◆ activated

bool QGLOffscreen::activated
private

Definition at line 297 of file qpaintengine_opengl.cpp.

◆ bound

bool QGLOffscreen::bound
private

Definition at line 300 of file qpaintengine_opengl.cpp.

◆ ctx

QGLContext* QGLOffscreen::ctx
private

Definition at line 289 of file qpaintengine_opengl.cpp.

◆ device

QGLPaintDevice* QGLOffscreen::device
private

Definition at line 286 of file qpaintengine_opengl.cpp.

◆ drawable_fbo

bool QGLOffscreen::drawable_fbo
private

Definition at line 295 of file qpaintengine_opengl.cpp.

◆ initialized

bool QGLOffscreen::initialized
private

Definition at line 298 of file qpaintengine_opengl.cpp.

◆ last_failed_size

QSize QGLOffscreen::last_failed_size
private

Definition at line 293 of file qpaintengine_opengl.cpp.

◆ mask_dim

int QGLOffscreen::mask_dim
private

Definition at line 292 of file qpaintengine_opengl.cpp.

◆ offscreen

QGLFramebufferObject* QGLOffscreen::offscreen
private

Definition at line 288 of file qpaintengine_opengl.cpp.


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