SolarSim
Loading...
Searching...
No Matches
solarsim::Shader Struct Reference

Manages OpenGL shader program compilation and uniform setting. More...

#include <shader.hpp>

Public Member Functions

void use ()
 Activate this shader for rendering.
void bindBlocks ()
 Bind uniform buffer blocks to predefined binding points.
void setUniform (const std::string &name, const glm::mat4 &value)
 Set a mat4 uniform value.
void setUniform (const std::string &name, const glm::vec3 &value)
 Set a vec3 uniform value.
void setUniform (const std::string &name, float value)
 Set a float uniform value.
void setUniform (const std::string &name, int value)
 Set an integer uniform value.
void setUniform (const std::string &name, bool value)
 Set a boolean uniform value.
void compile (const std::string &vertexSrc, const std::string &fragmentSrc)
 Compile and link shader program from source code.
void checkCompileErrors (uint32_t shader, const std::string &type)
 Check for shader compilation or linking errors.

Data Fields

uint32_t programID = 0

Detailed Description

Manages OpenGL shader program compilation and uniform setting.

Note
Automatically binds common uniform blocks (Camera, Lights, Rigidbody)
Warning
Shader sources must be valid GLSL code

Member Function Documentation

◆ bindBlocks()

void solarsim::Shader::bindBlocks ( )
inline

Bind uniform buffer blocks to predefined binding points.

Note
Binds CameraBuffer(0), LightsBuffer(1), RigidbodyBuffer(2)
Warning
Call this after compilation, it's called automatically by compile()

◆ checkCompileErrors()

void solarsim::Shader::checkCompileErrors ( uint32_t shader,
const std::string & type )
inline

Check for shader compilation or linking errors.

Parameters
shaderShader or program object to check
typeType of shader ("VERTEX", "FRAGMENT", or "PROGRAM")
Note
Prints errors to std::cerr

◆ compile()

void solarsim::Shader::compile ( const std::string & vertexSrc,
const std::string & fragmentSrc )
inline

Compile and link shader program from source code.

Parameters
vertexSrcVertex shader source code
fragmentSrcFragment shader source code
Note
Automatically calls bindBlocks() after successful compilation

◆ setUniform() [1/5]

void solarsim::Shader::setUniform ( const std::string & name,
bool value )
inline

Set a boolean uniform value.

Parameters
nameUniform variable name in shader
valueBoolean value (converted to 0 or 1)

◆ setUniform() [2/5]

void solarsim::Shader::setUniform ( const std::string & name,
const glm::mat4 & value )
inline

Set a mat4 uniform value.

Parameters
nameUniform variable name in shader
value4x4 matrix value

◆ setUniform() [3/5]

void solarsim::Shader::setUniform ( const std::string & name,
const glm::vec3 & value )
inline

Set a vec3 uniform value.

Parameters
nameUniform variable name in shader
value3-component vector value

◆ setUniform() [4/5]

void solarsim::Shader::setUniform ( const std::string & name,
float value )
inline

Set a float uniform value.

Parameters
nameUniform variable name in shader
valueSingle float value

◆ setUniform() [5/5]

void solarsim::Shader::setUniform ( const std::string & name,
int value )
inline

Set an integer uniform value.

Parameters
nameUniform variable name in shader
valueInteger value

◆ use()

void solarsim::Shader::use ( )
inline

Activate this shader for rendering.

Field Documentation

◆ programID

uint32_t solarsim::Shader::programID = 0

The OpenGL shader program handle


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