5#include "../engine/exception.hpp"
7#define CANGINE_DEFAULT_VERT_SRC R"(#version 330 core
8layout (location = 0) in vec3 aPos;
9layout (location = 1) in vec4 aColor;
10layout (location = 2) in vec2 uv;
15 gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
21#define CANGINE_DEFAULT_FRAG_SRC R"(#version 330 core
25uniform sampler2D uTexture;
26uniform bool uUseTexture;
34 float alpha = texture(uTexture, vUv).r;
35 FragColor = vec4(ColorOut.rgb, alpha * ColorOut.a);
39 vec4 t = texture(uTexture, vUv) * ColorOut;
101 void setInt(
const std::string&
name,
int value);
114 void setVec2(
const std::string&
name,
float x,
float y);
122 void setVec3(
const std::string&
name,
float x,
float y,
float z);
131 void setVec4(
const std::string&
name,
float x,
float y,
float z,
float w);
146 static Shader*
fromSource(
const std::string& vsSrc,
const std::string& fsSrc);
Wraps a compiled and linked OpenGL shader program.
Definition shader.hpp:61
void cleanUp()
Deletes the intermediate shader stage objects after linking.
Definition shader.cpp:69
void setBool(const std::string &name, bool value)
Sets a boolean uniform.
Definition shader.cpp:170
static Shader * fromSource(const std::string &vsSrc, const std::string &fsSrc)
Creates a shader program compiled from source strings.
Definition shader.cpp:153
void setVec4(const std::string &name, float x, float y, float z, float w)
Sets a vec4 uniform.
Definition shader.cpp:195
void setFloat(const std::string &name, float value)
Sets a float uniform.
Definition shader.cpp:180
void setVec2(const std::string &name, float x, float y)
Sets a vec2 uniform.
Definition shader.cpp:185
void use()
Activates this shader program for subsequent draw calls.
Definition shader.cpp:157
~Shader()
Deletes the OpenGL shader program.
Definition shader.cpp:47
void setInt(const std::string &name, int value)
Sets an integer uniform.
Definition shader.cpp:175
unsigned int ID
OpenGL shader program handle.
Definition shader.hpp:83
unsigned int vs
Compiled vertex shader handle.
Definition shader.hpp:63
void compileShaders()
Reads and compiles the vertex and fragment shader sources.
Definition shader.cpp:87
void setVec3(const std::string &name, float x, float y, float z)
Sets a vec3 uniform.
Definition shader.cpp:190
void compileFromSource(const std::string &vsSrc, const std::string &fsSrc)
Compiles vertex and fragment shaders directly from source strings.
Definition shader.cpp:74
std::string shaderPath
Directory the shader sources are loaded from.
Definition shader.hpp:80
unsigned int fs
Compiled fragment shader handle.
Definition shader.hpp:64
void attach()
Attaches and links the compiled shader stages into the program.
Definition shader.cpp:51
std::string name
Base name of the shader source files.
Definition shader.hpp:84
void unbind()
Deactivates the current shader program.
Definition shader.cpp:166
bool valid
Whether compilation and linking succeeded.
Definition shader.hpp:82
Definition audiomanager.cpp:4