Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::ShaderProgram Class Reference

Linked GLSL program with cached uniform locations. More...

#include <ShaderProgram.h>

Public Member Functions

 ShaderProgram ()=delete
 
 ShaderProgram (const ShaderProgram &)=delete
 
ShaderProgramoperator= (const ShaderProgram &)=delete
 
 ShaderProgram (GLuint shaderProgramID)
 Wraps an existing linked GL program.
 
 ~ShaderProgram ()
 Calls glDeleteProgram() to release the GPU resource.
 
void Bind ()
 Activate this program for subsequent draw calls (glUseProgram).
 
GLint GetUniformLocation (const std::string &name)
 Look up a uniform location, caching the result for future calls.
 
Uniform Setters

Upload typed values to named GLSL uniforms.

void SetUniform (const std::string &name, float value)
 Upload a float uniform.
 
void SetUniform (const std::string &name, float v0, float v1)
 Upload a vec2 uniform.
 
void SetUniform (const std::string &name, float v0, float v1, float v2)
 Upload a vec3 uniform.
 
void SetUniform (const std::string &name, float v0, float v1, float v2, float v3)
 Upload a vec4 uniform.
 
void SetUniform (const std::string &name, const mat4 &mat)
 Upload a 4×4 matrix (column-major).
 
void SetUniform (const std::string &name, const vec3 &value)
 Upload a vec3 from a glm::vec3.
 
void SetUniform (const std::string &name, const mat4 *matrices, std::size_t count)
 Upload an array of 4×4 matrices.
 
void SetTexture (const std::string &name, Texture *texture)
 Bind a texture to the next available texture unit and set the sampler uniform.
 

Detailed Description

Linked GLSL program with cached uniform locations.

Non-copyable — each GL program handle is unique. Created exclusively by GraphicsAPI and typically stored in a std::shared_ptr<ShaderProgram>.

Definition at line 40 of file ShaderProgram.h.

Constructor & Destructor Documentation

◆ ShaderProgram() [1/3]

mnd::ShaderProgram::ShaderProgram ( )
delete

◆ ShaderProgram() [2/3]

mnd::ShaderProgram::ShaderProgram ( const ShaderProgram )
delete

◆ ShaderProgram() [3/3]

mnd::ShaderProgram::ShaderProgram ( GLuint  shaderProgramID)
explicit

Wraps an existing linked GL program.

Parameters
shaderProgramIDA GL program handle returned by glCreateProgram().

Definition at line 8 of file ShaderProgram.cpp.

References LOG_INFO.

◆ ~ShaderProgram()

mnd::ShaderProgram::~ShaderProgram ( )

Calls glDeleteProgram() to release the GPU resource.

Definition at line 14 of file ShaderProgram.cpp.

References LOG_INFO.

Member Function Documentation

◆ Bind()

void mnd::ShaderProgram::Bind ( )

Activate this program for subsequent draw calls (glUseProgram).

Definition at line 20 of file ShaderProgram.cpp.

◆ GetUniformLocation()

GLint mnd::ShaderProgram::GetUniformLocation ( const std::string &  name)

Look up a uniform location, caching the result for future calls.

Parameters
nameThe GLSL uniform variable name.
Returns
The GL uniform location, or -1 if not found.

Definition at line 26 of file ShaderProgram.cpp.

References LOG_WARN.

Referenced by SetTexture(), SetUniform(), SetUniform(), SetUniform(), SetUniform(), SetUniform(), SetUniform(), and SetUniform().

◆ operator=()

ShaderProgram & mnd::ShaderProgram::operator= ( const ShaderProgram )
delete

◆ SetTexture()

void mnd::ShaderProgram::SetTexture ( const std::string &  name,
Texture texture 
)

Bind a texture to the next available texture unit and set the sampler uniform.

Parameters
nameGLSL sampler uniform name (e.g. "uDiffuse").
textureTexture to bind; must not be nullptr.

Definition at line 86 of file ShaderProgram.cpp.

References mnd::Texture::GetID(), and GetUniformLocation().

◆ SetUniform() [1/7]

void mnd::ShaderProgram::SetUniform ( const std::string &  name,
const mat4 mat 
)

Upload a 4×4 matrix (column-major).

Definition at line 64 of file ShaderProgram.cpp.

References GetUniformLocation().

◆ SetUniform() [2/7]

void mnd::ShaderProgram::SetUniform ( const std::string &  name,
const mat4 matrices,
std::size_t  count 
)

Upload an array of 4×4 matrices.

Definition at line 76 of file ShaderProgram.cpp.

References GetUniformLocation().

◆ SetUniform() [3/7]

void mnd::ShaderProgram::SetUniform ( const std::string &  name,
const vec3 value 
)

Upload a vec3 from a glm::vec3.

Definition at line 70 of file ShaderProgram.cpp.

References GetUniformLocation().

◆ SetUniform() [4/7]

void mnd::ShaderProgram::SetUniform ( const std::string &  name,
float  v0,
float  v1 
)

Upload a vec2 uniform.

Definition at line 46 of file ShaderProgram.cpp.

References GetUniformLocation().

◆ SetUniform() [5/7]

void mnd::ShaderProgram::SetUniform ( const std::string &  name,
float  v0,
float  v1,
float  v2 
)

Upload a vec3 uniform.

Definition at line 52 of file ShaderProgram.cpp.

References GetUniformLocation().

◆ SetUniform() [6/7]

void mnd::ShaderProgram::SetUniform ( const std::string &  name,
float  v0,
float  v1,
float  v2,
float  v3 
)

Upload a vec4 uniform.

Definition at line 58 of file ShaderProgram.cpp.

References GetUniformLocation().

◆ SetUniform() [7/7]

void mnd::ShaderProgram::SetUniform ( const std::string &  name,
float  value 
)

Upload a float uniform.

Definition at line 40 of file ShaderProgram.cpp.

References GetUniformLocation().


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