1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/log.hxx>
12 #include <opengl/framebuffer.hxx>
14 #include <vcl/opengl/OpenGLHelper.hxx>
16 OpenGLFramebuffer::OpenGLFramebuffer() :
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
);
40 void OpenGLFramebuffer::Unbind()
42 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
43 VCL_GL_INFO( "vcl.opengl", "Binding default framebuffer" );
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
)
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");
79 void OpenGLFramebuffer::DetachTexture()
81 if( mnAttachedTexture
!= 0 )
84 mnAttachedTexture
= 0;
85 glFramebufferTexture2D( GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, 0, 0 );
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */