[Libreoffice-commits] core.git: vcl/inc vcl/opengl

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Wed Oct 19 08:09:13 UTC 2016


 vcl/inc/opengl/framebuffer.hxx |    5 ++-
 vcl/opengl/framebuffer.cxx     |    8 ++---
 vcl/opengl/gdiimpl.cxx         |   56 +++++++++++------------------------------
 3 files changed, 23 insertions(+), 46 deletions(-)

New commits:
commit 94b6b4678b4736b6f4974ec8ee73df5c11ff06d1
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Jul 28 21:45:56 2016 +0900

    opengl: blit offscreen framebuffer instead of drawing
    
    Change-Id: I3ab0da9cf83e0e85b8442b34ecd6eb91dd3d1bd3
    Reviewed-on: https://gerrit.libreoffice.org/27875
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/inc/opengl/framebuffer.hxx b/vcl/inc/opengl/framebuffer.hxx
index 9f94a8f..4bad28a 100644
--- a/vcl/inc/opengl/framebuffer.hxx
+++ b/vcl/inc/opengl/framebuffer.hxx
@@ -30,8 +30,9 @@ public:
     int     GetWidth() const { return mnWidth; };
     int     GetHeight() const { return mnHeight; };
 
-    void    Bind();
-    static void Unbind();
+    void    Bind(GLenum eTarget = GL_FRAMEBUFFER);
+
+    static void Unbind(GLenum eTarget = GL_FRAMEBUFFER);
 
     bool    IsFree() const;
     bool    IsAttached( GLuint nTexture ) const;
diff --git a/vcl/opengl/framebuffer.cxx b/vcl/opengl/framebuffer.cxx
index aa20a93..cb91ea4 100644
--- a/vcl/opengl/framebuffer.cxx
+++ b/vcl/opengl/framebuffer.cxx
@@ -32,16 +32,16 @@ OpenGLFramebuffer::~OpenGLFramebuffer()
     CHECK_GL_ERROR();
 }
 
-void OpenGLFramebuffer::Bind()
+void OpenGLFramebuffer::Bind(GLenum eTarget)
 {
     VCL_GL_INFO( "Binding framebuffer " << (int)mnId );
-    glBindFramebuffer( GL_FRAMEBUFFER, mnId );
+    glBindFramebuffer(eTarget, mnId);
     CHECK_GL_ERROR();
 }
 
-void OpenGLFramebuffer::Unbind()
+void OpenGLFramebuffer::Unbind(GLenum eTarget)
 {
-    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+    glBindFramebuffer(eTarget, 0);
     CHECK_GL_ERROR();
     VCL_GL_INFO( "Binding default framebuffer" );
 }
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 5fd46b6..b1898df 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -2096,11 +2096,11 @@ void OpenGLSalGraphicsImpl::doFlush()
 
     VCL_GL_INFO( "doFlush - acquire default framebuffer" );
 
-    mpWindowContext->state()->sync();
-
     mpWindowContext->AcquireDefaultFramebuffer();
+
     CHECK_GL_ERROR();
 
+    mpWindowContext->state()->sync();
     mpWindowContext->state()->viewport(Rectangle(Point(0, 0), Size(GetWidth(), GetHeight())));
     mpWindowContext->state()->scissor().disable();
     mpWindowContext->state()->stencil().disable();
@@ -2108,54 +2108,30 @@ void OpenGLSalGraphicsImpl::doFlush()
 #if OSL_DEBUG_LEVEL > 0 // random background glClear
     glClearColor((float)rand()/RAND_MAX, (float)rand()/RAND_MAX,
                  (float)rand()/RAND_MAX, 1.0);
-#else
-    glClearColor(1.0, 1.0, 1.0, 1.0);
-#endif
     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
     CHECK_GL_ERROR();
+#endif
 
     VCL_GL_INFO( "Texture height " << maOffscreenTex.GetHeight() << " vs. window height " << GetHeight() );
 
-    OpenGLProgram *pProgram =
-        mpWindowContext->UseProgram("combinedTextureVertexShader", "combinedTextureFragmentShader", "// flush shader\n" ); // flush helps profiling
-    if( !pProgram )
-        VCL_GL_INFO( "Can't compile simple copying shader !" );
-    else
+    OpenGLFramebuffer* pFrameBuffer = mpWindowContext->AcquireFramebuffer(maOffscreenTex);
+    CHECK_GL_ERROR();
+    if (pFrameBuffer)
     {
-        pProgram->SetShaderType(TextureShaderType::Normal);
-        pProgram->SetIdentityTransform("transform");
-        pProgram->SetTexture("texture", maOffscreenTex);
-
-        SalTwoRect aPosAry( 0, 0, maOffscreenTex.GetWidth(), maOffscreenTex.GetHeight(),
-                            0, 0, maOffscreenTex.GetWidth(), maOffscreenTex.GetHeight() );
-
-        GLfloat aTexCoord[8];
-        maOffscreenTex.GetCoord( aTexCoord, aPosAry );
-        pProgram->SetTextureCoord(aTexCoord);
-        pProgram->SetMaskCoord(aTexCoord);
-        pProgram->SetAlphaCoord(aTexCoord);
-
-        GLfloat fWidth( maOffscreenTex.GetWidth() );
-        GLfloat fHeight( maOffscreenTex.GetHeight() );
-        std::vector<GLfloat> aVertices {
-            0, fHeight,
-            0, 0,
-            fWidth, 0,
-            fWidth, fHeight
-        };
+        OpenGLFramebuffer::Unbind(GL_DRAW_FRAMEBUFFER);
+        pFrameBuffer->Bind(GL_READ_FRAMEBUFFER);
 
-        pProgram->ApplyMatrix(GetWidth(), GetHeight(), 0.0);
-        pProgram->DrawArrays(GL_TRIANGLE_FAN, aVertices);
-
-        pProgram->Clean();
-
-        maOffscreenTex.Unbind();
+        glBlitFramebuffer(0, 0, GetWidth(), GetHeight(),
+                          0, 0, GetWidth(), GetHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
+        CHECK_GL_ERROR();
 
-        static bool bNoSwap = getenv("SAL_GL_NO_SWAP");
-        if (!bNoSwap)
-            mpWindowContext->swapBuffers();
+        pFrameBuffer->Bind();
     }
 
+    static bool bNoSwap = getenv("SAL_GL_NO_SWAP");
+    if (!bNoSwap)
+        mpWindowContext->swapBuffers();
+
     VCL_GL_INFO( "doFlush - end." );
 }
 


More information about the Libreoffice-commits mailing list