2013-07-23 16:39:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-05-02 13:56:16 +00:00
|
|
|
* Copyright (C) 2013-2016 CERN
|
2020-12-21 23:42:21 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
2013-07-23 16:39:07 +00:00
|
|
|
* @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
|
2020-12-21 23:42:21 +00:00
|
|
|
* Handle multitarget rendering (ie. to different textures/surfaces) and later compositing
|
|
|
|
* into a single image (OpenGL flavor).
|
2013-07-23 16:39:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPENGL_COMPOSITOR_H_
|
|
|
|
#define OPENGL_COMPOSITOR_H_
|
|
|
|
|
2020-11-10 23:24:01 +00:00
|
|
|
#include <gal/opengl/kiglew.h> // Must be included first
|
|
|
|
|
2013-07-23 16:39:07 +00:00
|
|
|
#include <gal/compositor.h>
|
2016-12-22 17:58:29 +00:00
|
|
|
#include <gal/opengl/antialiasing.h>
|
2016-12-23 15:21:00 +00:00
|
|
|
#include <gal/gal_display_options.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
|
|
|
{
|
2016-12-22 17:58:29 +00:00
|
|
|
|
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()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void Initialize() override;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::Resize()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void Resize( unsigned int aWidth, unsigned int aHeight ) override;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2013-08-19 09:02:38 +00:00
|
|
|
/// @copydoc COMPOSITOR::CreateBuffer()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual unsigned int CreateBuffer() override;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::SetBuffer()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void SetBuffer( unsigned int aBufferHandle ) override;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2013-08-19 09:02:38 +00:00
|
|
|
/// @copydoc COMPOSITOR::GetBuffer()
|
2016-09-24 18:53:15 +00:00
|
|
|
inline virtual unsigned int GetBuffer() const override
|
2013-08-19 09:02:38 +00:00
|
|
|
{
|
2016-05-02 13:56:16 +00:00
|
|
|
if( m_curFbo == DIRECT_RENDERING )
|
2013-08-19 09:02:38 +00:00
|
|
|
return DIRECT_RENDERING;
|
|
|
|
|
2016-05-02 13:56:16 +00:00
|
|
|
return m_curBuffer + 1;
|
2013-08-19 09:02:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::ClearBuffer()
|
2017-08-04 12:43:02 +00:00
|
|
|
virtual void ClearBuffer( const COLOR4D& aColor ) override;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2013-07-24 13:06:59 +00:00
|
|
|
/// @copydoc COMPOSITOR::DrawBuffer()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void DrawBuffer( unsigned int aBufferHandle ) override;
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2016-12-22 17:58:29 +00:00
|
|
|
/// @copydoc COMPOSITOR::Begin()
|
|
|
|
virtual void Begin() override;
|
|
|
|
|
|
|
|
// @copydoc COMPOSITOR::Present()
|
|
|
|
virtual void Present() override;
|
|
|
|
|
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;
|
|
|
|
|
2023-06-28 20:48:07 +00:00
|
|
|
VECTOR2I GetScreenSize() const;
|
2016-12-22 17:58:29 +00:00
|
|
|
GLenum GetBufferTexture( unsigned int aBufferHandle );
|
|
|
|
void DrawBuffer( unsigned int aSourceHandle, unsigned int aDestHandle );
|
2023-06-28 20:48:07 +00:00
|
|
|
unsigned int CreateBuffer( VECTOR2I aDimensions );
|
2016-12-22 17:58:29 +00:00
|
|
|
|
2016-12-23 15:21:00 +00:00
|
|
|
void SetAntialiasingMode( OPENGL_ANTIALIASING_MODE aMode ); // clears all buffers
|
|
|
|
OPENGL_ANTIALIASING_MODE GetAntialiasingMode() const;
|
|
|
|
|
2019-01-21 18:42:06 +00:00
|
|
|
int GetAntialiasSupersamplingFactor() const;
|
2021-06-02 13:04:23 +00:00
|
|
|
VECTOR2D GetAntialiasRenderingOffset() const;
|
2019-01-21 18:42:06 +00:00
|
|
|
|
2013-07-23 16:39:07 +00:00
|
|
|
protected:
|
2020-12-21 23:42:21 +00:00
|
|
|
/// Binds a specific Framebuffer Object.
|
|
|
|
void bindFb( unsigned int aFb );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform freeing of resources.
|
|
|
|
*/
|
|
|
|
void clean();
|
|
|
|
|
|
|
|
/// Returns number of used buffers
|
|
|
|
inline unsigned int usedBuffers()
|
|
|
|
{
|
|
|
|
return m_buffers.size();
|
|
|
|
}
|
|
|
|
|
2016-05-02 13:56:16 +00:00
|
|
|
// Buffers are simply textures storing a result of certain target rendering.
|
2021-07-01 22:28:41 +00:00
|
|
|
struct OPENGL_BUFFER
|
2013-07-23 16:39:07 +00:00
|
|
|
{
|
2023-06-28 20:48:07 +00:00
|
|
|
VECTOR2I dimensions;
|
2013-07-23 16:39:07 +00:00
|
|
|
GLuint textureTarget; ///< Main texture handle
|
2013-07-24 13:06:59 +00:00
|
|
|
GLuint attachmentPoint; ///< Point to which an image from texture is attached
|
2021-07-01 22:28:41 +00:00
|
|
|
};
|
2013-07-23 16:39:07 +00:00
|
|
|
|
2014-07-09 09:22:42 +00:00
|
|
|
bool m_initialized; ///< Initialization status flag
|
2016-05-02 13:56:16 +00:00
|
|
|
unsigned int m_curBuffer; ///< Currently used buffer handle
|
|
|
|
GLuint m_mainFbo; ///< Main FBO handle (storing all target textures)
|
2014-07-09 09:22:42 +00:00
|
|
|
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
|
|
|
|
2016-05-02 13:56:16 +00:00
|
|
|
/// Store the used FBO name in case there was more than one compositor used
|
|
|
|
GLuint m_curFbo;
|
|
|
|
|
2016-12-23 15:21:00 +00:00
|
|
|
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode;
|
2017-01-11 15:19:58 +00:00
|
|
|
std::unique_ptr<OPENGL_PRESENTOR> m_antialiasing;
|
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
|
|
|
|
|
|
|
#endif /* COMPOSITOR_H_ */
|