Qt 4.8
Public Functions | Static Public Functions | Public Variables | Static Public Variables | List of all members
QGLContextPrivate Class Reference

#include <qgl_p.h>

Public Functions

QGLTexturebindTexture (const QImage &image, GLenum target, GLint format, QGLContext::BindOptions options)
 
QGLTexturebindTexture (const QImage &image, GLenum target, GLint format, const qint64 key, QGLContext::BindOptions options)
 
QGLTexturebindTexture (const QPixmap &pixmap, GLenum target, GLint format, QGLContext::BindOptions options)
 
QGLTexturebindTextureFromNativePixmap (QPixmap *, const qint64 key, QGLContext::BindOptions options)
 
void cleanup ()
 
void clearDrawable ()
 
QImage convertToGLFormat (const QImage &image, bool force_premul, GLenum texture_format)
 
void destroyEglSurfaceForDevice ()
 
EGLSurface eglSurfaceForDevice () const
 
void init (QPaintDevice *dev, const QGLFormat &format)
 
int maxTextureSize ()
 
 QGLContextPrivate (QGLContext *context)
 
void setVertexAttribArrayEnabled (int arrayIndex, bool enabled=true)
 
void swapRegion (const QRegion &region)
 
void syncGlState ()
 
QGLTexturetextureCacheLookup (const qint64 key, GLenum target)
 
void * tryFormat (const QGLFormat &format)
 
void updateFormatVersion ()
 
 ~QGLContextPrivate ()
 

Static Public Functions

static QGLContextGroupcontextGroup (const QGLContext *ctx)
 
static void destroyGlSurfaceForPixmap (QPixmapData *)
 
static QGLExtensionFuncsextensionFuncs (const QGLContext *ctx)
 
static Q_OPENGL_EXPORT QGLExtensionFuncsextensionFuncs (const QGLContext *)
 
static void setExtraWindowSurfaceCreationProps (QEglProperties *props)
 
static void unbindPixmapFromTexture (QPixmapData *)
 
static void setCurrentContext (QGLContext *context)
 

Public Variables

QPaintEngineactive_engine
 
QHash< QPixmapData *, QPixmapboundPixmaps
 
QGLCmapcmap
 
uint crWin: 1
 
GLuint current_fbo
 
void * cx
 
HDC dc
 
GLuint default_fbo
 
QEglContexteglContext
 
EGLSurface eglSurface
 
QGLExtensions::Extensions extension_flags
 
uint extension_flags_cached: 1
 
GLuint fbo
 
QGLFormat glFormat
 
quint32 gpm
 
QGLContextGroupgroup
 
HBITMAP hbitmap
 
HDC hbitmap_hdc
 
uint initDone: 1
 
uint internal_context: 1
 
QHash< QGLContextResourceBase *, void * > m_resources
 
GLint max_texture_size
 
uint ownsEglContext: 1
 
QPaintDevicepaintDevice
 
void * pbuf
 
int pixelFormatId
 
QGLContextq_ptr
 
HGLRC rc
 
QGLFormat reqFormat
 
int screen
 
uint sharing: 1
 
QGLTextureDestroyertexture_destroyer
 
Qt::HANDLE threadId
 
QColor transpColor
 
bool update
 
uint valid: 1
 
QGLFormat::OpenGLVersionFlags version_flags
 
uint version_flags_cached: 1
 
bool vertexAttributeArraysEnabledState [QT_GL_VERTEX_ARRAY_TRACKED_COUNT]
 
void * vi
 
WId win
 
uint workaround_brokenAlphaTexSubImage: 1
 
uint workaround_brokenAlphaTexSubImage_init: 1
 
uint workaround_brokenFBOReadBack: 1
 
uint workaround_brokenScissor: 1
 
uint workaround_brokenTexSubImage: 1
 
uint workaround_brokenTextureFromPixmap: 1
 
uint workaround_brokenTextureFromPixmap_init: 1
 
uint workaround_needsFullClearOnEveryFrame: 1
 
uint workaroundsCached: 1
 

Static Public Variables

static QEglPropertiesextraWindowSurfaceCreationProps = NULL
 
static Q_OPENGL_EXPORT QGLExtensionFuncs qt_extensionFuncs
 

Detailed Description

Definition at line 347 of file qgl_p.h.

Constructors and Destructors

◆ QGLContextPrivate()

QGLContextPrivate::QGLContextPrivate ( QGLContext context)
explicit

Definition at line 1728 of file qgl.cpp.

1729  : internal_context(false)
1730  , q_ptr(context)
1731 {
1732  group = new QGLContextGroup(context);
1734  texture_destroyer->moveToThread(qApp->thread());
1735 }
QGLContextGroup * group
Definition: qgl_p.h:453
uint internal_context
Definition: qgl_p.h:426
#define qApp
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
QGLContext * q_ptr
Definition: qgl_p.h:449
QGLTextureDestroyer * texture_destroyer
Definition: qgl_p.h:460

◆ ~QGLContextPrivate()

QGLContextPrivate::~QGLContextPrivate ( )

Definition at line 1737 of file qgl.cpp.

1738 {
1739  if (!group->m_refs.deref()) {
1740  Q_ASSERT(group->context() == q_ptr);
1741  delete group;
1742  }
1743 
1744  delete texture_destroyer;
1745 }
QGLContextGroup * group
Definition: qgl_p.h:453
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAtomicInt m_refs
Definition: qgl_p.h:270
bool deref()
Atomically decrements the value of this QAtomicInt.
QGLContext * q_ptr
Definition: qgl_p.h:449
QGLTextureDestroyer * texture_destroyer
Definition: qgl_p.h:460
const QGLContext * context() const
Definition: qgl_p.h:252

Functions

◆ bindTexture() [1/3]

QGLTexture * QGLContextPrivate::bindTexture ( const QImage image,
GLenum  target,
GLint  format,
QGLContext::BindOptions  options 
)
Warning
This function is not part of the public interface.

Definition at line 2394 of file qgl.cpp.

2396 {
2397  Q_Q(QGLContext);
2398 
2399  const qint64 key = image.cacheKey();
2400  QGLTexture *texture = textureCacheLookup(key, target);
2401  if (texture) {
2402  if (image.paintingActive()) {
2403  // A QPainter is active on the image - take the safe route and replace the texture.
2404  q->deleteTexture(texture->id);
2405  texture = 0;
2406  } else {
2407  glBindTexture(target, texture->id);
2408  return texture;
2409  }
2410  }
2411 
2412  if (!texture)
2413  texture = bindTexture(image, target, format, key, options);
2414  // NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null
2415  Q_ASSERT(texture);
2416 
2417  // Enable the cleanup hooks for this image so that the texture cache entry is removed when the
2418  // image gets deleted:
2420 
2421  return texture;
2422 }
static void enableCleanupHooks(const QImage &image)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool paintingActive() const
Definition: qpaintdevice.h:170
#define Q_Q(Class)
Definition: qglobal.h:2483
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
__int64 qint64
Definition: qglobal.h:942
int key
QGLTexture * bindTexture(const QImage &image, GLenum target, GLint format, QGLContext::BindOptions options)
Definition: qgl.cpp:2394
QGLTexture * textureCacheLookup(const qint64 key, GLenum target)
Definition: qgl.cpp:2665
qint64 cacheKey() const
Returns a number that identifies the contents of this QImage object.
Definition: qimage.cpp:6282

◆ bindTexture() [2/3]

QGLTexture * QGLContextPrivate::bindTexture ( const QImage image,
GLenum  target,
GLint  format,
const qint64  key,
QGLContext::BindOptions  options 
)

Definition at line 2449 of file qgl.cpp.

2451 {
2452  Q_Q(QGLContext);
2453 
2454 #ifdef QGL_BIND_TEXTURE_DEBUG
2455  printf("QGLContextPrivate::bindTexture(), imageSize=(%d,%d), internalFormat =0x%x, options=%x, key=%llx\n",
2456  image.width(), image.height(), internalFormat, int(options), key);
2457  QTime time;
2458  time.start();
2459 #endif
2460 
2461 #ifndef QT_NO_DEBUG
2462  // Reset the gl error stack...git
2463  while (glGetError() != GL_NO_ERROR) ;
2464 #endif
2465 
2466  // Scale the pixmap if needed. GL textures needs to have the
2467  // dimensions 2^n+2(border) x 2^m+2(border), unless we're using GL
2468  // 2.0 or use the GL_TEXTURE_RECTANGLE texture target
2469  int tx_w = qt_next_power_of_two(image.width());
2470  int tx_h = qt_next_power_of_two(image.height());
2471 
2472  QImage img = image;
2473 
2476  && (target == GL_TEXTURE_2D && (tx_w != image.width() || tx_h != image.height())))
2477  {
2478  img = img.scaled(tx_w, tx_h);
2479 #ifdef QGL_BIND_TEXTURE_DEBUG
2480  printf(" - upscaled to %dx%d (%d ms)\n", tx_w, tx_h, time.elapsed());
2481 
2482 #endif
2483  }
2484 
2485  GLuint filtering = options & QGLContext::LinearFilteringBindOption ? GL_LINEAR : GL_NEAREST;
2486 
2487  GLuint tx_id;
2488  glGenTextures(1, &tx_id);
2489  glBindTexture(target, tx_id);
2490  glTexParameterf(target, GL_TEXTURE_MAG_FILTER, filtering);
2491 
2492 #if defined(QT_OPENGL_ES_2)
2493  bool genMipmap = false;
2494 #endif
2497  && target == GL_TEXTURE_2D
2498  && (options & QGLContext::MipmapBindOption))
2499  {
2500 #if !defined(QT_OPENGL_ES_2)
2502 #ifndef QT_OPENGL_ES
2503  glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
2504 #else
2505  glTexParameterf(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
2506 #endif
2507 #else
2509  genMipmap = true;
2510 #endif
2511  glTexParameterf(target, GL_TEXTURE_MIN_FILTER, options & QGLContext::LinearFilteringBindOption
2513 #ifdef QGL_BIND_TEXTURE_DEBUG
2514  printf(" - generating mipmaps (%d ms)\n", time.elapsed());
2515 #endif
2516  } else {
2517  glTexParameterf(target, GL_TEXTURE_MIN_FILTER, filtering);
2518  }
2519 
2520  QImage::Format target_format = img.format();
2522  GLenum externalFormat;
2523  GLuint pixel_type;
2525  externalFormat = GL_BGRA;
2527  pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV;
2528  else
2529  pixel_type = GL_UNSIGNED_BYTE;
2530  } else {
2531  externalFormat = GL_RGBA;
2532  pixel_type = GL_UNSIGNED_BYTE;
2533  }
2534 
2535  switch (target_format) {
2536  case QImage::Format_ARGB32:
2537  if (premul) {
2538  img = img.convertToFormat(target_format = QImage::Format_ARGB32_Premultiplied);
2539 #ifdef QGL_BIND_TEXTURE_DEBUG
2540  printf(" - converted ARGB32 -> ARGB32_Premultiplied (%d ms) \n", time.elapsed());
2541 #endif
2542  }
2543  break;
2545  if (!premul) {
2546  img = img.convertToFormat(target_format = QImage::Format_ARGB32);
2547 #ifdef QGL_BIND_TEXTURE_DEBUG
2548  printf(" - converted ARGB32_Premultiplied -> ARGB32 (%d ms)\n", time.elapsed());
2549 #endif
2550  }
2551  break;
2552  case QImage::Format_RGB16:
2553  pixel_type = GL_UNSIGNED_SHORT_5_6_5;
2554  externalFormat = GL_RGB;
2555  internalFormat = GL_RGB;
2556  break;
2557  case QImage::Format_RGB32:
2558  break;
2559  default:
2560  if (img.hasAlphaChannel()) {
2561  img = img.convertToFormat(premul
2564 #ifdef QGL_BIND_TEXTURE_DEBUG
2565  printf(" - converted to 32-bit alpha format (%d ms)\n", time.elapsed());
2566 #endif
2567  } else {
2568  img = img.convertToFormat(QImage::Format_RGB32);
2569 #ifdef QGL_BIND_TEXTURE_DEBUG
2570  printf(" - converted to 32-bit (%d ms)\n", time.elapsed());
2571 #endif
2572  }
2573  }
2574 
2575  if (options & QGLContext::InvertedYBindOption) {
2576  if (img.isDetached()) {
2577  int ipl = img.bytesPerLine() / 4;
2578  int h = img.height();
2579  for (int y=0; y<h/2; ++y) {
2580  int *a = (int *) img.scanLine(y);
2581  int *b = (int *) img.scanLine(h - y - 1);
2582  for (int x=0; x<ipl; ++x)
2583  qSwap(a[x], b[x]);
2584  }
2585  } else {
2586  // Create a new image and copy across. If we use the
2587  // above in-place code then a full copy of the image is
2588  // made before the lines are swapped, which processes the
2589  // data twice. This version should only do it once.
2590  img = img.mirrored();
2591  }
2592 #ifdef QGL_BIND_TEXTURE_DEBUG
2593  printf(" - flipped bits over y (%d ms)\n", time.elapsed());
2594 #endif
2595  }
2596 
2597  if (externalFormat == GL_RGBA) {
2598  // The only case where we end up with a depth different from
2599  // 32 in the switch above is for the RGB16 case, where we set
2600  // the format to GL_RGB
2601  Q_ASSERT(img.depth() == 32);
2602  qgl_byteSwapImage(img, pixel_type);
2603 #ifdef QGL_BIND_TEXTURE_DEBUG
2604  printf(" - did byte swapping (%d ms)\n", time.elapsed());
2605 #endif
2606  }
2607 #ifdef QT_OPENGL_ES
2608  // OpenGL/ES requires that the internal and external formats be
2609  // identical.
2610  internalFormat = externalFormat;
2611 #endif
2612 #ifdef QGL_BIND_TEXTURE_DEBUG
2613  printf(" - uploading, image.format=%d, externalFormat=0x%x, internalFormat=0x%x, pixel_type=0x%x\n",
2614  img.format(), externalFormat, internalFormat, pixel_type);
2615 #endif
2616 
2617  const QImage &constRef = img; // to avoid detach in bits()...
2618 #ifdef Q_OS_SYMBIAN
2619  // On Symbian we always use texture pool to reserve the texture
2621  target,
2622  0, internalFormat,
2623  img.width(), img.height(),
2624  externalFormat,
2625  pixel_type,
2626  constRef.bits());
2627 #else
2628  glTexImage2D(target, 0, internalFormat, img.width(), img.height(), 0, externalFormat,
2629  pixel_type, constRef.bits());
2630 #endif
2631 
2632 #if defined(QT_OPENGL_ES_2)
2633  if (genMipmap)
2634  glGenerateMipmap(target);
2635 #endif
2636 #ifndef QT_NO_DEBUG
2637  GLenum error = glGetError();
2638  if (error != GL_NO_ERROR) {
2639  qWarning(" - texture upload failed, error code 0x%x, enum: %d (%x)\n", error, target, target);
2640  }
2641 #endif
2642 
2643 #ifdef QGL_BIND_TEXTURE_DEBUG
2644  static int totalUploadTime = 0;
2645  totalUploadTime += time.elapsed();
2646  printf(" - upload done in %d ms, (accumulated: %d ms)\n", time.elapsed(), totalUploadTime);
2647 #endif
2648 
2649 
2650  // this assumes the size of a texture is always smaller than the max cache size
2651  int cost = img.width()*img.height()*4/1024;
2652  QGLTexture *texture = new QGLTexture(q, tx_id, target, options);
2653  QGLTextureCache::instance()->insert(q, key, texture, cost);
2654 
2655 #ifdef Q_OS_SYMBIAN
2656  // Store the key so that QGLTexturePool
2657  // is able to release this texture when needed.
2658  texture->boundKey = key;
2659  // And append to LRU list
2661 #endif
2662  return texture;
2663 }
void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost)
Definition: qgl.cpp:1922
#define GL_BGRA
Definition: glfunctions.h:63
Format
The following image formats are available in Qt.
Definition: qimage.h:91
#define GL_RGB
bool createPermanentTexture(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data)
#define GL_TEXTURE_MIN_FILTER
static OpenGLVersionFlags openGLVersionFlags()
#define GL_TRUE
static QGLTextureCache * instance()
Definition: qgl.cpp:1995
void start()
Sets this time to the current time.
Definition: qdatetime.cpp:2070
#define error(msg)
#define GL_UNSIGNED_INT_8_8_8_8_REV
#define GL_NICEST
void useTexture(QGLTexture *texture)
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define GL_TEXTURE_2D
bool directRendering() const
Returns true if direct rendering is enabled; otherwise returns false.
Definition: qgl.h:648
#define Q_Q(Class)
Definition: qglobal.h:2483
#define premul(x)
int qt_next_power_of_two(int v)
Definition: qgl.cpp:1886
#define GL_UNSIGNED_SHORT_5_6_5
The QTime class provides clock time functions.
Definition: qdatetime.h:148
static void qgl_byteSwapImage(QImage &img, GLenum pixel_type)
Definition: qgl.cpp:2427
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
QGLFormat glFormat
Definition: qgl_p.h:418
#define GL_GENERATE_MIPMAP_HINT
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
#define GL_NEAREST_MIPMAP_NEAREST
static QGLTexturePool * instance()
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
#define GL_LINEAR
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
unsigned int GLenum
Definition: main.cpp:50
#define GL_UNSIGNED_BYTE
int key
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
static Extensions glExtensions()
Definition: qgl.cpp:5781
#define GL_RGBA
#define GL_LINEAR_MIPMAP_LINEAR
#define GL_GENERATE_MIPMAP_HINT_SGIS
#define GL_TEXTURE_MAG_FILTER
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qimage.h:232
#define glGenerateMipmap
Definition: glfunctions.h:70
#define GL_NO_ERROR
#define GL_GENERATE_MIPMAP_SGIS
#define GL_NEAREST

◆ bindTexture() [3/3]

QGLTexture * QGLContextPrivate::bindTexture ( const QPixmap pixmap,
GLenum  target,
GLint  format,
QGLContext::BindOptions  options 
)
Warning
This function is not part of the public interface.

Definition at line 2678 of file qgl.cpp.

2679 {
2680  Q_Q(QGLContext);
2681  QPixmapData *pd = pixmap.pixmapData();
2682 #if !defined(QT_OPENGL_ES_1)
2683  if (target == GL_TEXTURE_2D && pd->classId() == QPixmapData::OpenGLClass) {
2684  const QGLPixmapData *data = static_cast<const QGLPixmapData *>(pd);
2685 
2686  if (data->isValidContext(q)) {
2687  data->bind();
2688  return data->texture();
2689  }
2690  }
2691 #else
2692  Q_UNUSED(pd);
2693 #endif
2694 
2695  const qint64 key = pixmap.cacheKey();
2696  QGLTexture *texture = textureCacheLookup(key, target);
2697  if (texture) {
2698  if (pixmap.paintingActive()) {
2699  // A QPainter is active on the pixmap - take the safe route and replace the texture.
2700  q->deleteTexture(texture->id);
2701  texture = 0;
2702  } else {
2703  glBindTexture(target, texture->id);
2704  return texture;
2705  }
2706  }
2707 
2708 #if defined(Q_WS_X11)
2709  // Try to use texture_from_pixmap
2710  const QX11Info *xinfo = qt_x11Info(paintDevice);
2712  && xinfo && xinfo->screen() == pixmap.x11Info().screen()
2713  && target == GL_TEXTURE_2D
2715  {
2718 
2719  const QByteArray versionString(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
2720  const int pos = versionString.indexOf("NVIDIA ");
2721 
2722  if (pos >= 0) {
2723  const QByteArray nvidiaVersionString = versionString.mid(pos + strlen("NVIDIA "));
2724 
2725  if (nvidiaVersionString.startsWith("195") || nvidiaVersionString.startsWith("256"))
2727  }
2728  }
2729 
2731  texture = bindTextureFromNativePixmap(const_cast<QPixmap*>(&pixmap), key, options);
2732  if (texture) {
2734  texture->boundPixmap = pd;
2735  boundPixmaps.insert(pd, QPixmap(pixmap));
2736  }
2737  }
2738  }
2739 #endif
2740 
2741  if (!texture) {
2742 #ifdef Q_OS_SYMBIAN
2743  // On Symbian pixmaps are backed up by native CFbsBitmap
2744  // which can be shared across processes. QVolatileImage wraps
2745  // it and provides locking mechanism to pixel access.
2746  QVolatileImage volatileImage = pd->toVolatileImage();
2747  if (volatileImage.isNull()) { // TODO: raster graphics system don't provide volatile image (yet)
2748  // NOTE! On Symbian raster graphics system QPixmap::toImage() makes deep copy
2749  texture = bindTexture(pixmap.toImage(), target, format, key, options);
2750  } else {
2751  volatileImage.beginDataAccess();
2752  texture = bindTexture(volatileImage.imageRef(), target, format, key, options);
2753  volatileImage.endDataAccess(true);
2754  }
2755 #else
2756  QImage image = pixmap.toImage();
2757  // If the system depth is 16 and the pixmap doesn't have an alpha channel
2758  // then we convert it to RGB16 in the hope that it gets uploaded as a 16
2759  // bit texture which is much faster to access than a 32-bit one.
2760  if (pixmap.depth() == 16 && !image.hasAlphaChannel() )
2761  image = image.convertToFormat(QImage::Format_RGB16);
2762  texture = bindTexture(image, target, format, key, options);
2763 #endif
2764  }
2765  // NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null
2766  Q_ASSERT(texture);
2767 
2768  if (texture->id > 0)
2770 
2771  return texture;
2772 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
bool isValidContext(const QGLContext *ctx) const
void beginDataAccess() const
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
GLuint bind(bool copyBack=true) const
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
static void enableCleanupHooks(const QImage &image)
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
QHash< QPixmapData *, QPixmap > boundPixmaps
Definition: qgl_p.h:407
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
QPaintDevice * paintDevice
Definition: qgl_p.h:447
QGLContext::BindOptions options
Definition: qgl_p.h:611
#define GL_TEXTURE_2D
void endDataAccess(bool readOnly=false) const
bool isNull() const
bool paintingActive() const
Definition: qpaintdevice.h:170
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
#define Q_Q(Class)
Definition: qglobal.h:2483
QGLTexture * bindTextureFromNativePixmap(QPixmap *, const qint64 key, QGLContext::BindOptions options)
Definition: qgl_x11.cpp:1765
PixelType pixelType() const
QGLTexture * texture() const
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
uint workaround_brokenTextureFromPixmap_init
Definition: qgl_p.h:437
#define GL_VERSION
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
ClassId classId() const
__int64 qint64
Definition: qglobal.h:942
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
QPixmapData * boundPixmap
Definition: qgl_p.h:614
The QX11Info class provides information about the X display configuration.
Definition: qx11info_x11.h:63
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
const QX11Info * qt_x11Info(const QPaintDevice *pd)
int key
QGLTexture * bindTexture(const QImage &image, GLenum target, GLint format, QGLContext::BindOptions options)
Definition: qgl.cpp:2394
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QGLTexture * textureCacheLookup(const qint64 key, GLenum target)
Definition: qgl.cpp:2665
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
uint workaround_brokenTextureFromPixmap
Definition: qgl_p.h:436
#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
QImage & imageRef()
Returns a reference to the image that is potentially using some native buffer internally.
int screen() const
Returns the number of the screen currently in use.
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277

◆ bindTextureFromNativePixmap()

QGLTexture * QGLContextPrivate::bindTextureFromNativePixmap ( QPixmap pixmap,
const qint64  key,
QGLContext::BindOptions  options 
)

defined(GLX_VERSION_1_3) || defined(Q_OS_HPUX)

Definition at line 1765 of file qgl_x11.cpp.

1767 {
1768 #if !defined(GLX_VERSION_1_3) || defined(Q_OS_HPUX)
1769  return 0;
1770 #else
1771 
1772  // Check we have GLX 1.3, as it is needed for glXCreatePixmap & glXDestroyPixmap
1773  int majorVersion = 0;
1774  int minorVersion = 0;
1775  glXQueryVersion(X11->display, &majorVersion, &minorVersion);
1776  if (majorVersion < 1 || (majorVersion == 1 && minorVersion < 3))
1777  return 0;
1778 
1779  Q_Q(QGLContext);
1780 
1781  QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pixmap->data_ptr().data());
1782  Q_ASSERT(pixmapData->classId() == QPixmapData::X11Class);
1783 
1784  // We can't use TFP if the pixmap has a separate X11 mask
1785  if (pixmapData->x11_mask)
1786  return 0;
1787 
1788  if (!qt_resolveTextureFromPixmap(paintDevice))
1789  return 0;
1790 
1791  const QX11Info &x11Info = pixmapData->xinfo;
1792 
1793  // Store the configs (Can be static because configs aren't dependent on current context)
1794  static GLXFBConfig glxRGBPixmapConfig = 0;
1795  static bool RGBConfigInverted = false;
1796  static GLXFBConfig glxRGBAPixmapConfig = 0;
1797  static bool RGBAConfigInverted = false;
1798 
1799  bool hasAlpha = pixmapData->hasAlphaChannel();
1800 
1801  // Check to see if we need a config
1802  if ( (hasAlpha && !glxRGBAPixmapConfig) || (!hasAlpha && !glxRGBPixmapConfig) ) {
1803  GLXFBConfig *configList = 0;
1804  int configCount = 0;
1805 
1806  int configAttribs[] = {
1808  GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
1810  // QGLContext::bindTexture() can't return an inverted texture, but QPainter::drawPixmap() can:
1811  GLX_Y_INVERTED_EXT, int(options & QGLContext::CanFlipNativePixmapBindOption ? GLX_DONT_CARE : False),
1812  XNone
1813  };
1814  configList = glXChooseFBConfig(x11Info.display(), x11Info.screen(), configAttribs, &configCount);
1815  if (!configList)
1816  return 0;
1817 
1818  int yInv;
1819  glXGetFBConfigAttrib(x11Info.display(), configList[0], GLX_Y_INVERTED_EXT, &yInv);
1820 
1821  if (hasAlpha) {
1822  glxRGBAPixmapConfig = configList[0];
1823  RGBAConfigInverted = yInv;
1824  }
1825  else {
1826  glxRGBPixmapConfig = configList[0];
1827  RGBConfigInverted = yInv;
1828  }
1829 
1830  XFree(configList);
1831  }
1832 
1833  // Check to see if the surface is still valid
1834  if (pixmapData->gl_surface &&
1835  hasAlpha != (pixmapData->flags & QX11PixmapData::GlSurfaceCreatedWithAlpha))
1836  {
1837  // Surface is invalid!
1838  destroyGlSurfaceForPixmap(pixmapData);
1839  }
1840 
1841  // Check to see if we need a surface
1842  if (!pixmapData->gl_surface) {
1843  GLXPixmap glxPixmap;
1844  int pixmapAttribs[] = {
1847  GLX_MIPMAP_TEXTURE_EXT, False, // Maybe needs to be don't care
1848  XNone
1849  };
1850 
1851  // Wrap the X Pixmap into a GLXPixmap:
1852  glxPixmap = glXCreatePixmap(x11Info.display(),
1853  hasAlpha ? glxRGBAPixmapConfig : glxRGBPixmapConfig,
1854  pixmapData->handle(), pixmapAttribs);
1855 
1856  if (!glxPixmap)
1857  return 0;
1858 
1859  pixmapData->gl_surface = (void*)glxPixmap;
1860 
1861  // Make sure the cleanup hook gets called so we can delete the glx pixmap
1863  }
1864 
1865  GLuint textureId;
1866  glGenTextures(1, &textureId);
1867  glBindTexture(GL_TEXTURE_2D, textureId);
1868  glXBindTexImageEXT(x11Info.display(), (GLXPixmap)pixmapData->gl_surface, GLX_FRONT_LEFT_EXT, 0);
1869 
1870  glBindTexture(GL_TEXTURE_2D, textureId);
1871  GLuint filtering = (options & QGLContext::LinearFilteringBindOption) ? GL_LINEAR : GL_NEAREST;
1872  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
1873  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
1874 
1875  if (!((hasAlpha && RGBAConfigInverted) || (!hasAlpha && RGBConfigInverted)))
1876  options &= ~QGLContext::InvertedYBindOption;
1877 
1878  QGLTexture *texture = new QGLTexture(q, textureId, GL_TEXTURE_2D, options);
1881 
1882  // We assume the cost of bound pixmaps is zero
1883  QGLTextureCache::instance()->insert(q, key, texture, 0);
1884 
1885  return texture;
1886 #endif
1887 }
DataPtr & data_ptr()
Definition: qpixmap.h:297
void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost)
Definition: qgl.cpp:1922
#define GL_TEXTURE_MIN_FILTER
#define GLX_FRONT_LEFT_EXT
Definition: qgl_x11.cpp:116
static QGLTextureCache * instance()
Definition: qgl.cpp:1995
#define GLX_TEXTURE_TARGET_EXT
Definition: qgl_x11.cpp:109
#define GLX_TEXTURE_2D_EXT
Definition: qgl_x11.cpp:114
#define glXGetFBConfigAttrib
static void enableCleanupHooks(const QImage &image)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
#define glXChooseFBConfig
QPaintDevice * paintDevice
Definition: qgl_p.h:447
QGLContext::BindOptions options
Definition: qgl_p.h:611
#define GL_TEXTURE_2D
#define GLX_BIND_TO_TEXTURE_RGB_EXT
Definition: qgl_x11.cpp:103
#define Q_Q(Class)
Definition: qglobal.h:2483
#define GLX_BIND_TO_TEXTURE_TARGETS_EXT
Definition: qgl_x11.cpp:106
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
#define GLX_DRAWABLE_TYPE
Qt::HANDLE handle() const
Definition: qpixmap_x11_p.h:95
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define GLX_TEXTURE_FORMAT_RGB_EXT
Definition: qgl_x11.cpp:112
ClassId classId() const
static void destroyGlSurfaceForPixmap(QPixmapData *)
Definition: qgl_x11.cpp:1890
#define GLX_Y_INVERTED_EXT
Definition: qgl_x11.cpp:107
#define GL_LINEAR
The QX11Info class provides information about the X display configuration.
Definition: qx11info_x11.h:63
Qt::HANDLE x11_mask
bool hasAlphaChannel() const
#define GLX_MIPMAP_TEXTURE_EXT
Definition: qgl_x11.cpp:110
int key
#define GLX_TEXTURE_FORMAT_EXT
Definition: qgl_x11.cpp:108
#define GLX_TEXTURE_2D_BIT_EXT
Definition: qgl_x11.cpp:101
#define GL_TEXTURE_MAG_FILTER
#define GLX_BIND_TO_TEXTURE_RGBA_EXT
Definition: qgl_x11.cpp:104
static Display * display()
Returns the default display for the application.
int screen() const
Returns the number of the screen currently in use.
#define GLX_TEXTURE_FORMAT_RGBA_EXT
Definition: qgl_x11.cpp:113
#define GL_NEAREST

◆ cleanup()

void QGLContextPrivate::cleanup ( )

Definition at line 2180 of file qgl.cpp.

2181 {
2183  for (it = m_resources.begin(); it != m_resources.end(); ++it)
2184  it.key()->freeResource(it.value());
2185  m_resources.clear();
2186 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
const Key & key() const
Returns the current item&#39;s key.
Definition: qhash.h:419
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
QHash< QGLContextResourceBase *, void * > m_resources
Definition: qgl_p.h:459

◆ clearDrawable()

void QGLContextPrivate::clearDrawable ( )

Definition at line 473 of file qgl_mac.mm.

474 {
475  [static_cast<NSOpenGLContext *>(cx) clearDrawable];
476 }
void clearDrawable()
Definition: qgl_mac.mm:473

◆ contextGroup()

static QGLContextGroup* QGLContextPrivate::contextGroup ( const QGLContext ctx)
inlinestatic

Definition at line 464 of file qgl_p.h.

Referenced by QGLFramebufferObject::bind(), QGLFBOGLPaintDevice::context(), QGL2PaintEngineExPrivate::drawCachedGlyphs(), QGLTextureCache::getTexture(), and QGLFramebufferObject::release().

464 { return ctx->d_ptr->group; }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
QGLContextGroup * group
Definition: qgl_p.h:453

◆ convertToGLFormat()

QImage QGLContextPrivate::convertToGLFormat ( const QImage image,
bool  force_premul,
GLenum  texture_format 
)

Definition at line 2381 of file qgl.cpp.

2383 {
2384  QImage::Format target_format = image.format();
2385  if (force_premul || image.format() != QImage::Format_ARGB32)
2386  target_format = QImage::Format_ARGB32_Premultiplied;
2387 
2388  QImage result(image.width(), image.height(), target_format);
2389  convertToGLFormatHelper(result, image.convertToFormat(target_format), texture_format);
2390  return result;
2391 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
static void convertToGLFormatHelper(QImage &dst, const QImage &img, GLenum texture_format)
Definition: qgl.cpp:2286

◆ destroyEglSurfaceForDevice()

void QGLContextPrivate::destroyEglSurfaceForDevice ( )

Definition at line 296 of file qgl_egl.cpp.

297 {
298  if (eglSurface != EGL_NO_SURFACE) {
299 #if defined(Q_WS_X11) || defined(Q_OS_SYMBIAN)
300  // Make sure we don't call eglDestroySurface on a surface which
301  // was created for a different winId. This applies only to QGLWidget
302  // paint device, so make sure this is the one we're operating on
303  // (as opposed to a QGLWindowSurface use case).
305  QWidget *w = static_cast<QWidget *>(paintDevice);
306  if (QGLWidget *wgl = qobject_cast<QGLWidget *>(w)) {
307  if (wgl->d_func()->eglSurfaceWindowId != wgl->winId()) {
308  qWarning("WARNING: Potential EGL surface leak! Not destroying surface.");
309  eglSurface = EGL_NO_SURFACE;
310  return;
311  }
312  }
313  }
314 #endif
315  eglDestroySurface(eglContext->display(), eglSurface);
316  eglSurface = EGL_NO_SURFACE;
317  }
318 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QPaintDevice * paintDevice
Definition: qgl_p.h:447
virtual int devType() const
Definition: qpaintdevice.h:167
Q_CORE_EXPORT void qWarning(const char *,...)
EGLSurface eglSurface
Definition: qgl_p.h:386
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
EGLDisplay display()
Definition: qeglcontext_p.h:94
QEglContext * eglContext
Definition: qgl_p.h:385

◆ destroyGlSurfaceForPixmap()

void QGLContextPrivate::destroyGlSurfaceForPixmap ( QPixmapData pmd)
static

Definition at line 1890 of file qgl_x11.cpp.

1891 {
1892 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX)
1894  QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pmd);
1895  if (pixmapData->gl_surface) {
1896  glXDestroyPixmap(QX11Info::display(), (GLXPixmap)pixmapData->gl_surface);
1897  pixmapData->gl_surface = 0;
1898  }
1899 #endif
1900 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
ClassId classId() const
static Display * display()
Returns the default display for the application.

◆ eglSurfaceForDevice()

EGLSurface QGLContextPrivate::eglSurfaceForDevice ( ) const

Definition at line 320 of file qgl_egl.cpp.

321 {
322  // If a QPixmapData had to create the QGLContext, we don't have a paintDevice
323  if (!paintDevice)
324  return eglSurface;
325 
326 #ifdef Q_WS_X11
328  QPixmapData *pmd = static_cast<QPixmap*>(paintDevice)->data_ptr().data();
329  if (pmd->classId() == QPixmapData::X11Class) {
330  QX11PixmapData* x11PixmapData = static_cast<QX11PixmapData*>(pmd);
331  return (EGLSurface)x11PixmapData->gl_surface;
332  }
333  }
334 #endif
335 
337  QGLPixelBuffer* pbuf = static_cast<QGLPixelBuffer*>(paintDevice);
338  return pbuf->d_func()->pbuf;
339  }
340 
341  return eglSurface;
342 }
QPaintDevice * paintDevice
Definition: qgl_p.h:447
virtual int devType() const
Definition: qpaintdevice.h:167
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
ClassId classId() const
EGLSurface eglSurface
Definition: qgl_p.h:386
void * data_ptr(const QTransform &t)
Definition: qpainter_p.h:81
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void * pbuf
Definition: qgl_p.h:404

◆ extensionFuncs() [1/2]

QGLExtensionFuncs & QGLContextPrivate::extensionFuncs ( const QGLContext ctx)
inlinestatic

Definition at line 467 of file qgl_p.h.

Referenced by qt_resolve_buffer_extensions(), and qt_resolve_glsl_extensions().

467 { return ctx->d_ptr->group->extensionFuncs(); }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
QGLContextGroup * group
Definition: qgl_p.h:453
QGLExtensionFuncs & extensionFuncs()
Definition: qgl_p.h:251

◆ extensionFuncs() [2/2]

static Q_OPENGL_EXPORT QGLExtensionFuncs& QGLContextPrivate::extensionFuncs ( const QGLContext )
static

◆ init()

void QGLContextPrivate::init ( QPaintDevice dev,
const QGLFormat format 
)

Definition at line 1747 of file qgl.cpp.

1748 {
1749  Q_Q(QGLContext);
1751  valid = false;
1752  q->setDevice(dev);
1753 #if defined(Q_WS_X11)
1754  pbuf = 0;
1755  gpm = 0;
1756  vi = 0;
1758 #endif
1759 #if defined(Q_WS_WIN)
1760  dc = 0;
1761  win = 0;
1762  threadId = 0;
1763  pixelFormatId = 0;
1764  cmap = 0;
1765  hbitmap = 0;
1766  hbitmap_hdc = 0;
1767 #endif
1768 #if defined(Q_WS_MAC)
1769 # ifndef QT_MAC_USE_COCOA
1770  update = false;
1771 # endif
1772  vi = 0;
1773 #endif
1774 #if defined(Q_WS_QPA)
1775  platformContext = 0;
1776 #endif
1777 #if !defined(QT_NO_EGL)
1778  ownsEglContext = false;
1779  eglContext = 0;
1780  eglSurface = EGL_NO_SURFACE;
1781 #endif
1782  fbo = 0;
1783  crWin = false;
1784  initDone = false;
1785  sharing = false;
1786  max_texture_size = -1;
1787  version_flags_cached = false;
1789  extension_flags_cached = false;
1790  extension_flags = 0;
1791  current_fbo = 0;
1792  default_fbo = 0;
1793  active_engine = 0;
1797  workaroundsCached = false;
1798 
1801 
1802  workaround_brokenScissor = false;
1805 
1806  for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
1808 }
GLuint fbo
Definition: qgl_p.h:420
int pixelFormatId
Definition: qgl_p.h:378
uint ownsEglContext
Definition: qgl_p.h:444
quint32 gpm
Definition: qgl_p.h:405
static int appScreen()
Returns the number of the screen where the application is being displayed.
uint workaround_needsFullClearOnEveryFrame
Definition: qgl_p.h:431
uint workaroundsCached
Definition: qgl_p.h:434
GLint max_texture_size
Definition: qgl_p.h:454
uint workaround_brokenTexSubImage
Definition: qgl_p.h:433
uint workaround_brokenAlphaTexSubImage
Definition: qgl_p.h:440
#define Q_Q(Class)
Definition: qglobal.h:2483
uint workaround_brokenTextureFromPixmap_init
Definition: qgl_p.h:437
#define QT_GL_VERTEX_ARRAY_TRACKED_COUNT
Definition: qgl_p.h:343
Qt::HANDLE threadId
Definition: qgl_p.h:382
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
QGLExtensions::Extensions extension_flags
Definition: qgl_p.h:451
QGLFormat glFormat
Definition: qgl_p.h:418
uint workaround_brokenAlphaTexSubImage_init
Definition: qgl_p.h:441
HBITMAP hbitmap
Definition: qgl_p.h:380
EGLSurface eglSurface
Definition: qgl_p.h:386
GLuint current_fbo
Definition: qgl_p.h:456
QGLCmap * cmap
Definition: qgl_p.h:379
QGLFormat::OpenGLVersionFlags version_flags
Definition: qgl_p.h:450
bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT]
Definition: qgl_p.h:462
uint extension_flags_cached
Definition: qgl_p.h:428
QEglContext * eglContext
Definition: qgl_p.h:385
GLuint default_fbo
Definition: qgl_p.h:457
uint workaround_brokenScissor
Definition: qgl_p.h:439
QGLFormat reqFormat
Definition: qgl_p.h:419
void * pbuf
Definition: qgl_p.h:404
QPaintEngine * active_engine
Definition: qgl_p.h:458
uint workaround_brokenTextureFromPixmap
Definition: qgl_p.h:436
uint version_flags_cached
Definition: qgl_p.h:427
uint workaround_brokenFBOReadBack
Definition: qgl_p.h:432

◆ maxTextureSize()

int QGLContextPrivate::maxTextureSize ( )
Warning
This function is not part of the public interface.

Definition at line 2775 of file qgl.cpp.

Referenced by QGLTextureGlyphCache::maxTextureHeight(), and QGLTextureGlyphCache::maxTextureWidth().

2776 {
2777  if (max_texture_size != -1)
2778  return max_texture_size;
2779 
2780  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
2781 
2782 #if defined(QT_OPENGL_ES)
2783  return max_texture_size;
2784 #else
2785  GLenum proxy = GL_PROXY_TEXTURE_2D;
2786 
2787  GLint size;
2788  GLint next = 64;
2789  glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
2790  glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size);
2791  if (size == 0) {
2792  return max_texture_size;
2793  }
2794  do {
2795  size = next;
2796  next = size * 2;
2797 
2798  if (next > max_texture_size)
2799  break;
2800  glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
2801  glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next);
2802  } while (next > size);
2803 
2804  max_texture_size = size;
2805  return max_texture_size;
2806 #endif
2807 }
#define GL_MAX_TEXTURE_SIZE
GLint max_texture_size
Definition: qgl_p.h:454
unsigned int GLenum
Definition: main.cpp:50
#define GL_UNSIGNED_BYTE
typedef GLint
Definition: glfunctions.h:67
#define GL_RGBA

◆ setCurrentContext()

void QGLContextPrivate::setCurrentContext ( QGLContext context)
static

Definition at line 3577 of file qgl.cpp.

Referenced by QGLContext::chooseMacVisual(), QGLContext::choosePixelFormat(), QGLContext::doneCurrent(), QGLContext::makeCurrent(), QGLContext::tryVisual(), and QGLContext::updatePaintDevice().

3578 {
3579 #ifdef Q_WS_QPA
3580  Q_UNUSED(context);
3581 #else
3582  QGLThreadContext *threadContext = qgl_context_storage.localData();
3583  if (!threadContext) {
3584  if (!QThread::currentThread()) {
3585  // We don't have a current QThread, so just set the static.
3586  QGLContext::currentCtx = context;
3587  return;
3588  }
3589  threadContext = new QGLThreadContext;
3590  qgl_context_storage.setLocalData(threadContext);
3591  }
3592  threadContext->context = context;
3593  QGLContext::currentCtx = context; // XXX: backwards-compat, not thread-safe
3594 #endif
3595 }
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
QGLContext * context
Definition: qgl.cpp:126
static QThreadStorage< QGLThreadContext * > qgl_context_storage
Definition: qgl.cpp:130
static QGLContext * currentCtx
Definition: qgl.h:423
#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

◆ setExtraWindowSurfaceCreationProps()

void QGLContextPrivate::setExtraWindowSurfaceCreationProps ( QEglProperties props)
static

Definition at line 352 of file qgl_egl.cpp.

Referenced by QMeeGoGraphicsSystem::setSurfaceFixedSize().

353 {
355 }
static QEglProperties * extraWindowSurfaceCreationProps
Definition: qgl_p.h:389

◆ setVertexAttribArrayEnabled()

void QGLContextPrivate::setVertexAttribArrayEnabled ( int  arrayIndex,
bool  enabled = true 
)

Definition at line 2189 of file qgl.cpp.

Referenced by QGLEngineShaderManager::useBlitProgram(), QGLEngineShaderManager::useCorrectShaderProg(), and QGLEngineShaderManager::useSimpleProgram().

2190 {
2192 #ifdef glEnableVertexAttribArray
2194 #endif
2195 
2196  if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled)
2197  glDisableVertexAttribArray(arrayIndex);
2198 
2199  if (!vertexAttributeArraysEnabledState[arrayIndex] && enabled)
2200  glEnableVertexAttribArray(arrayIndex);
2201 
2203 }
#define glEnableVertexAttribArray
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define QT_GL_VERTEX_ARRAY_TRACKED_COUNT
Definition: qgl_p.h:343
bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT]
Definition: qgl_p.h:462
#define glDisableVertexAttribArray
#define enabled

◆ swapRegion()

void QGLContextPrivate::swapRegion ( const QRegion region)

Definition at line 344 of file qgl_egl.cpp.

345 {
346  if (!valid || !eglContext)
347  return;
348 
350 }
bool swapBuffersRegion2NOK(EGLSurface surface, const QRegion *region)
Definition: qegl.cpp:543
QEglContext * eglContext
Definition: qgl_p.h:385
EGLSurface eglSurfaceForDevice() const
Definition: qgl_egl.cpp:320

◆ syncGlState()

void QGLContextPrivate::syncGlState ( )

Definition at line 2205 of file qgl.cpp.

2206 {
2207 #ifdef glEnableVertexAttribArray
2209 #endif
2210  for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) {
2213  else
2215  }
2216 
2217 }
#define glEnableVertexAttribArray
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define QT_GL_VERTEX_ARRAY_TRACKED_COUNT
Definition: qgl_p.h:343
bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT]
Definition: qgl_p.h:462
#define glDisableVertexAttribArray

◆ textureCacheLookup()

QGLTexture * QGLContextPrivate::textureCacheLookup ( const qint64  key,
GLenum  target 
)

Definition at line 2665 of file qgl.cpp.

2666 {
2667  Q_Q(QGLContext);
2669  if (texture && texture->target == target
2670  && (texture->context == q || QGLContext::areSharing(q, texture->context)))
2671  {
2672  return texture;
2673  }
2674  return 0;
2675 }
GLenum target
Definition: qgl_p.h:609
static QGLTextureCache * instance()
Definition: qgl.cpp:1995
QGLTexture * getTexture(QGLContext *ctx, qint64 key)
Definition: qgl_p.h:697
#define Q_Q(Class)
Definition: qglobal.h:2483
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
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
QGLContext * context
Definition: qgl_p.h:607
int key

◆ tryFormat()

void * QGLContextPrivate::tryFormat ( const QGLFormat format)

Definition at line 351 of file qgl_mac.mm.

352 {
353  static const int Max = 40;
354 #ifndef QT_MAC_USE_COCOA
355  GLint attribs[Max], cnt = 0;
356  bool device_is_pixmap = (paintDevice->devType() == QInternal::Pixmap);
357 
358  attribs[cnt++] = AGL_RGBA;
359  attribs[cnt++] = AGL_BUFFER_SIZE;
360  attribs[cnt++] = device_is_pixmap ? static_cast<QPixmap *>(paintDevice)->depth() : 32;
361  attribs[cnt++] = AGL_LEVEL;
362  attribs[cnt++] = format.plane();
363 
364  if (format.redBufferSize() != -1) {
365  attribs[cnt++] = AGL_RED_SIZE;
366  attribs[cnt++] = format.redBufferSize();
367  }
368  if (format.greenBufferSize() != -1) {
369  attribs[cnt++] = AGL_GREEN_SIZE;
370  attribs[cnt++] = format.greenBufferSize();
371  }
372  if (format.blueBufferSize() != -1) {
373  attribs[cnt++] = AGL_BLUE_SIZE;
374  attribs[cnt++] = format.blueBufferSize();
375  }
376  if (device_is_pixmap) {
377  attribs[cnt++] = AGL_PIXEL_SIZE;
378  attribs[cnt++] = static_cast<QPixmap *>(paintDevice)->depth();
379  attribs[cnt++] = AGL_OFFSCREEN;
380  if (!format.alpha()) {
381  attribs[cnt++] = AGL_ALPHA_SIZE;
382  attribs[cnt++] = 8;
383  }
384  } else {
385  if (format.doubleBuffer())
386  attribs[cnt++] = AGL_DOUBLEBUFFER;
387  }
388 
389  if (format.stereo())
390  attribs[cnt++] = AGL_STEREO;
391  if (format.alpha()) {
392  attribs[cnt++] = AGL_ALPHA_SIZE;
393  attribs[cnt++] = format.alphaBufferSize() == -1 ? 8 : format.alphaBufferSize();
394  }
395  if (format.stencil()) {
396  attribs[cnt++] = AGL_STENCIL_SIZE;
397  attribs[cnt++] = format.stencilBufferSize() == -1 ? 8 : format.stencilBufferSize();
398  }
399  if (format.depth()) {
400  attribs[cnt++] = AGL_DEPTH_SIZE;
401  attribs[cnt++] = format.depthBufferSize() == -1 ? 32 : format.depthBufferSize();
402  }
403  if (format.accum()) {
404  attribs[cnt++] = AGL_ACCUM_RED_SIZE;
405  attribs[cnt++] = format.accumBufferSize() == -1 ? 1 : format.accumBufferSize();
406  attribs[cnt++] = AGL_ACCUM_BLUE_SIZE;
407  attribs[cnt++] = format.accumBufferSize() == -1 ? 1 : format.accumBufferSize();
408  attribs[cnt++] = AGL_ACCUM_GREEN_SIZE;
409  attribs[cnt++] = format.accumBufferSize() == -1 ? 1 : format.accumBufferSize();
410  attribs[cnt++] = AGL_ACCUM_ALPHA_SIZE;
411  attribs[cnt++] = format.accumBufferSize() == -1 ? 1 : format.accumBufferSize();
412  }
413  if (format.sampleBuffers()) {
414  attribs[cnt++] = AGL_SAMPLE_BUFFERS_ARB;
415  attribs[cnt++] = 1;
416  attribs[cnt++] = AGL_SAMPLES_ARB;
417  attribs[cnt++] = format.samples() == -1 ? 4 : format.samples();
418  }
419 
420  attribs[cnt] = AGL_NONE;
421  Q_ASSERT(cnt < Max);
422  return aglChoosePixelFormat(0, 0, attribs);
423 #else
424  NSOpenGLPixelFormatAttribute attribs[Max];
425  int cnt = 0;
426  int devType = paintDevice->devType();
427  bool device_is_pixmap = (devType == QInternal::Pixmap);
428  int depth = device_is_pixmap ? static_cast<QPixmap *>(paintDevice)->depth() : 32;
429 
430  attribs[cnt++] = NSOpenGLPFAColorSize;
431  attribs[cnt++] = depth;
432 
433  if (device_is_pixmap) {
434  attribs[cnt++] = NSOpenGLPFAOffScreen;
435  } else {
436  if (format.doubleBuffer())
437  attribs[cnt++] = NSOpenGLPFADoubleBuffer;
438  }
439  if (glFormat.stereo())
440  attribs[cnt++] = NSOpenGLPFAStereo;
441  if (device_is_pixmap || format.alpha()) {
442  attribs[cnt++] = NSOpenGLPFAAlphaSize;
443  attribs[cnt++] = def(format.alphaBufferSize(), 8);
444  }
445  if (format.stencil()) {
446  attribs[cnt++] = NSOpenGLPFAStencilSize;
447  attribs[cnt++] = def(format.stencilBufferSize(), 8);
448  }
449  if (format.depth()) {
450  attribs[cnt++] = NSOpenGLPFADepthSize;
451  attribs[cnt++] = def(format.depthBufferSize(), 32);
452  }
453  if (format.accum()) {
454  attribs[cnt++] = NSOpenGLPFAAccumSize;
455  attribs[cnt++] = def(format.accumBufferSize(), 1);
456  }
457  if (format.sampleBuffers()) {
458  attribs[cnt++] = NSOpenGLPFASampleBuffers;
459  attribs[cnt++] = 1;
460  attribs[cnt++] = NSOpenGLPFASamples;
461  attribs[cnt++] = def(format.samples(), 4);
462  }
463 
464  if (devType == QInternal::Pbuffer)
465  attribs[cnt++] = NSOpenGLPFAPixelBuffer;
466 
467  attribs[cnt] = 0;
468  Q_ASSERT(cnt < Max);
469  return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
470 #endif
471 }
int greenBufferSize() const
Returns the green buffer size.
Definition: qgl.cpp:1070
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int redBufferSize() const
Returns the red buffer size.
Definition: qgl.cpp:1035
QPaintDevice * paintDevice
Definition: qgl_p.h:447
virtual int devType() const
Definition: qpaintdevice.h:167
bool sampleBuffers() const
Returns true if multisample buffer support is enabled; otherwise returns false.
Definition: qgl.h:658
int plane() const
Returns the plane of this format.
Definition: qgl.cpp:924
int alphaBufferSize() const
Returns the alpha buffer size.
Definition: qgl.cpp:1132
bool depth() const
Returns true if the depth buffer is enabled; otherwise returns false.
Definition: qgl.h:618
int accumBufferSize() const
Returns the accumulation buffer size.
Definition: qgl.cpp:1159
int depthBufferSize() const
Returns the depth buffer size.
Definition: qgl.cpp:1000
QGLFormat glFormat
Definition: qgl_p.h:418
bool stencil() const
Returns true if the stencil buffer is enabled; otherwise returns false.
Definition: qgl.h:638
bool accum() const
Returns true if the accumulation buffer is enabled; otherwise returns false.
Definition: qgl.h:633
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
Definition: qgl.h:628
int blueBufferSize() const
Returns the blue buffer size.
Definition: qgl.cpp:1105
bool doubleBuffer() const
Returns true if double buffering is enabled; otherwise returns false.
Definition: qgl.h:613
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
typedef GLint
Definition: glfunctions.h:67
int stencilBufferSize() const
Returns the stencil buffer size.
Definition: qgl.cpp:1185
bool stereo() const
Returns true if stereo buffering is enabled; otherwise returns false.
Definition: qgl.h:643
int samples() const
Returns the number of samples per pixel when multisampling is enabled.
Definition: qgl.cpp:824

◆ unbindPixmapFromTexture()

void QGLContextPrivate::unbindPixmapFromTexture ( QPixmapData pmd)
static

Definition at line 1902 of file qgl_x11.cpp.

Referenced by QGLTextureDestroyer::freeTexture_slot().

1903 {
1904 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX)
1907  QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pmd);
1908  if (pixmapData->gl_surface)
1909  glXReleaseTexImageEXT(QX11Info::display(), (GLXPixmap)pixmapData->gl_surface, GLX_FRONT_LEFT_EXT);
1910 #endif
1911 }
#define GLX_FRONT_LEFT_EXT
Definition: qgl_x11.cpp:116
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
ClassId classId() const
static Display * display()
Returns the default display for the application.

◆ updateFormatVersion()

void QGLContextPrivate::updateFormatVersion ( )

Definition at line 770 of file qgl_win.cpp.

771 {
772  const GLubyte *s = glGetString(GL_VERSION);
773 
774  if (!(s && s[0] >= '0' && s[0] <= '9' && s[1] == '.' && s[2] >= '0' && s[2] <= '9')) {
775  if (!s)
776  qWarning("QGLContext::chooseContext(): OpenGL version string is null.");
777  else
778  qWarning("QGLContext::chooseContext(): Unexpected OpenGL version string format.");
779  glFormat.setVersion(0, 0);
782  return;
783  }
784 
785  int major = s[0] - '0';
786  int minor = s[2] - '0';
787  glFormat.setVersion(major, minor);
788 
789  if (major < 3) {
792  } else {
793  GLint value = 0;
794  if (major > 3 || minor >= 2)
795  glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value);
796 
797  switch (value) {
800  break;
803  break;
804  default:
806  break;
807  }
808 
809  glGetIntegerv(GL_CONTEXT_FLAGS, &value);
812  else
814  }
815 }
void setProfile(OpenGLContextProfile profile)
Set the OpenGL context profile to profile.
Definition: qgl.cpp:1270
#define GL_CONTEXT_FLAGS
Definition: qgl_win.cpp:145
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
Definition: qgl_win.cpp:134
void setVersion(int major, int minor)
Set the OpenGL version to the major and minor numbers.
Definition: qgl.cpp:1202
#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
Definition: qgl_win.cpp:146
#define GL_VERSION
QGLFormat glFormat
Definition: qgl_p.h:418
Q_CORE_EXPORT void qWarning(const char *,...)
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB
Definition: qgl_win.cpp:133
#define GL_CONTEXT_PROFILE_MASK
Definition: qgl_win.cpp:141
void setOption(QGL::FormatOptions opt)
Sets the format option to opt.
Definition: qgl.cpp:954
typedef GLint
Definition: glfunctions.h:67

Properties

◆ active_engine

QPaintEngine* QGLContextPrivate::active_engine

Definition at line 458 of file qgl_p.h.

Referenced by QGLPixmapData::copy(), and QGL2PaintEngineEx::ensureActive().

◆ boundPixmaps

QHash<QPixmapData*, QPixmap> QGLContextPrivate::boundPixmaps

Definition at line 407 of file qgl_p.h.

◆ cmap

QGLCmap* QGLContextPrivate::cmap

Definition at line 379 of file qgl_p.h.

◆ crWin

uint QGLContextPrivate::crWin

Definition at line 425 of file qgl_p.h.

◆ current_fbo

GLuint QGLContextPrivate::current_fbo

◆ cx

void* QGLContextPrivate::cx

Definition at line 398 of file qgl_p.h.

◆ dc

HDC QGLContextPrivate::dc

Definition at line 376 of file qgl_p.h.

◆ default_fbo

GLuint QGLContextPrivate::default_fbo

◆ eglContext

QEglContext* QGLContextPrivate::eglContext

Definition at line 385 of file qgl_p.h.

◆ eglSurface

EGLSurface QGLContextPrivate::eglSurface

Definition at line 386 of file qgl_p.h.

◆ extension_flags

QGLExtensions::Extensions QGLContextPrivate::extension_flags

Definition at line 451 of file qgl_p.h.

◆ extension_flags_cached

uint QGLContextPrivate::extension_flags_cached

Definition at line 428 of file qgl_p.h.

◆ extraWindowSurfaceCreationProps

QEglProperties * QGLContextPrivate::extraWindowSurfaceCreationProps = NULL
static

Definition at line 389 of file qgl_p.h.

◆ fbo

GLuint QGLContextPrivate::fbo

Definition at line 420 of file qgl_p.h.

Referenced by QGLPixmapData::copy(), and QGLPixmapData::copyBackFromRenderFbo().

◆ glFormat

QGLFormat QGLContextPrivate::glFormat

Definition at line 418 of file qgl_p.h.

◆ gpm

quint32 QGLContextPrivate::gpm

Definition at line 405 of file qgl_p.h.

◆ group

QGLContextGroup* QGLContextPrivate::group

Definition at line 453 of file qgl_p.h.

Referenced by contextGroup(), and extensionFuncs().

◆ hbitmap

HBITMAP QGLContextPrivate::hbitmap

Definition at line 380 of file qgl_p.h.

◆ hbitmap_hdc

HDC QGLContextPrivate::hbitmap_hdc

Definition at line 381 of file qgl_p.h.

◆ initDone

uint QGLContextPrivate::initDone

Definition at line 424 of file qgl_p.h.

◆ internal_context

uint QGLContextPrivate::internal_context

◆ m_resources

QHash<QGLContextResourceBase *, void *> QGLContextPrivate::m_resources

Definition at line 459 of file qgl_p.h.

Referenced by QGLContextResourceBase::insert(), and QGLContextResourceBase::value().

◆ max_texture_size

GLint QGLContextPrivate::max_texture_size

Definition at line 454 of file qgl_p.h.

◆ ownsEglContext

uint QGLContextPrivate::ownsEglContext

Definition at line 444 of file qgl_p.h.

◆ paintDevice

QPaintDevice* QGLContextPrivate::paintDevice

Definition at line 447 of file qgl_p.h.

◆ pbuf

void* QGLContextPrivate::pbuf

Definition at line 404 of file qgl_p.h.

◆ pixelFormatId

int QGLContextPrivate::pixelFormatId

Definition at line 378 of file qgl_p.h.

◆ q_ptr

QGLContext* QGLContextPrivate::q_ptr

Definition at line 449 of file qgl_p.h.

◆ qt_extensionFuncs

QGLExtensionFuncs QGLContextPrivate::qt_extensionFuncs
static

Definition at line 471 of file qgl_p.h.

◆ rc

HGLRC QGLContextPrivate::rc

Definition at line 375 of file qgl_p.h.

Referenced by qgl_create_context().

◆ reqFormat

QGLFormat QGLContextPrivate::reqFormat

Definition at line 419 of file qgl_p.h.

Referenced by qgl_create_context().

◆ screen

int QGLContextPrivate::screen

Definition at line 406 of file qgl_p.h.

◆ sharing

uint QGLContextPrivate::sharing

Definition at line 423 of file qgl_p.h.

Referenced by qgl_create_context().

◆ texture_destroyer

QGLTextureDestroyer* QGLContextPrivate::texture_destroyer

Definition at line 460 of file qgl_p.h.

◆ threadId

Qt::HANDLE QGLContextPrivate::threadId

Definition at line 382 of file qgl_p.h.

◆ transpColor

QColor QGLContextPrivate::transpColor

Definition at line 448 of file qgl_p.h.

◆ update

bool QGLContextPrivate::update

Definition at line 414 of file qgl_p.h.

◆ valid

uint QGLContextPrivate::valid

Definition at line 422 of file qgl_p.h.

Referenced by qgl_create_context().

◆ version_flags

QGLFormat::OpenGLVersionFlags QGLContextPrivate::version_flags

Definition at line 450 of file qgl_p.h.

◆ version_flags_cached

uint QGLContextPrivate::version_flags_cached

Definition at line 427 of file qgl_p.h.

◆ vertexAttributeArraysEnabledState

bool QGLContextPrivate::vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT]

Definition at line 462 of file qgl_p.h.

◆ vi

void* QGLContextPrivate::vi

Definition at line 401 of file qgl_p.h.

◆ win

WId QGLContextPrivate::win

Definition at line 377 of file qgl_p.h.

◆ workaround_brokenAlphaTexSubImage

uint QGLContextPrivate::workaround_brokenAlphaTexSubImage

Definition at line 440 of file qgl_p.h.

Referenced by QGLTextureGlyphCache::fillTexture().

◆ workaround_brokenAlphaTexSubImage_init

uint QGLContextPrivate::workaround_brokenAlphaTexSubImage_init

Definition at line 441 of file qgl_p.h.

Referenced by QGLTextureGlyphCache::fillTexture().

◆ workaround_brokenFBOReadBack

uint QGLContextPrivate::workaround_brokenFBOReadBack

◆ workaround_brokenScissor

uint QGLContextPrivate::workaround_brokenScissor

Definition at line 439 of file qgl_p.h.

◆ workaround_brokenTexSubImage

uint QGLContextPrivate::workaround_brokenTexSubImage

Definition at line 433 of file qgl_p.h.

Referenced by QGLTextureGlyphCache::maxTextureHeight().

◆ workaround_brokenTextureFromPixmap

uint QGLContextPrivate::workaround_brokenTextureFromPixmap

Definition at line 436 of file qgl_p.h.

◆ workaround_brokenTextureFromPixmap_init

uint QGLContextPrivate::workaround_brokenTextureFromPixmap_init

Definition at line 437 of file qgl_p.h.

◆ workaround_needsFullClearOnEveryFrame

uint QGLContextPrivate::workaround_needsFullClearOnEveryFrame

Definition at line 431 of file qgl_p.h.

◆ workaroundsCached

uint QGLContextPrivate::workaroundsCached

Definition at line 434 of file qgl_p.h.


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