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 ( OPENGL_COMPOSITOR aCompositor,
SUPERSAMPLING_MODE  aMode 
)

Definition at line 129 of file antialiasing.cpp.

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

Member Function Documentation

void ANTIALIASING_SUPERSAMPLING::Begin ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 182 of file antialiasing.cpp.

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

183 {
186 }
static const COLOR4D BLACK
Definition: color4d.h:296
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
unsigned int ANTIALIASING_SUPERSAMPLING::CreateBuffer ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 225 of file antialiasing.cpp.

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

226 {
228 }
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.
void ANTIALIASING_SUPERSAMPLING::DrawBuffer ( GLuint  aBuffer)
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 189 of file antialiasing.cpp.

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

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

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 175 of file antialiasing.cpp.

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

Referenced by CreateBuffer().

176 {
177  unsigned int factor = ( mode == SUPERSAMPLING_MODE::X2 ) ? 2 : 4;
178  return compositor->GetScreenSize() * factor;
179 }
OPENGL_COMPOSITOR * compositor
Definition: antialiasing.h:95
VECTOR2U GetScreenSize() const
bool ANTIALIASING_SUPERSAMPLING::Init ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 137 of file antialiasing.cpp.

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.

138 {
140  {
141  x4_shader.reset( new SHADER() );
144  x4_shader->Link();
145  checkGlError( "linking supersampling x4 shader" );
146 
147  GLint source_parameter = x4_shader->AddParameter( "source" ); checkGlError( "getting pass 1 colorTex" );
148 
149  x4_shader->Use(); checkGlError( "using pass 1 shader" );
150  x4_shader->SetParameter( source_parameter, 0 ); checkGlError( "setting colorTex uniform" );
151  x4_shader->Deactivate(); checkGlError( "deactivating pass 2 shader" );
152 
153  areShadersCreated = true;
154  }
155 
157  {
158  x4_shader.reset();
159  areShadersCreated = false;
160  }
161 
162  if( !areBuffersCreated )
163  {
165  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
166  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
167 
168  areBuffersCreated = true;
169  }
170 
171  return true;
172 }
Fragment shader.
Definition: shader.h:45
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:44
Class SHADER provides the access to the OpenGL shaders.
Definition: shader.h:74
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.
void ANTIALIASING_SUPERSAMPLING::OnLostBuffers ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 219 of file antialiasing.cpp.

References areBuffersCreated.

220 {
221  areBuffersCreated = false;
222 }
void ANTIALIASING_SUPERSAMPLING::Present ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 195 of file antialiasing.cpp.

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

196 {
197  glDisable( GL_BLEND );
198  glDisable( GL_DEPTH_TEST );
199  glActiveTexture( GL_TEXTURE0 );
200  glBindTexture( GL_TEXTURE_2D, compositor->GetBufferTexture( ssaaMainBuffer ) );
202 
204  {
205  x4_shader->Use();
206  checkGlError( "activating supersampling x4 shader" );
207  }
208 
209  draw_fullscreen_primitive();
210 
212  {
213  x4_shader->Deactivate();
214  checkGlError( "deactivating supersampling x4 shader" );
215  }
216 }
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)

Member Data Documentation

bool KIGFX::ANTIALIASING_SUPERSAMPLING::areBuffersCreated
private

Definition at line 99 of file antialiasing.h.

Referenced by Init(), and OnLostBuffers().

bool KIGFX::ANTIALIASING_SUPERSAMPLING::areShadersCreated
private

Definition at line 101 of file antialiasing.h.

Referenced by Init().

OPENGL_COMPOSITOR* KIGFX::ANTIALIASING_SUPERSAMPLING::compositor
private

Definition at line 95 of file antialiasing.h.

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

SUPERSAMPLING_MODE KIGFX::ANTIALIASING_SUPERSAMPLING::mode
private

Definition at line 96 of file antialiasing.h.

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

unsigned int KIGFX::ANTIALIASING_SUPERSAMPLING::ssaaMainBuffer
private

Definition at line 98 of file antialiasing.h.

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

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: