Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::xgl::ShaderProgram Class Referencefinal

Shader program having a default vertex and fragment shader. More...

#include <ShaderProgram.h>

Inheritance diagram for sf::xgl::ShaderProgram:
Collaboration diagram for sf::xgl::ShaderProgram:

Public Types

enum  Attribute { aPosition , aNormal , aColor , aTexCoord }
 Enumeration of available shader attributes to map data in the object buffers. The names of the enumerates need to correspond with the names in the vertex shader source. More...
 
enum  Uniform {
  uProgram , uPointSize , uModelMatrix , uViewMatrix ,
  uOffsetMatrix , uProjectionMatrix , uLightPosition , uLightDirection ,
  uCutoff , uOuterCutoff , uLightColor , uAmbientStrength ,
  uDiffuseStrength , uSpecularStrength , uShininess , uColor ,
  uTexture , uTextureEnable
}
 Enumeration of available shader uniforms. The names of the enumerates need to correspond with the names in the fragment shader source. More...
 

Public Member Functions

 Q_ENUM (Attribute)
 
 Q_ENUM (Uniform)
 
 ShaderProgram (QObject *parent=nullptr)
 Constructs a new shader program and attaches it to parent. The program will be invalid until addShader() is called. The shader program will be associated with the current QOpenGLContext.
 
const QOpenGLContext * context () const
 Get the OpenGL context of the program.
 
bool link () override
 Overridden from base class. Adds the shader sources to this instance.
 
int attributeLocation (Attribute sa) const
 Gets layout input location of the given shader attribute.
 
template<typename T >
getUniform (Uniform su)
 
template<typename T >
void setUniform (Uniform su, const T &value)
 Sets a uniform value by type.
 
void report (std::ostream &os) const
 Writes information on the shader programs.
 

Detailed Description

Shader program having a default vertex and fragment shader.

Member Enumeration Documentation

◆ Attribute

Enumeration of available shader attributes to map data in the object buffers. The names of the enumerates need to correspond with the names in the vertex shader source.

Enumerator
aPosition 

The vertex position as type 'vec3'.

aNormal 

The vertex normal as type 'vec3'.

aColor 

The vertex color as type 'vec4' having an alpha value.

aTexCoord 

The texture as 2D vector type 'vec2'.

◆ Uniform

Enumeration of available shader uniforms. The names of the enumerates need to correspond with the names in the fragment shader source.

Enumerator
uProgram 

Fragment uniform int for selecting the fragment program. Where the default is 'passthrough' and value 1 uses the 'spotlight' program.

uPointSize 

Vertex uniform float for setting the size a point when 'GL_PROGRAM_POINT_SIZE' is enabled.

uModelMatrix 

Vertex uniform mat4 for positioning an object in the 3D space.

uViewMatrix 

Vertex uniform mat4 for view/camera orientation position and passed by the vertex program and retrieved from the uViewMatrix.

uOffsetMatrix 

Vertex uniform mat4 as optional offset matrix for the model view matrix. The matrix translation W-value is the actual usage switch.

uProjectionMatrix 

Vertex and fragment uniform mat4 for the projection matrix set when the window resized using getPerspectiveMatrix().

uLightPosition 

Fragment uniform vec3 for positioning the spotlight.

uLightDirection 

Fragment uniform vec3 setting the direction of the spotlight.

uCutoff 

Fragment uniform vec3 cutoff angle in radians for the spotlight.

uOuterCutoff 

Fragment uniform float outer cutoff angle in radians for the spotlight.

uLightColor 

Fragment uniform vec4 for the light color in general.

uAmbientStrength 

Fragment uniform vec4 for the ambient light strength.

uDiffuseStrength 

Fragment uniform float for the diffused light strength.

uSpecularStrength 

Fragment uniform float for the specular light strength.

uShininess 

Fragment uniform float for the surface reflection light strength.

uColor 

Vertex uniform vec4 for a fixed color for drawing and is used when the alpha value is non-zero.

uTexture 

Fragment uniform sampler2D for sampling of the texture.

uTextureEnable 

Fragment uniform int to switch to texture for selecting the color.

Constructor & Destructor Documentation

◆ ShaderProgram()

sf::xgl::ShaderProgram::ShaderProgram ( QObject *  parent = nullptr)
explicit

Constructs a new shader program and attaches it to parent. The program will be invalid until addShader() is called. The shader program will be associated with the current QOpenGLContext.

Member Function Documentation

◆ attributeLocation()

int sf::xgl::ShaderProgram::attributeLocation ( Attribute  sa) const

Gets layout input location of the given shader attribute.

Returns
The location of input value

◆ context()

const QOpenGLContext * sf::xgl::ShaderProgram::context ( ) const

Get the OpenGL context of the program.

Returns
The current active context.

◆ getUniform()

template<typename T >
T sf::xgl::ShaderProgram::getUniform ( Uniform  su)

◆ link()

bool sf::xgl::ShaderProgram::link ( )
override

Overridden from base class. Adds the shader sources to this instance.

◆ Q_ENUM() [1/2]

sf::xgl::ShaderProgram::Q_ENUM ( Attribute  )

◆ Q_ENUM() [2/2]

sf::xgl::ShaderProgram::Q_ENUM ( Uniform  )

◆ report()

void sf::xgl::ShaderProgram::report ( std::ostream &  os) const

Writes information on the shader programs.

Parameters
os

◆ setUniform()

template<typename T >
void sf::xgl::ShaderProgram::setUniform ( Uniform  su,
const T &  value 
)

Sets a uniform value by type.

Template Parameters
TType of the passed value.
Parameters
suUniform to be set.
valueValue content.

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