[webkit-qt] WebGL rendering offscreen

Jorge Fernandez Monteagudo jorgefm at cirsa.com
Tue Nov 11 13:19:38 PST 2014


>>>
>>>See the documentation of QGraphicsView and especially setViewPort (
>>>http://qt-project.org/doc/qt-5/qgraphicsview.html ). In Qt 5.4 you can
>>>also use a QOpenGLWidget. It basically sets a specific widget as the
>>>output, qtwebkit can find that widget and use the same opengl-context in
>>>case it uses one. Without this qtwebkit would have its own widget that
>>>can mess with yours and would still need copying over CPU to blit
>>>textures.
>>
>> Only to clarify... Which I need QGraphicsView or QGraphicsWebView?? And
>> do you recommend me to update to Qt 5.4 or remain in the Qt 5.3.2?
>>
>You need both, the QGraphicsView hosts the scene graph and the
>QGraphicsWebView is an item in the scene. Qt 5.4 is not released yet, so for a
>stable development 5.3.2 is probably better, but 5.4 will be out before the
>end of the year.
>
>You can try looking in Tools/QtTestBrowser for an example that can both work
>with QWebView or a QGraphicsWebView, it is probably overcomplicated for your
>usecase, but it should demonstrate what is needed.
>

I've found a post with an example with the same structure you're talking about., if I'm
not wrong. It's a post from you and Jori Liesenborgs:

http://lists.qt-project.org/pipermail/interest/2014-March/011452.html

I've modified a little the demo code he posted (qtwebkit_gl.zip) and now I create
a custom QGLWidget instead of a normal QGLWidget. The code outlined in your
last email is something similar to the usegl==true branch:

MainWin::MainWin(bool usegl)
{
        m_pWebPage = new QWebPage(this);

         // Create custom widget
        m_pWidget = new GLWidget();

        i f (usegl)
        {
                GraphicsView *pView = new GraphicsView(new QGraphicsScene(), this);
                setCentralWidget(pView);

                 pView->setViewport(m_pWidget);
                // Replaced code.
                / /pView->setViewport(new QGLWidget());

                QGraphicsWebView *pWebView = new QGraphicsWebView();
                 pWebView->setPage(m_pWebPage);

                pView->scene()->addItem(pWebView);

                // This is to resize the webview in case of a resize of the window
                pView->setBrowserView(pWebView);
         }
        else
         {
                QWebView *pWebView = new QWebView(this);

                pWebView->setPage(m_pWebPage);
                setCentralWidget(pWebView);
        }
}

The custom QGLWidget is only a wrapper to show traces when the widget methods are called
(the code is at the end of this post) but I don't get any trace message although I can see the page
rendered on screen!

Maybe the parent widget of my GLWidget has to be the GraphicView? But I've checked and no
changes observed.

At this point your next comment comes to my mind:

>>>See the documentation of QGraphicsView and especially setViewPort...
>>>It basically sets a specific widget as the output, qtwebkit can find that
>>>widget and use the same opengl-context in case it uses one.

Does it means that I have to call create the widget OGL context before I call the setViewport method?
But, although the OGL context is now shared between widget and rendered how can I get the page rendered
content? I need to do a render onto a FBO like in my first post setting first the widget context?

        m_pWidget->context()->makeCurrent();
        m_Painter.begin( mp_fbo );
        mp_Page->mainFrame()->render( &m_Painter, _rect );
        m_Painter.end();

I'm near but I can't still see the light :)

Best regards,
Jorge


-- 8< ----- glwidget.h --

class GLWidget : public QGLWidget
{
    Q_OBJECT

public:
    GLWidget(QWidget *parent = 0);
    ~GLWidget();

protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int width, int height);

private:
        void checkGLError();
};

-- 8< ----- glwidget.cpp --

#include "glwidget.h"


GLWidget::GLWidget(QWidget *parent)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
}


GLWidget::~GLWidget()
{
}


void GLWidget::checkGLError()
{
        GLenum gl_error = glGetError();

        if (gl_error != GL_NO_ERROR)
                qDebug() << "[MyGLWidget] OpenGL error " << gl_error;
}


void GLWidget::initializeGL()
{
        qDebug() << "[GLWidget] initializeGL... ctx" << QGLContext::currentContext();
        QGLWidget::initializeGL();
}


void GLWidget::resizeGL(int width, int height)
{
        qDebug() << "[GLWidget] resizeGL ....... ctx" << QGLContext::currentContext();
        QGLWidget::resizeGL(width, height);
}


void GLWidget::paintGL()
{
        qDebug() << "[GLWidget] paintGL......... ctx" << QGLContext::currentContext();
        QGLWidget::paintGL();
}

Este mensaje se dirige exclusivamente a su destinatario y puede contener información privilegiada o CONFIDENCIAL. Si no es vd. el destinatario indicado, queda notificado de que la utilización, divulgación y/o copia sin autorización está prohibida en virtud de la legislación vigente. Si ha recibido este mensaje por error, le rogamos que nos lo comunique inmediatamente por esta misma vía y proceda a su destrucción.

This message is intended exclusively for its addressee and may contain information that is CONFIDENTIAL and protected by professional privilege.
If you are not the intended recipient you are hereby notified that any dissemination, copy or disclosure of this communication is strictly prohibited by law. If this message has been received in error, please immediately notify us via e-mail and delete it.


More information about the webkit-qt mailing list