KiCad PCB EDA Suite
KIGFX::OPENGL_COMPOSITOR Class Reference

#include <opengl_compositor.h>

Inheritance diagram for KIGFX::OPENGL_COMPOSITOR:
KIGFX::COMPOSITOR

Classes

struct  OPENGL_BUFFER
 

Public Member Functions

 OPENGL_COMPOSITOR ()
 
virtual ~OPENGL_COMPOSITOR ()
 
virtual void Initialize () override
 Perform primary initialization, necessary to use the object. More...
 
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. More...
 
virtual unsigned int CreateBuffer () override
 Prepare a new buffer that may be used as a rendering target. More...
 
virtual void SetBuffer (unsigned int aBufferHandle) override
 Set the selected buffer as the rendering target. More...
 
virtual unsigned int GetBuffer () const override
 Return currently used buffer handle. More...
 
virtual void ClearBuffer (const COLOR4D &aColor) override
 Clear the selected buffer (set by the SetBuffer() function). More...
 
virtual void DrawBuffer (unsigned int aBufferHandle) override
 Draw the selected buffer to the output buffer. More...
 
virtual void Begin () override
 Call this at the beginning of each frame. More...
 
virtual void Present () override
 Call this to present the output buffer to the screen. More...
 
VECTOR2U GetScreenSize () const
 
GLenum GetBufferTexture (unsigned int aBufferHandle)
 
void DrawBuffer (unsigned int aSourceHandle, unsigned int aDestHandle)
 
unsigned int CreateBuffer (VECTOR2U aDimensions)
 
void SetAntialiasingMode (OPENGL_ANTIALIASING_MODE aMode)
 
OPENGL_ANTIALIASING_MODE GetAntialiasingMode () const
 
int GetAntialiasSupersamplingFactor () const
 
VECTOR2D GetAntialiasRenderingOffset () const
 

Static Public Attributes

static const unsigned int DIRECT_RENDERING = 0
 

Protected Types

typedef std::deque< OPENGL_BUFFEROPENGL_BUFFERS
 

Protected Member Functions

void bindFb (unsigned int aFb)
 Binds a specific Framebuffer Object. More...
 
void clean ()
 Perform freeing of resources. More...
 
unsigned int usedBuffers ()
 Returns number of used buffers. More...
 

Protected Attributes

bool m_initialized
 Initialization status flag. More...
 
unsigned int m_curBuffer
 Currently used buffer handle. More...
 
GLuint m_mainFbo
 Main FBO handle (storing all target textures) More...
 
GLuint m_depthBuffer
 Depth buffer handle. More...
 
OPENGL_BUFFERS m_buffers
 Stores information about initialized buffers. More...
 
GLuint m_curFbo
 Store the used FBO name in case there was more than one compositor used. More...
 
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode
 
std::unique_ptr< OPENGL_PRESENTORm_antialiasing
 
unsigned int m_width
 Width of the buffer (in pixels) More...
 
unsigned int m_height
 Height of the buffer (in pixels) More...
 

Detailed Description

Definition at line 46 of file opengl_compositor.h.

Member Typedef Documentation

◆ OPENGL_BUFFERS

Definition at line 126 of file opengl_compositor.h.

Constructor & Destructor Documentation

◆ OPENGL_COMPOSITOR()

OPENGL_COMPOSITOR::OPENGL_COMPOSITOR ( )

Definition at line 45 of file opengl_compositor.cpp.

45  :
46  m_initialized( false ),
47  m_curBuffer( 0 ),
48  m_mainFbo( 0 ),
49  m_depthBuffer( 0 ),
52 {
53  m_antialiasing = std::make_unique<ANTIALIASING_NONE>( this );
54 }
unsigned int m_curBuffer
Currently used buffer handle.
bool m_initialized
Initialization status flag.
static const unsigned int DIRECT_RENDERING
std::unique_ptr< OPENGL_PRESENTOR > m_antialiasing
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode
GLuint m_curFbo
Store the used FBO name in case there was more than one compositor used.
GLuint m_mainFbo
Main FBO handle (storing all target textures)
GLuint m_depthBuffer
Depth buffer handle.

References m_antialiasing.

◆ ~OPENGL_COMPOSITOR()

OPENGL_COMPOSITOR::~OPENGL_COMPOSITOR ( )
virtual

Definition at line 57 of file opengl_compositor.cpp.

58 {
59  if( m_initialized )
60  {
61  try
62  {
63  clean();
64  }
65  catch( const std::runtime_error& exc )
66  {
67  wxLogError( wxT( "Run time exception `%s` occurred in OPENGL_COMPOSITOR destructor." ),
68  exc.what() );
69  }
70  }
71 }
bool m_initialized
Initialization status flag.
void clean()
Perform freeing of resources.

References clean(), and m_initialized.

Member Function Documentation

◆ Begin()

void OPENGL_COMPOSITOR::Begin ( )
overridevirtual

Call this at the beginning of each frame.

Implements KIGFX::COMPOSITOR.

Definition at line 323 of file opengl_compositor.cpp.

324 {
325  m_antialiasing->Begin();
326 }
std::unique_ptr< OPENGL_PRESENTOR > m_antialiasing

References m_antialiasing.

Referenced by KIGFX::OPENGL_GAL::beginDrawing().

◆ bindFb()

void OPENGL_COMPOSITOR::bindFb ( unsigned int  aFb)
protected

Binds a specific Framebuffer Object.

Definition at line 388 of file opengl_compositor.cpp.

389 {
390  // Currently there are only 2 valid FBOs
391  assert( aFb == DIRECT_RENDERING || aFb == m_mainFbo );
392 
393  if( m_curFbo != aFb )
394  {
395  glBindFramebufferEXT( GL_FRAMEBUFFER, aFb );
396  checkGlError( "switching framebuffer", __FILE__, __LINE__ );
397  m_curFbo = aFb;
398  }
399 }
int checkGlError(const std::string &aInfo, const char *aFile, int aLine, bool aThrow)
Check if a recent OpenGL operation has failed.
Definition: utils.cpp:45
static const unsigned int DIRECT_RENDERING
GLuint m_curFbo
Store the used FBO name in case there was more than one compositor used.
GLuint m_mainFbo
Main FBO handle (storing all target textures)

References checkGlError(), DIRECT_RENDERING, m_curFbo, and m_mainFbo.

Referenced by clean(), CreateBuffer(), Initialize(), and SetBuffer().

◆ clean()

void OPENGL_COMPOSITOR::clean ( )
protected

Perform freeing of resources.

Definition at line 402 of file opengl_compositor.cpp.

403 {
404  assert( m_initialized );
405 
407 
408  for( OPENGL_BUFFERS::const_iterator it = m_buffers.begin(); it != m_buffers.end(); ++it )
409  {
410  glDeleteTextures( 1, &it->textureTarget );
411  }
412 
413  m_buffers.clear();
414 
415  if( glDeleteFramebuffersEXT )
416  glDeleteFramebuffersEXT( 1, &m_mainFbo );
417 
418  if( glDeleteRenderbuffersEXT )
419  glDeleteRenderbuffersEXT( 1, &m_depthBuffer );
420 
421  m_initialized = false;
422 }
void bindFb(unsigned int aFb)
Binds a specific Framebuffer Object.
bool m_initialized
Initialization status flag.
static const unsigned int DIRECT_RENDERING
GLuint m_mainFbo
Main FBO handle (storing all target textures)
GLuint m_depthBuffer
Depth buffer handle.
OPENGL_BUFFERS m_buffers
Stores information about initialized buffers.

References bindFb(), DIRECT_RENDERING, m_buffers, m_depthBuffer, m_initialized, and m_mainFbo.

Referenced by Resize(), SetAntialiasingMode(), and ~OPENGL_COMPOSITOR().

◆ ClearBuffer()

void OPENGL_COMPOSITOR::ClearBuffer ( const COLOR4D aColor)
overridevirtual

Clear the selected buffer (set by the SetBuffer() function).

Implements KIGFX::COMPOSITOR.

Definition at line 308 of file opengl_compositor.cpp.

309 {
310  assert( m_initialized );
311 
312  glClearColor( aColor.r, aColor.g, aColor.b, 0.0f );
313  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
314 }
double g
Green component.
Definition: color4d.h:372
bool m_initialized
Initialization status flag.
double b
Blue component.
Definition: color4d.h:373
double r
Red component.
Definition: color4d.h:371

References KIGFX::COLOR4D::b, KIGFX::COLOR4D::g, m_initialized, and KIGFX::COLOR4D::r.

Referenced by KIGFX::ANTIALIASING_SUPERSAMPLING::Begin(), KIGFX::ANTIALIASING_SMAA::Begin(), KIGFX::OPENGL_GAL::ClearTarget(), CreateBuffer(), and KIGFX::ANTIALIASING_SMAA::Present().

◆ CreateBuffer() [1/2]

unsigned int OPENGL_COMPOSITOR::CreateBuffer ( )
overridevirtual

Prepare a new buffer that may be used as a rendering target.

Returns
is the handle of the buffer. In case of failure 0 (zero) is returned as the handle.

Implements KIGFX::COMPOSITOR.

Definition at line 157 of file opengl_compositor.cpp.

158 {
159  return m_antialiasing->CreateBuffer();
160 }
std::unique_ptr< OPENGL_PRESENTOR > m_antialiasing

References m_antialiasing.

Referenced by KIGFX::OPENGL_GAL::beginDrawing(), KIGFX::ANTIALIASING_NONE::CreateBuffer(), KIGFX::ANTIALIASING_SUPERSAMPLING::CreateBuffer(), KIGFX::ANTIALIASING_SMAA::CreateBuffer(), KIGFX::ANTIALIASING_SUPERSAMPLING::Init(), and KIGFX::ANTIALIASING_SMAA::Init().

◆ CreateBuffer() [2/2]

unsigned int OPENGL_COMPOSITOR::CreateBuffer ( VECTOR2U  aDimensions)

Definition at line 163 of file opengl_compositor.cpp.

164 {
165  assert( m_initialized );
166 
167  int maxBuffers, maxTextureSize;
168 
169  // Get the maximum number of buffers
170  glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS, (GLint*) &maxBuffers );
171 
172  if( (int) usedBuffers() >= maxBuffers )
173  {
174  throw std::runtime_error(
175  "Cannot create more framebuffers. OpenGL rendering "
176  "backend requires at least 3 framebuffers. You may try to update/change "
177  "your graphic drivers." );
178  }
179 
180  glGetIntegerv( GL_MAX_TEXTURE_SIZE, (GLint*) &maxTextureSize );
181 
182  if( maxTextureSize < (int) aDimensions.x || maxTextureSize < (int) aDimensions.y )
183  {
184  throw std::runtime_error( "Requested texture size is not supported. "
185  "Could not create a buffer." );
186  }
187 
188  // GL_COLOR_ATTACHMENTn are consecutive integers
189  GLuint attachmentPoint = GL_COLOR_ATTACHMENT0 + usedBuffers();
190  GLuint textureTarget;
191 
192  // Generate the texture for the pixel storage
193  glActiveTexture( GL_TEXTURE0 );
194  glGenTextures( 1, &textureTarget );
195  checkGlError( "generating framebuffer texture target", __FILE__, __LINE__ );
196  glBindTexture( GL_TEXTURE_2D, textureTarget );
197  checkGlError( "binding framebuffer texture target", __FILE__, __LINE__ );
198 
199  // Set texture parameters
200  glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
201  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, aDimensions.x, aDimensions.y, 0, GL_RGBA,
202  GL_UNSIGNED_BYTE, nullptr );
203  checkGlError( "creating framebuffer texture", __FILE__, __LINE__ );
204  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
205  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
206 
207  // Bind the texture to the specific attachment point, clear and rebind the screen
208  bindFb( m_mainFbo );
209  glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachmentPoint, GL_TEXTURE_2D, textureTarget,
210  0 );
211 
212  // Check the status, exit if the framebuffer can't be created
213  GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
214 
215  if( status != GL_FRAMEBUFFER_COMPLETE_EXT )
216  {
217  switch( status )
218  {
219  case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
220  throw std::runtime_error( "The framebuffer attachment points are incomplete." );
221  break;
222 
223  case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
224  throw std::runtime_error( "No images attached to the framebuffer." );
225  break;
226 
227  case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
228  throw std::runtime_error( "The framebuffer does not have at least one "
229  "image attached to it." );
230  break;
231 
232  case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
233  throw std::runtime_error( "The framebuffer read buffer is incomplete." );
234  break;
235 
236  case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
237  throw std::runtime_error(
238  "The combination of internal formats of the attached "
239  "images violates an implementation-dependent set of restrictions." );
240  break;
241 
242  case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
243  throw std::runtime_error( "GL_RENDERBUFFER_SAMPLES is not the same for "
244  "all attached renderbuffers" );
245  break;
246 
247  case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT:
248  throw std::runtime_error( "Framebuffer incomplete layer targets errors." );
249  break;
250 
251  case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
252  throw std::runtime_error( "Framebuffer attachments have different dimensions" );
253  break;
254 
255  default:
256  throw std::runtime_error( "Unknown error occurred when creating the framebuffer." );
257  break;
258  }
259 
260  return 0;
261  }
262 
264 
265  // Return to direct rendering (we were asked only to create a buffer, not switch to one)
267 
268  // Store the new buffer
269  OPENGL_BUFFER buffer = { aDimensions, textureTarget, attachmentPoint };
270  m_buffers.push_back( buffer );
271 
272  return usedBuffers();
273 }
void bindFb(unsigned int aFb)
Binds a specific Framebuffer Object.
static const COLOR4D BLACK
Definition: color4d.h:381
unsigned int usedBuffers()
Returns number of used buffers.
int checkGlError(const std::string &aInfo, const char *aFile, int aLine, bool aThrow)
Check if a recent OpenGL operation has failed.
Definition: utils.cpp:45
bool m_initialized
Initialization status flag.
static const unsigned int DIRECT_RENDERING
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).
GLuint m_mainFbo
Main FBO handle (storing all target textures)
OPENGL_BUFFERS m_buffers
Stores information about initialized buffers.

References bindFb(), KIGFX::COLOR4D::BLACK, checkGlError(), ClearBuffer(), DIRECT_RENDERING, m_buffers, m_initialized, m_mainFbo, usedBuffers(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ DrawBuffer() [1/2]

void OPENGL_COMPOSITOR::DrawBuffer ( unsigned int  aBufferHandle)
overridevirtual

Draw the selected buffer to the output buffer.

Parameters
aBufferHandleis the handle of the buffer to be drawn.

Implements KIGFX::COMPOSITOR.

Definition at line 329 of file opengl_compositor.cpp.

330 {
331  m_antialiasing->DrawBuffer( aBufferHandle );
332 }
std::unique_ptr< OPENGL_PRESENTOR > m_antialiasing

References m_antialiasing.

Referenced by KIGFX::ANTIALIASING_NONE::DrawBuffer(), KIGFX::ANTIALIASING_SUPERSAMPLING::DrawBuffer(), KIGFX::ANTIALIASING_SMAA::DrawBuffer(), and KIGFX::OPENGL_GAL::endDrawing().

◆ DrawBuffer() [2/2]

void OPENGL_COMPOSITOR::DrawBuffer ( unsigned int  aSourceHandle,
unsigned int  aDestHandle 
)

Definition at line 335 of file opengl_compositor.cpp.

336 {
337  assert( m_initialized );
338  assert( aSourceHandle != 0 && aSourceHandle <= usedBuffers() );
339  assert( aDestHandle <= usedBuffers() );
340 
341  // Switch to the destination buffer and blit the scene
342  SetBuffer( aDestHandle );
343 
344  // Depth test has to be disabled to make transparency working
345  glDisable( GL_DEPTH_TEST );
346  glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
347 
348  // Enable texturing and bind the main texture
349  glEnable( GL_TEXTURE_2D );
350  glBindTexture( GL_TEXTURE_2D, m_buffers[aSourceHandle - 1].textureTarget );
351 
352  // Draw a full screen quad with the texture
353  glMatrixMode( GL_MODELVIEW );
354  glPushMatrix();
355  glLoadIdentity();
356  glMatrixMode( GL_PROJECTION );
357  glPushMatrix();
358  glLoadIdentity();
359 
360  glBegin( GL_TRIANGLES );
361  glTexCoord2f( 0.0f, 1.0f );
362  glVertex2f( -1.0f, 1.0f );
363  glTexCoord2f( 0.0f, 0.0f );
364  glVertex2f( -1.0f, -1.0f );
365  glTexCoord2f( 1.0f, 1.0f );
366  glVertex2f( 1.0f, 1.0f );
367 
368  glTexCoord2f( 1.0f, 1.0f );
369  glVertex2f( 1.0f, 1.0f );
370  glTexCoord2f( 0.0f, 0.0f );
371  glVertex2f( -1.0f, -1.0f );
372  glTexCoord2f( 1.0f, 0.0f );
373  glVertex2f( 1.0f, -1.0f );
374  glEnd();
375 
376  glPopMatrix();
377  glMatrixMode( GL_MODELVIEW );
378  glPopMatrix();
379 }
unsigned int usedBuffers()
Returns number of used buffers.
bool m_initialized
Initialization status flag.
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
OPENGL_BUFFERS m_buffers
Stores information about initialized buffers.

References m_buffers, m_initialized, SetBuffer(), and usedBuffers().

◆ GetAntialiasingMode()

OPENGL_ANTIALIASING_MODE OPENGL_COMPOSITOR::GetAntialiasingMode ( ) const

Definition at line 83 of file opengl_compositor.cpp.

84 {
86 }
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode

References m_currentAntialiasingMode.

Referenced by KIGFX::OPENGL_GAL::updatedGalDisplayOptions().

◆ GetAntialiasRenderingOffset()

VECTOR2D OPENGL_COMPOSITOR::GetAntialiasRenderingOffset ( ) const

Definition at line 436 of file opengl_compositor.cpp.

437 {
438  switch( m_currentAntialiasingMode )
439  {
440  case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING: return VECTOR2D( 0.5, -0.5 );
441  default: return VECTOR2D( 0, 0 );
442  }
443 }
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622

References m_currentAntialiasingMode, and KIGFX::SUPERSAMPLING.

Referenced by KIGFX::OPENGL_GAL::beginDrawing().

◆ GetAntialiasSupersamplingFactor()

int OPENGL_COMPOSITOR::GetAntialiasSupersamplingFactor ( ) const

Definition at line 425 of file opengl_compositor.cpp.

426 {
427  switch ( m_currentAntialiasingMode )
428  {
430  return 2;
431  default:
432  return 1;
433  }
434 }
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode

References m_currentAntialiasingMode, and KIGFX::SUPERSAMPLING.

Referenced by KIGFX::OPENGL_GAL::beginDrawing().

◆ GetBuffer()

virtual unsigned int KIGFX::OPENGL_COMPOSITOR::GetBuffer ( ) const
inlineoverridevirtual

Return currently used buffer handle.

Returns
Currently used buffer handle.

Implements KIGFX::COMPOSITOR.

Definition at line 65 of file opengl_compositor.h.

66  {
67  if( m_curFbo == DIRECT_RENDERING )
68  return DIRECT_RENDERING;
69 
70  return m_curBuffer + 1;
71  }
unsigned int m_curBuffer
Currently used buffer handle.
static const unsigned int DIRECT_RENDERING
GLuint m_curFbo
Store the used FBO name in case there was more than one compositor used.

References DIRECT_RENDERING, m_curBuffer, and m_curFbo.

Referenced by KIGFX::OPENGL_GAL::ClearTarget().

◆ GetBufferTexture()

GLenum OPENGL_COMPOSITOR::GetBufferTexture ( unsigned int  aBufferHandle)

Definition at line 276 of file opengl_compositor.cpp.

277 {
278  assert( aBufferHandle > 0 && aBufferHandle <= usedBuffers() );
279  return m_buffers[aBufferHandle - 1].textureTarget;
280 }
unsigned int usedBuffers()
Returns number of used buffers.
OPENGL_BUFFERS m_buffers
Stores information about initialized buffers.

References m_buffers, and usedBuffers().

Referenced by KIGFX::ANTIALIASING_SUPERSAMPLING::Present(), and KIGFX::ANTIALIASING_SMAA::Present().

◆ GetScreenSize()

◆ Initialize()

void OPENGL_COMPOSITOR::Initialize ( )
overridevirtual

Perform primary initialization, necessary to use the object.

Implements KIGFX::COMPOSITOR.

Definition at line 89 of file opengl_compositor.cpp.

90 {
91  if( m_initialized )
92  return;
93 
95  {
97  m_antialiasing = std::make_unique<ANTIALIASING_SMAA>( this );
98  break;
100  m_antialiasing = std::make_unique<ANTIALIASING_SUPERSAMPLING>( this );
101  break;
102  default:
103  m_antialiasing = std::make_unique<ANTIALIASING_NONE>( this );
104  break;
105  }
106 
107  VECTOR2U dims = m_antialiasing->GetInternalBufferSize();
108  assert( dims.x != 0 && dims.y != 0 );
109 
110  GLint maxBufSize;
111  glGetIntegerv( GL_MAX_RENDERBUFFER_SIZE_EXT, &maxBufSize );
112 
113  // VECTOR2U is unsigned, so no need to check if < 0
114  if( dims.x > (unsigned) maxBufSize || dims.y >= (unsigned) maxBufSize )
115  throw std::runtime_error( "Requested render buffer size is not supported" );
116 
117  // We need framebuffer objects for drawing the screen contents
118  // Generate framebuffer and a depth buffer
119  glGenFramebuffersEXT( 1, &m_mainFbo );
120  checkGlError( "generating framebuffer", __FILE__, __LINE__ );
121  bindFb( m_mainFbo );
122 
123  // Allocate memory for the depth buffer
124  // Attach the depth buffer to the framebuffer
125  glGenRenderbuffersEXT( 1, &m_depthBuffer );
126  checkGlError( "generating renderbuffer", __FILE__, __LINE__ );
127  glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_depthBuffer );
128  checkGlError( "binding renderbuffer", __FILE__, __LINE__ );
129 
130  glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8, dims.x, dims.y );
131  checkGlError( "creating renderbuffer storage", __FILE__, __LINE__ );
132  glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT,
133  GL_RENDERBUFFER_EXT, m_depthBuffer );
134  checkGlError( "attaching renderbuffer", __FILE__, __LINE__ );
135 
136  // Unbind the framebuffer, so by default all the rendering goes directly to the display
138 
139  m_initialized = true;
140 
141  m_antialiasing->Init();
142 }
void bindFb(unsigned int aFb)
Binds a specific Framebuffer Object.
int checkGlError(const std::string &aInfo, const char *aFile, int aLine, bool aThrow)
Check if a recent OpenGL operation has failed.
Definition: utils.cpp:45
bool m_initialized
Initialization status flag.
static const unsigned int DIRECT_RENDERING
std::unique_ptr< OPENGL_PRESENTOR > m_antialiasing
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode
GLuint m_mainFbo
Main FBO handle (storing all target textures)
GLuint m_depthBuffer
Depth buffer handle.

References bindFb(), checkGlError(), DIRECT_RENDERING, m_antialiasing, m_currentAntialiasingMode, m_depthBuffer, m_initialized, m_mainFbo, KIGFX::SMAA, KIGFX::SUPERSAMPLING, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIGFX::OPENGL_GAL::beginDrawing().

◆ Present()

void OPENGL_COMPOSITOR::Present ( )
overridevirtual

Call this to present the output buffer to the screen.

Implements KIGFX::COMPOSITOR.

Definition at line 382 of file opengl_compositor.cpp.

383 {
384  m_antialiasing->Present();
385 }
std::unique_ptr< OPENGL_PRESENTOR > m_antialiasing

References m_antialiasing.

Referenced by KIGFX::OPENGL_GAL::endDrawing().

◆ Resize()

void OPENGL_COMPOSITOR::Resize ( unsigned int  aWidth,
unsigned int  aHeight 
)
overridevirtual

Clear the state of COMPOSITOR, so it has to be reinitialized again with the new dimensions.

Parameters
aWidthis the framebuffer width (in pixels).
aHeightis the framebuffer height (in pixels).

Implements KIGFX::COMPOSITOR.

Definition at line 145 of file opengl_compositor.cpp.

146 {
147  if( m_initialized )
148  clean();
149 
150  m_antialiasing->OnLostBuffers();
151 
152  m_width = aWidth;
153  m_height = aHeight;
154 }
unsigned int m_width
Width of the buffer (in pixels)
Definition: compositor.h:112
bool m_initialized
Initialization status flag.
std::unique_ptr< OPENGL_PRESENTOR > m_antialiasing
void clean()
Perform freeing of resources.
unsigned int m_height
Height of the buffer (in pixels)
Definition: compositor.h:113

References clean(), m_antialiasing, KIGFX::COMPOSITOR::m_height, m_initialized, and KIGFX::COMPOSITOR::m_width.

Referenced by KIGFX::OPENGL_GAL::ResizeScreen().

◆ SetAntialiasingMode()

void OPENGL_COMPOSITOR::SetAntialiasingMode ( OPENGL_ANTIALIASING_MODE  aMode)

Definition at line 74 of file opengl_compositor.cpp.

75 {
77 
78  if( m_initialized )
79  clean();
80 }
bool m_initialized
Initialization status flag.
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode
void clean()
Perform freeing of resources.

References clean(), m_currentAntialiasingMode, and m_initialized.

Referenced by KIGFX::OPENGL_GAL::OPENGL_GAL(), and KIGFX::OPENGL_GAL::updatedGalDisplayOptions().

◆ SetBuffer()

void OPENGL_COMPOSITOR::SetBuffer ( unsigned int  aBufferHandle)
overridevirtual

Set the selected buffer as the rendering target.

All the following drawing functions are going to be rendered in the selected buffer.

Parameters
aBufferHandleis the handle of the buffer or 0 in case of rendering directly to the display.

Implements KIGFX::COMPOSITOR.

Definition at line 283 of file opengl_compositor.cpp.

284 {
285  assert( m_initialized );
286  assert( aBufferHandle <= usedBuffers() );
287 
288  // Either unbind the FBO for direct rendering, or bind the one with target textures
289  bindFb( aBufferHandle == DIRECT_RENDERING ? DIRECT_RENDERING : m_mainFbo );
290 
291  // Switch the target texture
292  if( m_curFbo != DIRECT_RENDERING )
293  {
294  m_curBuffer = aBufferHandle - 1;
295  glDrawBuffer( m_buffers[m_curBuffer].attachmentPoint );
296  checkGlError( "setting draw buffer", __FILE__, __LINE__ );
297 
298  glViewport( 0, 0, m_buffers[m_curBuffer].dimensions.x,
299  m_buffers[m_curBuffer].dimensions.y );
300  }
301  else
302  {
303  glViewport( 0, 0, GetScreenSize().x, GetScreenSize().y );
304  }
305 }
unsigned int m_curBuffer
Currently used buffer handle.
void bindFb(unsigned int aFb)
Binds a specific Framebuffer Object.
unsigned int usedBuffers()
Returns number of used buffers.
int checkGlError(const std::string &aInfo, const char *aFile, int aLine, bool aThrow)
Check if a recent OpenGL operation has failed.
Definition: utils.cpp:45
bool m_initialized
Initialization status flag.
static const unsigned int DIRECT_RENDERING
GLuint m_curFbo
Store the used FBO name in case there was more than one compositor used.
GLuint m_mainFbo
Main FBO handle (storing all target textures)
OPENGL_BUFFERS m_buffers
Stores information about initialized buffers.

References bindFb(), checkGlError(), DIRECT_RENDERING, GetScreenSize(), m_buffers, m_curBuffer, m_curFbo, m_initialized, m_mainFbo, and usedBuffers().

Referenced by KIGFX::ANTIALIASING_SUPERSAMPLING::Begin(), KIGFX::ANTIALIASING_SMAA::Begin(), KIGFX::OPENGL_GAL::beginDrawing(), KIGFX::OPENGL_GAL::blitCursor(), KIGFX::OPENGL_GAL::ClearScreen(), KIGFX::OPENGL_GAL::ClearTarget(), DrawBuffer(), KIGFX::OPENGL_GAL::DrawGrid(), KIGFX::OPENGL_GAL::endDrawing(), KIGFX::ANTIALIASING_SUPERSAMPLING::Present(), and KIGFX::ANTIALIASING_SMAA::Present().

◆ usedBuffers()

unsigned int KIGFX::OPENGL_COMPOSITOR::usedBuffers ( )
inlineprotected

Returns number of used buffers.

Definition at line 109 of file opengl_compositor.h.

110  {
111  return m_buffers.size();
112  }
OPENGL_BUFFERS m_buffers
Stores information about initialized buffers.

References m_buffers.

Referenced by CreateBuffer(), DrawBuffer(), GetBufferTexture(), and SetBuffer().

Member Data Documentation

◆ DIRECT_RENDERING

◆ m_antialiasing

std::unique_ptr<OPENGL_PRESENTOR> KIGFX::OPENGL_COMPOSITOR::m_antialiasing
protected

◆ m_buffers

OPENGL_BUFFERS KIGFX::OPENGL_COMPOSITOR::m_buffers
protected

Stores information about initialized buffers.

Definition at line 129 of file opengl_compositor.h.

Referenced by clean(), CreateBuffer(), DrawBuffer(), GetBufferTexture(), SetBuffer(), and usedBuffers().

◆ m_curBuffer

unsigned int KIGFX::OPENGL_COMPOSITOR::m_curBuffer
protected

Currently used buffer handle.

Definition at line 123 of file opengl_compositor.h.

Referenced by GetBuffer(), and SetBuffer().

◆ m_curFbo

GLuint KIGFX::OPENGL_COMPOSITOR::m_curFbo
protected

Store the used FBO name in case there was more than one compositor used.

Definition at line 132 of file opengl_compositor.h.

Referenced by bindFb(), GetBuffer(), and SetBuffer().

◆ m_currentAntialiasingMode

OPENGL_ANTIALIASING_MODE KIGFX::OPENGL_COMPOSITOR::m_currentAntialiasingMode
protected

◆ m_depthBuffer

GLuint KIGFX::OPENGL_COMPOSITOR::m_depthBuffer
protected

Depth buffer handle.

Definition at line 125 of file opengl_compositor.h.

Referenced by clean(), and Initialize().

◆ m_height

unsigned int KIGFX::COMPOSITOR::m_height
protectedinherited

Height of the buffer (in pixels)

Definition at line 113 of file compositor.h.

Referenced by KIGFX::CAIRO_COMPOSITOR::CreateBuffer(), GetScreenSize(), KIGFX::CAIRO_COMPOSITOR::Resize(), and Resize().

◆ m_initialized

bool KIGFX::OPENGL_COMPOSITOR::m_initialized
protected

Initialization status flag.

Definition at line 122 of file opengl_compositor.h.

Referenced by clean(), ClearBuffer(), CreateBuffer(), DrawBuffer(), Initialize(), Resize(), SetAntialiasingMode(), SetBuffer(), and ~OPENGL_COMPOSITOR().

◆ m_mainFbo

GLuint KIGFX::OPENGL_COMPOSITOR::m_mainFbo
protected

Main FBO handle (storing all target textures)

Definition at line 124 of file opengl_compositor.h.

Referenced by bindFb(), clean(), CreateBuffer(), Initialize(), and SetBuffer().

◆ m_width

unsigned int KIGFX::COMPOSITOR::m_width
protectedinherited

Width of the buffer (in pixels)

Definition at line 112 of file compositor.h.

Referenced by KIGFX::CAIRO_COMPOSITOR::CreateBuffer(), GetScreenSize(), KIGFX::CAIRO_COMPOSITOR::Resize(), and Resize().


The documentation for this class was generated from the following files: