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 128 of file antialiasing.cpp.

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

Member Function Documentation

void ANTIALIASING_SUPERSAMPLING::Begin ( )
overridevirtual

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 181 of file antialiasing.cpp.

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

182 {
185 }
virtual void ClearBuffer() 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 224 of file antialiasing.cpp.

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

225 {
227 }
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 188 of file antialiasing.cpp.

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

189 {
190  compositor->DrawBuffer( aBuffer, ssaaMainBuffer );
191 }
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 174 of file antialiasing.cpp.

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

Referenced by CreateBuffer().

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

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 136 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.

137 {
139  {
140  x4_shader.reset( new SHADER() );
143  x4_shader->Link();
144  checkGlError( "linking supersampling x4 shader" );
145 
146  GLint source_parameter = x4_shader->AddParameter( "source" ); checkGlError( "getting pass 1 colorTex" );
147 
148  x4_shader->Use(); checkGlError( "using pass 1 shader" );
149  x4_shader->SetParameter( source_parameter, 0 ); checkGlError( "setting colorTex uniform" );
150  x4_shader->Deactivate(); checkGlError( "deactivating pass 2 shader" );
151 
152  areShadersCreated = true;
153  }
154 
156  {
157  x4_shader.reset();
158  areShadersCreated = false;
159  }
160 
161  if( !areBuffersCreated )
162  {
164  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
165  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
166 
167  areBuffersCreated = true;
168  }
169 
170  return true;
171 }
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 218 of file antialiasing.cpp.

References areBuffersCreated.

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

Implements KIGFX::OPENGL_PRESENTOR.

Definition at line 194 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.

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