src/opengl/qgl_p.h
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
    62 #include "QtCore/qatomic.h"
    62 #include "QtCore/qatomic.h"
    63 #include "private/qwidget_p.h"
    63 #include "private/qwidget_p.h"
    64 #include "qcache.h"
    64 #include "qcache.h"
    65 #include "qglpaintdevice_p.h"
    65 #include "qglpaintdevice_p.h"
    66 
    66 
    67 #ifndef QT_OPENGL_ES_1_CL
    67 #ifndef QT_NO_EGL
    68 #define q_vertexType float
    68 #include <QtGui/private/qegl_p.h>
    69 #define q_vertexTypeEnum GL_FLOAT
       
    70 #define f2vt(f)     (f)
       
    71 #define vt2f(x)     (x)
       
    72 #define i2vt(i)     (float(i))
       
    73 #else
       
    74 #define FLOAT2X(f)      (int( (f) * (65536)))
       
    75 #define X2FLOAT(x)      (float(x) / 65536.0f)
       
    76 #define f2vt(f)     FLOAT2X(f)
       
    77 #define i2vt(i)     ((i)*65536)
       
    78 #define vt2f(x)     X2FLOAT(x)
       
    79 #define q_vertexType GLfixed
       
    80 #define q_vertexTypeEnum GL_FIXED
       
    81 #endif //QT_OPENGL_ES_1_CL
       
    82 
       
    83 #if defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2)
       
    84 QT_BEGIN_INCLUDE_NAMESPACE
       
    85 
       
    86 #if defined(QT_OPENGL_ES_2)
       
    87 #   include <GLES2/gl2.h>
       
    88 #endif
       
    89 
       
    90 #if defined(QT_GLES_EGL)
       
    91 #   include <GLES/egl.h>
       
    92 #else
       
    93 #   include <EGL/egl.h>
       
    94 #endif
       
    95 
       
    96 QT_END_INCLUDE_NAMESPACE
       
    97 #endif
    69 #endif
    98 
    70 
    99 QT_BEGIN_NAMESPACE
    71 QT_BEGIN_NAMESPACE
   100 
    72 
   101 class QGLContext;
    73 class QGLContext;
   122 
    94 
   123 #ifdef Q_WS_QWS
    95 #ifdef Q_WS_QWS
   124 class QWSGLWindowSurface;
    96 class QWSGLWindowSurface;
   125 #endif
    97 #endif
   126 
    98 
   127 #if defined(QT_OPENGL_ES)
    99 #ifndef QT_NO_EGL
   128 class QEglContext;
   100 class QEglContext;
   129 #endif
   101 #endif
   130 
   102 
   131 QT_BEGIN_INCLUDE_NAMESPACE
   103 QT_BEGIN_INCLUDE_NAMESPACE
   132 #include <QtOpenGL/private/qglextensions_p.h>
   104 #include <QtOpenGL/private/qglextensions_p.h>
   136 {
   108 {
   137 public:
   109 public:
   138     QGLFormatPrivate()
   110     QGLFormatPrivate()
   139         : ref(1)
   111         : ref(1)
   140     {
   112     {
   141         opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering | QGL::StencilBuffer;
   113         opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering
       
   114              | QGL::StencilBuffer | QGL::DeprecatedFunctions;
   142         pln = 0;
   115         pln = 0;
   143         depthSize = accumSize = stencilSize = redSize = greenSize = blueSize = alphaSize = -1;
   116         depthSize = accumSize = stencilSize = redSize = greenSize = blueSize = alphaSize = -1;
   144         numSamples = -1;
   117         numSamples = -1;
   145         swapInterval = -1;
   118         swapInterval = -1;
       
   119         majorVersion = 1;
       
   120         minorVersion = 0;
       
   121         profile = QGLFormat::NoProfile;
   146     }
   122     }
   147     QGLFormatPrivate(const QGLFormatPrivate *other)
   123     QGLFormatPrivate(const QGLFormatPrivate *other)
   148         : ref(1),
   124         : ref(1),
   149           opts(other->opts),
   125           opts(other->opts),
   150           pln(other->pln),
   126           pln(other->pln),
   154           redSize(other->redSize),
   130           redSize(other->redSize),
   155           greenSize(other->greenSize),
   131           greenSize(other->greenSize),
   156           blueSize(other->blueSize),
   132           blueSize(other->blueSize),
   157           alphaSize(other->alphaSize),
   133           alphaSize(other->alphaSize),
   158           numSamples(other->numSamples),
   134           numSamples(other->numSamples),
   159           swapInterval(other->swapInterval)
   135           swapInterval(other->swapInterval),
       
   136           majorVersion(other->majorVersion),
       
   137           minorVersion(other->minorVersion),
       
   138           profile(other->profile)
   160     {
   139     {
   161     }
   140     }
   162     QAtomicInt ref;
   141     QAtomicInt ref;
   163     QGL::FormatOptions opts;
   142     QGL::FormatOptions opts;
   164     int pln;
   143     int pln;
   169     int greenSize;
   148     int greenSize;
   170     int blueSize;
   149     int blueSize;
   171     int alphaSize;
   150     int alphaSize;
   172     int numSamples;
   151     int numSamples;
   173     int swapInterval;
   152     int swapInterval;
       
   153     int majorVersion;
       
   154     int minorVersion;
       
   155     QGLFormat::OpenGLContextProfile profile;
   174 };
   156 };
   175 
   157 
   176 class QGLWidgetPrivate : public QWidgetPrivate
   158 class QGLWidgetPrivate : public QWidgetPrivate
   177 {
   159 {
   178     Q_DECLARE_PUBLIC(QGLWidget)
   160     Q_DECLARE_PUBLIC(QGLWidget)
   180     QGLWidgetPrivate() : QWidgetPrivate()
   162     QGLWidgetPrivate() : QWidgetPrivate()
   181                        , disable_clear_on_painter_begin(false)
   163                        , disable_clear_on_painter_begin(false)
   182 #ifdef Q_WS_QWS
   164 #ifdef Q_WS_QWS
   183                        , wsurf(0)
   165                        , wsurf(0)
   184 #endif
   166 #endif
   185 #if defined(Q_WS_X11) && defined(QT_OPENGL_ES)
   167 #if defined(Q_WS_X11) && !defined(QT_NO_EGL)
   186                        , eglSurfaceWindowId(0)
   168                        , eglSurfaceWindowId(0)
   187 #endif
   169 #endif
   188     {
   170     {
   189         isGLWidget = 1;
   171         isGLWidget = 1;
   190     }
   172     }
   210 #if defined(Q_WS_WIN)
   192 #if defined(Q_WS_WIN)
   211     void updateColormap();
   193     void updateColormap();
   212     QGLContext *olcx;
   194     QGLContext *olcx;
   213 #elif defined(Q_WS_X11)
   195 #elif defined(Q_WS_X11)
   214     QGLOverlayWidget *olw;
   196     QGLOverlayWidget *olw;
   215 #if defined(QT_OPENGL_ES)
   197 #ifndef QT_NO_EGL
   216     void recreateEglSurface(bool force);
   198     void recreateEglSurface();
   217     WId eglSurfaceWindowId;
   199     WId eglSurfaceWindowId;
   218 #endif
   200 #endif
   219 #elif defined(Q_WS_MAC)
   201 #elif defined(Q_WS_MAC)
   220     QGLContext *olcx;
   202     QGLContext *olcx;
   221     void updatePaintDevice();
   203     void updatePaintDevice();
   294         FragmentShader          = 0x00040000
   276         FragmentShader          = 0x00040000
   295     };
   277     };
   296     Q_DECLARE_FLAGS(Extensions, Extension)
   278     Q_DECLARE_FLAGS(Extensions, Extension)
   297 
   279 
   298     static Extensions glExtensions();
   280     static Extensions glExtensions();
   299 
       
   300 private:
       
   301     static Extensions currentContextExtensions();
   281     static Extensions currentContextExtensions();
   302 };
   282 };
   303 
   283 
   304 /*
   284 /*
   305     QGLTemporaryContext - the main objective of this class is to have a way of
   285     QGLTemporaryContext - the main objective of this class is to have a way of
   350 
   330 
   351     void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true);
   331     void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true);
   352     void syncGlState(); // Makes sure the GL context's state is what we think it is
   332     void syncGlState(); // Makes sure the GL context's state is what we think it is
   353 
   333 
   354 #if defined(Q_WS_WIN)
   334 #if defined(Q_WS_WIN)
       
   335     void updateFormatVersion();
       
   336 #endif
       
   337 
       
   338 #if defined(Q_WS_WIN)
   355     HGLRC rc;
   339     HGLRC rc;
   356     HDC dc;
   340     HDC dc;
   357     WId        win;
   341     WId        win;
   358     int pixelFormatId;
   342     int pixelFormatId;
   359     QGLCmap* cmap;
   343     QGLCmap* cmap;
   360     HBITMAP hbitmap;
   344     HBITMAP hbitmap;
   361     HDC hbitmap_hdc;
   345     HDC hbitmap_hdc;
   362 #endif
   346 #endif
   363 #if defined(QT_OPENGL_ES)
   347 #ifndef QT_NO_EGL
       
   348     uint ownsEglContext : 1;
   364     QEglContext *eglContext;
   349     QEglContext *eglContext;
   365     EGLSurface eglSurface;
   350     EGLSurface eglSurface;
   366     void destroyEglSurfaceForDevice();
   351     void destroyEglSurfaceForDevice();
       
   352     EGLSurface eglSurfaceForDevice() const;
   367 #elif defined(Q_WS_X11) || defined(Q_WS_MAC)
   353 #elif defined(Q_WS_X11) || defined(Q_WS_MAC)
   368     void* cx;
   354     void* cx;
   369 #endif
   355 #endif
   370 #if defined(Q_WS_X11) || defined(Q_WS_MAC)
   356 #if defined(Q_WS_X11) || defined(Q_WS_MAC)
   371     void* vi;
   357     void* vi;
   373 #if defined(Q_WS_X11)
   359 #if defined(Q_WS_X11)
   374     void* pbuf;
   360     void* pbuf;
   375     quint32 gpm;
   361     quint32 gpm;
   376     int screen;
   362     int screen;
   377     QHash<QPixmapData*, QPixmap> boundPixmaps;
   363     QHash<QPixmapData*, QPixmap> boundPixmaps;
   378     QGLTexture *bindTextureFromNativePixmap(QPixmapData*, const qint64 key,
   364     QGLTexture *bindTextureFromNativePixmap(QPixmap*, const qint64 key,
   379                                             QGLContext::BindOptions options);
   365                                             QGLContext::BindOptions options);
   380     static void destroyGlSurfaceForPixmap(QPixmapData*);
   366     static void destroyGlSurfaceForPixmap(QPixmapData*);
   381     static void unbindPixmapFromTexture(QPixmapData*);
   367     static void unbindPixmapFromTexture(QPixmapData*);
   382 #endif
   368 #endif
   383 #if defined(Q_WS_MAC)
   369 #if defined(Q_WS_MAC)
   394     uint initDone : 1;
   380     uint initDone : 1;
   395     uint crWin : 1;
   381     uint crWin : 1;
   396     uint internal_context : 1;
   382     uint internal_context : 1;
   397     uint version_flags_cached : 1;
   383     uint version_flags_cached : 1;
   398     uint extension_flags_cached : 1;
   384     uint extension_flags_cached : 1;
       
   385 
       
   386     // workarounds for driver/hw bugs on different platforms
       
   387     uint workaround_needsFullClearOnEveryFrame : 1;
       
   388     uint workaround_brokenFBOReadBack : 1;
       
   389     uint workaroundsCached : 1;
       
   390 
   399     QPaintDevice *paintDevice;
   391     QPaintDevice *paintDevice;
   400     QColor transpColor;
   392     QColor transpColor;
   401     QGLContext *q_ptr;
   393     QGLContext *q_ptr;
   402     QGLFormat::OpenGLVersionFlags version_flags;
   394     QGLFormat::OpenGLVersionFlags version_flags;
   403     QGLExtensions::Extensions extension_flags;
   395     QGLExtensions::Extensions extension_flags;
   534 public:
   526 public:
   535     QGLTextureCache();
   527     QGLTextureCache();
   536     ~QGLTextureCache();
   528     ~QGLTextureCache();
   537 
   529 
   538     void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost);
   530     void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost);
   539     void remove(quint64 key) { m_cache.remove(key); }
   531     inline void remove(quint64 key);
       
   532     inline int size();
       
   533     inline void setMaxCost(int newMax);
       
   534     inline int maxCost();
       
   535     inline QGLTexture* getTexture(quint64 key);
       
   536 
   540     bool remove(QGLContext *ctx, GLuint textureId);
   537     bool remove(QGLContext *ctx, GLuint textureId);
   541     void removeContextTextures(QGLContext *ctx);
   538     void removeContextTextures(QGLContext *ctx);
   542     int size() { return m_cache.size(); }
       
   543     void setMaxCost(int newMax) { m_cache.setMaxCost(newMax); }
       
   544     int maxCost() {return m_cache.maxCost(); }
       
   545     QGLTexture* getTexture(quint64 key) { return m_cache.object(key); }
       
   546 
       
   547     static QGLTextureCache *instance();
   539     static QGLTextureCache *instance();
   548     static void deleteIfEmpty();
       
   549     static void cleanupTexturesForCacheKey(qint64 cacheKey);
   540     static void cleanupTexturesForCacheKey(qint64 cacheKey);
   550     static void cleanupTexturesForPixampData(QPixmapData* pixmap);
   541     static void cleanupTexturesForPixampData(QPixmapData* pixmap);
   551     static void cleanupBeforePixmapDestruction(QPixmapData* pixmap);
   542     static void cleanupBeforePixmapDestruction(QPixmapData* pixmap);
   552 
   543 
   553 private:
   544 private:
   554     QCache<qint64, QGLTexture> m_cache;
   545     QCache<qint64, QGLTexture> m_cache;
   555 };
   546     QReadWriteLock m_lock;
       
   547 };
       
   548 
       
   549 int QGLTextureCache::size() {
       
   550     QReadLocker locker(&m_lock);
       
   551     return m_cache.size();
       
   552 }
       
   553 
       
   554 void QGLTextureCache::setMaxCost(int newMax)
       
   555 {
       
   556     QWriteLocker locker(&m_lock);
       
   557     m_cache.setMaxCost(newMax);
       
   558 }
       
   559 
       
   560 int QGLTextureCache::maxCost()
       
   561 {
       
   562     QReadLocker locker(&m_lock);
       
   563     return m_cache.maxCost();
       
   564 }
       
   565 
       
   566 QGLTexture* QGLTextureCache::getTexture(quint64 key)
       
   567 {
       
   568     QReadLocker locker(&m_lock);
       
   569     return m_cache.object(key);
       
   570 }
       
   571 
       
   572 void QGLTextureCache::remove(quint64 key)
       
   573 {
       
   574     QWriteLocker locker(&m_lock);
       
   575     m_cache.remove(key);
       
   576 }
   556 
   577 
   557 
   578 
   558 extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine();
   579 extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine();
   559 
   580 
   560 bool qt_gl_preferGL2Engine();
   581 bool qt_gl_preferGL2Engine();