diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-07-28 21:45:56 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-10-19 08:08:51 +0000 |
commit | 94b6b4678b4736b6f4974ec8ee73df5c11ff06d1 (patch) | |
tree | 51b870d0cc7e6abae3069a673bd6a3c71ce48709 | |
parent | 877774c05731b7505a3d3a947a1dcb528f36df41 (diff) |
opengl: blit offscreen framebuffer instead of drawing
Change-Id: I3ab0da9cf83e0e85b8442b34ecd6eb91dd3d1bd3
Reviewed-on: https://gerrit.libreoffice.org/27875
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | vcl/inc/opengl/framebuffer.hxx | 5 | ||||
-rw-r--r-- | vcl/opengl/framebuffer.cxx | 8 | ||||
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 56 |
3 files changed, 23 insertions, 46 deletions
diff --git a/vcl/inc/opengl/framebuffer.hxx b/vcl/inc/opengl/framebuffer.hxx index 9f94a8f43000..4bad28a3827b 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 aa20a9382b52..cb91ea482b79 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 5fd46b6465f6..b1898df3e5c8 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." ); } |