Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qglpixelbuffer_egl.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtOpenGL module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4848#include <private/qgl_p.h>
    4949
     50#ifdef QT_OPENGL_ES_1_CL
     51#include "qgl_cl_p.h"
     52#endif
     53
    5054QT_BEGIN_NAMESPACE
    5155
     
    6064    // Create the EGL context.
    6165    ctx = new QEglContext();
    62     ctx->setApi(QEglContext::OpenGL);
     66    ctx->setApi(QEgl::OpenGL);
    6367
    6468    // Open the EGL display.
     
    6973    }
    7074
     75    // Find the shared context.
     76    QEglContext *shareContext = 0;
     77    if (shareWidget && shareWidget->d_func()->glcx)
     78        shareContext = shareWidget->d_func()->glcx->d_func()->eglContext;
     79
    7180    // Choose an appropriate configuration.  We use the best format
    7281    // we can find, even if it is greater than the requested format.
    7382    // We try for a pbuffer that is capable of texture rendering if possible.
    74     QEglProperties configProps;
    75     qt_egl_set_format(configProps, QInternal::Pbuffer, f);
    76     configProps.setRenderableType(ctx->api());
    77     bool ok = false;
    78 #if QGL_RENDER_TEXTURE
    79     textureFormat = EGL_TEXTURE_RGBA;
    80     configProps.setValue(EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE);
    81     ok = ctx->chooseConfig(configProps, QEglContext::BestPixelFormat);
    82     if (!ok) {
    83         // Try again with RGB texture rendering.
    84         textureFormat = EGL_TEXTURE_RGB;
    85         configProps.removeValue(EGL_BIND_TO_TEXTURE_RGBA);
    86         configProps.setValue(EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE);
    87         ok = ctx->chooseConfig(configProps, QEglContext::BestPixelFormat);
     83    textureFormat = EGL_NONE;
     84    if (shareContext) {
     85        // Use the same configuration as the widget we are sharing with.
     86        ctx->setConfig(shareContext->config());
     87#if QGL_RENDER_TEXTURE
     88        EGLint value = EGL_FALSE;
     89        if (ctx->configAttrib(EGL_BIND_TO_TEXTURE_RGBA, &value) && value)
     90            textureFormat = EGL_TEXTURE_RGBA;
     91        else if (ctx->configAttrib(EGL_BIND_TO_TEXTURE_RGB, &value) && value)
     92            textureFormat = EGL_TEXTURE_RGB;
     93#endif
     94    } else {
     95        QEglProperties configProps;
     96        qt_egl_set_format(configProps, QInternal::Pbuffer, f);
     97        configProps.setRenderableType(ctx->api());
     98        bool ok = false;
     99#if QGL_RENDER_TEXTURE
     100        textureFormat = EGL_TEXTURE_RGBA;
     101        configProps.setValue(EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE);
     102        ok = ctx->chooseConfig(configProps, QEgl::BestPixelFormat);
    88103        if (!ok) {
    89             // One last try for a pbuffer with no texture rendering.
    90             configProps.removeValue(EGL_BIND_TO_TEXTURE_RGB);
    91             textureFormat = EGL_NONE;
     104            // Try again with RGB texture rendering.
     105            textureFormat = EGL_TEXTURE_RGB;
     106            configProps.removeValue(EGL_BIND_TO_TEXTURE_RGBA);
     107            configProps.setValue(EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE);
     108            ok = ctx->chooseConfig(configProps, QEgl::BestPixelFormat);
     109            if (!ok) {
     110                // One last try for a pbuffer with no texture rendering.
     111                configProps.removeValue(EGL_BIND_TO_TEXTURE_RGB);
     112                textureFormat = EGL_NONE;
     113            }
    92114        }
    93     }
    94 #else
    95     textureFormat = EGL_NONE;
    96 #endif
    97     if (!ok) {
    98         if (!ctx->chooseConfig(configProps, QEglContext::BestPixelFormat)) {
    99             delete ctx;
    100             ctx = 0;
    101             return false;
     115#endif
     116        if (!ok) {
     117            if (!ctx->chooseConfig(configProps, QEgl::BestPixelFormat)) {
     118                delete ctx;
     119                ctx = 0;
     120                return false;
     121            }
    102122        }
    103123    }
     
    132152        return false;
    133153    }
    134     ctx->setSurface(pbuf);
    135154
    136155    // Create a new context for the configuration.
    137     QEglContext *shareContext = 0;
    138     if (shareWidget && shareWidget->d_func()->glcx)
    139         shareContext = shareWidget->d_func()->glcx->d_func()->eglContext;
    140156    if (!ctx->createContext(shareContext)) {
    141157        delete ctx;
     
    149165bool QGLPixelBufferPrivate::cleanup()
    150166{
    151     eglDestroySurface(QEglContext::defaultDisplay(0), pbuf);
     167    // No need to destroy "pbuf" here - it is done in QGLContext::reset().
    152168    return true;
    153169}
     
    160176        return false;
    161177    glBindTexture(GL_TEXTURE_2D, texture_id);
    162     return eglBindTexImage(d->ctx->display(), d->ctx->surface(), EGL_BACK_BUFFER);
     178    return eglBindTexImage(d->ctx->display(), d->pbuf, EGL_BACK_BUFFER);
    163179#else
    164180    Q_UNUSED(texture_id);
     
    173189    if (d->invalid || d->textureFormat == EGL_NONE || !d->ctx)
    174190        return;
    175     eglReleaseTexImage(d->ctx->display(), d->ctx->surface(), EGL_BACK_BUFFER);
     191    eglReleaseTexImage(d->ctx->display(), d->pbuf, EGL_BACK_BUFFER);
    176192#endif
    177193}
     
    189205    else
    190206        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, d->req_size.width(), d->req_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    191     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    192     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     207    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     208    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    193209    return texture;
    194210#else
     
    200216{
    201217    // See if we have at least 1 configuration that matches the default format.
    202     QEglContext ctx;
    203     if (!ctx.openDisplay(0))
     218    EGLDisplay dpy = QEglContext::defaultDisplay(0);
     219    if (dpy == EGL_NO_DISPLAY)
    204220        return false;
    205221    QEglProperties configProps;
    206222    qt_egl_set_format(configProps, QInternal::Pbuffer, QGLFormat::defaultFormat());
    207     configProps.setRenderableType(QEglContext::OpenGL);
    208     return ctx.chooseConfig(configProps);
     223    configProps.setRenderableType(QEgl::OpenGL);
     224    do {
     225        EGLConfig cfg = 0;
     226        EGLint matching = 0;
     227        if (eglChooseConfig(dpy, configProps.properties(),
     228                            &cfg, 1, &matching) && matching > 0)
     229            return true;
     230    } while (configProps.reduceConfiguration());
     231    return false;
    209232}
    210233
Note: See TracChangeset for help on using the changeset viewer.