Implement doxygen annotation for Shader class.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m55s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m55s
This commit is contained in:
@@ -21,59 +21,91 @@ namespace JGL {
|
||||
|
||||
class JGL::Shader {
|
||||
public:
|
||||
Shader() {}
|
||||
/// The default constructor does not initialize any member values.
|
||||
Shader() = default;
|
||||
|
||||
/// Creates a shader by compiling a vertex and fragment program from the sources in the respective filesystem paths.
|
||||
Shader(std::filesystem::path vertex_source_path, std::filesystem::path fragment_source_path);
|
||||
|
||||
/// Creates a shader by compiling a vertex and fragment program from the respective GLSL source-strings.
|
||||
Shader(const std::string& vertex_code, const std::string& fragment_code);
|
||||
|
||||
/// @return True if the shader program successfully loaded and compiled.
|
||||
bool Loaded() const;
|
||||
unsigned int ID() const;
|
||||
/// @return The integer handle that OpenGL links to this shader program.
|
||||
unsigned int Handle() const;
|
||||
/// Enable this shader. All rendering performed thereafter will be affected by this shader code.
|
||||
/// @see UseDefault.
|
||||
void Use();
|
||||
|
||||
static void Use(GLuint shader_program_id);
|
||||
static void UseDefault();
|
||||
|
||||
|
||||
// TODO: Implement for hot-reloading.
|
||||
void Reload();
|
||||
// TODO: Implement for hot-reloading.
|
||||
void Unload();
|
||||
|
||||
template <typename T>
|
||||
void Set(const std::string& name, T value) const {
|
||||
// TODO: Throw error, no function-specialization: cannot pass shader uniform of type T.
|
||||
}
|
||||
template <typename T>
|
||||
void Set(const std::string& name, const T& value) const {
|
||||
// TODO: Throw error, no function-specialization: cannot pass shader uniform of type T.
|
||||
}
|
||||
|
||||
/// @return The Uniform variable linked to the specified name.
|
||||
/// A Uniform is global a variable that is unique per shader program object, and can be accessed from any shader at any stage in the shader program.
|
||||
GLint Uniform(const std::string& name) const;
|
||||
|
||||
/// @return The Attribute variable linked to the specified name.
|
||||
/// Attributes differ from Uniforms in that their value is different for each instance of the shader-program as it is running.
|
||||
GLint Attribute(const std::string& name) const;
|
||||
|
||||
/*template<> void Set<bool> (const std::string& name, bool value) const { SetBool(name, value); }
|
||||
template<> void Set<int> (const std::string& name, int value) const { SetInt(name, value); }
|
||||
template<> void Set<float>(const std::string& name, float value) const { SetFloat(name, value); }
|
||||
template<> void Set<Vector2>(const std::string& name, const Vector2& value) const { SetVector2(name, value); }
|
||||
template<> void Set<Vector3>(const std::string& name, const Vector3& value) const { SetVector3(name, value); }
|
||||
template<> void Set<Vector4>(const std::string& name, const Vector4& value) const { SetVector4(name, value); }*/
|
||||
/// Sets a `uniform bool name = value` in the shader program.
|
||||
void SetBool (const std::string& name, bool value) const;
|
||||
/// Sets a `uniform int name = value` in the shader program.
|
||||
void SetInt (const std::string& name, int value) const;
|
||||
/// Sets a `uniform float name = value` in the shader program.
|
||||
void SetFloat(const std::string& name, float value) const;
|
||||
/// Sets a `uniform vec2 name = value` in the shader program.
|
||||
/// @note GLSL has builtin vec2, while we implement a Vector2 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Vector2.
|
||||
void SetVector2(const std::string& name, const Vector2& value) const;
|
||||
/// Sets a `uniform vec2 name = value` in the shader program.
|
||||
/// @note GLSL has builtin vec2, while we implement a Vector2 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Vector2.
|
||||
void SetVector2(const std::string& name, float x, float y) const;
|
||||
/// Sets a `uniform vec3 name = value` in the shader program.
|
||||
/// @note GLSL has builtin vec3, while we implement a Vector3 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Vector3.
|
||||
void SetVector3(const std::string& name, const Vector3& value) const;
|
||||
/// Sets a `uniform vec3 name = value` in the shader program.
|
||||
/// @note GLSL has builtin vec3, while we implement a Vector3 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Vector3.
|
||||
void SetVector3(const std::string& name, float x, float y, float z) const;
|
||||
/// Sets a `uniform vec4 name = value` in the shader program.
|
||||
/// @note GLSL has builtin vec4, while we implement aVector4 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Vector4.
|
||||
void SetVector4(const std::string& name, const Vector4& value) const;
|
||||
/// Sets a `uniform vec4 name = value` in the shader program.
|
||||
/// @note GLSL has builtin vec4, while we implement a Vector4 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Vector4.
|
||||
void SetVector4(const std::string& name, float x, float y, float z, float w) const;
|
||||
|
||||
void SetBool (const std::string& name, bool value) const { glUniform1i(Uniform(name), (int)value); }
|
||||
void SetInt (const std::string& name, int value) const { glUniform1i(Uniform(name), value); }
|
||||
void SetFloat(const std::string& name, float value) const { glUniform1f(Uniform(name), value); }
|
||||
void SetVector2(const std::string& name, const Vector2& value) const { glUniform2f(Uniform(name), value.x, value.y); }
|
||||
void SetVector2(const std::string& name, float x, float y) const { glUniform2f(Uniform(name), x, y); }
|
||||
void SetVector3(const std::string& name, const Vector3& value) const { glUniform3f(Uniform(name), value.x, value.y, value.z); }
|
||||
void SetVector3(const std::string& name, float x, float y, float z) const { glUniform3f(Uniform(name), x, y, z); }
|
||||
void SetVector4(const std::string& name, const Vector4& value) const { glUniform4f(Uniform(name), value.x, value.y, value.z, value.w); }
|
||||
void SetVector4(const std::string& name, float x, float y, float z, float w) const { glUniform4f(Uniform(name), x, y, z, w); }
|
||||
/// Sets a `uniform mat2 name = value` in the shader program.
|
||||
/// @note GLSL has builtin mat2, while we implement a Matrix2x2 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Matrix2x2
|
||||
void SetMatrix2x2(const std::string& name, const Matrix2x2& value) const;
|
||||
|
||||
void SetMatrix2x2(const std::string& name, const Matrix2x2& value) const {}
|
||||
void SetMatrix3x3(const std::string& name, const Matrix3x3& value) const {}
|
||||
void SetMatrix4x4(const std::string& name, const Matrix4x4& value) const {}
|
||||
/// Sets a `uniform mat3 name = value` in the shader program.
|
||||
/// @note GLSL has builtin mat3, while we implement a Matrix3x3 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Matrix3x3
|
||||
void SetMatrix3x3(const std::string& name, const Matrix3x3& value) const;
|
||||
|
||||
/// Sets a `uniform mat4 name = value` in the shader program.
|
||||
/// @note GLSL has builtin mat4, while we implement a Matrix4x4 type. Please be aware there may be differences in implementation between them!
|
||||
/// @see class J3ML::LinearAlgebra::Matrix4x4
|
||||
void SetMatrix4x4(const std::string& name, const Matrix4x4& value) const;
|
||||
|
||||
|
||||
// TODO: Implement Uniform-Setters for GLSL types that do not have a J3ML corollary (dmat3x4, dvec4, etc).
|
||||
|
||||
protected:
|
||||
private:
|
||||
bool loaded;
|
||||
unsigned int id;
|
||||
unsigned int id = 0;
|
||||
std::string vertexPath;
|
||||
std::string fragmentPath;
|
||||
static void checkCompileErrors(GLuint shader, const std::string& type);
|
||||
|
@@ -97,6 +97,8 @@ namespace JGL {
|
||||
if (false)
|
||||
glDeleteShader(geometry);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Shader::checkCompileErrors(GLuint shader, const std::string& type) {
|
||||
@@ -180,9 +182,9 @@ namespace JGL {
|
||||
glUseProgram(id);
|
||||
}
|
||||
|
||||
bool Shader::Loaded() const { return loaded;}
|
||||
bool Shader::Loaded() const { return id != 0; }
|
||||
|
||||
unsigned int Shader::ID() const { return id;}
|
||||
unsigned int Shader::Handle() const { return id;}
|
||||
|
||||
void Shader::UseDefault() {
|
||||
glUseProgram(0);
|
||||
@@ -191,4 +193,40 @@ namespace JGL {
|
||||
void Shader::Use(GLuint shader_program_id) {
|
||||
glUseProgram(shader_program_id);
|
||||
}
|
||||
|
||||
void Shader::SetBool(const std::string &name, bool value) const { glUniform1i(Uniform(name), (int)value); }
|
||||
|
||||
void Shader::SetInt(const std::string &name, int value) const { glUniform1i(Uniform(name), value); }
|
||||
|
||||
void Shader::SetFloat(const std::string &name, float value) const { glUniform1f(Uniform(name), value); }
|
||||
|
||||
void Shader::SetVector2(const std::string &name, const Vector2 &value) const { glUniform2f(Uniform(name), value.x, value.y); }
|
||||
|
||||
void Shader::SetVector2(const std::string &name, float x, float y) const { glUniform2f(Uniform(name), x, y); }
|
||||
|
||||
void Shader::SetVector3(const std::string &name, const Vector3 &value) const { glUniform3f(Uniform(name), value.x, value.y, value.z); }
|
||||
|
||||
void Shader::SetVector3(const std::string &name, float x, float y, float z) const { glUniform3f(Uniform(name), x, y, z); }
|
||||
|
||||
void Shader::SetVector4(const std::string &name, const Vector4 &value) const { glUniform4f(Uniform(name), value.x, value.y, value.z, value.w); }
|
||||
|
||||
void Shader::SetVector4(const std::string &name, float x, float y, float z, float w) const { glUniform4f(Uniform(name), x, y, z, w); }
|
||||
|
||||
void Shader::SetMatrix2x2(const std::string &name, const Matrix2x2 &value) const {
|
||||
/// TODO: Verify if glsl expects row-major or col-major!!
|
||||
bool transpose = false;
|
||||
glUniformMatrix2fv(Uniform(name), 4, transpose, value.ptr());
|
||||
}
|
||||
|
||||
void Shader::SetMatrix3x3(const std::string &name, const Matrix3x3 &value) const {
|
||||
/// TODO: Verify if glsl expects row-major or col-major!!
|
||||
bool transpose = false;
|
||||
glUniformMatrix3fv(Uniform(name), 9, transpose, value.ptr());
|
||||
}
|
||||
|
||||
void Shader::SetMatrix4x4(const std::string &name, const Matrix4x4 &value) const {
|
||||
/// TODO: Verify if glsl expects row-major or col-major!!
|
||||
bool transpose = false;
|
||||
glUniformMatrix4fv(Uniform(name), 16, transpose, value.ptr());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user