KiCad PCB EDA Suite
opengl_compositor.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013-2016 CERN
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <[email protected]>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
33 #ifndef OPENGL_COMPOSITOR_H_
34 #define OPENGL_COMPOSITOR_H_
35 
36 #include <gal/opengl/kiglew.h> // Must be included first
37 
38 #include <gal/compositor.h>
41 #include <deque>
42 
43 namespace KIGFX
44 {
45 
47 {
48 public:
50  virtual ~OPENGL_COMPOSITOR();
51 
53  virtual void Initialize() override;
54 
56  virtual void Resize( unsigned int aWidth, unsigned int aHeight ) override;
57 
59  virtual unsigned int CreateBuffer() override;
60 
62  virtual void SetBuffer( unsigned int aBufferHandle ) override;
63 
65  inline virtual unsigned int GetBuffer() const override
66  {
67  if( m_curFbo == DIRECT_RENDERING )
68  return DIRECT_RENDERING;
69 
70  return m_curBuffer + 1;
71  }
72 
74  virtual void ClearBuffer( const COLOR4D& aColor ) override;
75 
77  virtual void DrawBuffer( unsigned int aBufferHandle ) override;
78 
80  virtual void Begin() override;
81 
82  // @copydoc COMPOSITOR::Present()
83  virtual void Present() override;
84 
85  // Constant used by glBindFramebuffer to turn off rendering to framebuffers
86  static const unsigned int DIRECT_RENDERING = 0;
87 
88  VECTOR2U GetScreenSize() const;
89  GLenum GetBufferTexture( unsigned int aBufferHandle );
90  void DrawBuffer( unsigned int aSourceHandle, unsigned int aDestHandle );
91  unsigned int CreateBuffer( VECTOR2U aDimensions );
92 
93  void SetAntialiasingMode( OPENGL_ANTIALIASING_MODE aMode ); // clears all buffers
95 
98 
99 protected:
101  void bindFb( unsigned int aFb );
102 
106  void clean();
107 
109  inline unsigned int usedBuffers()
110  {
111  return m_buffers.size();
112  }
113 
114  // Buffers are simply textures storing a result of certain target rendering.
116  {
118  GLuint textureTarget;
120  };
121 
123  unsigned int m_curBuffer;
124  GLuint m_mainFbo;
125  GLuint m_depthBuffer;
126  typedef std::deque<OPENGL_BUFFER> OPENGL_BUFFERS;
127 
130 
132  GLuint m_curFbo;
133 
135  std::unique_ptr<OPENGL_PRESENTOR> m_antialiasing;
136 };
137 } // namespace KIGFX
138 
139 #endif /* COMPOSITOR_H_ */
unsigned int m_curBuffer
Currently used buffer handle.
virtual void DrawBuffer(unsigned int aBufferHandle) override
Draw the selected buffer to the output buffer.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
int GetAntialiasSupersamplingFactor() const
std::deque< OPENGL_BUFFER > OPENGL_BUFFERS
virtual void Begin() override
Call this at the beginning of each frame.
void bindFb(unsigned int aFb)
Binds a specific Framebuffer Object.
OPENGL_ANTIALIASING_MODE GetAntialiasingMode() const
unsigned int usedBuffers()
Returns number of used buffers.
bool m_initialized
Initialization status flag.
static const unsigned int DIRECT_RENDERING
std::unique_ptr< OPENGL_PRESENTOR > m_antialiasing
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode
void SetAntialiasingMode(OPENGL_ANTIALIASING_MODE aMode)
GLuint attachmentPoint
Point to which an image from texture is attached.
void clean()
Perform freeing of resources.
virtual void Present() override
Call this to present the output buffer to the screen.
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).
virtual void Resize(unsigned int aWidth, unsigned int aHeight) override
Clear the state of COMPOSITOR, so it has to be reinitialized again with the new dimensions.
GLuint m_curFbo
Store the used FBO name in case there was more than one compositor used.
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
GLuint m_mainFbo
Main FBO handle (storing all target textures)
GLuint m_depthBuffer
Depth buffer handle.
virtual void Initialize() override
Perform primary initialization, necessary to use the object.
OPENGL_BUFFERS m_buffers
Stores information about initialized buffers.
GLuint textureTarget
Main texture handle.
GLenum GetBufferTexture(unsigned int aBufferHandle)
virtual unsigned int GetBuffer() const override
Return currently used buffer handle.
virtual unsigned int CreateBuffer() override
Prepare a new buffer that may be used as a rendering target.
VECTOR2D GetAntialiasRenderingOffset() const
Class that handles multitarget rendering (ie.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103