Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Static Protected Variables | Properties | Friends | List of all members
QGLContext Class Reference

The QGLContext class encapsulates an OpenGL rendering context. More...

#include <qgl.h>

Public Types

enum  BindOption {
  NoBindOption = 0x0000, InvertedYBindOption = 0x0001, MipmapBindOption = 0x0002, PremultipliedAlphaBindOption = 0x0004,
  LinearFilteringBindOption = 0x0008, MemoryManagedBindOption = 0x0010, CanFlipNativePixmapBindOption = 0x0020, DefaultBindOption,
  InternalBindOption
}
 A set of options to decide how to bind a texture using bindTexture(). More...
 

Public Functions

GLuint bindTexture (const QImage &image, GLenum target, GLint format, BindOptions options)
 Generates and binds a 2D GL texture to the current context, based on image. More...
 
GLuint bindTexture (const QPixmap &pixmap, GLenum target, GLint format, BindOptions options)
 Generates and binds a 2D GL texture to the current context, based on pixmap. More...
 
GLuint bindTexture (const QImage &image, GLenum target=GL_TEXTURE_2D, GLint format=GL_RGBA)
 Generates and binds a 2D GL texture to the current context, based on image. More...
 
GLuint bindTexture (const QPixmap &pixmap, GLenum target=GL_TEXTURE_2D, GLint format=GL_RGBA)
 Generates and binds a 2D GL texture based on pixmap. More...
 
GLuint bindTexture (const QString &fileName)
 Reads the compressed texture file fileName and generates a 2D GL texture from it. More...
 
void deleteTexture (GLuint tx_id)
 Removes the texture identified by id from the texture cache, and calls glDeleteTextures() to delete the texture from the context. More...
 
void drawTexture (const QRectF &target, GLuint textureId, GLenum textureTarget=GL_TEXTURE_2D)
 This function supports the following use cases: More...
 
void drawTexture (const QPointF &point, GLuint textureId, GLenum textureTarget=GL_TEXTURE_2D)
 This function supports the following use cases: More...
 
 QGLContext (const QGLFormat &format, QPaintDevice *device)
 Constructs an OpenGL context for the given paint device, which can be a widget or a pixmap. More...
 
 QGLContext (const QGLFormat &format)
 Constructs an OpenGL context with the given format which specifies several display options for the context. More...
 
void setFormat (const QGLFormat &format)
 Sets a format for this context. More...
 
void updatePaintDevice ()
 
virtual ~QGLContext ()
 Destroys the OpenGL context and frees its resources. More...
 

Static Public Functions

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. More...
 
static void setTextureCacheLimit (int size)
 This function sets the limit for the texture cache to size, expressed in kilobytes. More...
 
static int textureCacheLimit ()
 Returns the current texture cache limit in kilobytes. More...
 

Protected Functions

virtual void * chooseMacVisual (GDHandle)
 Mac OS X only: This virtual function tries to find a visual that matches the format, reducing the demands if the original request cannot be met. More...
 
uint colorIndex (const QColor &c) const
 Returns a colormap index for the color c, in ColorIndex mode. More...
 
void setDevice (QPaintDevice *pDev)
 

Static Protected Variables

static QGLContextcurrentCtx = 0
 

Properties

QScopedPointer< QGLContextPrivated_ptr
 

Friends

class QGL2PaintEngineEx
 
class QGL2PaintEngineExPrivate
 
class QGLContextGroup
 
class QGLContextResourceBase
 
class QGLEngineShaderManager
 
class QGLExtensions
 
class QGLFBOGLPaintDevice
 
QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags ()
 
class QGLFramebufferObject
 
class QGLFramebufferObjectPrivate
 
class QGLGlyphCache
 
struct QGLGlyphTexture
 
class QGLPaintDevice
 
class QGLPixelBuffer
 
class QGLPixelBufferPrivate
 
class QGLPixmapBlurFilter
 
class QGLPixmapData
 
class QGLPixmapFilterBase
 
class QGLSharedResourceGuard
 
class QGLTexture
 
class QGLTextureGlyphCache
 
class QGLWidget
 
class QGLWidgetGLPaintDevice
 
class QGLWidgetPrivate
 
class QGLWindowSurface
 
class QMacGLWindowChangeEvent
 
class QOpenGLPaintEngine
 
class QOpenGLPaintEnginePrivate
 
QGLContextPrivateqt_phonon_get_dptr (const QGLContext *)
 
class QX11GLPixmapData
 
class QX11GLSharedContexts
 
virtual bool create (const QGLContext *shareContext=0)
 Creates the GL context. More...
 
bool isValid () const
 Returns true if a GL rendering context has been successfully created; otherwise returns false. More...
 
bool isSharing () const
 Returns true if this context is sharing its GL context with another QGLContext, otherwise false is returned. More...
 
void reset ()
 Resets the context and makes it invalid. More...
 
QGLFormat format () const
 Returns the frame buffer format that was obtained (this may be a subset of what was requested). More...
 
QGLFormat requestedFormat () const
 Returns the frame buffer format that was originally requested in the constructor or setFormat(). More...
 
virtual void makeCurrent ()
 Makes this context the current OpenGL rendering context. More...
 
virtual void doneCurrent ()
 Makes no GL context the current context. More...
 
virtual void swapBuffers () const
 Swaps the screen contents with an off-screen buffer. More...
 
void * getProcAddress (const QString &proc) const
 Returns a function pointer to the GL extension function passed in proc. More...
 
QPaintDevicedevice () const
 Returns the paint device set for this context. More...
 
QColor overlayTransparentColor () const
 If this context is a valid context in an overlay plane, returns the plane's transparent color. More...
 
static const QGLContextcurrentContext ()
 Returns the current context, i.e. More...
 
virtual bool chooseContext (const QGLContext *shareContext=0)
 This semi-internal function is called by create(). More...
 
virtual int choosePixelFormat (void *pfd, HDC pdc)
 Win32 only: This virtual function chooses a pixel format that matches the OpenGL format. More...
 
virtual void * tryVisual (const QGLFormat &f, int bufDepth=1)
 
virtual void * chooseVisual ()
 X11 only: This virtual function tries to find a visual that matches the format, reducing the demands if the original request cannot be met. More...
 
bool deviceIsPixmap () const
 Returns true if the paint device of this context is a pixmap; otherwise returns false. More...
 
bool windowCreated () const
 Returns true if a window has been created for this context; otherwise returns false. More...
 
void setWindowCreated (bool on)
 If on is true the context has had a window created for it. More...
 
bool initialized () const
 Returns true if this context has been initialized, i. More...
 
void setInitialized (bool on)
 If on is true the context has been initialized, i. More...
 
void generateFontDisplayLists (const QFont &fnt, int listBase)
 Generates a set of 256 display lists for the 256 first characters in the font font. More...
 
void setValid (bool valid)
 Forces the GL rendering context to be valid. More...
 

Detailed Description

The QGLContext class encapsulates an OpenGL rendering context.

An OpenGL rendering context is a complete set of OpenGL state variables. The rendering context's QGL::FormatOption {format} is set in the constructor, but it can also be set later with setFormat(). The format options that are actually set are returned by format(); the options you asked for are returned by requestedFormat(). Note that after a QGLContext object has been constructed, the actual OpenGL context must be created by explicitly calling the create() function. The makeCurrent() function makes this context the current rendering context. You can make no context current using doneCurrent(). The reset() function will reset the context and make it invalid.

You can examine properties of the context with, e.g. isValid(), isSharing(), initialized(), windowCreated() and overlayTransparentColor().

If you're using double buffering you can swap the screen contents with the off-screen buffer using swapBuffers().

Please note that QGLContext is not thread-safe.

Definition at line 310 of file qgl.h.

Enumerations

◆ BindOption

A set of options to decide how to bind a texture using bindTexture().

Since
4.6
  • NoBindOption Don't do anything, pass the texture straight through.
  • InvertedYBindOption Specifies that the texture should be flipped over the X axis so that the texture coordinate 0,0 corresponds to the top left corner. Inverting the texture implies a deep copy prior to upload.
  • MipmapBindOption Specifies that bindTexture() should try to generate mipmaps. If the GL implementation supports the GL_SGIS_generate_mipmap extension, mipmaps will be automatically generated for the texture. Mipmap generation is only supported for the GL_TEXTURE_2D target.
  • PremultipliedAlphaBindOption Specifies that the image should be uploaded with premultiplied alpha and does a conversion accordingly.
  • LinearFilteringBindOption Specifies that the texture filtering should be set to GL_LINEAR. Default is GL_NEAREST. If mipmap is also enabled, filtering will be set to GL_LINEAR_MIPMAP_LINEAR.
  • DefaultBindOption In Qt 4.5 and earlier, bindTexture() would mirror the image and automatically generate mipmaps. This option helps preserve this default behavior.
  • CanFlipNativePixmapBindOption Used by x11 from pixmap to choose whether or not it can bind the pixmap upside down or not.
  • MemoryManagedBindOption Used by paint engines to indicate that the pixmap should be memory managed along side with the pixmap/image that it stems from, e.g. installing destruction hooks in them.
  • InternalBindOption
Enumerator
NoBindOption 
InvertedYBindOption 
MipmapBindOption 
PremultipliedAlphaBindOption 
LinearFilteringBindOption 
MemoryManagedBindOption 
CanFlipNativePixmapBindOption 
DefaultBindOption 
InternalBindOption 

Definition at line 335 of file qgl.h.

Constructors and Destructors

◆ QGLContext() [1/2]

QGLContext::QGLContext ( const QGLFormat format,
QPaintDevice device 
)

Constructs an OpenGL context for the given paint device, which can be a widget or a pixmap.

The format specifies several display options for the context.

If the underlying OpenGL/Window system cannot satisfy all the features requested in format, the nearest subset of features will be used. After creation, the format() method will return the actual format obtained.

Note that after a QGLContext object has been constructed, create() must be called explicitly to create the actual OpenGL context. The context will be isValid(){invalid} if it was not possible to obtain a GL context at all.

Definition at line 2133 of file qgl.cpp.

Referenced by QGLWidget::event().

2134  : d_ptr(new QGLContextPrivate(this))
2135 {
2136  Q_D(QGLContext);
2137  d->init(device, format);
2138 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ QGLContext() [2/2]

QGLContext::QGLContext ( const QGLFormat format)

Constructs an OpenGL context with the given format which specifies several display options for the context.

If the underlying OpenGL/Window system cannot satisfy all the features requested in format, the nearest subset of features will be used. After creation, the format() method will return the actual format obtained.

Note that after a QGLContext object has been constructed, create() must be called explicitly to create the actual OpenGL context. The context will be isValid(){invalid} if it was not possible to obtain a GL context at all.

See also
format(), isValid()

Definition at line 2155 of file qgl.cpp.

2156  : d_ptr(new QGLContextPrivate(this))
2157 {
2158  Q_D(QGLContext);
2159  d->init(0, format);
2160 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ ~QGLContext()

QGLContext::~QGLContext ( )
virtual

Destroys the OpenGL context and frees its resources.

Definition at line 2166 of file qgl.cpp.

2167 {
2168  // remove any textures cached in this context
2170 
2171  // clean up resources specific to this context
2172  d_ptr->cleanup();
2173  // clean up resources belonging to this context's group
2174  d_ptr->group->cleanupResources(this);
2175 
2177  reset();
2178 }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
void emitAboutToDestroyContext(const QGLContext *context)
Definition: qgl_p.h:564
QGLContextGroup * group
Definition: qgl_p.h:453
static QGLTextureCache * instance()
Definition: qgl.cpp:1995
void removeContextTextures(QGLContext *ctx)
Definition: qgl.cpp:1956
static QGLSignalProxy * instance()
Definition: qgl.cpp:148
void cleanup()
Definition: qgl.cpp:2180
void reset()
Resets the context and makes it invalid.
Definition: qgl_egl.cpp:191
void cleanupResources(const QGLContext *ctx)
Definition: qgl.cpp:5961

Functions

◆ areSharing()

bool QGLContext::areSharing ( const QGLContext context1,
const QGLContext context2 
)
static

Returns true if context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.

Since
4.6

Definition at line 3319 of file qgl.cpp.

Referenced by QGLShaderProgram::addShader(), QOpenGLPaintEngine::begin(), QGLBuffer::bind(), QGLShaderProgram::bind(), QGLGlyphCache::cacheGlyphs(), QGLGradientCache::getBuffer(), QGLProgramCache::getProgram(), QGLOffscreen::initialize(), QGLPixmapData::isValidContext(), QGLShader::QGLShader(), QGLShareContextScope::QGLShareContextScope(), and QGLShaderProgram::release().

3320 {
3321  if (!context1 || !context2)
3322  return false;
3323  return context1->d_ptr->group == context2->d_ptr->group;
3324 }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
QGLContextGroup * group
Definition: qgl_p.h:453

◆ bindTexture() [1/5]

GLuint QGLContext::bindTexture ( const QImage image,
GLenum  target,
GLint  format,
BindOptions  options 
)

Generates and binds a 2D GL texture to the current context, based on image.

Since
4.6

The generated texture id is returned and can be used in later glBindTexture() calls.

The target parameter specifies the texture target. The default target is GL_TEXTURE_2D.

The format parameter sets the internal format for the texture. The default format is GL_RGBA.

The binding options are a set of options used to decide how to bind the texture to the context.

The texture that is generated is cached, so multiple calls to bindTexture() with the same QImage will return the same texture id.

Note that we assume default values for the glPixelStore() and glPixelTransfer() parameters.

See also
deleteTexture()

Definition at line 2854 of file qgl.cpp.

Referenced by QGLPixmapFilterBase::bindTexture(), QOpenGLPaintEnginePrivate::composite(), QGL2PaintEngineEx::drawImage(), QGL2PaintEngineEx::drawPixmap(), and QGL2PaintEngineExPrivate::updateBrushTexture().

2855 {
2856  if (image.isNull())
2857  return 0;
2858 
2859  Q_D(QGLContext);
2860  QGLTexture *texture = d->bindTexture(image, target, format, options);
2861  return texture->id;
2862 }
double d
Definition: qnumeric_p.h:62
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
#define Q_D(Class)
Definition: qglobal.h:2482
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ bindTexture() [2/5]

GLuint QGLContext::bindTexture ( const QPixmap pixmap,
GLenum  target,
GLint  format,
BindOptions  options 
)

Generates and binds a 2D GL texture to the current context, based on pixmap.

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

Since
4.6

Definition at line 2916 of file qgl.cpp.

2917 {
2918  if (pixmap.isNull())
2919  return 0;
2920 
2921  Q_D(QGLContext);
2922  QGLTexture *texture = d->bindTexture(pixmap, target, format, options);
2923  return texture->id;
2924 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ bindTexture() [3/5]

GLuint QGLContext::bindTexture ( const QImage image,
GLenum  target = GL_TEXTURE_2D,
GLint  format = GL_RGBA 
)

Generates and binds a 2D GL texture to the current context, based on image.

The generated texture id is returned and can be used in later glBindTexture() calls.

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

Definition at line 2816 of file qgl.cpp.

2817 {
2818  if (image.isNull())
2819  return 0;
2820 
2821  Q_D(QGLContext);
2822  QGLTexture *texture = d->bindTexture(image, target, format, DefaultBindOption);
2823  return texture->id;
2824 }
double d
Definition: qnumeric_p.h:62
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
#define Q_D(Class)
Definition: qglobal.h:2482
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ bindTexture() [4/5]

GLuint QGLContext::bindTexture ( const QPixmap pixmap,
GLenum  target = GL_TEXTURE_2D,
GLint  format = GL_RGBA 
)

Generates and binds a 2D GL texture based on pixmap.

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

Definition at line 2896 of file qgl.cpp.

2897 {
2898  if (pixmap.isNull())
2899  return 0;
2900 
2901  Q_D(QGLContext);
2902  QGLTexture *texture = d->bindTexture(pixmap, target, format, DefaultBindOption);
2903  return texture->id;
2904 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ bindTexture() [5/5]

GLuint QGLContext::bindTexture ( const QString fileName)

Reads the compressed texture file fileName and generates a 2D GL texture from it.

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

This function can load DirectDrawSurface (DDS) textures in the DXT1, DXT3 and DXT5 DDS formats if the GL_ARB_texture_compression and GL_EXT_texture_compression_s3tc extensions are supported.

Since 4.6.1, textures in the ETC1 format can be loaded if the GL_OES_compressed_ETC1_RGB8_texture extension is supported and the ETC1 texture has been encapsulated in the PVR container format. Also, textures in the PVRTC2 and PVRTC4 formats can be loaded if the GL_IMG_texture_compression_pvrtc extension is supported.

See also
deleteTexture()

Definition at line 2250 of file qgl.cpp.

2251 {
2252  QGLTexture texture(this);
2253  QSize size = texture.bindCompressedTexture(fileName);
2254  if (!size.isValid())
2255  return 0;
2256  return texture.id;
2257 }
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
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ chooseContext()

bool QGLContext::chooseContext ( const QGLContext shareContext = 0)
protectedvirtual

This semi-internal function is called by create().

It creates a system-dependent OpenGL handle that matches the format() of shareContext as closely as possible, returning true if successful or false if a suitable handle could not be found.

On Windows, it calls the virtual function choosePixelFormat(), which finds a matching pixel format identifier. On X11, it calls the virtual function chooseVisual() which finds an appropriate X visual. On other platforms it may work differently.

Definition at line 190 of file qgl_mac.mm.

Referenced by buildSpec(), qDeleteQGLContext(), qt_egl_create_surface(), and QGLContextPrivate::updateFormatVersion().

191 {
193  Q_D(QGLContext);
194  d->cx = 0;
195  d->vi = chooseMacVisual(0);
196  if (!d->vi)
197  return false;
198 
199 #ifndef QT_MAC_USE_COCOA
200  AGLPixelFormat fmt = (AGLPixelFormat)d->vi;
201  GLint res;
202  aglDescribePixelFormat(fmt, AGL_LEVEL, &res);
203  d->glFormat.setPlane(res);
204  if (deviceIsPixmap())
205  res = 0;
206  else
207  aglDescribePixelFormat(fmt, AGL_DOUBLEBUFFER, &res);
208  d->glFormat.setDoubleBuffer(res);
209  aglDescribePixelFormat(fmt, AGL_DEPTH_SIZE, &res);
210  d->glFormat.setDepth(res);
211  if (d->glFormat.depth())
212  d->glFormat.setDepthBufferSize(res);
213  aglDescribePixelFormat(fmt, AGL_RGBA, &res);
214  d->glFormat.setRgba(res);
215  aglDescribePixelFormat(fmt, AGL_RED_SIZE, &res);
216  d->glFormat.setRedBufferSize(res);
217  aglDescribePixelFormat(fmt, AGL_GREEN_SIZE, &res);
218  d->glFormat.setGreenBufferSize(res);
219  aglDescribePixelFormat(fmt, AGL_BLUE_SIZE, &res);
220  d->glFormat.setBlueBufferSize(res);
221  aglDescribePixelFormat(fmt, AGL_ALPHA_SIZE, &res);
222  d->glFormat.setAlpha(res);
223  if (d->glFormat.alpha())
224  d->glFormat.setAlphaBufferSize(res);
225  aglDescribePixelFormat(fmt, AGL_ACCUM_RED_SIZE, &res);
226  // Bug in Apple OpenGL (rdr://5015603), when we don't have an accumulation
227  // buffer, it still claims that we have a 16-bit one (which is pretty rare).
228  // So, we just assume we can never have a buffer that small.
229  d->glFormat.setAccum(res > 5);
230  if (d->glFormat.accum())
231  d->glFormat.setAccumBufferSize(res);
232  aglDescribePixelFormat(fmt, AGL_STENCIL_SIZE, &res);
233  d->glFormat.setStencil(res);
234  if (d->glFormat.stencil())
235  d->glFormat.setStencilBufferSize(res);
236  aglDescribePixelFormat(fmt, AGL_STEREO, &res);
237  d->glFormat.setStereo(res);
238  aglDescribePixelFormat(fmt, AGL_SAMPLE_BUFFERS_ARB, &res);
239  d->glFormat.setSampleBuffers(res);
240  if (d->glFormat.sampleBuffers()) {
241  aglDescribePixelFormat(fmt, AGL_SAMPLES_ARB, &res);
242  d->glFormat.setSamples(res);
243  }
244 #else
245  NSOpenGLPixelFormat *fmt = static_cast<NSOpenGLPixelFormat *>(d->vi);
246 
247  d->glFormat = QGLFormat();
248 
249  // ### make sure to reset other options
250  d->glFormat.setDoubleBuffer(attribValue(fmt, NSOpenGLPFADoubleBuffer));
251 
252  int depthSize = attribValue(fmt, NSOpenGLPFADepthSize);
253  d->glFormat.setDepth(depthSize > 0);
254  if (depthSize > 0)
255  d->glFormat.setDepthBufferSize(depthSize);
256 
257  int alphaSize = attribValue(fmt, NSOpenGLPFAAlphaSize);
258  d->glFormat.setAlpha(alphaSize > 0);
259  if (alphaSize > 0)
260  d->glFormat.setAlphaBufferSize(alphaSize);
261 
262  int accumSize = attribValue(fmt, NSOpenGLPFAAccumSize);
263  d->glFormat.setAccum(accumSize > 0);
264  if (accumSize > 0)
265  d->glFormat.setAccumBufferSize(accumSize);
266 
267  int stencilSize = attribValue(fmt, NSOpenGLPFAStencilSize);
268  d->glFormat.setStencil(stencilSize > 0);
269  if (stencilSize > 0)
270  d->glFormat.setStencilBufferSize(stencilSize);
271 
272  d->glFormat.setStereo(attribValue(fmt, NSOpenGLPFAStereo));
273 
274  int sampleBuffers = attribValue(fmt, NSOpenGLPFASampleBuffers);
275  d->glFormat.setSampleBuffers(sampleBuffers);
276  if (sampleBuffers > 0)
277  d->glFormat.setSamples(attribValue(fmt, NSOpenGLPFASamples));
278 #endif
279  if (shareContext && (!shareContext->isValid() || !shareContext->d_func()->cx)) {
280  qWarning("QGLContext::chooseContext: Cannot share with invalid context");
281  shareContext = 0;
282  }
283 
284  // sharing between rgba and color-index will give wrong colors
285  if (shareContext && (format().rgba() != shareContext->format().rgba()))
286  shareContext = 0;
287 
288 #ifndef QT_MAC_USE_COCOA
289  AGLContext ctx = aglCreateContext(fmt, (AGLContext) (shareContext ? shareContext->d_func()->cx : 0));
290 #else
291  NSOpenGLContext *ctx = [[NSOpenGLContext alloc] initWithFormat:fmt
292  shareContext:(shareContext ? static_cast<NSOpenGLContext *>(shareContext->d_func()->cx)
293  : 0)];
294 #endif
295  if (!ctx) {
296 #ifndef QT_MAC_USE_COCOA
297  GLenum err = aglGetError();
298  if (err == AGL_BAD_MATCH || err == AGL_BAD_CONTEXT) {
299  if (shareContext && shareContext->d_func()->cx) {
300  qWarning("QGLContext::chooseContext(): Context sharing mismatch!");
301  if (!(ctx = aglCreateContext(fmt, 0)))
302  return false;
303  shareContext = 0;
304  }
305  }
306 #else
307  if (shareContext) {
308  ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:0];
309  if (ctx) {
310  qWarning("QGLContext::chooseContext: Context sharing mismatch");
311  shareContext = 0;
312  }
313  }
314 #endif
315  if (!ctx) {
316  qWarning("QGLContext::chooseContext: Unable to create QGLContext");
317  return false;
318  }
319  }
320  d->cx = ctx;
321  if (shareContext && shareContext->d_func()->cx) {
322  QGLContext *share = const_cast<QGLContext *>(shareContext);
323  d->sharing = true;
324  share->d_func()->sharing = true;
325  }
326  if (deviceIsPixmap())
328 
329  // vblank syncing
330  GLint interval = d->reqFormat.swapInterval();
331  if (interval != -1) {
332 #ifndef QT_MAC_USE_COCOA
333  aglSetInteger((AGLContext)d->cx, AGL_SWAP_INTERVAL, &interval);
334  if (interval != 0)
335  aglEnable((AGLContext)d->cx, AGL_SWAP_INTERVAL);
336  else
337  aglDisable((AGLContext)d->cx, AGL_SWAP_INTERVAL);
338 #else
339  [ctx setValues:&interval forParameter:NSOpenGLCPSwapInterval];
340 #endif
341  }
342 #ifndef QT_MAC_USE_COCOA
343  aglGetInteger((AGLContext)d->cx, AGL_SWAP_INTERVAL, &interval);
344 #else
345  [ctx getValues:&interval forParameter:NSOpenGLCPSwapInterval];
346 #endif
347  d->glFormat.setSwapInterval(interval);
348  return true;
349 }
double d
Definition: qnumeric_p.h:62
bool rgba() const
Returns true if RGBA color mode is set.
Definition: qgl.h:623
void updatePaintDevice()
Definition: qgl_mac.mm:583
#define Q_D(Class)
Definition: qglobal.h:2482
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 QGLFormat class specifies the display format of an OpenGL rendering context.
Definition: qgl.h:175
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
bool deviceIsPixmap() const
Returns true if the paint device of this context is a pixmap; otherwise returns false.
Definition: qgl.cpp:3513
unsigned int GLenum
Definition: main.cpp:50
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
typedef GLint
Definition: glfunctions.h:67
static QHash< QString, QVariant > getValues(const QString &prefix)
Definition: proxyconf.cpp:200
virtual void * chooseMacVisual(GDHandle)
Mac OS X only: This virtual function tries to find a visual that matches the format, reducing the demands if the original request cannot be met.
Definition: qgl_mac.mm:492

◆ chooseMacVisual()

void * QGLContext::chooseMacVisual ( GDHandle  )
protectedvirtual

Mac OS X only: This virtual function tries to find a visual that matches the format, reducing the demands if the original request cannot be met.

The algorithm for reducing the demands of the format is quite simple-minded, so override this method in your subclass if your application has spcific requirements on visual selection.

The handle argument is always zero and is not used

See also
chooseContext()

Definition at line 492 of file qgl_mac.mm.

493 {
494  Q_D(QGLContext);
495 
496  void *fmt = d->tryFormat(d->glFormat);
497  if (!fmt && d->glFormat.stereo()) {
498  d->glFormat.setStereo(false);
499  fmt = d->tryFormat(d->glFormat);
500  }
501  if (!fmt && d->glFormat.sampleBuffers()) {
502  d->glFormat.setSampleBuffers(false);
503  fmt = d->tryFormat(d->glFormat);
504  }
505  if (!fmt)
506  qWarning("QGLContext::chooseMacVisual: Unable to choose a pixel format");
507  return fmt;
508 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)

◆ choosePixelFormat()

int QGLContext::choosePixelFormat ( void *  dummyPfd,
HDC  pdc 
)
protectedvirtual

Win32 only: This virtual function chooses a pixel format that matches the OpenGL format.

Reimplement this function in a subclass if you need a custom context.

Warning
The dummyPfd pointer and pdc are used as a PIXELFORMATDESCRIPTOR*. We use void to avoid using Windows-specific types in our header files.
See also
chooseContext()

Definition at line 1015 of file qgl_win.cpp.

Referenced by qLogEq().

1016 {
1017  Q_D(QGLContext);
1018  // workaround for matrox driver:
1019  // make a cheap call to opengl to force loading of DLL
1020  if (!opengl32dll) {
1021  GLint params;
1022  glGetIntegerv(GL_DEPTH_BITS, &params);
1023  opengl32dll = true;
1024  }
1025 
1026  PFNWGLCHOOSEPIXELFORMATARB wglChoosePixelFormatARB =
1027  (PFNWGLCHOOSEPIXELFORMATARB) wglGetProcAddress("wglChoosePixelFormatARB");
1028  int chosenPfi = 0;
1029  if (!deviceIsPixmap() && wglChoosePixelFormatARB) {
1030  bool valid;
1031  int pixelFormat = 0;
1032  uint numFormats = 0;
1033  QVarLengthArray<int> iAttributes(40);
1034  int i = 0;
1035  iAttributes[i++] = WGL_ACCELERATION_ARB;
1036  if (d->glFormat.directRendering())
1037  iAttributes[i++] = WGL_FULL_ACCELERATION_ARB;
1038  else
1039  iAttributes[i++] = WGL_NO_ACCELERATION_ARB;
1040  iAttributes[i++] = WGL_SUPPORT_OPENGL_ARB;
1041  iAttributes[i++] = TRUE;
1042  iAttributes[i++] = WGL_DRAW_TO_WINDOW_ARB;
1043  iAttributes[i++] = TRUE;
1044  iAttributes[i++] = WGL_COLOR_BITS_ARB;
1045  iAttributes[i++] = 24;
1046  iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB;
1047  iAttributes[i++] = d->glFormat.doubleBuffer();
1048  if (d->glFormat.stereo()) {
1049  iAttributes[i++] = WGL_STEREO_ARB;
1050  iAttributes[i++] = TRUE;
1051  }
1052  if (d->glFormat.depth()) {
1053  iAttributes[i++] = WGL_DEPTH_BITS_ARB;
1054  iAttributes[i++] = d->glFormat.depthBufferSize() == -1 ? 24 : d->glFormat.depthBufferSize();
1055  }
1056  iAttributes[i++] = WGL_PIXEL_TYPE_ARB;
1057  if (d->glFormat.rgba()) {
1058  iAttributes[i++] = WGL_TYPE_RGBA_ARB;
1059  if (d->glFormat.redBufferSize() != -1) {
1060  iAttributes[i++] = WGL_RED_BITS_ARB;
1061  iAttributes[i++] = d->glFormat.redBufferSize();
1062  }
1063  if (d->glFormat.greenBufferSize() != -1) {
1064  iAttributes[i++] = WGL_GREEN_BITS_ARB;
1065  iAttributes[i++] = d->glFormat.greenBufferSize();
1066  }
1067  if (d->glFormat.blueBufferSize() != -1) {
1068  iAttributes[i++] = WGL_BLUE_BITS_ARB;
1069  iAttributes[i++] = d->glFormat.blueBufferSize();
1070  }
1071  } else {
1072  iAttributes[i++] = WGL_TYPE_COLORINDEX_ARB;
1073  }
1074  if (d->glFormat.alpha()) {
1075  iAttributes[i++] = WGL_ALPHA_BITS_ARB;
1076  iAttributes[i++] = d->glFormat.alphaBufferSize() == -1 ? 8 : d->glFormat.alphaBufferSize();
1077  }
1078  if (d->glFormat.accum()) {
1079  iAttributes[i++] = WGL_ACCUM_BITS_ARB;
1080  iAttributes[i++] = d->glFormat.accumBufferSize() == -1 ? 16 : d->glFormat.accumBufferSize();
1081  }
1082  if (d->glFormat.stencil()) {
1083  iAttributes[i++] = WGL_STENCIL_BITS_ARB;
1084  iAttributes[i++] = d->glFormat.stencilBufferSize() == -1 ? 8 : d->glFormat.stencilBufferSize();
1085  }
1086  if (d->glFormat.hasOverlay()) {
1087  iAttributes[i++] = WGL_NUMBER_OVERLAYS_ARB;
1088  iAttributes[i++] = 1;
1089  }
1090  int si = 0;
1091  bool trySampleBuffers = QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers;
1092  if (trySampleBuffers && d->glFormat.sampleBuffers()) {
1093  iAttributes[i++] = WGL_SAMPLE_BUFFERS_ARB;
1094  iAttributes[i++] = TRUE;
1095  iAttributes[i++] = WGL_SAMPLES_ARB;
1096  si = i;
1097  iAttributes[i++] = d->glFormat.samples() == -1 ? 4 : d->glFormat.samples();
1098  }
1099  iAttributes[i] = 0;
1100 
1101  do {
1102  valid = wglChoosePixelFormatARB(pdc, iAttributes.constData(), 0, 1,
1103  &pixelFormat, &numFormats);
1104  if (trySampleBuffers && (!valid || numFormats < 1) && d->glFormat.sampleBuffers())
1105  iAttributes[si] /= 2; // try different no. samples - we aim for the best one
1106  else
1107  break;
1108  } while ((!valid || numFormats < 1) && iAttributes[si] > 1);
1109  chosenPfi = pixelFormat;
1110  }
1111 
1112  if (!chosenPfi) { // fallback if wglChoosePixelFormatARB() failed
1113  int pmDepth = deviceIsPixmap() ? ((QPixmap*)d->paintDevice)->depth() : 0;
1114  PIXELFORMATDESCRIPTOR* p = (PIXELFORMATDESCRIPTOR*)dummyPfd;
1115  memset(p, 0, sizeof(PIXELFORMATDESCRIPTOR));
1116  p->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1117  p->nVersion = 1;
1118  p->dwFlags = PFD_SUPPORT_OPENGL;
1119  if (deviceIsPixmap())
1120  p->dwFlags |= PFD_DRAW_TO_BITMAP;
1121  else
1122  p->dwFlags |= PFD_DRAW_TO_WINDOW;
1123  if (!d->glFormat.directRendering())
1124  p->dwFlags |= PFD_GENERIC_FORMAT;
1125  if (d->glFormat.doubleBuffer() && !deviceIsPixmap())
1126  p->dwFlags |= PFD_DOUBLEBUFFER;
1127  if (d->glFormat.stereo())
1128  p->dwFlags |= PFD_STEREO;
1129  if (d->glFormat.depth())
1130  p->cDepthBits = d->glFormat.depthBufferSize() == -1 ? 32 : d->glFormat.depthBufferSize();
1131  else
1132  p->dwFlags |= PFD_DEPTH_DONTCARE;
1133  if (d->glFormat.rgba()) {
1134  p->iPixelType = PFD_TYPE_RGBA;
1135  if (d->glFormat.redBufferSize() != -1)
1136  p->cRedBits = d->glFormat.redBufferSize();
1137  if (d->glFormat.greenBufferSize() != -1)
1138  p->cGreenBits = d->glFormat.greenBufferSize();
1139  if (d->glFormat.blueBufferSize() != -1)
1140  p->cBlueBits = d->glFormat.blueBufferSize();
1141  if (deviceIsPixmap())
1142  p->cColorBits = pmDepth;
1143  else
1144  p->cColorBits = 32;
1145  } else {
1146  p->iPixelType = PFD_TYPE_COLORINDEX;
1147  p->cColorBits = 8;
1148  }
1149  if (d->glFormat.alpha())
1150  p->cAlphaBits = d->glFormat.alphaBufferSize() == -1 ? 8 : d->glFormat.alphaBufferSize();
1151  if (d->glFormat.accum()) {
1152  p->cAccumRedBits = p->cAccumGreenBits = p->cAccumBlueBits = p->cAccumAlphaBits =
1153  d->glFormat.accumBufferSize() == -1 ? 16 : d->glFormat.accumBufferSize();
1154  }
1155  if (d->glFormat.stencil())
1156  p->cStencilBits = d->glFormat.stencilBufferSize() == -1 ? 8 : d->glFormat.stencilBufferSize();
1157  p->iLayerType = PFD_MAIN_PLANE;
1158  chosenPfi = ChoosePixelFormat(pdc, p);
1159 
1160  if (!chosenPfi)
1161  qErrnoWarning("QGLContext: ChoosePixelFormat failed");
1162 
1163  // Since the GDI function ChoosePixelFormat() does not handle
1164  // overlay and direct-rendering requests, we must roll our own here
1165 
1166  bool doSearch = chosenPfi <= 0;
1167  PIXELFORMATDESCRIPTOR pfd;
1168  QGLFormat fmt;
1169  if (!doSearch) {
1170  DescribePixelFormat(pdc, chosenPfi, sizeof(PIXELFORMATDESCRIPTOR),
1171  &pfd);
1172  fmt = pfdToQGLFormat(&pfd);
1173  if (d->glFormat.hasOverlay() && !fmt.hasOverlay())
1174  doSearch = true;
1175  else if (!qLogEq(d->glFormat.directRendering(), fmt.directRendering()))
1176  doSearch = true;
1177  else if (deviceIsPixmap() && (!(pfd.dwFlags & PFD_DRAW_TO_BITMAP) ||
1178  pfd.cColorBits != pmDepth))
1179  doSearch = true;
1180  else if (!deviceIsPixmap() && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))
1181  doSearch = true;
1182  else if (!qLogEq(d->glFormat.rgba(), fmt.rgba()))
1183  doSearch = true;
1184  }
1185 
1186  if (doSearch) {
1187  int pfiMax = DescribePixelFormat(pdc, 0, 0, NULL);
1188  int bestScore = -1;
1189  int bestPfi = -1;
1190  for (int pfi = 1; pfi <= pfiMax; pfi++) {
1191  DescribePixelFormat(pdc, pfi, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
1192  if (!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
1193  continue;
1194  if (deviceIsPixmap() && (!(pfd.dwFlags & PFD_DRAW_TO_BITMAP) ||
1195  pfd.cColorBits != pmDepth))
1196  continue;
1197  if (!deviceIsPixmap() && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))
1198  continue;
1199 
1200  fmt = pfdToQGLFormat(&pfd);
1201  if (d->glFormat.hasOverlay() && !fmt.hasOverlay())
1202  continue;
1203 
1204  int score = pfd.cColorBits;
1205  if (qLogEq(d->glFormat.depth(), fmt.depth()))
1206  score += pfd.cDepthBits;
1207  if (qLogEq(d->glFormat.alpha(), fmt.alpha()))
1208  score += pfd.cAlphaBits;
1209  if (qLogEq(d->glFormat.accum(), fmt.accum()))
1210  score += pfd.cAccumBits;
1211  if (qLogEq(d->glFormat.stencil(), fmt.stencil()))
1212  score += pfd.cStencilBits;
1213  if (qLogEq(d->glFormat.doubleBuffer(), fmt.doubleBuffer()))
1214  score += 1000;
1215  if (qLogEq(d->glFormat.stereo(), fmt.stereo()))
1216  score += 2000;
1217  if (qLogEq(d->glFormat.directRendering(), fmt.directRendering()))
1218  score += 4000;
1219  if (qLogEq(d->glFormat.rgba(), fmt.rgba()))
1220  score += 8000;
1221  if (score > bestScore) {
1222  bestScore = score;
1223  bestPfi = pfi;
1224  }
1225  }
1226 
1227  if (bestPfi > 0)
1228  chosenPfi = bestPfi;
1229  }
1230  }
1231  return chosenPfi;
1232 }
double d
Definition: qnumeric_p.h:62
bool rgba() const
Returns true if RGBA color mode is set.
Definition: qgl.h:623
#define WGL_RED_BITS_ARB
Definition: qgl_win.cpp:99
#define WGL_TYPE_RGBA_ARB
Definition: qgl_win.cpp:121
#define WGL_DRAW_TO_WINDOW_ARB
Definition: qgl_win.cpp:75
#define Q_D(Class)
Definition: qglobal.h:2482
bool directRendering() const
Returns true if direct rendering is enabled; otherwise returns false.
Definition: qgl.h:648
#define GL_DEPTH_BITS
#define WGL_GREEN_BITS_ARB
Definition: qgl_win.cpp:101
bool depth() const
Returns true if the depth buffer is enabled; otherwise returns false.
Definition: qgl.h:618
The QGLFormat class specifies the display format of an OpenGL rendering context.
Definition: qgl.h:175
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define WGL_TYPE_COLORINDEX_ARB
Definition: qgl_win.cpp:122
#define WGL_SAMPLE_BUFFERS_ARB
Definition: qgl_win.cpp:69
bool stencil() const
Returns true if the stencil buffer is enabled; otherwise returns false.
Definition: qgl.h:638
unsigned int uint
Definition: qglobal.h:996
static bool opengl32dll
Definition: qgl_win.cpp:428
static QGLFormat pfdToQGLFormat(const PIXELFORMATDESCRIPTOR *pfd)
Definition: qgl_win.cpp:542
#define WGL_NO_ACCELERATION_ARB
Definition: qgl_win.cpp:115
bool(APIENTRY * PFNWGLCHOOSEPIXELFORMATARB)(HDC hdc, const int *piAttribList, const float *pfAttribFList, uint nMaxFormats, int *piFormats, UINT *nNumFormats)
Definition: qgl_win.cpp:62
bool accum() const
Returns true if the accumulation buffer is enabled; otherwise returns false.
Definition: qgl.h:633
bool deviceIsPixmap() const
Returns true if the paint device of this context is a pixmap; otherwise returns false.
Definition: qgl.cpp:3513
#define WGL_BLUE_BITS_ARB
Definition: qgl_win.cpp:103
static bool qLogEq(bool a, bool b)
Definition: qgl_win.cpp:1007
#define TRUE
Synonym for true.
Definition: qglobal.h:1018
bool hasOverlay() const
Returns true if overlay plane is enabled; otherwise returns false.
Definition: qgl.h:653
#define WGL_DEPTH_BITS_ARB
Definition: qgl_win.cpp:112
#define WGL_STEREO_ARB
Definition: qgl_win.cpp:96
#define WGL_SAMPLES_ARB
Definition: qgl_win.cpp:70
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
Definition: qgl.h:628
if(void) toggleToolbarShown
#define WGL_ACCUM_BITS_ARB
Definition: qgl_win.cpp:107
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 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
#define WGL_DOUBLE_BUFFER_ARB
Definition: qgl_win.cpp:95
#define WGL_ACCELERATION_ARB
Definition: qgl_win.cpp:77
#define WGL_COLOR_BITS_ARB
Definition: qgl_win.cpp:98
#define WGL_STENCIL_BITS_ARB
Definition: qgl_win.cpp:113
bool stereo() const
Returns true if stereo buffering is enabled; otherwise returns false.
Definition: qgl.h:643
#define WGL_SUPPORT_OPENGL_ARB
Definition: qgl_win.cpp:94
#define WGL_PIXEL_TYPE_ARB
Definition: qgl_win.cpp:97
#define WGL_ALPHA_BITS_ARB
Definition: qgl_win.cpp:105
#define WGL_FULL_ACCELERATION_ARB
Definition: qgl_win.cpp:117
#define WGL_NUMBER_OVERLAYS_ARB
Definition: qgl_win.cpp:82
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ chooseVisual()

void * QGLContext::chooseVisual ( )
protectedvirtual

X11 only: This virtual function tries to find a visual that matches the format, reducing the demands if the original request cannot be met.

The algorithm for reducing the demands of the format is quite simple-minded, so override this method in your subclass if your application has spcific requirements on visual selection.

See also
chooseContext()

Definition at line 762 of file qgl_x11.cpp.

763 {
764  Q_D(QGLContext);
765  static const int bufDepths[] = { 8, 4, 2, 1 }; // Try 16, 12 also?
766  //todo: if pixmap, also make sure that vi->depth == pixmap->depth
767  void* vis = 0;
768  int i = 0;
769  bool fail = false;
770  QGLFormat fmt = format();
771  bool tryDouble = !fmt.doubleBuffer(); // Some GL impl's only have double
772  bool triedDouble = false;
773  bool triedSample = false;
774  if (fmt.sampleBuffers())
776  while(!fail && !(vis = tryVisual(fmt, bufDepths[i]))) {
777  if (!fmt.rgba() && bufDepths[i] > 1) {
778  i++;
779  continue;
780  }
781  if (tryDouble) {
782  fmt.setDoubleBuffer(true);
783  tryDouble = false;
784  triedDouble = true;
785  continue;
786  } else if (triedDouble) {
787  fmt.setDoubleBuffer(false);
788  triedDouble = false;
789  }
790  if (!triedSample && fmt.sampleBuffers()) {
791  fmt.setSampleBuffers(false);
792  triedSample = true;
793  continue;
794  }
795  if (fmt.stereo()) {
796  fmt.setStereo(false);
797  continue;
798  }
799  if (fmt.accum()) {
800  fmt.setAccum(false);
801  continue;
802  }
803  if (fmt.stencil()) {
804  fmt.setStencil(false);
805  continue;
806  }
807  if (fmt.alpha()) {
808  fmt.setAlpha(false);
809  continue;
810  }
811  if (fmt.depth()) {
812  fmt.setDepth(false);
813  continue;
814  }
815  if (fmt.doubleBuffer()) {
816  fmt.setDoubleBuffer(false);
817  continue;
818  }
819  fail = true;
820  }
821  d->glFormat = fmt;
822  return vis;
823 }
double d
Definition: qnumeric_p.h:62
void setStencil(bool enable)
If enable is true enables the stencil buffer; otherwise disables the stencil buffer.
Definition: qgl.cpp:724
bool rgba() const
Returns true if RGBA color mode is set.
Definition: qgl.h:623
virtual void * tryVisual(const QGLFormat &f, int bufDepth=1)
Definition: qgl_x11.cpp:828
void setAlpha(bool enable)
If enable is true enables the alpha buffer; otherwise disables the alpha buffer.
Definition: qgl.cpp:664
void setSampleBuffers(bool enable)
If enable is true, a GL context with multisample buffer support is picked; otherwise ignored...
Definition: qgl.cpp:812
#define Q_D(Class)
Definition: qglobal.h:2482
bool sampleBuffers() const
Returns true if multisample buffer support is enabled; otherwise returns false.
Definition: qgl.h:658
bool depth() const
Returns true if the depth buffer is enabled; otherwise returns false.
Definition: qgl.h:618
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 QGLFormat class specifies the display format of an OpenGL rendering context.
Definition: qgl.h:175
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool stencil() const
Returns true if the stencil buffer is enabled; otherwise returns false.
Definition: qgl.h:638
void setDoubleBuffer(bool enable)
If enable is true sets double buffering; otherwise sets single buffering.
Definition: qgl.cpp:566
void setDepth(bool enable)
If enable is true enables the depth buffer; otherwise disables the depth buffer.
Definition: qgl.cpp:599
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
bool doubleBuffer() const
Returns true if double buffering is enabled; otherwise returns false.
Definition: qgl.h:613
static Extensions glExtensions()
Definition: qgl.cpp:5781
void setStereo(bool enable)
If enable is true enables stereo buffering; otherwise disables stereo buffering.
Definition: qgl.cpp:754
bool stereo() const
Returns true if stereo buffering is enabled; otherwise returns false.
Definition: qgl.h:643
void setAccum(bool enable)
If enable is true enables the accumulation buffer; otherwise disables the accumulation buffer...
Definition: qgl.cpp:694

◆ colorIndex()

uint QGLContext::colorIndex ( const QColor c) const
protected

Returns a colormap index for the color c, in ColorIndex mode.

Warning
This function is not part of the public interface.

Used by qglColor() and qglClearColor().

Definition at line 367 of file qgl_egl.cpp.

Referenced by choosePixelFormat(), qDeleteQGLContext(), and qt_transparent_pixel().

368 {
369  Q_UNUSED(c);
370  return 0;
371 }
#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

◆ create()

bool QGLContext::create ( const QGLContext shareContext = 0)
virtual

Creates the GL context.

Returns true if it was successful in creating a valid GL rendering context on the paint device specified in the constructor; otherwise returns false (i.e. the context is invalid).

After successful creation, format() returns the set of features of the created GL rendering context.

If shareContext points to a valid QGLContext, this method will try to establish OpenGL display list and texture object sharing between this context and the shareContext. Note that this may fail if the two contexts have different format() {formats}. Use isSharing() to see if sharing is in effect.

Warning
Implementation note: initialization of C++ class members usually takes place in the class constructor. QGLContext is an exception because it must be simple to customize. The virtual functions chooseContext() (and chooseVisual() for X11) can be reimplemented in a subclass to select a particular context. The problem is that virtual functions are not properly called during construction (even though this is correct C++) because C++ constructs class hierarchies from the bottom up. For this reason we need a create() function.
See also
chooseContext(), format(), isValid()

Definition at line 3454 of file qgl.cpp.

Referenced by QGLWindowSurface::hijackWindow(), and nearest_gl_texture_size().

3455 {
3456  Q_D(QGLContext);
3457 #ifdef Q_WS_QPA
3458  if (!d->paintDevice && !d->platformContext)
3459 #else
3460  if (!d->paintDevice)
3461 #endif
3462  return false;
3463 
3464  reset();
3465  d->valid = chooseContext(shareContext);
3466  if (d->valid && d->paintDevice && d->paintDevice->devType() == QInternal::Widget) {
3467  QWidgetPrivate *wd = qt_widget_private(static_cast<QWidget *>(d->paintDevice));
3468  wd->usesDoubleBufferedGLContext = d->glFormat.doubleBuffer();
3469  }
3470 #ifndef Q_WS_QPA //We do this in choose context->setupSharing()
3471  if (d->sharing) // ok, we managed to share
3472  QGLContextGroup::addShare(this, shareContext);
3473 #endif
3474  return d->valid;
3475 }
double d
Definition: qnumeric_p.h:62
static void addShare(const QGLContext *context, const QGLContext *share)
Definition: qgl.cpp:5846
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
void reset()
Resets the context and makes it invalid.
Definition: qgl_egl.cpp:191
virtual bool chooseContext(const QGLContext *shareContext=0)
This semi-internal function is called by create().
Definition: qgl_mac.mm:190
uint usesDoubleBufferedGLContext
Definition: qwidget_p.h:776
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920

◆ currentContext()

const QGLContext * QGLContext::currentContext ( )
static

Returns the current context, i.e.

the context to which any OpenGL commands will currently be directed. Returns 0 if no context is current.

See also
makeCurrent()

Definition at line 3545 of file qgl.cpp.

Referenced by QGLPaintDevice::beginPaint(), QGLFramebufferObject::bind(), QGLBuffer::bind(), QGLShaderProgram::bind(), QGLFramebufferObject::bindDefault(), QGLPixmapFilterBase::bindTexture(), QGLFramebufferObject::blitFramebuffer(), buildSpec(), QGLGlyphCache::cleanCache(), QGLFBOGLPaintDevice::context(), QGLBuffer::create(), ShaderEffect::draw(), QGL2PaintEngineExPrivate::drawCachedGlyphs(), drawTexture(), QGLFramebufferObject::drawTexture(), QGLPaintDevice::ensureActiveTarget(), QX11GLWindowSurface::flush(), QGLWindowSurface::flush(), QGLTextureDestroyer::freeTexture_slot(), QX11GLWindowSurface::grabWidget(), QGLShaderProgram::hasOpenGLShaderPrograms(), QGLShader::hasOpenGLShaders(), QGLFramebufferObjectPrivate::init(), QGLShaderProgram::init(), QMeeGoExtensions::initialize(), QGLFramebufferObject::isBound(), ShaderEffectItem::paint(), QGLPixmapData::paintEngine(), QGLEngineSelector::preferredPaintEngine(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), qglfResolveCheckFramebufferStatus(), qglfResolveCreateProgram(), qglfResolveCreateShader(), qglfResolveGetAttribLocation(), qglfResolveGetUniformLocation(), qglfResolveIsBuffer(), qglfResolveIsFramebuffer(), qglfResolveIsProgram(), qglfResolveIsRenderbuffer(), qglfResolveIsShader(), QGLShader::QGLShader(), QGLShareContextScope::QGLShareContextScope(), qt_format_to_attrib_list(), qt_gl_functions(), QGLFramebufferObject::release(), QGLBuffer::release(), QGLShaderProgram::release(), ShaderEffectItem::renderEffect(), QX11GLWindowSurface::scroll(), QGLFBOGLPaintDevice::setFBO(), QGLContextPrivate::unbindPixmapFromTexture(), ShaderEffectSource::updateBackbuffer(), QGL2PaintEngineExPrivate::updateBrushTexture(), QGLWindowSurface::updateGeometry(), QGLGlyphTexture::~QGLGlyphTexture(), and QGLPixelBuffer::~QGLPixelBuffer().

3546 {
3547 #ifdef Q_WS_QPA
3548  if (const QPlatformGLContext *threadContext = QPlatformGLContext::currentContext()) {
3549  return QGLContext::fromPlatformGLContext(const_cast<QPlatformGLContext *>(threadContext));
3550  }
3551  return 0;
3552 #else
3553  QGLThreadContext *threadContext = qgl_context_storage.localData();
3554  if (threadContext) {
3555 #ifdef Q_OS_SYMBIAN
3556  // Query the current context and return null if it is different.
3557  // This is needed to support mixed VG-GL rendering.
3558  // QtOpenVG is free to make a QEglContext current at any time and
3559  // QGLContext gets no notification that its underlying QEglContext is
3560  // not current anymore. We query directly from EGL to be thread-safe.
3561  // QEglContext does not store all the contexts per-thread.
3562  if (threadContext->context) {
3563  QEglContext *eglcontext = threadContext->context->d_func()->eglContext;
3564  if (eglcontext) {
3565  EGLContext ctx = eglcontext->context();
3566  if (ctx != eglGetCurrentContext())
3567  return 0;
3568  }
3569  }
3570 #endif
3571  return threadContext->context;
3572  }
3573  return 0;
3574 #endif //Q_WS_QPA
3575 }
static const QPlatformGLContext * currentContext()
Returns the last context which called makeCurrent.
EGLContext context() const
Definition: qeglcontext_p.h:91
QGLContext * context
Definition: qgl.cpp:126
The QPlatformGLContext class provides an abstraction for native GL contexts.
static QThreadStorage< QGLThreadContext * > qgl_context_storage
Definition: qgl.cpp:130
#define ctx
Definition: qgl.cpp:6094

◆ deleteTexture()

void QGLContext::deleteTexture ( GLuint  id)

Removes the texture identified by id from the texture cache, and calls glDeleteTextures() to delete the texture from the context.

See also
bindTexture()

Definition at line 2957 of file qgl.cpp.

2958 {
2959  if (QGLTextureCache::instance()->remove(this, id))
2960  return;
2961  glDeleteTextures(1, &id);
2962 }
static QGLTextureCache * instance()
Definition: qgl.cpp:1995

◆ device()

QPaintDevice * QGLContext::device ( ) const

Returns the paint device set for this context.

See also
QGLContext::QGLContext()

Definition at line 3507 of file qgl.cpp.

Referenced by QGLFramebufferObject::blitFramebuffer(), QGLGlyphCache::cacheGlyphs(), QGLOverlayWidget::paintGL(), qDeleteQGLContext(), qStoreColors(), and QGLWidgetPrivate::updateColormap().

3508 {
3509  Q_D(const QGLContext);
3510  return d->paintDevice;
3511 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ deviceIsPixmap()

bool QGLContext::deviceIsPixmap ( ) const
protected

Returns true if the paint device of this context is a pixmap; otherwise returns false.

Definition at line 3513 of file qgl.cpp.

Referenced by QGLOverlayWidget::paintGL(), qStoreColors(), and QGLWidgetPrivate::updateColormap().

3514 {
3515  Q_D(const QGLContext);
3516  return d->paintDevice->devType() == QInternal::Pixmap;
3517 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ doneCurrent()

void QGLContext::doneCurrent ( )
virtual

Makes no GL context the current context.

Normally, you do not need to call this function; QGLContext calls it as necessary.

Definition at line 277 of file qgl_egl.cpp.

Referenced by choosePixelFormat(), qDeleteQGLContext(), tryVisual(), QGLWindowSurface::updateGeometry(), updatePaintDevice(), and QGLThreadContext::~QGLThreadContext().

278 {
279  Q_D(QGLContext);
280  if (d->eglContext)
281  d->eglContext->doneCurrent();
282 
284 }
double d
Definition: qnumeric_p.h:62
static void setCurrentContext(QGLContext *context)
Definition: qgl.cpp:3577
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ drawTexture() [1/2]

void QGLContext::drawTexture ( const QRectF target,
GLuint  textureId,
GLenum  textureTarget = GL_TEXTURE_2D 
)

This function supports the following use cases:

  • On OpenGL and OpenGL ES 1.

    Since
    4.4

    x it draws the given texture, textureId, to the given target rectangle, target, in OpenGL model space. The textureTarget should be a 2D texture target.

  • On OpenGL and OpenGL ES 2.x, if a painter is active, not inside a beginNativePainting / endNativePainting block, and uses the engine with type QPaintEngine::OpenGL2, the function will draw the given texture, textureId, to the given target rectangle, target, respecting the current painter state. This will let you draw a texture with the clip, transform, render hints, and composition mode set by the painter. Note that the texture target needs to be GL_TEXTURE_2D for this use case, and that this is the only supported use case under OpenGL ES 2.x.

Definition at line 3067 of file qgl.cpp.

3068 {
3069 #if !defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2)
3070  if (d_ptr->active_engine &&
3072  QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine);
3073  if (!eng->isNativePaintingActive()) {
3074  QRectF src(0, 0, target.width(), target.height());
3075  QSize size(target.width(), target.height());
3076  if (eng->drawTexture(target, textureId, size, src))
3077  return;
3078  }
3079  }
3080 #endif
3081 
3082 #ifndef QT_OPENGL_ES_2
3083 #ifdef QT_OPENGL_ES
3084  if (textureTarget != GL_TEXTURE_2D) {
3085  qWarning("QGLContext::drawTexture(): texture target must be GL_TEXTURE_2D on OpenGL ES");
3086  return;
3087  }
3088 #else
3089  const bool wasEnabled = glIsEnabled(GL_TEXTURE_2D);
3090  GLint oldTexture;
3091  glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture);
3092 #endif
3093 
3094  glEnable(textureTarget);
3095  glBindTexture(textureTarget, textureId);
3096 
3097  qDrawTextureRect(target, -1, -1, textureTarget);
3098 
3099 #ifdef QT_OPENGL_ES
3100  glDisable(textureTarget);
3101 #else
3102  if (!wasEnabled)
3103  glDisable(textureTarget);
3104  glBindTexture(textureTarget, oldTexture);
3105 #endif
3106 #else
3107  Q_UNUSED(target);
3108  Q_UNUSED(textureId);
3109  Q_UNUSED(textureTarget);
3110  qWarning("drawTexture() with OpenGL ES 2.0 requires an active OpenGL2 paint engine");
3111 #endif
3112 }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
#define GL_TEXTURE_BINDING_2D
#define GL_TEXTURE_2D
static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint textureHeight, GLenum textureTarget)
Definition: qgl.cpp:3003
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
Q_CORE_EXPORT void qWarning(const char *,...)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
bool drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr)
typedef GLint
Definition: glfunctions.h:67
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QPaintEngine * active_engine
Definition: qgl_p.h:458
#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

◆ drawTexture() [2/2]

void QGLContext::drawTexture ( const QPointF point,
GLuint  textureId,
GLenum  textureTarget = GL_TEXTURE_2D 
)

This function supports the following use cases:

  • By default it draws the given texture, textureId, at the given point in OpenGL model space.

    Since
    4.4

    The textureTarget should be a 2D texture target.

  • If a painter is active, not inside a beginNativePainting / endNativePainting block, and uses the engine with type QPaintEngine::OpenGL2, the function will draw the given texture, textureId, at the given point, respecting the current painter state. This will let you draw a texture with the clip, transform, render hints, and composition mode set by the painter. Note that the texture target needs to be GL_TEXTURE_2D for this use case.
Note
This function is not supported under any version of OpenGL ES.

Definition at line 3146 of file qgl.cpp.

3147 {
3148 #ifdef QT_OPENGL_ES
3149  Q_UNUSED(point);
3150  Q_UNUSED(textureId);
3151  Q_UNUSED(textureTarget);
3152  qWarning("drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) not supported with OpenGL ES, use rect version instead");
3153 #else
3154 
3155  const bool wasEnabled = glIsEnabled(GL_TEXTURE_2D);
3156  GLint oldTexture;
3157  glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture);
3158 
3159  glEnable(textureTarget);
3160  glBindTexture(textureTarget, textureId);
3161 
3162  GLint textureWidth;
3163  GLint textureHeight;
3164 
3165  glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth);
3166  glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight);
3167 
3168  if (d_ptr->active_engine &&
3170  QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine);
3171  if (!eng->isNativePaintingActive()) {
3172  QRectF dest(point, QSizeF(textureWidth, textureHeight));
3173  QRectF src(0, 0, textureWidth, textureHeight);
3174  QSize size(textureWidth, textureHeight);
3175  if (eng->drawTexture(dest, textureId, size, src))
3176  return;
3177  }
3178  }
3179 
3180  qDrawTextureRect(QRectF(point, QSizeF(textureWidth, textureHeight)), textureWidth, textureHeight, textureTarget);
3181 
3182  if (!wasEnabled)
3183  glDisable(textureTarget);
3184  glBindTexture(textureTarget, oldTexture);
3185 #endif
3186 }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
#define GL_TEXTURE_BINDING_2D
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
#define GL_TEXTURE_2D
static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint textureHeight, GLenum textureTarget)
Definition: qgl.cpp:3003
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
Q_CORE_EXPORT void qWarning(const char *,...)
bool drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr)
typedef GLint
Definition: glfunctions.h:67
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QPaintEngine * active_engine
Definition: qgl_p.h:458
#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

◆ format()

QGLFormat QGLContext::format ( ) const

Returns the frame buffer format that was obtained (this may be a subset of what was requested).

See also
requestedFormat()

Definition at line 3495 of file qgl.cpp.

Referenced by QGLWindowSurface::beginPaint(), buildSpec(), chooseContext(), QGLWindowSurface::flush(), QGLPaintDevice::format(), nearest_gl_texture_size(), QGLOverlayWidget::paintGL(), and QGLFBOGLPaintDevice::setFBO().

3496 {
3497  Q_D(const QGLContext);
3498  return d->glFormat;
3499 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ generateFontDisplayLists()

void QGLContext::generateFontDisplayLists ( const QFont font,
int  listBase 
)
protected

Generates a set of 256 display lists for the 256 first characters in the font font.

See also
QGLWidget::renderText()

Definition at line 373 of file qgl_egl.cpp.

Referenced by choosePixelFormat(), qDeleteQGLContext(), and qgl_use_font().

374 {
375  Q_UNUSED(fnt);
376  Q_UNUSED(listBase);
377 }
#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

◆ getProcAddress()

void * QGLContext::getProcAddress ( const QString proc) const

Returns a function pointer to the GL extension function passed in proc.

0 is returned if a pointer to the function could not be obtained.

Definition at line 379 of file qgl_egl.cpp.

Referenced by choosePixelFormat(), qDeleteQGLContext(), qgl_use_font(), qt_getOpenGLBundle(), qt_gl_getProcAddress_search(), qt_resolve_eglimage_gl_extensions(), qt_resolve_frag_program_extensions(), qt_resolve_glsl_extensions(), qt_resolve_stencil_face_extension(), qt_resolve_version_1_3_functions(), and qt_resolve_version_2_0_functions().

380 {
381  return (void*)eglGetProcAddress(reinterpret_cast<const char *>(proc.toLatin1().data()));
382 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993

◆ initialized()

bool QGLContext::initialized ( ) const
protected

Returns true if this context has been initialized, i.

e. if QGLWidget::initializeGL() has been performed on it; otherwise returns false.

See also
setInitialized()

Definition at line 3533 of file qgl.cpp.

3534 {
3535  Q_D(const QGLContext);
3536  return d->initDone;
3537 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ isSharing()

bool QGLContext::isSharing ( ) const

Returns true if this context is sharing its GL context with another QGLContext, otherwise false is returned.

Note that context sharing might not be supported between contexts with different formats.

Definition at line 3489 of file qgl.cpp.

Referenced by QGLProgramCache::cleanupPrograms(), nearest_gl_texture_size(), and QGLWidgetPrivate::updateColormap().

3490 {
3491  Q_D(const QGLContext);
3492  return d->group->isSharing();
3493 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ isValid()

bool QGLContext::isValid ( ) const

Returns true if a GL rendering context has been successfully created; otherwise returns false.

Definition at line 3477 of file qgl.cpp.

Referenced by buildSpec(), QGLGlyphCache::cacheGlyphs(), chooseContext(), QX11GLWindowSurface::flush(), QX11GLWindowSurface::grabWidget(), QGLWindowSurface::hijackWindow(), and QX11GLWindowSurface::scroll().

3478 {
3479  Q_D(const QGLContext);
3480  return d->valid;
3481 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ makeCurrent()

void QGLContext::makeCurrent ( )
virtual

Makes this context the current OpenGL rendering context.

All GL functions you call operate on this context until another context is made current.

In some very rare cases the underlying call may fail. If this occurs an error message is output to stderr.

Definition at line 213 of file qgl_egl.cpp.

Referenced by QOpenGLPaintEngine::begin(), QGLPaintDevice::beginPaint(), chooseMacVisual(), choosePixelFormat(), QX11GLPixmapData::copy(), QGLPaintDevice::ensureActiveTarget(), QX11GLPixmapData::fill(), QGLWindowSurface::flush(), QGLTextureDestroyer::freeTexture_slot(), QGLWindowSurface::paintDevice(), qDeleteQGLContext(), QGLShareContextScope::QGLShareContextScope(), QX11GLPixmapData::scroll(), tryVisual(), QGLWindowSurface::updateGeometry(), and QGLPixelBuffer::~QGLPixelBuffer().

214 {
215  Q_D(QGLContext);
216  if (!d->valid || !d->eglContext || d->eglSurfaceForDevice() == EGL_NO_SURFACE) {
217  qWarning("QGLContext::makeCurrent(): Cannot make invalid context current");
218  return;
219  }
220 
221  if (d->eglContext->makeCurrent(d->eglSurfaceForDevice())) {
223  if (!d->workaroundsCached) {
224  d->workaroundsCached = true;
225  const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
226  if (!renderer)
227  return;
228  if ((strstr(renderer, "SGX") || strstr(renderer, "MBX"))) {
229  // PowerVR MBX/SGX chips needs to clear all buffers when starting to render
230  // a new frame, otherwise there will be a performance penalty to pay for
231  // each frame.
232  qDebug() << "Found SGX/MBX driver, enabling FullClearOnEveryFrame";
233  d->workaround_needsFullClearOnEveryFrame = true;
234 
235  // Older PowerVR SGX drivers (like the one in the N900) have a
236  // bug which prevents glCopyTexSubImage2D() to work with a POT
237  // or GL_ALPHA texture bound to an FBO. The only way to
238  // identify that driver is to check the EGL version number for it.
239  const char *egl_version = eglQueryString(d->eglContext->display(), EGL_VERSION);
240 
241  if (egl_version && strstr(egl_version, "1.3")) {
242  qDebug() << "Found v1.3 driver, enabling brokenFBOReadBack";
243  d->workaround_brokenFBOReadBack = true;
244  } else if (egl_version && strstr(egl_version, "1.4")) {
245  qDebug() << "Found v1.4 driver, enabling brokenTexSubImage";
246  d->workaround_brokenTexSubImage = true;
247 
248  // this is a bit complicated; 1.4 version SGX drivers from
249  // Nokia have fixed the brokenFBOReadBack problem, but
250  // official drivers from TI haven't, meaning that things
251  // like the beagleboard are broken unless we hack around it
252  // - but at the same time, we want to not reduce performance
253  // by not enabling this elsewhere.
254  //
255  // so, let's check for a Nokia-specific addon, and only
256  // enable if it isn't present.
257  // (see MeeGo bug #5616)
258  if (!QEgl::hasExtension("EGL_NOK_image_shared")) {
259  // no Nokia extension, this is probably a standard SGX
260  // driver, so enable the workaround
261  qDebug() << "Found non-Nokia v1.4 driver, enabling brokenFBOReadBack";
262  d->workaround_brokenFBOReadBack = true;
263  }
264  }
265  } else if (strstr(renderer, "VideoCore III")) {
266  // Some versions of VideoCore III drivers seem to pollute and use
267  // stencil buffer when using glScissors even if stencil test is disabled.
268  // Workaround is to clear stencil buffer before disabling scissoring.
269 
270  // qDebug() << "Found VideoCore III driver, enabling brokenDisableScissorTest";
271  d->workaround_brokenScissor = true;
272  }
273  }
274  }
275 }
double d
Definition: qnumeric_p.h:62
static void setCurrentContext(QGLContext *context)
Definition: qgl.cpp:3577
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
Q_GUI_EXPORT bool hasExtension(const char *extensionName)
Definition: qegl.cpp:791
#define GL_RENDERER

◆ overlayTransparentColor()

QColor QGLContext::overlayTransparentColor ( ) const

If this context is a valid context in an overlay plane, returns the plane's transparent color.

Otherwise returns an QColor::isValid()}{invalid} color.

The returned QColor object will generally work as expected only when passed as the argument to QGLWidget::qglColor() or QGLWidget::qglClearColor(). Under certain circumstances it can also be used to draw transparent graphics with a QPainter.

Definition at line 362 of file qgl_egl.cpp.

Referenced by choosePixelFormat(), QGLOverlayWidget::initializeGL(), qDeleteQGLContext(), tryVisual(), and updatePaintDevice().

363 {
364  return d_func()->transpColor;
365 }

◆ requestedFormat()

QGLFormat QGLContext::requestedFormat ( ) const

Returns the frame buffer format that was originally requested in the constructor or setFormat().

See also
format()

Definition at line 3501 of file qgl.cpp.

3502 {
3503  Q_D(const QGLContext);
3504  return d->reqFormat;
3505 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ reset()

void QGLContext::reset ( )

Resets the context and makes it invalid.

See also
create(), isValid()

Definition at line 191 of file qgl_egl.cpp.

Referenced by chooseMacVisual(), choosePixelFormat(), qDeleteQGLContext(), and tryVisual().

192 {
193  Q_D(QGLContext);
194  if (!d->valid)
195  return;
196  d->cleanup();
197  doneCurrent();
198  if (d->eglContext && d->ownsEglContext) {
199  d->destroyEglSurfaceForDevice();
200  delete d->eglContext;
201  }
202  d->ownsEglContext = false;
203  d->eglContext = 0;
204  d->eglSurface = EGL_NO_SURFACE;
205  d->crWin = false;
206  d->sharing = false;
207  d->valid = false;
208  d->transpColor = QColor();
209  d->initDone = false;
211 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
static void removeShare(const QGLContext *context)
Definition: qgl.cpp:5867
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
virtual void doneCurrent()
Makes no GL context the current context.
Definition: qgl_egl.cpp:277

◆ setDevice()

void QGLContext::setDevice ( QPaintDevice pDev)
protected
Warning
This function is not part of the public interface.

Definition at line 3267 of file qgl.cpp.

Referenced by qDeleteQGLContext().

3268 {
3269  Q_D(QGLContext);
3270  if (isValid())
3271  reset();
3272  d->paintDevice = pDev;
3273  if (d->paintDevice && (d->paintDevice->devType() != QInternal::Widget
3274  && d->paintDevice->devType() != QInternal::Pixmap
3275  && d->paintDevice->devType() != QInternal::Pbuffer)) {
3276  qWarning("QGLContext: Unsupported paint device type");
3277  }
3278 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
void reset()
Resets the context and makes it invalid.
Definition: qgl_egl.cpp:191
bool isValid() const
Returns true if a GL rendering context has been successfully created; otherwise returns false...
Definition: qgl.cpp:3477

◆ setFormat()

void QGLContext::setFormat ( const QGLFormat format)

Sets a format for this context.

The context is reset.

Call create() to create a new GL context that tries to match the new format.

// ...
f.setStereo(true);
cx->setFormat(f);
if (!cx->create())
exit(); // no OpenGL support, or cannot render on the specified paintdevice
if (!cx->format().stereo())
exit(); // could not create stereo context
See also
format(), reset(), create()

Definition at line 3257 of file qgl.cpp.

3258 {
3259  Q_D(QGLContext);
3260  reset();
3261  d->glFormat = d->reqFormat = format;
3262 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
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
void reset()
Resets the context and makes it invalid.
Definition: qgl_egl.cpp:191

◆ setInitialized()

void QGLContext::setInitialized ( bool  on)
protected

If on is true the context has been initialized, i.

e. QGLContext::setInitialized() has been called on it. If on is false the context has not been initialized.

See also
initialized()

Definition at line 3539 of file qgl.cpp.

3540 {
3541  Q_D(QGLContext);
3542  d->initDone = on;
3543 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ setTextureCacheLimit()

void QGLContext::setTextureCacheLimit ( int  size)
static

This function sets the limit for the texture cache to size, expressed in kilobytes.

By default, the cache limit is approximately 64 MB.

See also
textureCacheLimit()

Definition at line 3205 of file qgl.cpp.

3206 {
3208 }
void setMaxCost(int newMax)
Definition: qgl_p.h:685
static QGLTextureCache * instance()
Definition: qgl.cpp:1995

◆ setValid()

void QGLContext::setValid ( bool  valid)
protected

Forces the GL rendering context to be valid.

Warning
This function is not part of the public interface.

Definition at line 3483 of file qgl.cpp.

3484 {
3485  Q_D(QGLContext);
3486  d->valid = valid;
3487 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ setWindowCreated()

void QGLContext::setWindowCreated ( bool  on)
protected

If on is true the context has had a window created for it.

If on is false no window has been created for the context.

See also
windowCreated()

Definition at line 3527 of file qgl.cpp.

3528 {
3529  Q_D(QGLContext);
3530  d->crWin = on;
3531 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ swapBuffers()

void QGLContext::swapBuffers ( ) const
virtual

Swaps the screen contents with an off-screen buffer.

Only works if the context is in double buffer mode.

See also
QGLFormat::setDoubleBuffer()

Definition at line 287 of file qgl_egl.cpp.

Referenced by choosePixelFormat(), QGLWindowSurface::flush(), qDeleteQGLContext(), tryVisual(), and updatePaintDevice().

288 {
289  Q_D(const QGLContext);
290  if (!d->valid || !d->eglContext)
291  return;
292 
293  d->eglContext->swapBuffers(d->eglSurfaceForDevice());
294 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ textureCacheLimit()

int QGLContext::textureCacheLimit ( )
static

Returns the current texture cache limit in kilobytes.

See also
setTextureCacheLimit()

Definition at line 3215 of file qgl.cpp.

3216 {
3217  return QGLTextureCache::instance()->maxCost();
3218 }
static QGLTextureCache * instance()
Definition: qgl.cpp:1995
int maxCost()
Definition: qgl_p.h:691

◆ tryVisual()

void * QGLContext::tryVisual ( const QGLFormat f,
int  bufDepth = 1 
)
protectedvirtual
Warning
This function is not part of the public interface.

X11 only: This virtual function chooses a visual that matches the OpenGL format. Reimplement this function in a subclass if you need a custom visual.

See also
chooseContext()

Definition at line 828 of file qgl_x11.cpp.

829 {
830  Q_D(QGLContext);
831  int spec[45];
832  const QX11Info *xinfo = qt_x11Info(d->paintDevice);
833  bool useFBConfig = buildSpec(spec, f, d->paintDevice, bufDepth, false);
834 
835  XVisualInfo* chosenVisualInfo = 0;
836 
837 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX)
838  while (useFBConfig) {
839  GLXFBConfig *configs;
840  int configCount = 0;
841  configs = glXChooseFBConfig(xinfo->display(), xinfo->screen(), spec, &configCount);
842 
843  if (!configs)
844  break; // fallback to trying glXChooseVisual
845 
846  for (int i = 0; i < configCount; ++i) {
847  XVisualInfo* vi;
848  vi = glXGetVisualFromFBConfig(xinfo->display(), configs[i]);
849  if (!vi)
850  continue;
851 
852 #if !defined(QT_NO_XRENDER)
853  QWidget* w = 0;
854  if (d->paintDevice->devType() == QInternal::Widget)
855  w = static_cast<QWidget*>(d->paintDevice);
856 
857  if (w && w->testAttribute(Qt::WA_TranslucentBackground) && f.alpha()) {
858  // Attempt to find a config who's visual has a proper alpha channel
859  XRenderPictFormat *pictFormat;
860  pictFormat = XRenderFindVisualFormat(xinfo->display(), vi->visual);
861 
862  if (pictFormat && (pictFormat->type == PictTypeDirect) && pictFormat->direct.alphaMask) {
863  // The pict format for the visual matching the FBConfig indicates ARGB
864  if (chosenVisualInfo)
865  XFree(chosenVisualInfo);
866  chosenVisualInfo = vi;
867  break;
868  }
869  } else
870 #endif //QT_NO_XRENDER
871  if (chosenVisualInfo) {
872  // If we've got a visual we can use and we're not trying to find one with a
873  // real alpha channel, we might as well just use the one we've got
874  break;
875  }
876 
877  if (!chosenVisualInfo)
878  chosenVisualInfo = vi; // Have something to fall back to
879  else
880  XFree(vi);
881  }
882 
883  XFree(configs);
884  break;
885  }
886 #endif // defined(GLX_VERSION_1_3)
887 
888  if (!chosenVisualInfo)
889  chosenVisualInfo = glXChooseVisual(xinfo->display(), xinfo->screen(), spec);
890 
891  return chosenVisualInfo;
892 }
double d
Definition: qnumeric_p.h:62
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_D(Class)
Definition: qglobal.h:2482
#define glXChooseFBConfig
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
The QX11Info class provides information about the X display configuration.
Definition: qx11info_x11.h:63
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
Definition: qgl.h:628
const QX11Info * qt_x11Info(const QPaintDevice *pd)
static Display * display()
Returns the default display for the application.
int screen() const
Returns the number of the screen currently in use.
static bool buildSpec(int *spec, const QGLFormat &f, QPaintDevice *paintDevice, int bufDepth, bool onlyFBConfig=false)
Definition: qgl_x11.cpp:421

◆ updatePaintDevice()

void QGLContext::updatePaintDevice ( )
Warning
This function is not part of the public interface.

Definition at line 583 of file qgl_mac.mm.

Referenced by QGLWindowSurface::updateGeometry().

584 {
585  Q_D(QGLContext);
586 #ifndef QT_MAC_USE_COCOA
587  d->update = false;
588  if (d->paintDevice->devType() == QInternal::Widget) {
589  //get control information
590  QWidget *w = (QWidget *)d->paintDevice;
591  HIViewRef hiview = (HIViewRef)w->winId();
592  WindowRef window = HIViewGetWindow(hiview);
593 #ifdef DEBUG_OPENGL_REGION_UPDATE
594  static int serial_no_gl = 0;
595  qDebug("[%d] %p setting on %s::%s %p/%p [%s]", ++serial_no_gl, w,
597  hiview, window, w->handle() ? "Inside" : "Outside");
598 #endif
599 
600  //update drawable
601  if (0 && w->isWindow() && w->isFullScreen()) {
602  aglSetDrawable((AGLContext)d->cx, 0);
603  aglSetFullScreen((AGLContext)d->cx, w->width(), w->height(), 0, QApplication::desktop()->screenNumber(w));
604  w->hide();
605  } else {
606  AGLDrawable old_draw = aglGetDrawable((AGLContext)d->cx), new_draw = GetWindowPort(window);
607  if (old_draw != new_draw)
608  aglSetDrawable((AGLContext)d->cx, new_draw);
609  }
610 
611  float scale = qt_mac_get_scale_factor(w);
612 
613  if (!w->isWindow()) {
614  QRegion clp = qt_mac_get_widget_rgn(w); //get drawable area
615 
616 #ifdef DEBUG_OPENGL_REGION_UPDATE
617  if (clp.isEmpty()) {
618  qDebug(" Empty area!");
619  } else {
620  QVector<QRect> rs = clp.rects();
621  for(int i = 0; i < rs.count(); i++)
622  qDebug(" %d %d %d %d", rs[i].x(), rs[i].y(), rs[i].width(), rs[i].height());
623  }
624 #endif
625  //update the clip
626  if (!aglIsEnabled((AGLContext)d->cx, AGL_BUFFER_RECT))
627  aglEnable((AGLContext)d->cx, AGL_BUFFER_RECT);
628  if (clp.isEmpty()) {
629  GLint offs[4] = { 0, 0, 0, 0 };
630  aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs);
631  if (aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION))
632  aglDisable((AGLContext)d->cx, AGL_CLIP_REGION);
633  } else {
634  HIPoint origin = { 0., 0. };
635  HIViewConvertPoint(&origin, HIViewRef(w->winId()), 0);
636  const GLint offs[4] = { qRound(origin.x),
637  w->window()->frameGeometry().height() * scale
638  - (qRound(origin.y) + w->height() * scale),
639  w->width() * scale, w->height() * scale};
640 
641  RgnHandle region = clp.handle(true);
642 
643  if (scale != float(1)) {
644  // Sacle the clip region by the scale factor
645  Rect regionBounds;
646  GetRegionBounds(region, &regionBounds);
647  Rect regionBoundsDest = regionBounds;
648  regionBoundsDest.bottom *= scale;
649  regionBoundsDest.right *= scale;
650  MapRgn(region, &regionBounds, &regionBoundsDest);
651  }
652 
653  aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs);
654  aglSetInteger((AGLContext)d->cx, AGL_CLIP_REGION, (const GLint *)region);
655  if (!aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION))
656  aglEnable((AGLContext)d->cx, AGL_CLIP_REGION);
657  }
658  } else {
659  // Set the buffer rect for top-level gl contexts when scaled.
660  if (scale != float(1)) {
661  aglEnable((AGLContext)d->cx, AGL_BUFFER_RECT);
662  const GLint offs[4] = { 0, 0, w->width() * scale , w->height() * scale};
663  aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs);
664  }
665  }
666  } else if (d->paintDevice->devType() == QInternal::Pixmap) {
667  QPixmap *pm = reinterpret_cast<QPixmap *>(d->paintDevice);
668 
669  unsigned long qdformat = k32ARGBPixelFormat;
670  if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)
671  qdformat = k32BGRAPixelFormat;
672  Rect rect;
673  SetRect(&rect, 0, 0, pm->width(), pm->height());
674 
675  GWorldPtr gworld;
676  NewGWorldFromPtr(&gworld, qdformat, &rect, 0, 0, 0,
677  reinterpret_cast<char *>(qt_mac_pixmap_get_base(pm)),
679 
680  PixMapHandle pixmapHandle = GetGWorldPixMap(gworld);
681  aglSetOffScreen(reinterpret_cast<AGLContext>(d->cx), pm->width(), pm->height(),
682  GetPixRowBytes(pixmapHandle), GetPixBaseAddr(pixmapHandle));
683  } else {
684  qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!");
685  }
686  aglUpdateContext((AGLContext)d->cx);
687 
688 #else
690 
691  if (d->paintDevice->devType() == QInternal::Widget) {
692  //get control information
693  QWidget *w = (QWidget *)d->paintDevice;
694  NSView *view = qt_mac_nativeview_for(w);
695 
696  // Trying to attach the GL context to the NSView will fail with
697  // "invalid drawable" if done too soon, but we have to make sure
698  // the connection is made before the first paint event. Using
699  // the NSView do to this check fails as the NSView is visible
700  // before it's safe to connect, and using the NSWindow fails as
701  // the NSWindow will become visible after the first paint event.
702  // This leaves us with the QWidget, who's visible state seems
703  // to match the point in time when it's safe to connect.
704  if (!w || !w->isVisible())
705  return; // Not safe to attach GL context to view yet
706 
707  if ([static_cast<NSOpenGLContext *>(d->cx) view] != view && ![view isHidden])
708  [static_cast<NSOpenGLContext *>(d->cx) setView:view];
709  } else if (d->paintDevice->devType() == QInternal::Pixmap) {
710  const QPixmap *pm = static_cast<const QPixmap *>(d->paintDevice);
711  [static_cast<NSOpenGLContext *>(d->cx) setOffScreen:qt_mac_pixmap_get_base(pm)
712  width:pm->width()
713  height:pm->height()
714  rowbytes:qt_mac_pixmap_get_bytes_per_line(pm)];
715  } else {
716  qWarning("QGLContext::updatePaintDevice: Not sure how to render OpenGL on this device");
717  }
718  [static_cast<NSOpenGLContext *>(d->cx) update];
719 #endif
720 }
double d
Definition: qnumeric_p.h:62
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
float qt_mac_get_scale_factor(QWidget *widget)
Definition: qgl_mac.mm:565
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
struct OpaqueWindowPtr * WindowRef
bool isVisible() const
Definition: qwidget.h:1005
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect frameGeometry
geometry of the widget relative to its parent including any window frame
Definition: qwidget.h:159
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_D(Class)
Definition: qglobal.h:2482
QRegion qt_mac_get_widget_rgn(const QWidget *widget)
Definition: qgl_mac.mm:836
Q_CORE_EXPORT void qDebug(const char *,...)
NSWindow * window
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
struct OpaqueControlRef * HIViewRef
Q_CORE_EXPORT void qWarning(const char *,...)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
struct OpaqueRgnHandle * RgnHandle
void hide()
Hides the widget.
Definition: qwidget.h:501
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int qt_mac_pixmap_get_bytes_per_line(const QPixmap *)
Definition: qpixmap_mac.cpp:83
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
bool isFullScreen() const
Definition: qwidget.cpp:3153
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QString objectName() const
OSViewRef qt_mac_nativeview_for(const QWidget *)
Definition: qwidget_mac.mm:419
quint32 * qt_mac_pixmap_get_base(const QPixmap *)
Definition: qpixmap_mac.cpp:75
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
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 height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
int screenNumber(const QWidget *widget=0) const
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
Handle handle() const
Returns a platform-specific region handle.

◆ windowCreated()

bool QGLContext::windowCreated ( ) const
protected

Returns true if a window has been created for this context; otherwise returns false.

See also
setWindowCreated()

Definition at line 3520 of file qgl.cpp.

Referenced by QGLOverlayWidget::paintGL().

3521 {
3522  Q_D(const QGLContext);
3523  return d->crWin;
3524 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

Friends and Related Functions

◆ QGL2PaintEngineEx

friend class QGL2PaintEngineEx
friend

Definition at line 439 of file qgl.h.

◆ QGL2PaintEngineExPrivate

Definition at line 440 of file qgl.h.

◆ QGLContextGroup

friend class QGLContextGroup
friend

Definition at line 447 of file qgl.h.

◆ QGLContextResourceBase

Definition at line 467 of file qgl.h.

◆ QGLEngineShaderManager

Definition at line 441 of file qgl.h.

◆ QGLExtensions

friend class QGLExtensions
friend

Definition at line 450 of file qgl.h.

◆ QGLFBOGLPaintDevice

friend class QGLFBOGLPaintDevice
friend

Definition at line 462 of file qgl.h.

◆ QGLFormat::openGLVersionFlags

QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags ( )
friend

◆ QGLFramebufferObject

friend class QGLFramebufferObject
friend

Definition at line 460 of file qgl.h.

◆ QGLFramebufferObjectPrivate

Definition at line 461 of file qgl.h.

◆ QGLGlyphCache

friend class QGLGlyphCache
friend

Definition at line 436 of file qgl.h.

◆ QGLGlyphTexture

friend struct QGLGlyphTexture
friend

Definition at line 446 of file qgl.h.

◆ QGLPaintDevice

friend class QGLPaintDevice
friend

Definition at line 463 of file qgl.h.

◆ QGLPixelBuffer

friend class QGLPixelBuffer
friend

Definition at line 432 of file qgl.h.

◆ QGLPixelBufferPrivate

Definition at line 433 of file qgl.h.

◆ QGLPixmapBlurFilter

friend class QGLPixmapBlurFilter
friend

Definition at line 449 of file qgl.h.

◆ QGLPixmapData

friend class QGLPixmapData
friend

Definition at line 443 of file qgl.h.

◆ QGLPixmapFilterBase

friend class QGLPixmapFilterBase
friend

Definition at line 444 of file qgl.h.

◆ QGLSharedResourceGuard

Definition at line 448 of file qgl.h.

◆ QGLTexture

friend class QGLTexture
friend

Definition at line 451 of file qgl.h.

◆ QGLTextureGlyphCache

friend class QGLTextureGlyphCache
friend

Definition at line 445 of file qgl.h.

◆ QGLWidget

friend class QGLWidget
friend

Definition at line 434 of file qgl.h.

◆ QGLWidgetGLPaintDevice

Definition at line 464 of file qgl.h.

◆ QGLWidgetPrivate

friend class QGLWidgetPrivate
friend

Definition at line 435 of file qgl.h.

◆ QGLWindowSurface

friend class QGLWindowSurface
friend

Definition at line 442 of file qgl.h.

◆ QMacGLWindowChangeEvent

friend class QMacGLWindowChangeEvent
friend

Definition at line 457 of file qgl.h.

◆ QOpenGLPaintEngine

friend class QOpenGLPaintEngine
friend

Definition at line 437 of file qgl.h.

◆ QOpenGLPaintEnginePrivate

Definition at line 438 of file qgl.h.

◆ qt_phonon_get_dptr

QGLContextPrivate* qt_phonon_get_dptr ( const QGLContext )
friend

◆ QX11GLPixmapData

friend class QX11GLPixmapData
friend

Definition at line 465 of file qgl.h.

◆ QX11GLSharedContexts

friend class QX11GLSharedContexts
friend

Definition at line 466 of file qgl.h.

Properties

◆ currentCtx

QGLContext * QGLContext::currentCtx = 0
staticprotected

Definition at line 423 of file qgl.h.

◆ d_ptr

QScopedPointer<QGLContextPrivate> QGLContext::d_ptr
private

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