KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KIGFX::SHADER Class Reference

Provide the access to the OpenGL shaders. More...

#include <shader.h>

Public Member Functions

 SHADER ()
 
virtual ~SHADER ()
 
template<typename... Args>
bool LoadShaderFromStrings (SHADER_TYPE aShaderType, Args &&... aArgs)
 Add a shader and compile the shader sources.
 
bool LoadShaderFromFile (SHADER_TYPE aShaderType, const std::string &aShaderSourceName)
 Load one of the built-in shaders and compiles it.
 
bool Link ()
 Link the shaders.
 
bool IsLinked () const
 Return true if shaders are linked correctly.
 
void Use ()
 Use the shader.
 
void Deactivate ()
 Deactivate the shader and use the default OpenGL program.
 
bool IsActive () const
 Return the current state of the shader.
 
void ConfigureGeometryShader (GLuint maxVertices, GLuint geometryInputType, GLuint geometryOutputType)
 Configure the geometry shader - has to be done before linking!
 
int AddParameter (const std::string &aParameterName)
 Add a parameter to the parameter queue.
 
void SetParameter (int aParameterNumber, float aValue) const
 Set a parameter of the shader.
 
void SetParameter (int aParameterNumber, int aValue) const
 
void SetParameter (int aParameterNumber, const VECTOR2D &aValue) const
 
void SetParameter (int aParameterNumber, float f0, float f1, float f2, float f3) const
 
int GetAttribute (const std::string &aAttributeName) const
 Get an attribute location.
 

Static Public Member Functions

static std::string ReadSource (const std::string &aShaderSourceName)
 Read the shader source file.
 

Private Member Functions

bool loadShaderFromStringArray (SHADER_TYPE aShaderType, const char **aArray, size_t aSize)
 Compile vertex of fragment shader source code into the program.
 
void programInfo (GLuint aProgram)
 Get the shader program information.
 
void shaderInfo (GLuint aShader)
 Get the shader information.
 

Private Attributes

std::deque< GLuint > shaderNumbers
 Shader number list.
 
GLuint programNumber
 Shader program number.
 
bool isProgramCreated
 Flag for program creation.
 
bool isShaderLinked
 Is the shader linked?
 
bool active
 Is any of shaders used?
 
GLuint maximumVertices
 The maximum of vertices to be generated.
 
GLuint geomInputType
 Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.].
 
GLuint geomOutputType
 
std::deque< GLint > parameterLocation
 Location of the parameter.
 

Detailed Description

Provide the access to the OpenGL shaders.

The purpose of this class is advanced drawing with OpenGL. One example is using the pixel shader for drawing exact circles or for anti-aliasing. This class supports vertex, geometry and fragment shaders.

Make sure that the hardware supports these features. This can be identified with the "GLEW" library.

Definition at line 76 of file shader.h.

Constructor & Destructor Documentation

◆ SHADER()

SHADER::SHADER ( )

Definition at line 41 of file shader.cpp.

References programNumber.

◆ ~SHADER()

SHADER::~SHADER ( )
virtual

Definition at line 55 of file shader.cpp.

References active, Deactivate(), isProgramCreated, programNumber, and shaderNumbers.

Member Function Documentation

◆ AddParameter()

int SHADER::AddParameter ( const std::string &  aParameterName)

Add a parameter to the parameter queue.

To communicate with the shader use this function to set up the names for the uniform variables. These are queued in a list and can be assigned with the SetParameter(..) method using the queue position.

Parameters
aParameterNameis the name of the parameter.
Returns
the added parameter location.

Definition at line 130 of file shader.cpp.

References parameterLocation, and programNumber.

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

◆ ConfigureGeometryShader()

void SHADER::ConfigureGeometryShader ( GLuint  maxVertices,
GLuint  geometryInputType,
GLuint  geometryOutputType 
)

Configure the geometry shader - has to be done before linking!

Parameters
maxVerticesis the maximum of vertices to be generated.
geometryInputTypeis the input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]
geometryOutputTypeis the output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]

Definition at line 92 of file shader.cpp.

References geomInputType, geomOutputType, and maximumVertices.

◆ Deactivate()

void KIGFX::SHADER::Deactivate ( )
inline

Deactivate the shader and use the default OpenGL program.

Definition at line 135 of file shader.h.

References active.

Referenced by KIGFX::OPENGL_GAL::BeginDrawing(), KIGFX::GPU_CACHED_MANAGER::EndDrawing(), KIGFX::GPU_NONCACHED_MANAGER::EndDrawing(), and ~SHADER().

◆ GetAttribute()

int SHADER::GetAttribute ( const std::string &  aAttributeName) const

Get an attribute location.

Parameters
aAttributeNameis the name of the attribute.
Returns
the location.

Definition at line 172 of file shader.cpp.

References programNumber.

Referenced by KIGFX::GPU_MANAGER::SetShader().

◆ IsActive()

bool KIGFX::SHADER::IsActive ( ) const
inline

Return the current state of the shader.

Returns
True if any of shaders is enabled.

Definition at line 146 of file shader.h.

References active.

◆ IsLinked()

bool KIGFX::SHADER::IsLinked ( ) const
inline

Return true if shaders are linked correctly.

Definition at line 118 of file shader.h.

References isShaderLinked.

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

◆ Link()

bool SHADER::Link ( )

Link the shaders.

Returns
true in case of success, false otherwise.

Definition at line 101 of file shader.cpp.

References isShaderLinked, programInfo(), and programNumber.

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

◆ LoadShaderFromFile()

bool SHADER::LoadShaderFromFile ( SHADER_TYPE  aShaderType,
const std::string &  aShaderSourceName 
)

Load one of the built-in shaders and compiles it.

Parameters
aShaderSourceNameis the shader source file name.
aShaderTypeis the type of the shader.
Returns
True in case of success, false otherwise.

Definition at line 83 of file shader.cpp.

References LoadShaderFromStrings(), and ReadSource().

◆ loadShaderFromStringArray()

bool SHADER::loadShaderFromStringArray ( SHADER_TYPE  aShaderType,
const char **  aArray,
size_t  aSize 
)
private

Compile vertex of fragment shader source code into the program.

Definition at line 238 of file shader.cpp.

References geomInputType, geomOutputType, isProgramCreated, isShaderLinked, maximumVertices, programInfo(), programNumber, KIGFX::SHADER_TYPE_GEOMETRY, shaderInfo(), and shaderNumbers.

Referenced by LoadShaderFromStrings().

◆ LoadShaderFromStrings()

template<typename... Args>
bool KIGFX::SHADER::LoadShaderFromStrings ( SHADER_TYPE  aShaderType,
Args &&...  aArgs 
)
inline

Add a shader and compile the shader sources.

Parameters
aArgsis the list of strings (std::string or convertible to const char*) which are concatenated and compiled as a single shader source code.
aShaderTypeis the type of the shader.
Returns
True in case of success, false otherwise.

Definition at line 93 of file shader.h.

References loadShaderFromStringArray(), and KIGFX::DETAIL::translateStringArg().

Referenced by KIGFX::OPENGL_GAL::init(), and LoadShaderFromFile().

◆ programInfo()

void SHADER::programInfo ( GLuint  aProgram)
private

Get the shader program information.

Parameters
aProgramis the program number.

Definition at line 178 of file shader.cpp.

Referenced by Link(), and loadShaderFromStringArray().

◆ ReadSource()

std::string SHADER::ReadSource ( const std::string &  aShaderSourceName)
static

Read the shader source file.

Parameters
aShaderSourceNameis the shader source file name.
Returns
the source as string

Definition at line 216 of file shader.cpp.

Referenced by LoadShaderFromFile().

◆ SetParameter() [1/4]

void SHADER::SetParameter ( int  aParameterNumber,
const VECTOR2D aValue 
) const

Definition at line 165 of file shader.cpp.

References parameterLocation, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SetParameter() [2/4]

void SHADER::SetParameter ( int  aParameterNumber,
float  aValue 
) const

Set a parameter of the shader.

Parameters
aParameterNumberis the number of the parameter.
aValueis the value of the parameter.

Definition at line 143 of file shader.cpp.

References parameterLocation.

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

◆ SetParameter() [3/4]

void SHADER::SetParameter ( int  aParameterNumber,
float  f0,
float  f1,
float  f2,
float  f3 
) const

Definition at line 158 of file shader.cpp.

References parameterLocation.

◆ SetParameter() [4/4]

void SHADER::SetParameter ( int  aParameterNumber,
int  aValue 
) const

Definition at line 151 of file shader.cpp.

References parameterLocation.

◆ shaderInfo()

void SHADER::shaderInfo ( GLuint  aShader)
private

Get the shader information.

Parameters
aShaderis the shader number.

Definition at line 197 of file shader.cpp.

Referenced by loadShaderFromStringArray().

◆ Use()

void KIGFX::SHADER::Use ( )
inline

Member Data Documentation

◆ active

bool KIGFX::SHADER::active
private

Is any of shaders used?

Definition at line 224 of file shader.h.

Referenced by Deactivate(), IsActive(), Use(), and ~SHADER().

◆ geomInputType

GLuint KIGFX::SHADER::geomInputType
private

Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.].

Definition at line 228 of file shader.h.

Referenced by ConfigureGeometryShader(), and loadShaderFromStringArray().

◆ geomOutputType

GLuint KIGFX::SHADER::geomOutputType
private

Definition at line 231 of file shader.h.

Referenced by ConfigureGeometryShader(), and loadShaderFromStringArray().

◆ isProgramCreated

bool KIGFX::SHADER::isProgramCreated
private

Flag for program creation.

Definition at line 222 of file shader.h.

Referenced by loadShaderFromStringArray(), and ~SHADER().

◆ isShaderLinked

bool KIGFX::SHADER::isShaderLinked
private

Is the shader linked?

Definition at line 223 of file shader.h.

Referenced by IsLinked(), Link(), and loadShaderFromStringArray().

◆ maximumVertices

GLuint KIGFX::SHADER::maximumVertices
private

The maximum of vertices to be generated.

Input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]

Definition at line 225 of file shader.h.

Referenced by ConfigureGeometryShader(), and loadShaderFromStringArray().

◆ parameterLocation

std::deque<GLint> KIGFX::SHADER::parameterLocation
private

Location of the parameter.

Definition at line 232 of file shader.h.

Referenced by AddParameter(), and SetParameter().

◆ programNumber

GLuint KIGFX::SHADER::programNumber
private

Shader program number.

Definition at line 221 of file shader.h.

Referenced by AddParameter(), GetAttribute(), Link(), loadShaderFromStringArray(), SHADER(), Use(), and ~SHADER().

◆ shaderNumbers

std::deque<GLuint> KIGFX::SHADER::shaderNumbers
private

Shader number list.

Definition at line 220 of file shader.h.

Referenced by loadShaderFromStringArray(), and ~SHADER().


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