Euphoria
Public Member Functions | Public Attributes | List of all members
eu::render::ShaderProgram Struct Reference

RAII representation of a open gl shader program. More...

Public Member Functions

 ShaderProgram (DEBUG_LABEL_ARG_MANY const std::string &vertex_source, const std::string &fragment_source, const CompiledShaderVertexAttributes &layout)
 Compile and link a shader.
 
 ~ShaderProgram ()
 Destroy the shader if it's loaded.
 
 ShaderProgram (const ShaderProgram &)=delete
 Copying is not allowed.
 
void operator= (const ShaderProgram &)=delete
 Copying is not allowed.
 
 ShaderProgram (ShaderProgram &&other) noexcept
 Take ownership of another shader.
 
ShaderProgramoperator= (ShaderProgram &&rhs) noexcept
 Take ownership of another shader.
 
void clear ()
 Turn this object into a zombie by destroying it.
 
bool is_loaded () const
 Checks if the ShaderProgram is loaded and valid.
 
void use () const
 Activates the ShaderProgram for rendering.
 
Uniform get_uniform (const std::string &name) const
 Get a uniform by name.
 
void set_float (const Uniform &uniform, float value)
 Sets a uniform float value.
 
void set_bool (const Uniform &uniform, bool value)
 Sets a uniform boolean value.
 
void set_vec2 (const Uniform &uniform, float x, float y)
 Sets a uniform 2d vector.
 
void set_vec2 (const Uniform &uniform, const v2 &v)
 Sets a uniform 2d vector.
 
void set_vec3 (const Uniform &uniform, float x, float y, float z)
 Sets a uniform 3d vector.
 
void set_vec3 (const Uniform &uniform, const v3 &v)
 Sets a uniform 3d vector.
 
void set_vec4 (const Uniform &uniform, float x, float y, float z, float w)
 Sets a uniform 4d vector.
 
void set_vec4 (const Uniform &uniform, const v4 &v)
 Sets a uniform 4d vector.
 
void set_texture (const Uniform &uniform)
 Sets a texture for a uniform.
 
void set_mat (const Uniform &uniform, const m4 &mat)
 Sets a uniform 4x4 matrix.
 
void setup_uniform_block (const UniformBufferSetup &setup)
 Configures a uniform block binding for the shader.
 

Public Attributes

unsigned int shader_program
 The id of the shader program.
 
VertexTypes debug_vertex_types
 The debug information describing the vertex layout that this shader expects.
 

Detailed Description

RAII representation of a open gl shader program.

Definition at line 24 of file shader.h.

Constructor & Destructor Documentation

◆ ShaderProgram() [1/3]

eu::render::ShaderProgram::ShaderProgram ( DEBUG_LABEL_ARG_MANY const std::string &  vertex_source,
const std::string &  fragment_source,
const CompiledShaderVertexAttributes layout 
)

Compile and link a shader.

If there are any errors, they are logged and a zombie object is created instead.

Parameters
vertex_sourceglsl code for the vertex shader
fragment_sourceglsl code for the fragment shader
layoutthe vertex layout to use

◆ ~ShaderProgram()

eu::render::ShaderProgram::~ShaderProgram ( )

Destroy the shader if it's loaded.

See also
clear

◆ ShaderProgram() [2/3]

eu::render::ShaderProgram::ShaderProgram ( const ShaderProgram )
delete

Copying is not allowed.

◆ ShaderProgram() [3/3]

eu::render::ShaderProgram::ShaderProgram ( ShaderProgram &&  other)
noexcept

Take ownership of another shader.

Parameters
otherthe shader to take ownership from

Member Function Documentation

◆ clear()

void eu::render::ShaderProgram::clear ( )

Turn this object into a zombie by destroying it.

Note
Does nothing if it already is a zombie

◆ get_uniform()

Uniform eu::render::ShaderProgram::get_uniform ( const std::string &  name) const

Get a uniform by name.

Parameters
namethe name of the uniform in the shader program
Returns
Uniform object representing the location or a zombie if not found

◆ is_loaded()

bool eu::render::ShaderProgram::is_loaded ( ) const

Checks if the ShaderProgram is loaded and valid.

Returns
true if the program is valid; otherwise, false

◆ operator=() [1/2]

void eu::render::ShaderProgram::operator= ( const ShaderProgram )
delete

Copying is not allowed.

◆ operator=() [2/2]

ShaderProgram & eu::render::ShaderProgram::operator= ( ShaderProgram &&  rhs)
noexcept

Take ownership of another shader.

Parameters
rhsthe shader to take ownership from

◆ set_bool()

void eu::render::ShaderProgram::set_bool ( const Uniform uniform,
bool  value 
)

Sets a uniform boolean value.

Parameters
uniformthe target uniform
valuethe value
Note
The shader must be bound before calling this method

◆ set_float()

void eu::render::ShaderProgram::set_float ( const Uniform uniform,
float  value 
)

Sets a uniform float value.

Does nothing if the uniform is a zombie.

Parameters
uniformthe target uniform
valuethe value
Note
The shader must be bound before calling this method

◆ set_mat()

void eu::render::ShaderProgram::set_mat ( const Uniform uniform,
const m4 mat 
)

Sets a uniform 4x4 matrix.

Parameters
uniformthe target uniform
matthe matrix data
Note
The shader must be bound before calling this method.

◆ set_texture()

void eu::render::ShaderProgram::set_texture ( const Uniform uniform)

Sets a texture for a uniform.

Does nothing if the uniform is a zombie.

Parameters
uniformthe target uniform (must be a texture uniform)
Note
The shader must be bound before calling this method.

◆ set_vec2() [1/2]

void eu::render::ShaderProgram::set_vec2 ( const Uniform uniform,
const v2 v 
)

Sets a uniform 2d vector.

Does nothing if the uniform is a zombie.

Parameters
uniformthe target uniform
vthe value
Note
The shader must be bound before calling this method.

◆ set_vec2() [2/2]

void eu::render::ShaderProgram::set_vec2 ( const Uniform uniform,
float  x,
float  y 
)

Sets a uniform 2d vector.

Does nothing if the uniform is a zombie.

Parameters
uniformthe target uniform
xthe x value of the vector
ythe y value of the vector
Note
The shader must be bound before calling this method.

◆ set_vec3() [1/2]

void eu::render::ShaderProgram::set_vec3 ( const Uniform uniform,
const v3 v 
)

Sets a uniform 3d vector.

Does nothing if the uniform is a zombie.

Parameters
uniformthe target uniform
vthe vector
Note
The shader must be bound before calling this method.

◆ set_vec3() [2/2]

void eu::render::ShaderProgram::set_vec3 ( const Uniform uniform,
float  x,
float  y,
float  z 
)

Sets a uniform 3d vector.

Does nothing if the uniform is a zombie.

Parameters
uniformthe target uniform
xthe x value of the vector
ythe y value of the vector
zthe z value of the vector
Note
The shader must be bound before calling this method.

◆ set_vec4() [1/2]

void eu::render::ShaderProgram::set_vec4 ( const Uniform uniform,
const v4 v 
)

Sets a uniform 4d vector.

Does nothing if the uniform is a zombie.

Parameters
uniformthe target uniform
vthe vector
Note
The shader must be bound before calling this method.

◆ set_vec4() [2/2]

void eu::render::ShaderProgram::set_vec4 ( const Uniform uniform,
float  x,
float  y,
float  z,
float  w 
)

Sets a uniform 4d vector.

Does nothing if the uniform is a zombie.

Parameters
uniformthe target uniform
xthe x value of the vector
ythe y value of the vector
zthe z value of the vector
wthe w value of the vector
Note
The shader must be bound before calling this method.

◆ setup_uniform_block()

void eu::render::ShaderProgram::setup_uniform_block ( const UniformBufferSetup setup)

Configures a uniform block binding for the shader.

Parameters
setupthe information about the uniform block setup

◆ use()

void eu::render::ShaderProgram::use ( ) const

Activates the ShaderProgram for rendering.

Member Data Documentation

◆ debug_vertex_types

VertexTypes eu::render::ShaderProgram::debug_vertex_types

The debug information describing the vertex layout that this shader expects.

Definition at line 170 of file shader.h.

◆ shader_program

unsigned int eu::render::ShaderProgram::shader_program

The id of the shader program.

Definition at line 169 of file shader.h.


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