2014-11-26 09:22:25 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sal/log.hxx>
|
|
|
|
|
|
|
|
#include <opengl/framebuffer.hxx>
|
|
|
|
|
|
|
|
#include <vcl/opengl/OpenGLHelper.hxx>
|
|
|
|
|
|
|
|
OpenGLFramebuffer::OpenGLFramebuffer() :
|
|
|
|
mnId( 0 ),
|
2014-12-04 22:25:56 -05:00
|
|
|
mnWidth( 0 ),
|
|
|
|
mnHeight( 0 ),
|
2014-12-04 22:27:38 -05:00
|
|
|
mnAttachedTexture( 0 ),
|
2014-11-26 09:22:25 -05:00
|
|
|
mpPrevFramebuffer( NULL ),
|
|
|
|
mpNextFramebuffer( NULL )
|
|
|
|
{
|
|
|
|
glGenFramebuffers( 1, &mnId );
|
2015-08-28 11:34:11 +01:00
|
|
|
VCL_GL_INFO( "vcl.opengl", "Created framebuffer " << (int)mnId );
|
2014-11-26 09:22:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLFramebuffer::~OpenGLFramebuffer()
|
|
|
|
{
|
|
|
|
glDeleteFramebuffers( 1, &mnId );
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLFramebuffer::Bind()
|
|
|
|
{
|
|
|
|
glBindFramebuffer( GL_FRAMEBUFFER, mnId );
|
2015-08-28 11:34:11 +01:00
|
|
|
VCL_GL_INFO( "vcl.opengl", "Binding framebuffer " << (int)mnId );
|
2014-11-26 09:22:25 -05:00
|
|
|
CHECK_GL_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLFramebuffer::Unbind()
|
|
|
|
{
|
|
|
|
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
2015-08-28 11:34:11 +01:00
|
|
|
VCL_GL_INFO( "vcl.opengl", "Binding default framebuffer" );
|
2014-11-26 09:22:25 -05:00
|
|
|
CHECK_GL_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenGLFramebuffer::IsFree() const
|
|
|
|
{
|
2015-08-31 12:11:50 +01:00
|
|
|
return !mnAttachedTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenGLFramebuffer::IsAttached( GLuint nTexture ) const
|
|
|
|
{
|
|
|
|
return mnAttachedTexture == nTexture;
|
2014-11-26 09:22:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenGLFramebuffer::IsAttached( const OpenGLTexture& rTexture ) const
|
|
|
|
{
|
2015-08-31 12:11:50 +01:00
|
|
|
return mnAttachedTexture == rTexture.Id();
|
2014-11-26 09:22:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLFramebuffer::AttachTexture( const OpenGLTexture& rTexture )
|
|
|
|
{
|
2014-12-04 22:27:38 -05:00
|
|
|
if( rTexture.Id() == mnAttachedTexture )
|
|
|
|
return;
|
|
|
|
|
2015-08-28 11:34:11 +01:00
|
|
|
VCL_GL_INFO( "vcl.opengl", "Attaching texture " << rTexture.Id() << " to framebuffer " << (int)mnId );
|
2014-12-04 22:27:38 -05:00
|
|
|
mnAttachedTexture = rTexture.Id();
|
2014-12-04 22:25:56 -05:00
|
|
|
mnWidth = rTexture.GetWidth();
|
|
|
|
mnHeight = rTexture.GetHeight();
|
2014-11-26 09:22:25 -05:00
|
|
|
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
2014-12-04 22:27:38 -05:00
|
|
|
mnAttachedTexture, 0 );
|
2014-11-26 09:22:25 -05:00
|
|
|
CHECK_GL_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLFramebuffer::DetachTexture()
|
|
|
|
{
|
2014-12-04 22:27:38 -05:00
|
|
|
if( mnAttachedTexture != 0 )
|
|
|
|
{
|
|
|
|
CHECK_GL_ERROR();
|
|
|
|
mnAttachedTexture = 0;
|
|
|
|
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0 );
|
|
|
|
CHECK_GL_ERROR();
|
|
|
|
}
|
2014-11-26 09:22:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|