More work on shader support.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m24s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m24s
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <JGL/types/enums.h>
|
||||
#include <JGL/types/FontCache.h>
|
||||
#include <JGL/types/Font.h>
|
||||
#include <JGL/types/Shader.h>
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector3.hpp>
|
||||
@@ -72,6 +73,11 @@ namespace JGL {
|
||||
/// @see Begin().
|
||||
void End();
|
||||
|
||||
/// Sets the active shader program to be used for rendering.
|
||||
/// 0 for default shader (fixed-function rendering).
|
||||
void UseProgram(const Shader& shader);
|
||||
void UseProgram(unsigned int shader_program_handle);
|
||||
|
||||
/// Plots a single pixel on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param coordinates The pixel-point on-screen at which to plot the pixel.
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/J3ML.hpp>
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
#include <glad/glad.h>
|
||||
|
||||
namespace JGL {
|
||||
@@ -11,8 +12,76 @@ namespace JGL {
|
||||
FRAGMENT = 1,
|
||||
COMBINED = 2,
|
||||
};
|
||||
|
||||
//You could definitely do this with Typename T.
|
||||
//Idk it increases the likelihood for mistakes.
|
||||
class Uniform;
|
||||
|
||||
class Uniform_Float;
|
||||
class Uniform_Int;
|
||||
class Uniform_Bool;
|
||||
|
||||
class Uniform_Vector2;
|
||||
class Uniform_Vector3;
|
||||
class Uniform_Vector4;
|
||||
|
||||
class Uniform_Matrix2x2;
|
||||
class Uniform_Matrix3x3;
|
||||
class Uniform_Matrix4x4;
|
||||
}
|
||||
|
||||
class JGL::Uniform {
|
||||
public:
|
||||
std::string name;
|
||||
GLint location = NULL;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Float : public Uniform {
|
||||
public:
|
||||
float value = 0;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Int : public Uniform {
|
||||
public:
|
||||
int value = 0;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Bool : public Uniform {
|
||||
public:
|
||||
bool value = false;
|
||||
};
|
||||
|
||||
|
||||
class JGL::Uniform_Vector2 : public Uniform {
|
||||
public:
|
||||
Vector2 value;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Vector3 : public Uniform {
|
||||
public:
|
||||
Vector3 value;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Vector4 : public Uniform {
|
||||
public:
|
||||
Vector4 value;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Matrix2x2 : public Uniform {
|
||||
public:
|
||||
Matrix2x2 value;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Matrix3x3 : public Uniform {
|
||||
public:
|
||||
Matrix3x3 value;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Matrix4x4 : public Uniform {
|
||||
public:
|
||||
Matrix4x4 value;
|
||||
};
|
||||
|
||||
class JGL::Shader {
|
||||
private:
|
||||
///Shader program.
|
||||
@@ -23,6 +92,24 @@ private:
|
||||
///Individual shaders which are compiled into the shader program.
|
||||
GLuint vertex_shader = 0;
|
||||
GLuint fragment_shader = 0;
|
||||
|
||||
/// Uniforms allow you to DMA values from the CPU to the GPU for this draw call.
|
||||
/// The Uniform will be the same for both the Vertex Shader & the Fragment Shader.
|
||||
std::vector<Uniform_Float> float_uniforms;
|
||||
std::vector<Uniform_Int> int_uniforms;
|
||||
std::vector<Uniform_Bool> bool_uniforms;
|
||||
|
||||
// TODO v2i, v3i, v4i
|
||||
std::vector<Uniform_Vector2> vector2_uniforms;
|
||||
std::vector<Uniform_Vector3> vector3_uniforms;
|
||||
std::vector<Uniform_Vector4> vector4_uniforms;
|
||||
|
||||
std::vector<Uniform_Matrix2x2> matrix2x2_uniforms;
|
||||
std::vector<Uniform_Matrix3x3> matrix3x3_uniforms;
|
||||
std::vector<Uniform_Matrix4x4> matrix4x4_uniforms;
|
||||
|
||||
/// Varyings allow you to pass values from the Vertex pass to the Fragment pass.
|
||||
/// They are defined in the shader source only.
|
||||
private:
|
||||
void load(const char* file_path, ShaderType type);
|
||||
void load(const std::string& shader_program_text, ShaderType type);
|
||||
@@ -30,11 +117,23 @@ private:
|
||||
public:
|
||||
[[nodiscard]] GLuint GetGLShaderProgramHandle() const;
|
||||
[[nodiscard]] ShaderType GetShaderType() const;
|
||||
void Erase() const;
|
||||
public:
|
||||
void SetFloat(const std::string& uniform_name, float value);
|
||||
void SetInt(const std::string& uniform_name, int value);
|
||||
void SetBool(const std::string& uniform_name, bool value);
|
||||
|
||||
void SetVector2(const std::string& uniform_name, const Vector2& value);
|
||||
void SetVector3(const std::string& uniform_name, const Vector3& value);
|
||||
void SetVector4(const std::string& uniform_name, const Vector4& value);
|
||||
|
||||
void SetMatrix2x2(const std::string& uniform_name, const Matrix2x2& value);
|
||||
void SetMatrix3x3(const std::string& uniform_name, const Matrix3x3& value);
|
||||
void SetMatrix4x4(const std::string& uniform_name, const Matrix4x4& value);
|
||||
|
||||
void ResetUniforms();
|
||||
public:
|
||||
Shader(const char* vertex_shader_file, const char* fragment_shader_file);
|
||||
Shader(const char* shader_file, ShaderType type);
|
||||
Shader(const std::string& vertex_shader_text, const std::string& fragment_shader_text);
|
||||
Shader(const std::string& shader_text, ShaderType type);
|
||||
void Erase() const;
|
||||
~Shader();
|
||||
};
|
Reference in New Issue
Block a user