Eneboo - Documentación para desarrolladores
src/qt/src/opengl/qgl.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qgl.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of OpenGL classes for Qt
00005 **
00006 ** Created : 970112
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the opengl module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00022 ** file in accordance with the Qt Commercial License Agreement provided
00023 ** with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QGL_H
00039 #define QGL_H
00040 
00041 #ifndef QT_H
00042 #include "qwidget.h"
00043 #include "qglcolormap.h"
00044 #endif // QT_H
00045 
00046 #if !defined( QT_MODULE_OPENGL ) || defined( QT_LICENSE_PROFESSIONAL )
00047 #define QM_EXPORT_OPENGL
00048 #else
00049 #define QM_EXPORT_OPENGL Q_EXPORT
00050 #endif
00051 
00052 #ifndef QT_NO_COMPAT
00053 #define QGL_VERSION     450
00054 #define QGL_VERSION_STR "4.5"
00055 QM_EXPORT_OPENGL inline const char *qGLVersion() {
00056     qObsolete( 0, "qGLVersion", "qVersion" );
00057     return QGL_VERSION_STR;
00058 }
00059 #endif
00060 
00061 #if defined(Q_WS_WIN)
00062 # include "qt_windows.h"
00063 #endif
00064 
00065 #if defined(Q_WS_MAC)
00066 #if !defined( QMAC_OPENGL_DOUBLEBUFFER )
00067 /* This macro is different now. If the macro is not defined QGLWidget will
00068  * try to determine when you need double buffering.  If set to 0 it will
00069  * never double buffer and *can* be acclerated. If set to 1 (the default)
00070  * it will always double buffer. Unlike before the value of this macro does
00071  * not upset binary compatability either. */
00072 #if QT_MACOSX_VERSION >= 0x1020
00073 # define QMAC_OPENGL_DOUBLEBUFFER 0
00074 #endif
00075 #endif
00076 # include <OpenGL/gl.h>
00077 # include <OpenGL/glu.h>
00078 #else
00079 # include <GL/gl.h>
00080 # include <GL/glu.h>
00081 #endif
00082 
00083 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
00084 class QGLCmap;
00085 #endif
00086 
00087 class QPixmap;
00088 #if defined(Q_WS_X11)
00089 class QGLOverlayWidget;
00090 #endif
00091 
00092 // Namespace class:
00093 class QM_EXPORT_OPENGL QGL
00094 {
00095 public:
00096     enum FormatOption {
00097         DoubleBuffer            = 0x0001,
00098         DepthBuffer             = 0x0002,
00099         Rgba                    = 0x0004,
00100         AlphaChannel            = 0x0008,
00101         AccumBuffer             = 0x0010,
00102         StencilBuffer           = 0x0020,
00103         StereoBuffers           = 0x0040,
00104         DirectRendering         = 0x0080,
00105         HasOverlay              = 0x0100,
00106         SingleBuffer            = DoubleBuffer  << 16,
00107         NoDepthBuffer           = DepthBuffer   << 16,
00108         ColorIndex              = Rgba          << 16,
00109         NoAlphaChannel          = AlphaChannel  << 16,
00110         NoAccumBuffer           = AccumBuffer   << 16,
00111         NoStencilBuffer         = StencilBuffer << 16,
00112         NoStereoBuffers         = StereoBuffers << 16,
00113         IndirectRendering       = DirectRendering << 16,
00114         NoOverlay               = HasOverlay << 16
00115     };
00116 };
00117 
00118 
00119 
00120 class QM_EXPORT_OPENGL QGLFormat : public QGL
00121 {
00122 public:
00123     QGLFormat();
00124     QGLFormat( int options, int plane = 0 );
00125 
00126     bool doubleBuffer() const;
00127     void setDoubleBuffer( bool enable );
00128     bool depth() const;
00129     void setDepth( bool enable );
00130     bool rgba() const;
00131     void setRgba( bool enable );
00132     bool alpha() const;
00133     void setAlpha( bool enable );
00134     bool accum() const;
00135     void setAccum( bool enable );
00136     bool stencil() const;
00137     void setStencil( bool enable );
00138     bool stereo() const;
00139     void setStereo( bool enable );
00140     bool directRendering() const;
00141     void setDirectRendering( bool enable );
00142     bool hasOverlay() const;
00143     void setOverlay( bool enable );
00144 
00145     int plane() const;
00146     void setPlane( int plane );
00147 
00148     void setOption( FormatOption opt );
00149     bool testOption( FormatOption opt ) const;
00150 
00151     static QGLFormat defaultFormat();
00152     static void setDefaultFormat( const QGLFormat& f );
00153 
00154     static QGLFormat defaultOverlayFormat();
00155     static void setDefaultOverlayFormat( const QGLFormat& f );
00156 
00157     static bool hasOpenGL();
00158     static bool hasOpenGLOverlays();
00159 
00160     friend QM_EXPORT_OPENGL bool operator==( const QGLFormat&,
00161                                              const QGLFormat& );
00162     friend QM_EXPORT_OPENGL bool operator!=( const QGLFormat&,
00163                                              const QGLFormat& );
00164 private:
00165     uint opts;
00166     int pln;
00167 };
00168 
00169 
00170 QM_EXPORT_OPENGL bool operator==( const QGLFormat&, const QGLFormat& );
00171 QM_EXPORT_OPENGL bool operator!=( const QGLFormat&, const QGLFormat& );
00172 
00173 class QM_EXPORT_OPENGL QGLContext : public QGL
00174 {
00175 public:
00176     QGLContext( const QGLFormat& format, QPaintDevice* device );
00177     QGLContext( const QGLFormat& format );
00178     virtual ~QGLContext();
00179 
00180     virtual bool create( const QGLContext* shareContext = 0 );
00181     bool isValid() const;
00182     bool isSharing() const;
00183     virtual void reset();
00184 
00185     QGLFormat format() const;
00186     QGLFormat requestedFormat() const;
00187     virtual void setFormat( const QGLFormat& format );
00188 
00189     virtual void makeCurrent();
00190     virtual void swapBuffers() const;
00191 
00192     QPaintDevice* device() const;
00193 
00194     QColor overlayTransparentColor() const;
00195 
00196     static const QGLContext* currentContext();
00197 
00198 protected:
00199     virtual bool chooseContext( const QGLContext* shareContext = 0 );
00200     virtual void doneCurrent(); // ### 4.0: make this public - needed for multithreading stuff
00201 
00202 #if defined(Q_WS_WIN)
00203     virtual int choosePixelFormat( void* pfd, HDC pdc );
00204 #endif
00205 #if defined(Q_WS_X11)
00206     virtual void* tryVisual( const QGLFormat& f, int bufDepth = 1 );
00207     virtual void* chooseVisual();
00208 #endif
00209 #if defined(Q_WS_MAC)
00210     virtual void* chooseMacVisual(GDHandle);
00211 #endif
00212 
00213     bool deviceIsPixmap() const;
00214     bool windowCreated() const;
00215     void setWindowCreated( bool on );
00216     bool initialized() const;
00217     void setInitialized( bool on );
00218     void generateFontDisplayLists( const QFont & fnt, int listBase );
00219 
00220     uint colorIndex( const QColor& c ) const;
00221     void setValid( bool valid );
00222     void setDevice( QPaintDevice *pDev );
00223 
00224 protected:
00225 #if  defined(Q_WS_WIN)
00226     HGLRC rc;
00227     HDC dc;
00228     WId win;
00229     int pixelFormatId;
00230     QGLCmap* cmap;
00231 #elif defined(Q_WS_X11) || defined(Q_WS_MAC)
00232     void* vi;
00233     void* cx;
00234 #if defined(Q_WS_X11)
00235     Q_UINT32 gpm;
00236 #endif
00237 #endif
00238     QGLFormat glFormat;
00239     QGLFormat reqFormat;
00240     static QGLContext*  currentCtx;
00241 
00242 private:
00243     void init( QPaintDevice *dev = 0 );
00244     class Private {
00245     public:
00246         bool valid;
00247         bool sharing;
00248         bool initDone;
00249         bool crWin;
00250         QPaintDevice* paintDevice;
00251         QColor transpColor;
00252 #ifdef Q_WS_MAC
00253         QRect oldR;
00254 #endif
00255     };
00256     Private* d;
00257 
00258     friend class QGLWidget;
00259 #ifdef Q_WS_MAC
00260     void fixBufferRect();
00261 #endif
00262 
00263 private:        // Disabled copy constructor and operator=
00264     QGLContext() {}
00265     QGLContext( const QGLContext& ) {}
00266     QGLContext& operator=( const QGLContext& ) { return *this; }
00267 };
00268 
00269 
00270 
00271 
00272 class QM_EXPORT_OPENGL QGLWidget : public QWidget, public QGL
00273 {
00274     Q_OBJECT
00275 public:
00276     QGLWidget( QWidget* parent=0, const char* name=0,
00277                const QGLWidget* shareWidget = 0, WFlags f=0 );
00278     QGLWidget( QGLContext *context, QWidget* parent, const char* name=0,
00279                const QGLWidget* shareWidget = 0, WFlags f=0 );
00280     QGLWidget( const QGLFormat& format, QWidget* parent=0, const char* name=0,
00281                const QGLWidget* shareWidget = 0, WFlags f=0 );
00282     ~QGLWidget();
00283 
00284     void qglColor( const QColor& c ) const;
00285     void qglClearColor( const QColor& c ) const;
00286 
00287     bool isValid() const;
00288     bool isSharing() const;
00289     virtual void makeCurrent();
00290     void doneCurrent();
00291     
00292     bool doubleBuffer() const;
00293     virtual void swapBuffers();
00294 
00295     QGLFormat format() const;
00296 #ifndef Q_QDOC
00297     virtual void setFormat( const QGLFormat& format );
00298 #endif
00299 
00300     const QGLContext* context() const;
00301 #ifndef Q_QDOC
00302     virtual void setContext( QGLContext* context,
00303                              const QGLContext* shareContext = 0,
00304                              bool deleteOldContext = TRUE );
00305 #endif
00306 
00307     virtual QPixmap renderPixmap( int w = 0, int h = 0,
00308                                   bool useContext = FALSE );
00309     virtual QImage grabFrameBuffer( bool withAlpha = FALSE );
00310 
00311     virtual void makeOverlayCurrent();
00312     const QGLContext* overlayContext() const;
00313 
00314     static QImage convertToGLFormat( const QImage& img );
00315 
00316     void setMouseTracking( bool enable );
00317     virtual void  reparent( QWidget* parent, WFlags f, const QPoint& p,
00318                             bool showIt = FALSE );
00319 
00320     const QGLColormap & colormap() const;
00321     void  setColormap( const QGLColormap & map );
00322 
00323     void renderText( int x, int y, const QString & str,
00324                      const QFont & fnt = QFont(), int listBase = 2000 );
00325     void renderText( double x, double y, double z, const QString & str,
00326                      const QFont & fnt = QFont(), int listBase = 2000 );
00327 public slots:
00328     virtual void updateGL();
00329     virtual void updateOverlayGL();
00330 
00331 protected:
00332     virtual void initializeGL();
00333     virtual void resizeGL( int w, int h );
00334     virtual void paintGL();
00335 
00336     virtual void initializeOverlayGL();
00337     virtual void resizeOverlayGL( int w, int h );
00338     virtual void paintOverlayGL();
00339 
00340     void setAutoBufferSwap( bool on );
00341     bool autoBufferSwap() const;
00342 
00343     void paintEvent( QPaintEvent* );
00344     void resizeEvent( QResizeEvent* );
00345 
00346     virtual void glInit();
00347     virtual void glDraw();
00348 
00349 private:
00350     int displayListBase( const QFont & fnt, int listBase );
00351     void cleanupColormaps();
00352     void init( QGLContext *context, const QGLWidget* shareWidget );
00353     bool renderCxPm( QPixmap* pm );
00354     QGLContext* glcx;
00355     bool autoSwap;
00356 
00357     QGLColormap cmap;
00358 
00359 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
00360     QGLContext* olcx;
00361 #elif defined(Q_WS_X11)
00362     QGLOverlayWidget*   olw;
00363     friend class QGLOverlayWidget;
00364 #endif
00365 
00366 private:        // Disabled copy constructor and operator=
00367 #if defined(Q_DISABLE_COPY)
00368     QGLWidget( const QGLWidget& );
00369     QGLWidget& operator=( const QGLWidget& );
00370 #endif
00371 
00372 #if defined(Q_WS_MAC)
00373 private:
00374     const QGLContext *slcx;
00375     uint pending_fix : 1,
00376          glcx_dblbuf : 2,
00377          dblbuf : 1,
00378          clp_serial : 15;
00379     QPixmap *gl_pix;
00380     QGLFormat req_format;
00381 
00382     void macInternalRecreateContext( QGLContext *ctx,
00383                                      const QGLContext* = NULL,
00384                                      bool update = TRUE );
00385     bool macInternalDoubleBuffer( bool fix = TRUE );
00386     virtual void setRegionDirty( bool );
00387     virtual void macWidgetChangedWindow();
00388 #endif
00389 private slots:
00390     void macInternalFixBufferRect();
00391 };
00392 
00393 
00394 //
00395 // QGLFormat inline functions
00396 //
00397 
00398 inline bool QGLFormat::doubleBuffer() const
00399 {
00400     return testOption( DoubleBuffer );
00401 }
00402 
00403 inline bool QGLFormat::depth() const
00404 {
00405     return testOption( DepthBuffer );
00406 }
00407 
00408 inline bool QGLFormat::rgba() const
00409 {
00410     return testOption( Rgba );
00411 }
00412 
00413 inline bool QGLFormat::alpha() const
00414 {
00415     return testOption( AlphaChannel );
00416 }
00417 
00418 inline bool QGLFormat::accum() const
00419 {
00420     return testOption( AccumBuffer );
00421 }
00422 
00423 inline bool QGLFormat::stencil() const
00424 {
00425     return testOption( StencilBuffer );
00426 }
00427 
00428 inline bool QGLFormat::stereo() const
00429 {
00430     return testOption( StereoBuffers );
00431 }
00432 
00433 inline bool QGLFormat::directRendering() const
00434 {
00435     return testOption( DirectRendering );
00436 }
00437 
00438 inline bool QGLFormat::hasOverlay() const
00439 {
00440     return testOption( HasOverlay );
00441 }
00442 
00443 //
00444 // QGLContext inline functions
00445 //
00446 
00447 inline bool QGLContext::isValid() const
00448 {
00449     return d->valid;
00450 }
00451 
00452 inline void QGLContext::setValid( bool valid )
00453 {
00454     d->valid = valid;
00455 }
00456 
00457 inline bool QGLContext::isSharing() const
00458 {
00459     return d->sharing;
00460 }
00461 
00462 inline QGLFormat QGLContext::format() const
00463 {
00464     return glFormat;
00465 }
00466 
00467 inline QGLFormat QGLContext::requestedFormat() const
00468 {
00469     return reqFormat;
00470 }
00471 
00472 inline QPaintDevice* QGLContext::device() const
00473 {
00474     return d->paintDevice;
00475 }
00476 
00477 inline bool QGLContext::deviceIsPixmap() const
00478 {
00479     return d->paintDevice->devType() == QInternal::Pixmap;
00480 }
00481 
00482 
00483 inline bool QGLContext::windowCreated() const
00484 {
00485     return d->crWin;
00486 }
00487 
00488 
00489 inline void QGLContext::setWindowCreated( bool on )
00490 {
00491     d->crWin = on;
00492 }
00493 
00494 inline bool QGLContext::initialized() const
00495 {
00496     return d->initDone;
00497 }
00498 
00499 inline void QGLContext::setInitialized( bool on )
00500 {
00501     d->initDone = on;
00502 }
00503 
00504 inline const QGLContext* QGLContext::currentContext()
00505 {
00506     return currentCtx;
00507 }
00508 
00509 //
00510 // QGLWidget inline functions
00511 //
00512 
00513 inline QGLFormat QGLWidget::format() const
00514 {
00515     return glcx->format();
00516 }
00517 
00518 inline const QGLContext *QGLWidget::context() const
00519 {
00520     return glcx;
00521 }
00522 
00523 inline bool QGLWidget::doubleBuffer() const
00524 {
00525     return glcx->format().doubleBuffer();
00526 }
00527 
00528 inline void QGLWidget::setAutoBufferSwap( bool on )
00529 {
00530     autoSwap = on;
00531 }
00532 
00533 inline bool QGLWidget::autoBufferSwap() const
00534 {
00535     return autoSwap;
00536 }
00537 
00538 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'