jGL
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
jGL::Shader Struct Referenceabstract

Generic shader program with vertex and fragment shader. More...

#include <shader.h>

Inheritance diagram for jGL::Shader:
Inheritance graph
[legend]

Public Member Functions

 Shader (const char *v, const char *f)
 Construct a Shader from a vertex and fragment source.
 
 Shader ()
 Construct an empty Shader.
 
 Shader (std::string path, std::string name)
 Construct a Shader from source given by paths.
 
virtual ~Shader ()=default
 
bool operator== (const Shader &s)
 
bool lint ()
 Check for common shader errors.
 
template<class T >
void setUniform (std::string name, T value)
 Set a Uniform to a value.
 
const std::string & getVertex () const
 
const std::string & getFragment () const
 
template<class T >
jGLUniform< T > getUniform (std::string name)
 Get a Uniform by name.
 
std::vector< std::string > getUniformNames ()
 Get all the parsed uniforms in the Shader.
 
virtual void use ()=0
 Use the shader.
 
std::string displayVertexSource () const
 Display the vertex shader with line numbers.
 
std::string displayFragmentSource () const
 Display the fragment shader with line numbers.
 

Protected Member Functions

std::string parseShaderSource (std::ifstream &file)
 
virtual void compile ()=0
 
bool parseUniforms ()
 
std::string formatWithLineNumbers (std::string shader) const
 
template<class T >
void detectUniformsAndCreate (std::string code)
 
virtual void setValue (jGLUniform< int > *u, int value)
 
virtual void setValue (jGLUniform< Sampler2D > *u, Sampler2D value)
 
virtual void setValue (jGLUniform< float > *u, float value)
 
virtual void setValue (jGLUniform< glm::vec2 > *u, glm::vec2 value)
 
virtual void setValue (jGLUniform< glm::vec4 > *u, glm::vec4 value)
 
virtual void setValue (jGLUniform< glm::mat4 > *u, glm::mat4 value)
 

Protected Attributes

std::string vertex
 
std::string fragment
 
std::unordered_map< std::string, std::shared_ptr< AbstractjGLUniform > > uniforms
 

Detailed Description

Generic shader program with vertex and fragment shader.

Remarks
Uniforms are automatically detected.

Constructor & Destructor Documentation

◆ Shader() [1/3]

jGL::Shader::Shader ( const char *  v,
const char *  f 
)
inline

Construct a Shader from a vertex and fragment source.

Parameters
vvertex shader source.
ffragment shader source.

◆ Shader() [2/3]

jGL::Shader::Shader ( )
inline

Construct an empty Shader.

◆ Shader() [3/3]

jGL::Shader::Shader ( std::string  path,
std::string  name 
)

Construct a Shader from source given by paths.

Parameters
pathpath the .vs and .fs shader sources.
namename of sources in path: name.vs and name.fs

◆ ~Shader()

virtual jGL::Shader::~Shader ( )
virtualdefault

Member Function Documentation

◆ compile()

virtual void jGL::Shader::compile ( )
protectedpure virtual

Implemented in jGL::GL::glShader.

◆ detectUniformsAndCreate()

template<class T >
void jGL::Shader::detectUniformsAndCreate ( std::string  code)
inlineprotected

◆ displayFragmentSource()

std::string jGL::Shader::displayFragmentSource ( ) const
inline

Display the fragment shader with line numbers.

Returns
std::string the formatted fragment shader

◆ displayVertexSource()

std::string jGL::Shader::displayVertexSource ( ) const
inline

Display the vertex shader with line numbers.

Returns
std::string the formatted vertex shader

◆ formatWithLineNumbers()

std::string jGL::Shader::formatWithLineNumbers ( std::string  shader) const
inlineprotected

◆ getFragment()

const std::string & jGL::Shader::getFragment ( ) const
inline

◆ getUniform()

template<class T >
jGLUniform< T > jGL::Shader::getUniform ( std::string  name)
inline

Get a Uniform by name.

Template Parameters
Tthe type of the uniform.
Parameters
namethe name of the uniform to get.
Returns
jGLUniform<T> the uniform found.

◆ getUniformNames()

std::vector< std::string > jGL::Shader::getUniformNames ( )
inline

Get all the parsed uniforms in the Shader.

Returns
std::vector<std::string> the available uniform names.

◆ getVertex()

const std::string & jGL::Shader::getVertex ( ) const
inline

◆ lint()

bool jGL::Shader::lint ( )

Check for common shader errors.

Returns
true linting passes.
false linting fails.

◆ operator==()

bool jGL::Shader::operator== ( const Shader s)
inline

◆ parseShaderSource()

std::string jGL::Shader::parseShaderSource ( std::ifstream &  file)
protected

◆ parseUniforms()

bool jGL::Shader::parseUniforms ( )
protected

◆ setUniform()

template<class T >
void jGL::Shader::setUniform ( std::string  name,
value 
)
inline

Set a Uniform to a value.

Template Parameters
Tthe type of uniform.
Parameters
namethe name of the uniform.
valuethe value of type T.

◆ setValue() [1/6]

virtual void jGL::Shader::setValue ( jGLUniform< float > *  u,
float  value 
)
inlineprotectedvirtual

◆ setValue() [2/6]

virtual void jGL::Shader::setValue ( jGLUniform< glm::mat4 > *  u,
glm::mat4  value 
)
inlineprotectedvirtual

◆ setValue() [3/6]

virtual void jGL::Shader::setValue ( jGLUniform< glm::vec2 > *  u,
glm::vec2  value 
)
inlineprotectedvirtual

◆ setValue() [4/6]

virtual void jGL::Shader::setValue ( jGLUniform< glm::vec4 > *  u,
glm::vec4  value 
)
inlineprotectedvirtual

◆ setValue() [5/6]

virtual void jGL::Shader::setValue ( jGLUniform< int > *  u,
int  value 
)
inlineprotectedvirtual

◆ setValue() [6/6]

virtual void jGL::Shader::setValue ( jGLUniform< Sampler2D > *  u,
Sampler2D  value 
)
inlineprotectedvirtual

◆ use()

virtual void jGL::Shader::use ( )
pure virtual

Use the shader.

Remarks
Use will auto-compile if required.

Implemented in jGL::GL::glShader, and jGL::Vulkan::vkShader.

Member Data Documentation

◆ fragment

std::string jGL::Shader::fragment
protected

◆ uniforms

std::unordered_map<std::string, std::shared_ptr<AbstractjGLUniform> > jGL::Shader::uniforms
protected

◆ vertex

std::string jGL::Shader::vertex
protected

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