2013-07-23 16:39:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file opengl_compositor.h
|
|
|
|
* @brief Class that handles multitarget rendering (ie. to different textures/surfaces) and
|
|
|
|
* later compositing into a single image (OpenGL flavour).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPENGL_COMPOSITOR_H_
|
|
|
|
#define OPENGL_COMPOSITOR_H_
|
|
|
|
|
|
|
|
#include <gal/compositor.h>
|
|
|
|
#include <GL/glew.h>
|
2013-07-24 13:06:59 +00:00
|
|
|
#include <deque>
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
namespace KIGFX
|
2013-07-23 16:39:07 +00:00
|
|
|
{
|
|
|
|
class OPENGL_COMPOSITOR : public COMPOSITOR
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OPENGL_COMPOSITOR();
|
|
|
|
virtual ~OPENGL_COMPOSITOR();
|
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::Initialize()
|
2013-07-23 16:39:07 +00:00
|
|
|
virtual void Initialize();
|
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::Resize()
|
2013-07-23 16:39:07 +00:00
|
|
|
virtual void Resize( unsigned int aWidth, unsigned int aHeight );
|
|
|
|
|
2013-08-19 09:02:38 +00:00
|
|
|
/// @copydoc COMPOSITOR::CreateBuffer()
|
|
|
|
virtual unsigned int CreateBuffer();
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::SetBuffer()
|
2013-07-23 16:39:07 +00:00
|
|
|
virtual void SetBuffer( unsigned int aBufferHandle );
|
|
|
|
|
2013-08-19 09:02:38 +00:00
|
|
|
/// @copydoc COMPOSITOR::GetBuffer()
|
|
|
|
inline virtual unsigned int GetBuffer() const
|
|
|
|
{
|
|
|
|
if( m_currentFbo == DIRECT_RENDERING )
|
|
|
|
return DIRECT_RENDERING;
|
|
|
|
|
|
|
|
return m_current + 1;
|
|
|
|
}
|
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::ClearBuffer()
|
2013-07-23 16:39:07 +00:00
|
|
|
virtual void ClearBuffer();
|
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::DrawBuffer()
|
|
|
|
virtual void DrawBuffer( unsigned int aBufferHandle );
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2013-08-19 09:02:38 +00:00
|
|
|
// Constant used by glBindFramebuffer to turn off rendering to framebuffers
|
|
|
|
static const unsigned int DIRECT_RENDERING = 0;
|
|
|
|
|
2013-07-23 16:39:07 +00:00
|
|
|
protected:
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GLuint textureTarget; ///< Main texture handle
|
2013-07-24 13:06:59 +00:00
|
|
|
GLuint attachmentPoint; ///< Point to which an image from texture is attached
|
|
|
|
} OPENGL_BUFFER;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2014-07-09 09:22:42 +00:00
|
|
|
bool m_initialized; ///< Initialization status flag
|
|
|
|
unsigned int m_current; ///< Currently used buffer handle
|
|
|
|
GLuint m_framebuffer; ///< Main FBO handle
|
|
|
|
GLuint m_depthBuffer; ///< Depth buffer handle
|
2013-07-24 13:06:59 +00:00
|
|
|
typedef std::deque<OPENGL_BUFFER> OPENGL_BUFFERS;
|
|
|
|
|
|
|
|
/// Stores information about initialized buffers
|
2014-07-09 09:22:42 +00:00
|
|
|
OPENGL_BUFFERS m_buffers;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
|
|
|
/// Store the currently used FBO name in case there was more than one compositor used
|
2014-07-09 09:22:42 +00:00
|
|
|
GLuint m_currentFbo;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function clean()
|
|
|
|
* performs freeing of resources.
|
|
|
|
*/
|
|
|
|
void clean();
|
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// Returns number of used buffers
|
2014-07-09 09:22:42 +00:00
|
|
|
inline unsigned int usedBuffers()
|
2013-07-23 16:39:07 +00:00
|
|
|
{
|
|
|
|
return m_buffers.size();
|
|
|
|
}
|
|
|
|
};
|
2013-10-14 14:13:35 +00:00
|
|
|
} // namespace KIGFX
|
2013-07-23 16:39:07 +00:00
|
|
|
|
|
|
|
#endif /* COMPOSITOR_H_ */
|