Ignore:
Timestamp:
Mar 8, 2010, 12:52:58 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.2 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qgl_p.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    223223
    224224// QGLContextPrivate has the responsibility of creating context groups.
    225 // QGLContextPrivate and QGLShareRegister will both maintain the reference counter and destroy
     225// QGLContextPrivate
    226226// context groups when needed.
    227 // QGLShareRegister has the responsibility of keeping the context pointer up to date.
    228227class QGLContextGroup
    229228{
     
    234233    const QGLContext *context() const {return m_context;}
    235234    bool isSharing() const { return m_shares.size() >= 2; }
     235
    236236
    237237    void addGuard(QGLSharedResourceGuard *guard);
    238238    void removeGuard(QGLSharedResourceGuard *guard);
     239
     240
     241
    239242private:
    240243    QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { }
     
    250253    void cleanupResources(const QGLContext *ctx);
    251254
    252     friend class QGLShareRegister;
    253255    friend class QGLContext;
    254256    friend class QGLContextPrivate;
     
    256258};
    257259
    258 class QGLTexture;
    259 
    260 class QGLContextPrivate
    261 {
    262     Q_DECLARE_PUBLIC(QGLContext)
    263 public:
    264     explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);}
    265     ~QGLContextPrivate();
    266     QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format,
    267                             QGLContext::BindOptions options);
    268     QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format, const qint64 key,
    269                             QGLContext::BindOptions options);
    270     QGLTexture *bindTexture(const QPixmap &pixmap, GLenum target, GLint format,
    271                             QGLContext::BindOptions options);
    272     QGLTexture *textureCacheLookup(const qint64 key, GLenum target);
    273     void init(QPaintDevice *dev, const QGLFormat &format);
    274     QImage convertToGLFormat(const QImage &image, bool force_premul, GLenum texture_format);
    275     int maxTextureSize();
    276 
    277     void cleanup();
    278 
    279 #if defined(Q_WS_WIN)
    280     HGLRC rc;
    281     HDC dc;
    282     WId        win;
    283     int pixelFormatId;
    284     QGLCmap* cmap;
    285     HBITMAP hbitmap;
    286     HDC hbitmap_hdc;
    287 #endif
    288 #if defined(QT_OPENGL_ES)
    289     QEglContext *eglContext;
    290     EGLSurface eglSurface;
    291     void destroyEglSurfaceForDevice();
    292 #elif defined(Q_WS_X11) || defined(Q_WS_MAC)
    293     void* cx;
    294 #endif
    295 #if defined(Q_WS_X11) || defined(Q_WS_MAC)
    296     void* vi;
    297 #endif
    298 #if defined(Q_WS_X11)
    299     void* pbuf;
    300     quint32 gpm;
    301     int screen;
    302     QHash<QPixmapData*, QPixmap> boundPixmaps;
    303     QGLTexture *bindTextureFromNativePixmap(QPixmapData*, const qint64 key,
    304                                             QGLContext::BindOptions options);
    305     static void destroyGlSurfaceForPixmap(QPixmapData*);
    306     static void unbindPixmapFromTexture(QPixmapData*);
    307 #endif
    308 #if defined(Q_WS_MAC)
    309     bool update;
    310     void *tryFormat(const QGLFormat &format);
    311     void clearDrawable();
    312 #endif
    313     QGLFormat glFormat;
    314     QGLFormat reqFormat;
    315     GLuint fbo;
    316 
    317     uint valid : 1;
    318     uint sharing : 1;
    319     uint initDone : 1;
    320     uint crWin : 1;
    321     uint internal_context : 1;
    322     uint version_flags_cached : 1;
    323     QPaintDevice *paintDevice;
    324     QColor transpColor;
    325     QGLContext *q_ptr;
    326     QGLFormat::OpenGLVersionFlags version_flags;
    327 
    328     QGLContextGroup *group;
    329     GLint max_texture_size;
    330 
    331     GLuint current_fbo;
    332     GLuint default_fbo;
    333     QPaintEngine *active_engine;
    334 
    335     static inline QGLContextGroup *contextGroup(const QGLContext *ctx) { return ctx->d_ptr->group; }
    336 
    337 #ifdef Q_WS_WIN
    338     static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); }
    339 #endif
    340 
    341 #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
    342     static QGLExtensionFuncs qt_extensionFuncs;
    343     static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; }
    344 #endif
    345 
    346     static void setCurrentContext(QGLContext *context);
    347 };
    348 
    349 // ### make QGLContext a QObject in 5.0 and remove the proxy stuff
    350 class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
    351 {
    352     Q_OBJECT
    353 public:
    354     QGLSignalProxy() : QObject() {}
    355     void emitAboutToDestroyContext(const QGLContext *context) {
    356         emit aboutToDestroyContext(context);
    357     }
    358     static QGLSignalProxy *instance();
    359 Q_SIGNALS:
    360     void aboutToDestroyContext(const QGLContext *context);
    361 };
     260// Get the context that resources for "ctx" will transfer to once
     261// "ctx" is destroyed.  Returns null if nothing is sharing with ctx.
     262Q_OPENGL_EXPORT const QGLContext *qt_gl_transfer_context(const QGLContext *);
    362263
    363264// GL extension definitions
     
    387288    Q_DECLARE_FLAGS(Extensions, Extension)
    388289
    389     static Extensions glExtensions;
    390     static bool nvidiaFboNeedsFinish;
    391     static void init(); // sys dependent
    392     static void init_extensions(); // general: called by init()
     290    static Extensions glExtensions();
     291
     292private:
     293    static Extensions currentContextExtensions();
     294};
     295
     296/*
     297    QGLTemporaryContext - the main objective of this class is to have a way of
     298    creating a GL context and making it current, without going via QGLWidget
     299    and friends. At certain points during GL initialization we need a current
     300    context in order decide what GL features are available, and to resolve GL
     301    extensions. Having a light-weight way of creating such a context saves
     302    initial application startup time, and it doesn't wind up creating recursive
     303    conflicts.
     304    The class currently uses a private d pointer to hide the platform specific
     305    types. This could possibly been done inline with #ifdef'ery, but it causes
     306    major headaches on e.g. X11 due to namespace pollution.
     307*/
     308class QGLTemporaryContextPrivate;
     309class QGLTemporaryContext {
     310public:
     311    QGLTemporaryContext(bool directRendering = true, QWidget *parent = 0);
     312    ~QGLTemporaryContext();
     313
     314private:
     315    QScopedPointer<QGLTemporaryContextPrivate> d;
     316};
     317
     318class QGLTexture;
     319
     320// This probably needs to grow to GL_MAX_VERTEX_ATTRIBS, but 3 is ok for now as that's
     321// all the GL2 engine uses:
     322#define QT_GL_VERTEX_ARRAY_TRACKED_COUNT 3
     323
     324class QGLContextPrivate
     325{
     326    Q_DECLARE_PUBLIC(QGLContext)
     327public:
     328    explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);}
     329    ~QGLContextPrivate();
     330    QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format,
     331                            QGLContext::BindOptions options);
     332    QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format, const qint64 key,
     333                            QGLContext::BindOptions options);
     334    QGLTexture *bindTexture(const QPixmap &pixmap, GLenum target, GLint format,
     335                            QGLContext::BindOptions options);
     336    QGLTexture *textureCacheLookup(const qint64 key, GLenum target);
     337    void init(QPaintDevice *dev, const QGLFormat &format);
     338    QImage convertToGLFormat(const QImage &image, bool force_premul, GLenum texture_format);
     339    int maxTextureSize();
     340
     341    void cleanup();
     342
     343    void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true);
     344    void syncGlState(); // Makes sure the GL context's state is what we think it is
     345
     346#if defined(Q_WS_WIN)
     347    HGLRC rc;
     348    HDC dc;
     349    WId        win;
     350    int pixelFormatId;
     351    QGLCmap* cmap;
     352    HBITMAP hbitmap;
     353    HDC hbitmap_hdc;
     354#endif
     355#if defined(QT_OPENGL_ES)
     356    QEglContext *eglContext;
     357    EGLSurface eglSurface;
     358    void destroyEglSurfaceForDevice();
     359#elif defined(Q_WS_X11) || defined(Q_WS_MAC)
     360    void* cx;
     361#endif
     362#if defined(Q_WS_X11) || defined(Q_WS_MAC)
     363    void* vi;
     364#endif
     365#if defined(Q_WS_X11)
     366    void* pbuf;
     367    quint32 gpm;
     368    int screen;
     369    QHash<QPixmapData*, QPixmap> boundPixmaps;
     370    QGLTexture *bindTextureFromNativePixmap(QPixmapData*, const qint64 key,
     371                                            QGLContext::BindOptions options);
     372    static void destroyGlSurfaceForPixmap(QPixmapData*);
     373    static void unbindPixmapFromTexture(QPixmapData*);
     374#endif
     375#if defined(Q_WS_MAC)
     376    bool update;
     377    void *tryFormat(const QGLFormat &format);
     378    void clearDrawable();
     379#endif
     380    QGLFormat glFormat;
     381    QGLFormat reqFormat;
     382    GLuint fbo;
     383
     384    uint valid : 1;
     385    uint sharing : 1;
     386    uint initDone : 1;
     387    uint crWin : 1;
     388    uint internal_context : 1;
     389    uint version_flags_cached : 1;
     390    uint extension_flags_cached : 1;
     391    QPaintDevice *paintDevice;
     392    QColor transpColor;
     393    QGLContext *q_ptr;
     394    QGLFormat::OpenGLVersionFlags version_flags;
     395    QGLExtensions::Extensions extension_flags;
     396
     397    QGLContextGroup *group;
     398    GLint max_texture_size;
     399
     400    GLuint current_fbo;
     401    GLuint default_fbo;
     402    QPaintEngine *active_engine;
     403
     404    bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT];
     405
     406    static inline QGLContextGroup *contextGroup(const QGLContext *ctx) { return ctx->d_ptr->group; }
     407
     408#ifdef Q_WS_WIN
     409    static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); }
     410#endif
     411
     412#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
     413    static QGLExtensionFuncs qt_extensionFuncs;
     414    static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; }
     415#endif
     416
     417    static void setCurrentContext(QGLContext *context);
     418};
     419
     420// ### make QGLContext a QObject in 5.0 and remove the proxy stuff
     421class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
     422{
     423    Q_OBJECT
     424public:
     425    QGLSignalProxy() : QObject() {}
     426    void emitAboutToDestroyContext(const QGLContext *context) {
     427        emit aboutToDestroyContext(context);
     428    }
     429    static QGLSignalProxy *instance();
     430Q_SIGNALS:
     431    void aboutToDestroyContext(const QGLContext *context);
    393432};
    394433
    395434Q_DECLARE_OPERATORS_FOR_FLAGS(QGLExtensions::Extensions)
    396 
    397 
    398 class Q_OPENGL_EXPORT QGLShareRegister
    399 {
    400 public:
    401     QGLShareRegister() {}
    402     ~QGLShareRegister() {}
    403 
    404     void addShare(const QGLContext *context, const QGLContext *share);
    405     QList<const QGLContext *> shares(const QGLContext *context);
    406     void removeShare(const QGLContext *context);
    407 };
    408 
    409 extern Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg();
    410435
    411436// Temporarily make a context current if not already current or
     
    498523};
    499524
    500 class QGLTextureCache {
     525class QGLTextureCache {
    501526public:
    502527    QGLTextureCache();
     
    515540    static void deleteIfEmpty();
    516541    static void imageCleanupHook(qint64 cacheKey);
    517     static void cleanupTextures(QPixmap* pixmap);
    518 #ifdef Q_WS_X11
    519     // X11 needs to catch pixmap data destruction to delete EGL/GLX pixmap surfaces
    520     static void cleanupPixmapSurfaces(QPixmap* pixmap);
    521 #endif
     542    static void cleanupTextures(QPixmapData* pixmap);
     543    static void cleanupBeforePixmapDestruction(QPixmapData* pixmap);
    522544
    523545private:
     
    532554inline GLenum qt_gl_preferredTextureFormat()
    533555{
    534     return (QGLExtensions::glExtensions & QGLExtensions::BGRATextureFormat) && QSysInfo::ByteOrder == QSysInfo::LittleEndian
     556    return (QGLExtensions::glExtensions & QGLExtensions::BGRATextureFormat) && QSysInfo::ByteOrder == QSysInfo::LittleEndian
    535557        ? GL_BGRA : GL_RGBA;
    536558}
     
    541563    return GL_TEXTURE_2D;
    542564#else
    543     return (QGLExtensions::glExtensions & QGLExtensions::TextureRectangle)
     565    return (QGLExtensions::glExtensions & QGLExtensions::TextureRectangle)
    544566           && !qt_gl_preferGL2Engine()
    545567           ? GL_TEXTURE_RECTANGLE_NV
     
    613635
    614636
    615 // This class can be used to match GL extensions with doing any mallocs. The
     637// This class can be used to match GL extensions with doing any mallocs. The
    616638// class assumes that the GL extension string ends with a space character,
    617639// which it should do on all conformant platforms. Create the object and pass
Note: See TracChangeset for help on using the changeset viewer.