📄 qgl.cpp
字号:
additional context in an overlay plane. See the QGLWidget documentation for further information. \sa hasOverlay()*/void QGLFormat::setOverlay( bool enable ){ setOption( enable ? HasOverlay : NoOverlay );}/*! Returns the plane of this format. Default for normal formats is 0, which means the normal plane; default for overlay formats is 1, which is the first overlay plane. \sa setPlane()*/int QGLFormat::plane() const{ return pln;}/*! Sets the requested plane. 0 is the normal plane, 1 is the first overlay plane, 2 is the second overlay plane, etc., and -1, -2, etc. are underlay planes. Note that, in contrast to the other format specifications, the plane specifications will be matched exactly. Thus, if you specify a plane that the underlying OpenGL system cannot provide, an \link QGLWidget::isValid() invalid\endlink QGLWidget will be created. \sa plane()*/void QGLFormat::setPlane( int plane ){ pln = plane;}/*! Sets the option \a opt. \sa testOption()*/void QGLFormat::setOption( FormatOption opt ){ if ( opt & 0xffff ) opts |= opt; else opts &= ~( opt >> 16 );}/*! Returns TRUE if format option \a opt is set, otherwise FALSE. \sa setOption()*/bool QGLFormat::testOption( FormatOption opt ) const{ if ( opt & 0xffff ) return ( opts & opt ) != 0; else return ( opts & ( opt >> 16 ) ) == 0;}/*! \fn bool QGLFormat::hasOpenGL() Returns TRUE if the window system has any OpenGL support, otherwise FALSE. Note: This function may not be called until the QApplication object has been created.*//*! \fn bool QGLFormat::hasOpenGLOverlays() Returns TRUE if the window system supports OpenGL overlays, otherwise FALSE. Note: This function may not be called until the QApplication object has been created.*/static void cleanupGLFormat(){ delete qgl_default_format; qgl_default_format = 0; delete qgl_default_overlay_format; qgl_default_overlay_format = 0;}/*! Returns the default QGLFormat for the application. All QGLWidgets that are created use this format unless anything else is specified. If no special default format has been set using setDefaultFormat(), the default format is the same as that created with QGLFormat(). \sa setDefaultFormat()*/QGLFormat QGLFormat::defaultFormat(){ if ( !qgl_default_format ) { qgl_default_format = new QGLFormat; qAddPostRoutine( cleanupGLFormat ); } return *qgl_default_format;}/*! Sets a new default QGLFormat for the application. For example, to set single buffering as default instead of double buffering, your main() can contain: \code QApplication a(argc, argv); QGLFormat f; f.setDoubleBuffer( FALSE ); QGLFormat::setDefaultFormat( f ); \endcode \sa defaultFormat()*/void QGLFormat::setDefaultFormat( const QGLFormat &f ){ if ( !qgl_default_format ) { qgl_default_format = new QGLFormat; qAddPostRoutine( cleanupGLFormat ); } *qgl_default_format = f;}/*! Returns the default QGLFormat for overlay contexts. The factory default overlay format is: <ul> <li> \link setDoubleBuffer() Double buffer:\endlink Disabled. <li> \link setDepth() Depth buffer:\endlink Disabled. <li> \link setRgba() RGBA:\endlink Disabled (i.e. color index enabled). <li> \link setAlpha() Alpha channel:\endlink Disabled. <li> \link setAccum() Accumulator buffer:\endlink Disabled. <li> \link setStencil() Stencil buffer:\endlink Disabled. <li> \link setStereo() Stereo:\endlink Disabled. <li> \link setDirectRendering() Direct rendering:\endlink Enabled. <li> \link setOverlay() Overlay:\endlink Disabled. <li> \link setPlane() Plane:\endlink 1 (i.e. first overlay plane). </ul> \sa setDefaultFormat()*/QGLFormat QGLFormat::defaultOverlayFormat(){ if ( !qgl_default_overlay_format ) { qgl_default_overlay_format = new QGLFormat; qgl_default_overlay_format->opts = DirectRendering; qgl_default_overlay_format->pln = 1; qAddPostRoutine( cleanupGLFormat ); } return *qgl_default_overlay_format;}/*! Sets a new default QGLFormat for overlay contexts. This format is used whenever a QGLWidget is created with a format with hasOverlay() enabled. For example, to get a double buffered overlay contexts (if available), the code can do: \code QGLFormat f = QGLFormat::defaultOverlayFormat(); f.setDoubleBuffer( TRUE ); QGLFormat::setDefaultOverlayFormat( f ); \endcode As usual, you can test after the widget creation whether the underlying OpenGL system was able to provide the requested specification: \code // (...continued from above) MyGLWidget* myWidget = new MyGLWidget( QGLFormat( QGL::HasOverlay ), ... ); if ( myWidget->format().hasOverlay() ) { // Yes, we got an overlay, let's check _its_ format: QGLContext* olContext = myWidget->overlayContext(); if ( olContext->format().doubleBuffer() ) ; // yes, we got a double buffered overlay else ; // no, only single buffered overlays were available } \endcode \sa defaultOverlayFormat()*/void QGLFormat::setDefaultOverlayFormat( const QGLFormat &f ){ if ( !qgl_default_overlay_format ) { qgl_default_overlay_format = new QGLFormat; qAddPostRoutine( cleanupGLFormat ); } *qgl_default_overlay_format = f; // Make sure the user doesn't request that the overlays themselves // have overlays, since it is unlikely that the system supports // infinitely many planes... qgl_default_overlay_format->setOverlay( FALSE );}/*! Returns TRUE if all options of the two QGLFormats are equal.*/bool operator==( const QGLFormat& a, const QGLFormat& b ){ return (a.opts == b.opts) && (a.pln == b.pln);}/*! Returns FALSE if all options of the two QGLFormats are equal.*/bool operator!=( const QGLFormat& a, const QGLFormat& b ){ return !( a == b );}/***************************************************************************** QGLContext implementation *****************************************************************************/QGLContext* QGLContext::currentCtx = 0;/*! \class QGLContext qgl.h \brief The QGLContext class encapsulates an OpenGL rendering context. \module OpenGL An OpenGL rendering context is a complete set of OpenGL state variables.*//*! Constructs an OpenGL context for the paint device \a device, which can be a widget or a pixmap. The \a format specifies several display options for this context. If the underlying OpenGL/Window system cannot satisfy all the features requested in \a 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 have been constructed, \link create() create()\endlink have to be called explicitly to create the actual OpenGL context. The context will be \link isValid() invalid\endlink if it was not possible to obtain a GL context at all. \sa format(), isValid()*/QGLContext::QGLContext( const QGLFormat &format, QPaintDevice *device ) : glFormat(format), paintDevice(device){ valid = FALSE;#if defined(Q_GLX) gpm = 0;#endif#if defined(Q_WGL) dc = 0; win = 0; pixelFormatId = 0; cmap = 0;#endif crWin = FALSE; initDone = FALSE; sharing = FALSE; if ( paintDevice == 0 ) {#if defined(CHECK_NULL) qWarning( "QGLContext: Paint device cannot be null" ); return;#endif } if ( paintDevice->devType() != QInternal::Widget && paintDevice->devType() != QInternal::Pixmap ) {#if defined(CHECK_RANGE) qWarning( "QGLContext: Unsupported paint device type" );#endif }}/*! Destroys the OpenGL context.*/QGLContext::~QGLContext(){ reset();}/*! \fn QGLFormat QGLContext::format() const Returns the format.*//*! Sets a \a format for this context. The context is \link reset() reset\endlink. Call create() to create a new GL context that tries to match the new format. \code QGLContext *cx; ... QGLFormat f; f.setStereo( TRUE ); cx->setFormat( f ); if ( !cx->create() ) exit(); // no OpenGL support, or cannot render on specified paintdevice if ( !cx->format().stereo() ) exit(); // could not create stereo context \endcode \sa format(), reset(), create()*/void QGLContext::setFormat( const QGLFormat &format ){ reset(); glFormat = format;}/*! \fn bool QGLContext::isValid() const Returns TRUE if a GL rendering context has been successfully created.*//*! \fn bool QGLContext::isSharing() const Returns TRUE if display list sharing with another context was requested in the create() call, and the GL system was able to fulfill this request. Note that display list sharing may possibly not be supported between contexts with different formats.*//*! \fn bool QGLContext::deviceIsPixmap() const Returns TRUE if the paint device of this context is a pixmap, otherwise FALSE.*//*! \fn bool QGLContext::windowCreated() const Returns TRUE if a window has been created for this context, otherwise FALSE. \sa setWindowCreated()*//*! \fn void QGLContext::setWindowCreated( bool on ) Tells the context whether a window has already been created for it. \sa windowCreated()*//*! \fn uint QGLContext::colorIndex( const QColor& c ) const \internal Finds a colormap index for the color c, in ColorIndex mode. Used by qglColor() and qglClearColor().*//*! \fn bool QGLContext::initialized() const Returns TRUE if this context has been initialized, i.e. if QGLWidget::initializeGL() has been performed on it. \sa setInitialized()*//*! \fn void QGLContext::setInitialized( bool on ) Tells the context whether it has been initialized, i.e. whether QGLWidget::initializeGL() has been performed on it. \sa initialized()*//*! \fn const QGLContext* QGLContext::currentContext() Returns the current context, i.e. the context to which any OpenGL commands will currently be directed to. Returns 0 if no context is current. \sa makeCurrent()*//*! \fn QColor QGLContext::overlayTransparentColor() const If this context is a valid context in an overlay plane, returns the plane's transparent color. Otherwise returns an \link QColor::isValid() invalid \endlink color. The returned color's \link QColor::pixel() pixel \endlink value is the index of the transparent color in the colormap of the overlay
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -