|
KiCad PCB EDA Suite
|
Provide the access to the OpenGL shaders. More...
#include <shader.h>
Public Member Functions | |
| SHADER () | |
| virtual | ~SHADER () |
| void | Abandon () |
| Give up ownership of the program and shader objects without deleting them. | |
| 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 |
| Input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]. | |
| GLuint | geomOutputType |
| Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]. | |
| std::deque< GLint > | parameterLocation |
| Location of the parameter. | |
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 "GLAD" library.
| SHADER::SHADER | ( | ) |
Definition at line 37 of file shader.cpp.
References active, geomInputType, geomOutputType, isProgramCreated, isShaderLinked, maximumVertices, and programNumber.
|
virtual |
Definition at line 59 of file shader.cpp.
References active, Deactivate(), isProgramCreated, programNumber, and shaderNumbers.
| void SHADER::Abandon | ( | ) |
Give up ownership of the program and shader objects without deleting them.
Used when the owning context can no longer be made current. The names are released when that context is destroyed.
Definition at line 51 of file shader.cpp.
References active, isProgramCreated, and shaderNumbers.
| 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.
| aParameterName | is the name of the parameter. |
Definition at line 134 of file shader.cpp.
References location, parameterLocation, and programNumber.
| void SHADER::ConfigureGeometryShader | ( | GLuint | maxVertices, |
| GLuint | geometryInputType, | ||
| GLuint | geometryOutputType ) |
Configure the geometry shader - has to be done before linking!
| maxVertices | is the maximum of vertices to be generated. |
| geometryInputType | is the input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.] |
| geometryOutputType | is the output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.] |
Definition at line 96 of file shader.cpp.
References geomInputType, geomOutputType, and maximumVertices.
|
inline |
| int SHADER::GetAttribute | ( | const std::string & | aAttributeName | ) | const |
Get an attribute location.
| aAttributeName | is the name of the attribute. |
Definition at line 179 of file shader.cpp.
References programNumber.
|
inline |
|
inline |
Return true if shaders are linked correctly.
Definition at line 122 of file shader.h.
References isShaderLinked.
| bool SHADER::Link | ( | ) |
Link the shaders.
Definition at line 105 of file shader.cpp.
References isShaderLinked, programInfo(), and programNumber.
| bool SHADER::LoadShaderFromFile | ( | SHADER_TYPE | aShaderType, |
| const std::string & | aShaderSourceName ) |
Load one of the built-in shaders and compiles it.
| aShaderSourceName | is the shader source file name. |
| aShaderType | is the type of the shader. |
Definition at line 87 of file shader.cpp.
References LoadShaderFromStrings(), and ReadSource().
|
private |
Compile vertex of fragment shader source code into the program.
Definition at line 245 of file shader.cpp.
References geomInputType, geomOutputType, isProgramCreated, isShaderLinked, maximumVertices, programInfo(), programNumber, KIGFX::SHADER_TYPE_GEOMETRY, shaderInfo(), and shaderNumbers.
Referenced by LoadShaderFromStrings().
|
inline |
Add a shader and compile the shader sources.
| aArgs | is the list of strings (std::string or convertible to const char*) which are concatenated and compiled as a single shader source code. |
| aShaderType | is the type of the shader. |
Definition at line 97 of file shader.h.
References loadShaderFromStringArray(), and KIGFX::DETAIL::translateStringArg().
Referenced by LoadShaderFromFile().
|
private |
Get the shader program information.
| aProgram | is the program number. |
Definition at line 185 of file shader.cpp.
Referenced by Link(), and loadShaderFromStringArray().
|
static |
Read the shader source file.
| aShaderSourceName | is the shader source file name. |
Definition at line 223 of file shader.cpp.
Referenced by LoadShaderFromFile().
| void SHADER::SetParameter | ( | int | aParameterNumber, |
| const VECTOR2D & | aValue ) const |
Definition at line 171 of file shader.cpp.
References parameterLocation, VECTOR2< T >::x, and VECTOR2< T >::y.
| void SHADER::SetParameter | ( | int | aParameterNumber, |
| float | aValue ) const |
Set a parameter of the shader.
| aParameterNumber | is the number of the parameter. |
| aValue | is the value of the parameter. |
Definition at line 147 of file shader.cpp.
References parameterLocation.
| void SHADER::SetParameter | ( | int | aParameterNumber, |
| float | f0, | ||
| float | f1, | ||
| float | f2, | ||
| float | f3 ) const |
Definition at line 163 of file shader.cpp.
References parameterLocation.
| void SHADER::SetParameter | ( | int | aParameterNumber, |
| int | aValue ) const |
Definition at line 155 of file shader.cpp.
References parameterLocation.
|
private |
Get the shader information.
| aShader | is the shader number. |
Definition at line 204 of file shader.cpp.
Referenced by loadShaderFromStringArray().
|
inline |
|
private |
Is any of shaders used?
Definition at line 228 of file shader.h.
Referenced by Abandon(), Deactivate(), IsActive(), SHADER(), Use(), and ~SHADER().
|
private |
Input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.].
Definition at line 232 of file shader.h.
Referenced by ConfigureGeometryShader(), loadShaderFromStringArray(), and SHADER().
|
private |
Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.].
Definition at line 235 of file shader.h.
Referenced by ConfigureGeometryShader(), loadShaderFromStringArray(), and SHADER().
|
private |
|
private |
Is the shader linked?
Definition at line 227 of file shader.h.
Referenced by IsLinked(), Link(), loadShaderFromStringArray(), and SHADER().
|
private |
The maximum of vertices to be generated.
Definition at line 229 of file shader.h.
Referenced by ConfigureGeometryShader(), loadShaderFromStringArray(), and SHADER().
|
private |
Location of the parameter.
Definition at line 236 of file shader.h.
Referenced by AddParameter(), SetParameter(), SetParameter(), SetParameter(), and SetParameter().
|
private |
Shader program number.
Definition at line 225 of file shader.h.
Referenced by AddParameter(), GetAttribute(), Link(), loadShaderFromStringArray(), SHADER(), Use(), and ~SHADER().
|
private |
Shader number list.
Definition at line 224 of file shader.h.
Referenced by Abandon(), loadShaderFromStringArray(), and ~SHADER().