⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgl_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    bool ok = eglMakeCurrent(d->dpy, d->surface, d->surface, d->cx);    if (!ok) {        EGLint err = eglGetError();        qWarning("QGLContext::makeCurrent(): Failed %x.", err);    }    if (ok) {#endif        if (!qgl_context_storage.hasLocalData() && QThread::currentThread())            qgl_context_storage.setLocalData(new QGLThreadContext);        if (qgl_context_storage.hasLocalData())            qgl_context_storage.localData()->context = this;        currentCtx = this;#ifndef Q_USE_EGLWINDOWSURFACE    }#else#if 0    if (device()->devType() == QInternal::Widget) {        // EGL Only works if drawable is a QGLWidget. QGLFramebufferObject, QGLPixelBuffer not supported        static_cast<QGLWidget*>(device())->d_func()->wsurf->beginPaint(QRegion());    }#endif#endif}void QGLContext::doneCurrent(){#ifndef Q_USE_EGLWINDOWSURFACE    Q_D(QGLContext);    eglMakeCurrent(d->dpy, d->surface, d->surface, 0);#endif    QT_EGL_ERR("QGLContext::doneCurrent");    if (qgl_context_storage.hasLocalData())        qgl_context_storage.localData()->context = 0;    currentCtx = 0;#if 0#ifdef Q_USE_EGLWINDOWSURFACE    if (device()->devType() == QInternal::Widget) {        // EGL Only works if drawable is a QGLWidget, QGLFramebufferObject, QGLPixelBuffer not supported        static_cast<QGLWidget*>(device())->d_func()->wsurf->endPaint(QRegion());    }#endif#endif}void QGLContext::swapBuffers() const{    Q_D(const QGLContext);    if(!d->valid)        return;#ifndef Q_USE_EGLWINDOWSURFACE    eglSwapBuffers(d->dpy, d->surface);#else    if (device()->devType() == QInternal::Widget) {        // EGL Only works if drawable is a QGLWidget, QGLPixelBuffer not supported        QGLWidget *widget = static_cast<QGLWidget*>(device());        widget->d_func()->wsurf->flush(widget, widget->frameGeometry(), QPoint());    }#endif    QT_EGL_ERR("QGLContext::swapBuffers");}QColor QGLContext::overlayTransparentColor() const{    return QColor(0, 0, 0);                // Invalid color}uint QGLContext::colorIndex(const QColor &c) const{    //### color index doesn't work on egl    Q_UNUSED(c);    return 0;}void QGLContext::generateFontDisplayLists(const QFont & fnt, int listBase){    Q_UNUSED(fnt);    Q_UNUSED(listBase);}void *QGLContext::getProcAddress(const QString &proc) const{    return (void*)eglGetProcAddress(reinterpret_cast<const char *>(proc.toLatin1().data()));}#ifdef Q_USE_DIRECTPAINTERclass QGLDirectPainter : public QDirectPainter{public:    QGLDirectPainter(QGLContextPrivate *cd, QGLWidgetPrivate *wd) :glxPriv(cd), glwPriv(wd), image(0), nativePix(0) {}    ~QGLDirectPainter() {    }    void regionChanged(const QRegion &);    void render();    QRect geom;    QGLContextPrivate *glxPriv;    QGLWidgetPrivate *glwPriv;    QImage *image;    NativeWindowType nativePix;};void QGLDirectPainter::regionChanged(const QRegion&){#ifdef Q_USE_QEGL    if (geometry() != geom) {        geom = geometry();        uchar *fbp = QDirectPainter::frameBuffer() + geom.top() * QDirectPainter::linestep()                     + ((QDirectPainter::screenDepth()+7)/8) * geom.left();        QImage *oldImage = image;        NativeWindowType oldPix = nativePix;        image = new QImage(fbp, geom.width(), geom.height(), QDirectPainter::screenDepth(),                           QDirectPainter::linestep(), 0, 0, QImage::IgnoreEndian);#if 0 // debug        static int i = 0;        i = (i+13) %255;        for (int y = 0; y < image->height(); ++y)            for (int x = 0; x < image->width(); ++x)                image->setPixel(x, y, 0xff4000 + i);#endif        QT_EGL_ERR("before eglDestroySurface");        if (glxPriv->surface != EGL_NO_SURFACE) {            eglDestroySurface(glxPriv->dpy, glxPriv->surface);            QT_EGL_ERR("eglDestroySurface");        }#if 1        nativePix = QEGL::createNativePixmap(image);        glxPriv->surface =    eglCreatePixmapSurface(glxPriv->dpy, glxPriv->config, nativePix, 0);////const EGLint *attrib list);#else#endif        QT_EGL_ERR("createEGLSurface");        glxPriv->valid =  glxPriv->surface != EGL_NO_SURFACE;        glwPriv->resizeHandler(geom.size());        delete oldImage;        QEGL::destroyNativePixmap(oldPix);    }#endif    if (0) {    QRegion alloc = allocatedRegion();    int max = 0;    QRect allocR;    for (int i=0; i < alloc.rects().count(); ++i) {        QRect r = alloc.rects().at(i);        int a = r.width()*r.height();        if (a  > max) {            max = a;            allocR = r;        }    }    allocR.translate(-geom.topLeft());    glScissor(allocR.left(), geom.height() - allocR.bottom(), allocR.width(), allocR.height());    glwPriv->render(allocR);    }}#elseclass QWSGLPrivate{public:    QWSGLPrivate() : img(0), oldbsimg(0), nativePix(0), dirty(true) {}    QImage *img;    QImage *oldbsimg;    NativeWindowType nativePix;    bool dirty;};class QGLDirectPainter : public QWSGLPrivate {}; //####endif // Q_USE_DIRECTPAINTERvoid QGLWidgetPrivate::render(const QRegion &r){    Q_Q(QGLWidget);    QPaintEvent e(r);    q->paintEvent(&e); //### slightly hacky...}void QGLWidgetPrivate::resizeHandler(const QSize &s){    Q_Q(QGLWidget);    q->makeCurrent();    if (!glcx->initialized())        q->glInit();#ifndef Q_USE_EGLWINDOWSURFACE    eglWaitNative(EGL_CORE_NATIVE_ENGINE);#endif    QT_EGL_ERR("QGLWidgetPrivate::resizeHandler");    q->resizeGL(s.width(), s.height());}bool QGLWidget::event(QEvent *e){#if 0 // ??? we have to make sure update() works...    if (e->type() == QEvent::Paint)        return true; // We don't paint when the GL widget needs to be painted, but when the directpainter does#endif#ifdef Q_USE_EGLWINDOWSURFACE    return QWidget::event(e); // for EGL/GLES windowsurface do nothing in ::event()#else#ifndef Q_USE_DIRECTPAINTER    if (e->type() == QEvent::Paint) {        Q_D(QGLWidget);        QWindowSurface *ws = d->currentWindowSurface();        Q_ASSERT(ws);        QImage *bsImage = static_cast<QImage*>(ws->paintDevice());        if (bsImage            && (bsImage != d->directPainter->oldbsimg || !d->directPainter->img ||d->directPainter->img->size() != size())) {            QPoint offs = mapToGlobal(QPoint(0,0)) - window()->frameGeometry().topLeft();            uchar *fbp = bsImage->bits() + offs.y() * bsImage->bytesPerLine()                         + ((bsImage->depth()+7)/8) * offs.x();            QImage *oldImage = d->directPainter->img;            d->directPainter->img = new QImage(fbp, width(), height(), bsImage->depth(),                                            bsImage->bytesPerLine(), 0, 0, QImage::IgnoreEndian);            QGLContextPrivate *glxPriv = d->glcx->d_func();            if (glxPriv->surface != EGL_NO_SURFACE) {                eglDestroySurface(glxPriv->dpy, glxPriv->surface);                QT_EGL_ERR("eglDestroySurface");            }            NativeWindowType nativePix = QEGL::createNativePixmap(d->directPainter->img);            glxPriv->surface = eglCreatePixmapSurface(glxPriv->dpy, glxPriv->config, nativePix, 0);            glxPriv->valid =  glxPriv->surface != EGL_NO_SURFACE;            delete oldImage;            QEGL::destroyNativePixmap(d->directPainter->nativePix);            d->directPainter->nativePix = nativePix;        }    }#endif#endif    return QWidget::event(e);}void QGLWidget::setMouseTracking(bool enable){    QWidget::setMouseTracking(enable);}void QGLWidget::resizeEvent(QResizeEvent *){    Q_D(QGLWidget);//     if (!isValid())//         return;#ifdef Q_USE_DIRECTPAINTER    if (!d->directPainter)        d->directPainter = new QGLDirectPainter(d->glcx->d_func(), d);    d->directPainter->setGeometry(geometry());#else    if (!d->directPainter)        d->directPainter = new QGLDirectPainter;#endif    //handle overlay}const QGLContext* QGLWidget::overlayContext() const{    return 0;}void QGLWidget::makeOverlayCurrent(){    //handle overlay}void QGLWidget::updateOverlayGL(){    //handle overlay}void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, bool deleteOldContext){    Q_D(QGLWidget);    if(context == 0) {        qWarning("QGLWidget::setContext: Cannot set null context");        return;    }    if(d->glcx)        d->glcx->doneCurrent();    QGLContext* oldcx = d->glcx;    d->glcx = context;    if(!d->glcx->isValid())        d->glcx->create(shareContext ? shareContext : oldcx);    if(deleteOldContext)        delete oldcx;}void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget* shareWidget){    Q_Q(QGLWidget);    directPainter = 0;#ifdef Q_USE_EGLWINDOWSURFACE    wsurf = static_cast<QWSGLWindowSurface*>(QScreen::instance()->createSurface(q));    q->setWindowSurface(wsurf);#endif    initContext(context, shareWidget);    if(q->isValid() && glcx->format().hasOverlay()) {        //no overlay        qWarning("QtOpenGL ES doesn't currently support overlays");    }}bool QGLWidgetPrivate::renderCxPm(QPixmap*){    return false;}void QGLWidgetPrivate::cleanupColormaps(){}const QGLColormap & QGLWidget::colormap() const{    return d_func()->cmap;}void QGLWidget::setColormap(const QGLColormap &){}void QGLExtensions::init(){    static bool init_done = false;    if (init_done)        return;    init_done = true;#if 0 //### to avoid confusing experimental EGL: don't create two GL widgets    QGLWidget dmy;    dmy.makeCurrent();    init_extensions();#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -