cangine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
cangine::Shader Class Reference

Wraps a compiled and linked OpenGL shader program. More...

#include <shader.hpp>

Classes

struct  SourceTag
 

Public Member Functions

void use ()
 Activates this shader program for subsequent draw calls.
 
void unbind ()
 Deactivates the current shader program.
 
void setBool (const std::string &name, bool value)
 Sets a boolean uniform.
 
void setInt (const std::string &name, int value)
 Sets an integer uniform.
 
void setFloat (const std::string &name, float value)
 Sets a float uniform.
 
void setVec2 (const std::string &name, float x, float y)
 Sets a vec2 uniform.
 
void setVec3 (const std::string &name, float x, float y, float z)
 Sets a vec3 uniform.
 
void setVec4 (const std::string &name, float x, float y, float z, float w)
 Sets a vec4 uniform.
 
 Shader (std::string name, std::string shaderPath="./shaders")
 Loads, compiles and links a shader program.
 
 ~Shader ()
 Deletes the OpenGL shader program.
 

Static Public Member Functions

static Shader * fromSource (const std::string &vsSrc, const std::string &fsSrc)
 Creates a shader program compiled from source strings.
 

Public Attributes

std::string shaderPath
 Directory the shader sources are loaded from.
 
bool valid = true
 Whether compilation and linking succeeded.
 
unsigned int ID
 OpenGL shader program handle.
 
std::string name
 Base name of the shader source files.
 

Private Member Functions

void attach ()
 Attaches and links the compiled shader stages into the program.
 
void cleanUp ()
 Deletes the intermediate shader stage objects after linking.
 
void compileShaders ()
 Reads and compiles the vertex and fragment shader sources.
 
void compileFromSource (const std::string &vsSrc, const std::string &fsSrc)
 Compiles vertex and fragment shaders directly from source strings.
 
 Shader (const std::string &vsSrc, const std::string &fsSrc, SourceTag)
 

Private Attributes

unsigned int vs
 Compiled vertex shader handle.
 
unsigned int fs
 Compiled fragment shader handle.
 

Detailed Description

Wraps a compiled and linked OpenGL shader program.

Loads a vertex/fragment shader pair from disk, compiles and links them into a program, and exposes helpers for setting uniform values.

Constructor & Destructor Documentation

◆ Shader() [1/2]

cangine::Shader::Shader ( const std::string &  vsSrc,
const std::string &  fsSrc,
SourceTag   
)
private

◆ Shader() [2/2]

cangine::Shader::Shader ( std::string  name,
std::string  shaderPath = "./shaders" 
)

Loads, compiles and links a shader program.

Parameters
nameBase name of the shader source files.
shaderPathDirectory containing the shader sources.

◆ ~Shader()

cangine::Shader::~Shader ( )

Deletes the OpenGL shader program.

Member Function Documentation

◆ attach()

void cangine::Shader::attach ( )
private

Attaches and links the compiled shader stages into the program.

◆ cleanUp()

void cangine::Shader::cleanUp ( )
private

Deletes the intermediate shader stage objects after linking.

◆ compileFromSource()

void cangine::Shader::compileFromSource ( const std::string &  vsSrc,
const std::string &  fsSrc 
)
private

Compiles vertex and fragment shaders directly from source strings.

◆ compileShaders()

void cangine::Shader::compileShaders ( )
private

Reads and compiles the vertex and fragment shader sources.

◆ fromSource()

Shader * cangine::Shader::fromSource ( const std::string &  vsSrc,
const std::string &  fsSrc 
)
static

Creates a shader program compiled from source strings.

Parameters
vsSrcVertex shader GLSL source.
fsSrcFragment shader GLSL source.

◆ setBool()

void cangine::Shader::setBool ( const std::string &  name,
bool  value 
)

Sets a boolean uniform.

Parameters
nameUniform variable name.
valueValue to assign.

◆ setFloat()

void cangine::Shader::setFloat ( const std::string &  name,
float  value 
)

Sets a float uniform.

Parameters
nameUniform variable name.
valueValue to assign.

◆ setInt()

void cangine::Shader::setInt ( const std::string &  name,
int  value 
)

Sets an integer uniform.

Parameters
nameUniform variable name.
valueValue to assign.

◆ setVec2()

void cangine::Shader::setVec2 ( const std::string &  name,
float  x,
float  y 
)

Sets a vec2 uniform.

Parameters
nameUniform variable name.
xFirst component.
ySecond component.

◆ setVec3()

void cangine::Shader::setVec3 ( const std::string &  name,
float  x,
float  y,
float  z 
)

Sets a vec3 uniform.

Parameters
nameUniform variable name.
xFirst component.
ySecond component.
zThird component.

◆ setVec4()

void cangine::Shader::setVec4 ( const std::string &  name,
float  x,
float  y,
float  z,
float  w 
)

Sets a vec4 uniform.

Parameters
nameUniform variable name.
xFirst component.
ySecond component.
zThird component.
wFourth component.

◆ unbind()

void cangine::Shader::unbind ( )

Deactivates the current shader program.

◆ use()

void cangine::Shader::use ( )

Activates this shader program for subsequent draw calls.

Member Data Documentation

◆ fs

unsigned int cangine::Shader::fs
private

Compiled fragment shader handle.

◆ ID

unsigned int cangine::Shader::ID

OpenGL shader program handle.

◆ name

std::string cangine::Shader::name

Base name of the shader source files.

◆ shaderPath

std::string cangine::Shader::shaderPath

Directory the shader sources are loaded from.

◆ valid

bool cangine::Shader::valid = true

Whether compilation and linking succeeded.

◆ vs

unsigned int cangine::Shader::vs
private

Compiled vertex shader handle.


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