Refactor & undo shader commits AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 6m18s

This commit is contained in:
2024-09-05 11:20:57 -04:00
parent 55160044b6
commit ff2a8ab787
7 changed files with 97 additions and 1018 deletions

View File

@@ -21,7 +21,6 @@
#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,21 +71,9 @@ namespace JGL {
/// @see Begin().
void End();
/// Sets the active shader program to be used for rendering.
void UseShaderProgram(Shader& shader);
void UseShaderProgram(Shader* shader);
/// Changes back to fixed-function rendering.
void UseFixedFunction();
/// Returns true if we are not using fixed-function rendering.
bool IsUsingShaderProgram();
/// 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.
void DrawPoint(const Color3& color, const Vector2& coordinates, float radius = 1.f);
void DrawPoint(const Color3& color, float x, float y, float radius = 1.f);
void DrawPoint(const Color4& color, const Vector2& coordinates, float radius = 1.f);
void DrawPoint(const Color4& color, float x, float y, float radius = 1.f);
@@ -95,20 +82,15 @@ namespace JGL {
/// @param A The starting point of the line segment.
/// @param B The end point of the line segment.
/// @param thickness The width at which to render the line.
void DrawLine(const Color3& color, const Vector2& A, const Vector2& B, float thickness = 1);
void DrawLine(const Color3& color, float x, float y, float w, float h, float thickness = 1);
void DrawLine(const Color4& color, const Vector2& A, const Vector2& B, float thickness = 1);
void DrawLine(const Color4& color, float x1, float y1, float x2, float y2, float thickness = 1);
///Draws a line with a gradient that transitions across it.
void DrawGradientLine(const Color4& color1, const Color4& color2, const Vector2& A, const Vector2& B, float thickness = 1);
void DrawGradientLine(const Color3& color1, const Color3& color2, const Vector2& A, const Vector2& B, float thickness = 1);
void DrawGradientLine(const Color4& color1, const Color4& color2, float x, float y, float w, float h, float thickness = 1);
void DrawGradientLine(const Color3& color1, const Color3& color2, float x, float y, float w, float h, float thickness = 1);
/// Draws an outline of a rectangle on the screen.
void OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness = 1);
void OutlineRect(const Color3& color, const Vector2& pos, const Vector2& size, float thickness = 1);
/// Draws a sprite to the screen by passing a GLuint that represents a handle to a loaded texture.
/// @param texture
@@ -153,7 +135,6 @@ namespace JGL {
/// @param v3 bottom-right vertex.
/// @param v4 top-right vertex.
void FillQuad(const Color4& color, const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4);
void FillQuad(const Color3& color, const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4);
/// Draws a non axis-aligned outline rect to the screen.
/// @param color
@@ -163,76 +144,51 @@ namespace JGL {
/// @param v4 top-right vertex.
/// @param thickness the thickness of the GL_LINES to be connected together.
void OutlineQuad(const Color4& color, const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float thickness = 1);
void OutlineQuad(const Color3& color, const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float thickness = 1);
/// Draws a filled rectangle on the screen.
void FillRect(const Color4& color, const Vector2& pos, const Vector2& size);
void FillRect(const Color3& color, const Vector2& pos, const Vector2& size);
/// Draws a filled rectangle where the color transitions across it.
void FillGradientRect(const Color4& color1, const Color4& color2, const Gradient& gradient, const Vector2& pos, const Vector2& size);
void FillGradientRect(const Color3& color1, const Color3& color2, const Gradient& gradient, const Vector2& pos, const Vector2& size);
/// Draws a filled rectangle with rounded corners on the screen.
void FillRoundedRect(const Color4& color, const Vector2 &pos, const Vector2 &size, float radius = 5, unsigned int subdivisions = 8);
void FillRoundedRect(const Color3& color, const Vector2& pos, const Vector2& size, float radius = 5, unsigned int subdivisions = 8);
/// Draws an outline of a circle on the screen.
void OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions = 16, float thickness = 1);
void OutlineCircle(const Color3& color, const Vector2& center, float radius, unsigned int subdivisions = 16, float thickness = 1);
/// Draws a filled circle on the screen.
void FillCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions = 8);
void FillCircle(const Color3& color, const Vector2& center, float radius, unsigned int subdivisions = 8);
/// Draws an outline of a triangle on the screen.
/// @param color
/// @param tri
/// @param thickness
void OutlineTriangle(const Color4& color, const Triangle2D& tri, float thickness = 1);
void OutlineTriangle(const Color3& color, const Triangle2D& tri, float thickness = 1);
void OutlineTriangle(const Color4& color,
const Vector2& triA, const Vector2& triB, const Vector2& triC,
float thickness = 1);
void OutlineTriangle(const Color3& color,
const Vector2& triA, const Vector2& triB, const Vector2& triC,
float thickness = 1);
// TODO: Take more Focalin
void OutlineTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC, float thickness = 1);
/// Draws a filled triangle on the screen.
void FillTriangle(const Color4& color, const Triangle2D& tri);
void FIllTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC);
void FillTriangle(const Color3& color, const Triangle2D& tri);
/// Draws a triangle where each corner is defined by a given color, Smoothly transitioning between them.
void FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Triangle2D& tri);
void FillGradientTriangle(const Color3& a_color, const Color3& b_color, const Color3& c_color, const Triangle2D& tri);
// TODO: Implement an overload that simply takes 3 Vector3's
/// Draws a text string on the screen with a given point-size and font.
void DrawString(const Color4& color, const std::string& text, float x, float y, float scale, u32 size, const Font& font);
void DrawString(const Color3& color, const std::string& text, float x, float y, float scale, u32 size, const Font& font);
// TODO: Implement the following:
void FillTexturedTriangle();
void DrawCubicBezierCurve(const Color4& color,
const Vector2& controlA, const Vector2& pointA,
const Vector2& pointB, const Vector2& controlB,
int subdivisions = 10,
float thickness = 1);
void DrawCubicBezierCurve(const Color4& color, const Vector2& controlA, const Vector2& pointA, const Vector2& pointB, const Vector2& controlB,
int subdivisions = 10, float thickness = 1);
/// Draws a series of points where the last point always connects to the first point.
void OutlinePolygon (const Color4& color, const std::vector<Vector2>& points, float thickness = 1);
void OutlinePolygon(const Color4& color, const std::vector<Vector2>& points, float thickness = 1);
/// Draws a series of points where the last point always connects to the first point and fills it in.
///TODO these ones are going to be extremely annoying.
void FillPolygon (const Color4& color, const std::vector<Vector2>& points);
/// TODO Implement the following. These ones are going to be extremely annoying.
void FillPolygon(const Color4& color, const std::vector<Vector2>& points);
void FillTexturedPolygon();
void OutlineRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius = 5, float thickness = 1);
void FillTexturedTriangle();
}
/// Drawing functions for primitive 3D Shapes.

View File

@@ -45,14 +45,14 @@ public:
CachedGlyph* getGlyph(char c);
std::map<char, CachedGlyph*> getGlyphs();
const GLuint* getTexture();
GLsizei getTextureWidth() const;
GLsizei getTextureHeight() const;
[[nodiscard]] GLsizei getTextureWidth() const;
[[nodiscard]] GLsizei getTextureHeight() const;
CachedFont(GLuint texture_id, GLsizei texture_width, GLsizei texture_height, unsigned int font_size, unsigned int font_index);
};
class JGL::FontCache {
private:
std::vector<CachedFont*> cachedFonts = {};
std::vector<CachedFont*> cachedFonts{};
public:
std::vector<CachedFont*> getFonts();
CachedFont* getFont(unsigned int font_size, unsigned int font_index);

View File

@@ -1,191 +0,0 @@
#pragma once
#include <J3ML/J3ML.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <glad/glad.h>
#include <Color4.hpp>
#include <Color3.hpp>
namespace JGL {
class Shader;
enum class ShaderType : u8 {
VERTEX = 0,
FRAGMENT = 1,
COMBINED = 2,
};
// You could definitely do this with Typename T.
// Idk it increases the likelihood for mistakes.
class ShaderValue;
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 Attribute_Vector2;
class Attribute_Vector3;
class Attribute_Vector4;
}
class JGL::ShaderValue {
public:
std::string name;
GLint location = -1;
};
class JGL::Uniform_Float : public ShaderValue {
public:
float value = 0;
};
class JGL::Uniform_Int : public ShaderValue {
public:
int value = 0;
};
class JGL::Uniform_Bool : public ShaderValue {
public:
bool value = false;
};
class JGL::Uniform_Vector2 : public ShaderValue {
public:
Vector2 value;
};
class JGL::Uniform_Vector3 : public ShaderValue {
public:
Vector3 value;
};
class JGL::Uniform_Vector4 : public ShaderValue {
public:
Vector4 value;
};
class JGL::Uniform_Matrix2x2 : public ShaderValue {
public:
Matrix2x2 value;
};
class JGL::Uniform_Matrix3x3 : public ShaderValue {
public:
Matrix3x3 value;
};
class JGL::Uniform_Matrix4x4 : public ShaderValue {
public:
Matrix4x4 value;
};
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.
GLuint shader_program_handle = 0;
///Shader type.
ShaderType shader_type = ShaderType::COMBINED;
///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;
/// 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:
void load(const char* file_path, ShaderType type);
void load(const std::string& shader_program_text, ShaderType type);
void link();
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);
void SetUB(const std::string& uniform_name, bool value);
void SetUV2(const std::string& uniform_name, const Vector2& value);
void SetUV3(const std::string& uniform_name, const Vector3& value);
void SetUV3(const std::string& uniform_name, const Color3& value);
void SetUV4(const std::string& uniform_name, const Vector4& value);
void SetUV4(const std::string& uniform_name, const Color4& value);
void SetUMat2(const std::string& uniform_name, const Matrix2x2& value);
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.
void ResetUniforms();
/// 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();
Shader() = default;
~Shader();
};