Polygon Mesh Processing Library
Loading...
Searching...
No Matches
Shader Class Reference

Class for handling shaders. More...

#include <pmp/visualization/shader.h>

Public Member Functions

 ~Shader ()
 Default destructor, clears all shaders.
 
bool is_valid () const
 Indicate if shader is valid.
 
void source (const char *vshader, const char *fshader)
 Get source from strings, compile, and link vertex and fragment shader.
 
void load (const char *vfile, const char *ffile, const char *gfile=nullptr, const char *tcfile=nullptr, const char *tefile=nullptr)
 Load from file, compile, and link vertex and fragment shader, and optional geometry and tessellation shaders.
 
void use ()
 Enable/bind this shader program.
 
void disable ()
 Disable/unbind this shader program.
 
void bind_attribute (const char *name, GLuint index)
 Bind attribute to location.
 
void set_uniform (const char *name, float value)
 Upload float uniform.
 
void set_uniform (const char *name, int value)
 Upload int uniform.
 
void set_uniform (const char *name, const vec3 &vec)
 Upload vec3 uniform.
 
void set_uniform (const char *name, const vec4 &vec)
 Upload vec4 uniform.
 
void set_uniform (const char *name, const mat3 &mat)
 Upload mat3 uniform.
 
void set_uniform (const char *name, const mat4 &mat)
 Upload mat4 uniform.
 

Detailed Description

Class for handling shaders.

Member Function Documentation

◆ load()

void load ( const char *  vfile,
const char *  ffile,
const char *  gfile = nullptr,
const char *  tcfile = nullptr,
const char *  tefile = nullptr 
)

Load from file, compile, and link vertex and fragment shader, and optional geometry and tessellation shaders.

Unused shaders should be nullptr.

Parameters
vfilestring with the address to the vertex shader
ffilestring with the address to the fragment shader
gfilefilename of geometry shader
tcfilefilename of tessellation control shader
tefilefilename of tessellation evaluation shader

◆ set_uniform() [1/6]

void set_uniform ( const char *  name,
const mat3 mat 
)

Upload mat3 uniform.

Parameters
namestring of the uniform name
matthe value for the uniform

◆ set_uniform() [2/6]

void set_uniform ( const char *  name,
const mat4 mat 
)

Upload mat4 uniform.

Parameters
namestring of the uniform name
matthe value for the uniform

◆ set_uniform() [3/6]

void set_uniform ( const char *  name,
const vec3 vec 
)

Upload vec3 uniform.

Parameters
namestring of the uniform name
vecthe value for the uniform

◆ set_uniform() [4/6]

void set_uniform ( const char *  name,
const vec4 vec 
)

Upload vec4 uniform.

Parameters
namestring of the uniform name
vecthe value for the uniform

◆ set_uniform() [5/6]

void set_uniform ( const char *  name,
float  value 
)

Upload float uniform.

Parameters
namestring of the uniform name
valuethe value for the uniform

◆ set_uniform() [6/6]

void set_uniform ( const char *  name,
int  value 
)

Upload int uniform.

Parameters
namestring of the uniform name
valuethe value for the uniform

◆ source()

void source ( const char *  vshader,
const char *  fshader 
)

Get source from strings, compile, and link vertex and fragment shader.

Parameters
vshaderstring with the address to the vertex shader
fshaderstring with the address to the fragment shader