Add Attributes to Shader.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m40s

This commit is contained in:
2024-08-24 23:27:10 -04:00
parent f96a3851a1
commit 04a4cbd54d
6 changed files with 280 additions and 32 deletions

View File

@@ -15,9 +15,9 @@ namespace JGL {
COMBINED = 2,
};
//You could definitely do this with Typename T.
//Idk it increases the likelihood for mistakes.
class Uniform;
// You could definitely do this with Typename T.
// Idk it increases the likelihood for mistakes.
class ShaderValue;
class Uniform_Float;
class Uniform_Int;
@@ -30,61 +30,81 @@ namespace JGL {
class Uniform_Matrix2x2;
class Uniform_Matrix3x3;
class Uniform_Matrix4x4;
class Attribute_Vector2;
class Attribute_Vector3;
class Attribute_Vector4;
}
class JGL::Uniform {
class JGL::ShaderValue {
public:
std::string name;
GLint location = 0;
GLint location = -1;
};
class JGL::Uniform_Float : public Uniform {
class JGL::Uniform_Float : public ShaderValue {
public:
float value = 0;
};
class JGL::Uniform_Int : public Uniform {
class JGL::Uniform_Int : public ShaderValue {
public:
int value = 0;
};
class JGL::Uniform_Bool : public Uniform {
class JGL::Uniform_Bool : public ShaderValue {
public:
bool value = false;
};
class JGL::Uniform_Vector2 : public Uniform {
class JGL::Uniform_Vector2 : public ShaderValue {
public:
Vector2 value;
};
class JGL::Uniform_Vector3 : public Uniform {
class JGL::Uniform_Vector3 : public ShaderValue {
public:
Vector3 value;
};
class JGL::Uniform_Vector4 : public Uniform {
class JGL::Uniform_Vector4 : public ShaderValue {
public:
Vector4 value;
};
class JGL::Uniform_Matrix2x2 : public Uniform {
class JGL::Uniform_Matrix2x2 : public ShaderValue {
public:
Matrix2x2 value;
};
class JGL::Uniform_Matrix3x3 : public Uniform {
class JGL::Uniform_Matrix3x3 : public ShaderValue {
public:
Matrix3x3 value;
};
class JGL::Uniform_Matrix4x4 : public Uniform {
class JGL::Uniform_Matrix4x4 : public ShaderValue {
public:
Matrix4x4 value;
};
//TODO attributes.
class JGL::Attribute_Vector2 : public ShaderValue {
public:
std::vector<Vector2> value;
};
class JGL::Attribute_Vector3 : public ShaderValue {
public:
std::vector<Vector3> value;
};
class JGL::Attribute_Vector4 : public ShaderValue {
public:
std::vector<Vector4> value;
};
class JGL::Shader {
private:
///Shader program.
@@ -111,6 +131,12 @@ private:
std::vector<Uniform_Matrix3x3> matrix3x3_uniforms;
std::vector<Uniform_Matrix4x4> matrix4x4_uniforms;
/// Vertex Attributes are similar to Uniforms, but are per Vertex instead of per draw call.
/// Effectively an array list of elements such as position, normal, color, bone weights etc etc.
std::vector<Attribute_Vector2> vector2_attributes;
std::vector<Attribute_Vector3> vector3_attributes;
std::vector<Attribute_Vector4> vector4_attributes;
/// Varyings allow you to pass values from the Vertex pass to the Fragment pass.
/// They are defined in the shader source only.
private:
@@ -120,6 +146,7 @@ private:
public:
[[nodiscard]] GLuint GetGLShaderProgramHandle() const;
[[nodiscard]] ShaderType GetShaderType() const;
void ListUniforms();
public:
void SetUF(const std::string& uniform_name, float value);
void SetUI(const std::string& uniform_name, int value);
@@ -135,6 +162,13 @@ public:
void SetUMat3(const std::string& uniform_name, const Matrix3x3& value);
void SetUMat4(const std::string& uniform_name, const Matrix4x4& value);
void SetAV2(const std::string& attribute_name, const std::vector<Vector2>& value);
void SetAV2(const std::string& attribute_name, const Vector2* value, size_t size);
void SetAV3(const std::string& attribute_name, const std::vector<Vector3>& value);
void SetAV3(const std::string& attribute_name, const Vector3* value, size_t size);
void SetAV4(const std::string& attribute_name, const std::vector<Vector4>& value);
void SetAV4(const std::string& attribute_name, const Vector4* value, size_t size);
/// Zeroes out all uniforms locally.
void ResetLocalUniforms();
/// Zeroes out all uniforms locally and on the GPU.
@@ -142,9 +176,16 @@ public:
/// DMA the uniforms into the Shader Program.
void SubmitUniforms(bool reset_uniforms_in_local_store = true);
/// Sets the memory location at which the Shader Program will look for the Attribute list.
void SubmitAttributes();
/// Un-sets the memory location in the Shader Program and clears locally.
void ResetAttributes();
public:
Shader(const char* vertex_shader_file, const char* fragment_shader_file);
Shader(const std::string& vertex_shader_text, const std::string& fragment_shader_text);
void Erase() const;
void Erase();
Shader() = default;
~Shader();
};