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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
31 #ifndef OPENGL_COMPOSITOR_H_
32 #define OPENGL_COMPOSITOR_H_
33 
34 #include <gal/compositor.h>
37 #include <GL/glew.h>
38 #include <deque>
39 
40 namespace KIGFX
41 {
42 
44 {
45 public:
47  virtual ~OPENGL_COMPOSITOR();
48 
50  virtual void Initialize() override;
51 
53  virtual void Resize( unsigned int aWidth, unsigned int aHeight ) override;
54 
56  virtual unsigned int CreateBuffer() override;
57 
59  virtual void SetBuffer( unsigned int aBufferHandle ) override;
60 
62  inline virtual unsigned int GetBuffer() const override
63  {
64  if( m_curFbo == DIRECT_RENDERING )
65  return DIRECT_RENDERING;
66 
67  return m_curBuffer + 1;
68  }
69 
71  virtual void ClearBuffer() override;
72 
74  virtual void DrawBuffer( unsigned int aBufferHandle ) override;
75 
77  virtual void Begin() override;
78 
79  // @copydoc COMPOSITOR::Present()
80  virtual void Present() override;
81 
82  // Constant used by glBindFramebuffer to turn off rendering to framebuffers
83  static const unsigned int DIRECT_RENDERING = 0;
84 
85 public:
86  VECTOR2U GetScreenSize() const;
87  GLenum GetBufferTexture( unsigned int aBufferHandle );
88  void DrawBuffer( unsigned int aSourceHandle, unsigned int aDestHandle );
89  unsigned int CreateBuffer( VECTOR2U aDimensions );
90 
91  void SetAntialiasingMode( OPENGL_ANTIALIASING_MODE aMode ); // clears all buffers
93 
94 protected:
95  // Buffers are simply textures storing a result of certain target rendering.
96  typedef struct
97  {
99  GLuint textureTarget;
101  } OPENGL_BUFFER;
102 
104  unsigned int m_curBuffer;
105  GLuint m_mainFbo;
106  GLuint m_depthBuffer;
107  typedef std::deque<OPENGL_BUFFER> OPENGL_BUFFERS;
108 
110  OPENGL_BUFFERS m_buffers;
111 
113  GLuint m_curFbo;
114 
116  std::unique_ptr<OPENGL_PRESENTOR> m_antialiasing;
117 
119  void bindFb( unsigned int aFb );
120 
125  void clean();
126 
128  inline unsigned int usedBuffers()
129  {
130  return m_buffers.size();
131  }
132 };
133 } // namespace KIGFX
134 
135 #endif /* COMPOSITOR_H_ */
unsigned int m_curBuffer
Currently used buffer handle.
virtual void DrawBuffer(unsigned int aBufferHandle) override
Function DrawBuffer() draws the selected buffer to the output buffer.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:56
std::deque< OPENGL_BUFFER > OPENGL_BUFFERS
virtual void Begin() override
Function Begin() Call this at the beginning of each frame.
void bindFb(unsigned int aFb)
Binds a specific Framebuffer Object.
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.
virtual void ClearBuffer() override
Function ClearBuffer() clears the selected buffer (set by the SetBuffer() function).
void clean()
Function clean() performs freeing of resources.
virtual void Present() override
Function Present() Call this to present the output buffer to the screen.
virtual void Resize(unsigned int aWidth, unsigned int aHeight) override
Function Resize() clears the state of COMPOSITOR, so it has to be reinitialized again with the new di...
GLuint m_curFbo
Store the used FBO name in case there was more than one compositor used.
OPENGL_ANTIALIASING_MODE GetAntialiasingMode() const
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets 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
Function Reset() performs primary initialiation, necessary to use the object.
VECTOR2U GetScreenSize() const
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
Function GetBuffer() returns currently used buffer handle.
virtual unsigned int CreateBuffer() override
Function CreateBuffer() prepares a new buffer that may be used as a rendering target.
Class that handles multitarget rendering (ie.