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 46 of file opengl_compositor.cpp.

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

References m_antialiasing.

◆ ~OPENGL_COMPOSITOR()

OPENGL_COMPOSITOR::~OPENGL_COMPOSITOR ( )
virtual

Definition at line 58 of file opengl_compositor.cpp.

59{
60 if( m_initialized )
61 {
62 try
63 {
64 clean();
65 }
66 catch( const std::runtime_error& exc )
67 {
68 wxLogError( wxT( "Run time exception `%s` occurred in OPENGL_COMPOSITOR destructor." ),
69 exc.what() );
70 }
71 }
72}
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 312 of file opengl_compositor.cpp.

313{
314 m_antialiasing->Begin();
315}

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 377 of file opengl_compositor.cpp.

378{
379 // Currently there are only 2 valid FBOs
380 wxASSERT( aFb == DIRECT_RENDERING || aFb == m_mainFbo );
381
382 if( m_curFbo != aFb )
383 {
384 glBindFramebufferEXT( GL_FRAMEBUFFER, aFb );
385 checkGlError( "switching framebuffer", __FILE__, __LINE__ );
386 m_curFbo = aFb;
387 }
388}
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

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 391 of file opengl_compositor.cpp.

392{
393 wxASSERT( m_initialized );
394
396
397 for( const OPENGL_BUFFER& buffer : m_buffers )
398 glDeleteTextures( 1, &buffer.textureTarget );
399
400 m_buffers.clear();
401
402 if( glDeleteFramebuffersEXT )
403 glDeleteFramebuffersEXT( 1, &m_mainFbo );
404
405 if( glDeleteRenderbuffersEXT )
406 glDeleteRenderbuffersEXT( 1, &m_depthBuffer );
407
408 m_initialized = false;
409}
void bindFb(unsigned int aFb)
Binds a specific Framebuffer Object.
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 297 of file opengl_compositor.cpp.

298{
299 wxASSERT( m_initialized );
300
301 glClearColor( aColor.r, aColor.g, aColor.b, 0.0f );
302 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
303}
double r
Red component.
Definition: color4d.h:390
double g
Green component.
Definition: color4d.h:391
double b
Blue component.
Definition: color4d.h:392

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 158 of file opengl_compositor.cpp.

159{
160 return m_antialiasing->CreateBuffer();
161}

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 164 of file opengl_compositor.cpp.

165{
166 assert( m_initialized );
167
168 int maxBuffers, maxTextureSize;
169
170 // Get the maximum number of buffers
171 glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS, (GLint*) &maxBuffers );
172
173 if( (int) usedBuffers() >= maxBuffers )
174 {
175 throw std::runtime_error( "Cannot create more framebuffers. OpenGL rendering backend "
176 "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
222 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
223 throw std::runtime_error( "No images attached to the framebuffer." );
224
225 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
226 throw std::runtime_error( "The framebuffer does not have at least one "
227 "image attached to it." );
228
229 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
230 throw std::runtime_error( "The framebuffer read buffer is incomplete." );
231
232 case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
233 throw std::runtime_error( "The combination of internal formats of the attached "
234 "images violates an implementation-dependent set of "
235 "restrictions." );
236
237 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
238 throw std::runtime_error( "GL_RENDERBUFFER_SAMPLES is not the same for "
239 "all attached renderbuffers" );
240
241 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT:
242 throw std::runtime_error( "Framebuffer incomplete layer targets errors." );
243
244 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
245 throw std::runtime_error( "Framebuffer attachments have different dimensions" );
246
247 default:
248 throw std::runtime_error( "Unknown error occurred when creating the framebuffer." );
249 }
250 }
251
253
254 // Return to direct rendering (we were asked only to create a buffer, not switch to one)
256
257 // Store the new buffer
258 OPENGL_BUFFER buffer = { aDimensions, textureTarget, attachmentPoint };
259 m_buffers.push_back( buffer );
260
261 return usedBuffers();
262}
static const COLOR4D BLACK
Definition: color4d.h:400
unsigned int usedBuffers()
Returns number of used buffers.
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).

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 318 of file opengl_compositor.cpp.

319{
320 m_antialiasing->DrawBuffer( aBufferHandle );
321}

References m_antialiasing.

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

◆ DrawBuffer() [2/2]

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

Definition at line 324 of file opengl_compositor.cpp.

325{
326 wxASSERT( m_initialized );
327 wxASSERT( aSourceHandle != 0 && aSourceHandle <= usedBuffers() );
328 wxASSERT( aDestHandle <= usedBuffers() );
329
330 // Switch to the destination buffer and blit the scene
331 SetBuffer( aDestHandle );
332
333 // Depth test has to be disabled to make transparency working
334 glDisable( GL_DEPTH_TEST );
335 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
336
337 // Enable texturing and bind the main texture
338 glEnable( GL_TEXTURE_2D );
339 glBindTexture( GL_TEXTURE_2D, m_buffers[aSourceHandle - 1].textureTarget );
340
341 // Draw a full screen quad with the texture
342 glMatrixMode( GL_MODELVIEW );
343 glPushMatrix();
344 glLoadIdentity();
345 glMatrixMode( GL_PROJECTION );
346 glPushMatrix();
347 glLoadIdentity();
348
349 glBegin( GL_TRIANGLES );
350 glTexCoord2f( 0.0f, 1.0f );
351 glVertex2f( -1.0f, 1.0f );
352 glTexCoord2f( 0.0f, 0.0f );
353 glVertex2f( -1.0f, -1.0f );
354 glTexCoord2f( 1.0f, 1.0f );
355 glVertex2f( 1.0f, 1.0f );
356
357 glTexCoord2f( 1.0f, 1.0f );
358 glVertex2f( 1.0f, 1.0f );
359 glTexCoord2f( 0.0f, 0.0f );
360 glVertex2f( -1.0f, -1.0f );
361 glTexCoord2f( 1.0f, 0.0f );
362 glVertex2f( 1.0f, -1.0f );
363 glEnd();
364
365 glPopMatrix();
366 glMatrixMode( GL_MODELVIEW );
367 glPopMatrix();
368}
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.

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

◆ GetAntialiasingMode()

OPENGL_ANTIALIASING_MODE OPENGL_COMPOSITOR::GetAntialiasingMode ( ) const

Definition at line 84 of file opengl_compositor.cpp.

85{
87}

References m_currentAntialiasingMode.

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

◆ GetAntialiasRenderingOffset()

VECTOR2D OPENGL_COMPOSITOR::GetAntialiasRenderingOffset ( ) const

Definition at line 421 of file opengl_compositor.cpp.

422{
424 {
425 case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING: return VECTOR2D( 0.5, -0.5 );
426 default: return VECTOR2D( 0, 0 );
427 }
428}
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617

References m_currentAntialiasingMode, and KIGFX::SUPERSAMPLING.

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

◆ GetAntialiasSupersamplingFactor()

int OPENGL_COMPOSITOR::GetAntialiasSupersamplingFactor ( ) const

Definition at line 412 of file opengl_compositor.cpp.

413{
415 {
417 default: return 1;
418 }
419}

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 {
68 return DIRECT_RENDERING;
69
70 return m_curBuffer + 1;
71 }

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 265 of file opengl_compositor.cpp.

266{
267 wxASSERT( aBufferHandle > 0 && aBufferHandle <= usedBuffers() );
268 return m_buffers[aBufferHandle - 1].textureTarget;
269}

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 90 of file opengl_compositor.cpp.

91{
92 if( m_initialized )
93 return;
94
96 {
98 m_antialiasing = std::make_unique<ANTIALIASING_SMAA>( this );
99 break;
101 m_antialiasing = std::make_unique<ANTIALIASING_SUPERSAMPLING>( this );
102 break;
103 default:
104 m_antialiasing = std::make_unique<ANTIALIASING_NONE>( this );
105 break;
106 }
107
108 VECTOR2U dims = m_antialiasing->GetInternalBufferSize();
109 assert( dims.x != 0 && dims.y != 0 );
110
111 GLint maxBufSize;
112 glGetIntegerv( GL_MAX_RENDERBUFFER_SIZE_EXT, &maxBufSize );
113
114 // VECTOR2U is unsigned, so no need to check if < 0
115 if( dims.x > (unsigned) maxBufSize || dims.y >= (unsigned) maxBufSize )
116 throw std::runtime_error( "Requested render buffer size is not supported" );
117
118 // We need framebuffer objects for drawing the screen contents
119 // Generate framebuffer and a depth buffer
120 glGenFramebuffersEXT( 1, &m_mainFbo );
121 checkGlError( "generating framebuffer", __FILE__, __LINE__ );
122 bindFb( m_mainFbo );
123
124 // Allocate memory for the depth buffer
125 // Attach the depth buffer to the framebuffer
126 glGenRenderbuffersEXT( 1, &m_depthBuffer );
127 checkGlError( "generating renderbuffer", __FILE__, __LINE__ );
128 glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_depthBuffer );
129 checkGlError( "binding renderbuffer", __FILE__, __LINE__ );
130
131 glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8, dims.x, dims.y );
132 checkGlError( "creating renderbuffer storage", __FILE__, __LINE__ );
133 glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT,
134 GL_RENDERBUFFER_EXT, m_depthBuffer );
135 checkGlError( "attaching renderbuffer", __FILE__, __LINE__ );
136
137 // Unbind the framebuffer, so by default all the rendering goes directly to the display
139
140 m_initialized = true;
141
142 m_antialiasing->Init();
143}

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 371 of file opengl_compositor.cpp.

372{
373 m_antialiasing->Present();
374}

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 146 of file opengl_compositor.cpp.

147{
148 if( m_initialized )
149 clean();
150
151 m_antialiasing->OnLostBuffers();
152
153 m_width = aWidth;
154 m_height = aHeight;
155}

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)

◆ 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 272 of file opengl_compositor.cpp.

273{
274 wxASSERT( m_initialized );
275 wxASSERT( aBufferHandle <= usedBuffers() );
276
277 // Either unbind the FBO for direct rendering, or bind the one with target textures
278 bindFb( aBufferHandle == DIRECT_RENDERING ? DIRECT_RENDERING : m_mainFbo );
279
280 // Switch the target texture
282 {
283 m_curBuffer = aBufferHandle - 1;
284 glDrawBuffer( m_buffers[m_curBuffer].attachmentPoint );
285 checkGlError( "setting draw buffer", __FILE__, __LINE__ );
286
287 glViewport( 0, 0, m_buffers[m_curBuffer].dimensions.x,
288 m_buffers[m_curBuffer].dimensions.y );
289 }
290 else
291 {
292 glViewport( 0, 0, GetScreenSize().x, GetScreenSize().y );
293 }
294}

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 }

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: