Changeset 92615 in webkit


Ignore:
Timestamp:
Aug 8, 2011 11:42:21 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

[Qt] Implement WebGL antialiasing (part 3)
https://bugs.webkit.org/show_bug.cgi?id=64879

Patch by Andrew Wason <rectalogic@rectalogic.com> on 2011-08-08
Reviewed by Noam Rosenthal.

Existing WebGL layout tests cover this.

Implement WebGL antialiasing for Qt desktop.
Existing code in GraphicsContext3DOpenGL.cpp manages the
multisample FBO. GraphicsContext3DQt.cpp creates it and blits
it to the regular FBO when painting.
Requires adoption of Extensions3DOpenGL to be fully functional.

  • platform/graphics/qt/GraphicsContext3DQt.cpp:

(WebCore::GraphicsContext3DInternal::GraphicsContext3DInternal):
(WebCore::GraphicsContext3DInternal::paintToTextureMapper):
(WebCore::GraphicsContext3DInternal::paint):
(WebCore::GraphicsContext3DInternal::multisampleResolve):
(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::GraphicsContext3D::~GraphicsContext3D):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r92611 r92615  
     12011-08-08  Andrew Wason  <rectalogic@rectalogic.com>
     2
     3        [Qt] Implement WebGL antialiasing (part 3)
     4        https://bugs.webkit.org/show_bug.cgi?id=64879
     5
     6        Reviewed by Noam Rosenthal.
     7
     8        Existing WebGL layout tests cover this.
     9
     10        Implement WebGL antialiasing for Qt desktop.
     11        Existing code in GraphicsContext3DOpenGL.cpp manages the
     12        multisample FBO. GraphicsContext3DQt.cpp creates it and blits
     13        it to the regular FBO when painting.
     14        Requires adoption of Extensions3DOpenGL to be fully functional.
     15
     16        * platform/graphics/qt/GraphicsContext3DQt.cpp:
     17        (WebCore::GraphicsContext3DInternal::GraphicsContext3DInternal):
     18        (WebCore::GraphicsContext3DInternal::paintToTextureMapper):
     19        (WebCore::GraphicsContext3DInternal::paint):
     20        (WebCore::GraphicsContext3DInternal::multisampleResolve):
     21        (WebCore::GraphicsContext3D::GraphicsContext3D):
     22        (WebCore::GraphicsContext3D::~GraphicsContext3D):
     23
    1242011-08-08  Anders Carlsson  <andersca@apple.com>
    225
  • trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp

    r92596 r92615  
    8181    void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
    8282    QRectF boundingRect() const;
     83    void blitMultisampleFramebuffer() const;
     84    void blitMultisampleFramebufferAndRestoreContext() const;
    8385
    8486    GraphicsContext3D* m_context;
     
    114116
    115117    m_glWidget->makeCurrent();
    116 
    117 #if !defined(QT_OPENGL_ES_2)
    118     glEnable(GL_POINT_SPRITE);
    119     glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
    120 #endif
    121118}
    122119
     
    148145void GraphicsContext3DInternal::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, BitmapTexture* mask) const
    149146{
     147    blitMultisampleFramebufferAndRestoreContext();
     148
    150149    if (textureMapper->isOpenGLBacked()) {
    151150        TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
     
    210209    QRectF rect = option ? option->rect : boundingRect();
    211210
     211    m_glWidget->makeCurrent();
     212    blitMultisampleFramebuffer();
     213
    212214    // Use direct texture mapping if WebGL canvas has a shared OpenGL context
    213215    // with browsers OpenGL context.
     
    222224    quint32* imagePixels = reinterpret_cast<quint32*>(offscreenImage.bits());
    223225
    224     m_glWidget->makeCurrent();
    225226    glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_context->m_fbo);
    226227    glReadPixels(/* x */ 0, /* y */ 0, rect.width(), rect.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, imagePixels);
     
    252253
    253254    painter->drawImage(/* x */ 0, /* y */ 0, offscreenImage);
     255}
     256
     257void GraphicsContext3DInternal::blitMultisampleFramebuffer() const
     258{
     259    if (!m_context->m_attrs.antialias)
     260        return;
     261    glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, m_context->m_multisampleFBO);
     262    glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, m_context->m_fbo);
     263    glBlitFramebuffer(0, 0, m_context->m_currentWidth, m_context->m_currentHeight, 0, 0, m_context->m_currentWidth, m_context->m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
     264    glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_context->m_boundFBO);
     265}
     266
     267void GraphicsContext3DInternal::blitMultisampleFramebufferAndRestoreContext() const
     268{
     269    if (!m_context->m_attrs.antialias)
     270        return;
     271
     272    const QGLContext* currentContext = QGLContext::currentContext();
     273    const QGLContext* widgetContext = m_glWidget->context();
     274    if (currentContext != widgetContext)
     275        m_glWidget->makeCurrent();
     276    blitMultisampleFramebuffer();
     277    if (currentContext) {
     278        if (currentContext != widgetContext)
     279            const_cast<QGLContext*>(currentContext)->makeCurrent();
     280    } else
     281        m_glWidget->doneCurrent();
    254282}
    255283
     
    285313    m_attrs.stencil = false;
    286314#else
    287     if (m_attrs.stencil)
    288         m_attrs.depth = true;
    289 #endif
    290     m_attrs.antialias = false;
     315    validateAttributes();
     316#endif
    291317
    292318    if (!m_internal->m_glWidget->isValid()) {
     
    318344    glBindTexture(GraphicsContext3D::TEXTURE_2D, 0);
    319345
    320     if (m_attrs.depth)
    321         glGenRenderbuffers(/* count */ 1, &m_depthStencilBuffer);
    322 
    323     // Bind canvas FBO and set initial clear color to black.
    324     m_boundFBO = m_fbo;
    325     glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    326     glClearColor(0.0, 0.0, 0.0, 0.0);
     346    // Create a multisample FBO.
     347    if (m_attrs.antialias) {
     348        glGenFramebuffers(1, &m_multisampleFBO);
     349        glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
     350        m_boundFBO = m_multisampleFBO;
     351        glGenRenderbuffers(1, &m_multisampleColorBuffer);
     352        if (m_attrs.stencil || m_attrs.depth)
     353            glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer);
     354    } else {
     355        // Bind canvas FBO.
     356        glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     357        m_boundFBO = m_fbo;
     358        if (m_attrs.stencil || m_attrs.depth)
     359            glGenRenderbuffers(1, &m_depthStencilBuffer);
     360    }
    327361
    328362#if !defined(QT_OPENGL_ES_2)
     
    342376    ANGLEResources.MaxDrawBuffers = 1;
    343377    m_compiler.setResources(ANGLEResources);
    344 #endif
     378
     379    glEnable(GL_POINT_SPRITE);
     380    glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
     381#endif
     382
     383    glClearColor(0.0, 0.0, 0.0, 0.0);
    345384}
    346385
     
    348387{
    349388    m_internal->m_glWidget->makeCurrent();
    350     if (m_internal->m_glWidget->isValid()) {
    351         glDeleteTextures(1, &m_texture);
     389    if (!m_internal->m_glWidget->isValid())
     390        return;
     391    glDeleteTextures(1, &m_texture);
     392    glDeleteFramebuffers(1, &m_fbo);
     393    if (m_attrs.antialias) {
     394        glDeleteRenderbuffers(1, &m_multisampleColorBuffer);
     395        glDeleteFramebuffers(1, &m_multisampleFBO);
     396        if (m_attrs.stencil || m_attrs.depth)
     397            glDeleteRenderbuffers(1, &m_multisampleDepthStencilBuffer);
     398    } else if (m_attrs.stencil || m_attrs.depth)
    352399        glDeleteRenderbuffers(1, &m_depthStencilBuffer);
    353         glDeleteFramebuffers(1, &m_fbo);
    354     }
    355400}
    356401
Note: See TracChangeset for help on using the changeset viewer.