KiCad PCB EDA Suite
KIGFX::ANTIALIASING_SUPERSAMPLING Class Reference

#include <antialiasing.h>

Inheritance diagram for KIGFX::ANTIALIASING_SUPERSAMPLING:
KIGFX::OPENGL_PRESENTOR

Public Member Functions

 ANTIALIASING_SUPERSAMPLING (OPENGL_COMPOSITOR *aCompositor, SUPERSAMPLING_MODE aMode)
 
bool Init () override
 
unsigned int CreateBuffer () override
 
VECTOR2U GetInternalBufferSize () override
 
void OnLostBuffers () override
 
void Begin () override
 
void DrawBuffer (GLuint) override
 
void Present () override
 

Private Attributes

OPENGL_COMPOSITORcompositor
 
SUPERSAMPLING_MODE mode
 
unsigned int ssaaMainBuffer
 
bool areBuffersCreated
 
bool areShadersCreated
 
std::unique_ptr< SHADERx4_shader
 

Detailed Description

Definition at line 79 of file antialiasing.h.

Constructor & Destructor Documentation

◆ ANTIALIASING_SUPERSAMPLING()

ANTIALIASING_SUPERSAMPLING::ANTIALIASING_SUPERSAMPLING ( OPENGL_COMPOSITOR aCompositor,
SUPERSAMPLING_MODE  aMode 
)

Definition at line 130 of file antialiasing.cpp.

132  : compositor( aCompositor ), mode( aMode ), ssaaMainBuffer( 0 ),
133  areBuffersCreated( false ), areShadersCreated( false )
134 {
135 }
OPENGL_COMPOSITOR * compositor
Definition: antialiasing.h:95

Member Function Documentation

◆ Begin()

void ANTIALIASING_SUPERSAMPLING::Begin ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 183 of file antialiasing.cpp.

184 {
187 }
static const COLOR4D BLACK
Definition: color4d.h:312
virtual void ClearBuffer(const COLOR4D &aColor) override
Function ClearBuffer() clears the selected buffer (set by the SetBuffer() function).
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
OPENGL_COMPOSITOR * compositor
Definition: antialiasing.h:95

References KIGFX::COLOR4D::BLACK, KIGFX::OPENGL_COMPOSITOR::ClearBuffer(), compositor, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), and ssaaMainBuffer.

◆ CreateBuffer()

unsigned int ANTIALIASING_SUPERSAMPLING::CreateBuffer ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 226 of file antialiasing.cpp.

227 {
229 }
VECTOR2U GetInternalBufferSize() override
OPENGL_COMPOSITOR * compositor
Definition: antialiasing.h:95
virtual unsigned int CreateBuffer() override
Function CreateBuffer() prepares a new buffer that may be used as a rendering target.

References compositor, KIGFX::OPENGL_COMPOSITOR::CreateBuffer(), and GetInternalBufferSize().

◆ DrawBuffer()

void ANTIALIASING_SUPERSAMPLING::DrawBuffer ( GLuint  aBuffer)
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 190 of file antialiasing.cpp.

191 {
192  compositor->DrawBuffer( aBuffer, ssaaMainBuffer );
193 }
virtual void DrawBuffer(unsigned int aBufferHandle) override
Function DrawBuffer() draws the selected buffer to the output buffer.
OPENGL_COMPOSITOR * compositor
Definition: antialiasing.h:95

References compositor, KIGFX::OPENGL_COMPOSITOR::DrawBuffer(), and ssaaMainBuffer.

◆ GetInternalBufferSize()

VECTOR2U ANTIALIASING_SUPERSAMPLING::GetInternalBufferSize ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 176 of file antialiasing.cpp.

177 {
178  unsigned int factor = ( mode == SUPERSAMPLING_MODE::X2 ) ? 2 : 4;
179  return compositor->GetScreenSize() * factor;
180 }
OPENGL_COMPOSITOR * compositor
Definition: antialiasing.h:95

References compositor, KIGFX::OPENGL_COMPOSITOR::GetScreenSize(), mode, and KIGFX::X2.

Referenced by CreateBuffer().

◆ Init()

bool ANTIALIASING_SUPERSAMPLING::Init ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 138 of file antialiasing.cpp.

139 {
141  {
142  x4_shader = std::make_unique<SHADER>( );
145  x4_shader->Link();
146  checkGlError( "linking supersampling x4 shader" );
147 
148  GLint source_parameter = x4_shader->AddParameter( "source" ); checkGlError( "getting pass 1 colorTex" );
149 
150  x4_shader->Use(); checkGlError( "using pass 1 shader" );
151  x4_shader->SetParameter( source_parameter, 0 ); checkGlError( "setting colorTex uniform" );
152  x4_shader->Deactivate(); checkGlError( "deactivating pass 2 shader" );
153 
154  areShadersCreated = true;
155  }
156 
158  {
159  x4_shader.reset();
160  areShadersCreated = false;
161  }
162 
163  if( !areBuffersCreated )
164  {
166  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
167  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
168 
169  areBuffersCreated = true;
170  }
171 
172  return true;
173 }
Fragment shader.
Definition: shader.h:47
int checkGlError(const std::string &aInfo, bool aThrow)
Checks if one of recent OpenGL operations has failed.
Definition: utils.cpp:30
std::unique_ptr< SHADER > x4_shader
Definition: antialiasing.h:102
Vertex shader.
Definition: shader.h:46
OPENGL_COMPOSITOR * compositor
Definition: antialiasing.h:95
virtual unsigned int CreateBuffer() override
Function CreateBuffer() prepares a new buffer that may be used as a rendering target.

References areBuffersCreated, areShadersCreated, checkGlError(), compositor, KIGFX::OPENGL_COMPOSITOR::CreateBuffer(), mode, KIGFX::SHADER_TYPE_FRAGMENT, KIGFX::SHADER_TYPE_VERTEX, KIGFX::BUILTIN_SHADERS::ssaa_x4_fragment_shader, KIGFX::BUILTIN_SHADERS::ssaa_x4_vertex_shader, ssaaMainBuffer, KIGFX::X4, and x4_shader.

◆ OnLostBuffers()

void ANTIALIASING_SUPERSAMPLING::OnLostBuffers ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 220 of file antialiasing.cpp.

221 {
222  areBuffersCreated = false;
223 }

References areBuffersCreated.

◆ Present()

void ANTIALIASING_SUPERSAMPLING::Present ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 196 of file antialiasing.cpp.

197 {
198  glDisable( GL_BLEND );
199  glDisable( GL_DEPTH_TEST );
200  glActiveTexture( GL_TEXTURE0 );
201  glBindTexture( GL_TEXTURE_2D, compositor->GetBufferTexture( ssaaMainBuffer ) );
203 
205  {
206  x4_shader->Use();
207  checkGlError( "activating supersampling x4 shader" );
208  }
209 
210  draw_fullscreen_primitive();
211 
213  {
214  x4_shader->Deactivate();
215  checkGlError( "deactivating supersampling x4 shader" );
216  }
217 }
int checkGlError(const std::string &aInfo, bool aThrow)
Checks if one of recent OpenGL operations has failed.
Definition: utils.cpp:30
static const unsigned int DIRECT_RENDERING
std::unique_ptr< SHADER > x4_shader
Definition: antialiasing.h:102
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
OPENGL_COMPOSITOR * compositor
Definition: antialiasing.h:95
GLenum GetBufferTexture(unsigned int aBufferHandle)

References checkGlError(), compositor, KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, KIGFX::OPENGL_COMPOSITOR::GetBufferTexture(), mode, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), ssaaMainBuffer, KIGFX::X4, and x4_shader.

Member Data Documentation

◆ areBuffersCreated

bool KIGFX::ANTIALIASING_SUPERSAMPLING::areBuffersCreated
private

Definition at line 99 of file antialiasing.h.

Referenced by Init(), and OnLostBuffers().

◆ areShadersCreated

bool KIGFX::ANTIALIASING_SUPERSAMPLING::areShadersCreated
private

Definition at line 101 of file antialiasing.h.

Referenced by Init().

◆ compositor

OPENGL_COMPOSITOR* KIGFX::ANTIALIASING_SUPERSAMPLING::compositor
private

Definition at line 95 of file antialiasing.h.

Referenced by Begin(), CreateBuffer(), DrawBuffer(), GetInternalBufferSize(), Init(), and Present().

◆ mode

SUPERSAMPLING_MODE KIGFX::ANTIALIASING_SUPERSAMPLING::mode
private

Definition at line 96 of file antialiasing.h.

Referenced by GetInternalBufferSize(), Init(), and Present().

◆ ssaaMainBuffer

unsigned int KIGFX::ANTIALIASING_SUPERSAMPLING::ssaaMainBuffer
private

Definition at line 98 of file antialiasing.h.

Referenced by Begin(), DrawBuffer(), Init(), and Present().

◆ x4_shader

std::unique_ptr<SHADER> KIGFX::ANTIALIASING_SUPERSAMPLING::x4_shader
private

Definition at line 102 of file antialiasing.h.

Referenced by Init(), and Present().


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