Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / opengl / framebuffer.cxx
blob403c3792269570bd1cfa0244c216a2a270b56661
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/log.hxx>
12 #include <opengl/framebuffer.hxx>
14 #include <vcl/opengl/OpenGLHelper.hxx>
16 OpenGLFramebuffer::OpenGLFramebuffer() :
17 mnId( 0 ),
18 mnWidth( 0 ),
19 mnHeight( 0 ),
20 mnAttachedTexture( 0 ),
21 mpPrevFramebuffer( NULL ),
22 mpNextFramebuffer( NULL )
24 glGenFramebuffers( 1, &mnId );
25 VCL_GL_INFO( "vcl.opengl", "Created framebuffer " << (int)mnId );
28 OpenGLFramebuffer::~OpenGLFramebuffer()
30 glDeleteFramebuffers( 1, &mnId );
33 void OpenGLFramebuffer::Bind()
35 VCL_GL_INFO( "vcl.opengl", "Binding framebuffer " << (int)mnId );
36 glBindFramebuffer( GL_FRAMEBUFFER, mnId );
37 CHECK_GL_ERROR();
40 void OpenGLFramebuffer::Unbind()
42 glBindFramebuffer( GL_FRAMEBUFFER, 0 );
43 VCL_GL_INFO( "vcl.opengl", "Binding default framebuffer" );
44 CHECK_GL_ERROR();
47 bool OpenGLFramebuffer::IsFree() const
49 return !mnAttachedTexture;
52 bool OpenGLFramebuffer::IsAttached( GLuint nTexture ) const
54 return mnAttachedTexture == nTexture;
57 bool OpenGLFramebuffer::IsAttached( const OpenGLTexture& rTexture ) const
59 return mnAttachedTexture == rTexture.Id();
62 void OpenGLFramebuffer::AttachTexture( const OpenGLTexture& rTexture )
64 if( rTexture.Id() == mnAttachedTexture )
65 return;
67 VCL_GL_INFO( "vcl.opengl", "Attaching texture " << rTexture.Id() << " to framebuffer " << (int)mnId );
68 mnAttachedTexture = rTexture.Id();
69 mnWidth = rTexture.GetWidth();
70 mnHeight = rTexture.GetHeight();
71 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mnAttachedTexture, 0);
72 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
74 SAL_WARN("vcl.opengl", "Framebuffer incomplete");
76 CHECK_GL_ERROR();
79 void OpenGLFramebuffer::DetachTexture()
81 if( mnAttachedTexture != 0 )
83 CHECK_GL_ERROR();
84 mnAttachedTexture = 0;
85 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0 );
86 CHECK_GL_ERROR();
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */