Update engine components
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m32s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m32s
This commit is contained in:
@@ -17,17 +17,17 @@ include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME mcolor
|
||||
URL https://git.redacted.cc/maxine/mcolor/archive/Prerelease-3.zip
|
||||
URL https://git.redacted.cc/maxine/mcolor/archive/Prerelease-4.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME J3ML
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.0.zip
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.1.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-12.zip
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-13.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
|
@@ -28,11 +28,11 @@
|
||||
#include <J3ML/Geometry/Sphere.hpp>
|
||||
#include <J3ML/Geometry/Capsule.hpp>
|
||||
#include <J3ML/Geometry/TriangleMesh.hpp>
|
||||
#include <JGL/Logger.h>
|
||||
|
||||
|
||||
/// OpenGL Wrapper for rendering 2D graphics primitives in both a 2D and 3D context
|
||||
namespace JGL {
|
||||
|
||||
using namespace J3ML::LinearAlgebra;
|
||||
using namespace J3ML::Geometry;
|
||||
|
||||
@@ -63,7 +63,6 @@ namespace JGL {
|
||||
/// Drawing functions for primitive 2D Shapes.
|
||||
/// Each function is overloaded with Color3 and Color4 for optional transparency.
|
||||
namespace J2D {
|
||||
|
||||
/// Open a 2-D rendering context with the underlying graphics system (In this case & by default OpenGL).
|
||||
/// @note This call may not strictly be necessary on some setups, but is provided to keep the API constant.
|
||||
/// It is recommended to always open a JGL 2D context to render your content, then close when completed.
|
||||
@@ -74,9 +73,14 @@ namespace JGL {
|
||||
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);
|
||||
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
|
||||
|
11
include/JGL/Logger.h
Normal file
11
include/JGL/Logger.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <jlog/Logger.hpp>
|
||||
|
||||
namespace JGL::Logger {
|
||||
using namespace jlog;
|
||||
|
||||
extern GenericLogger Fatal;
|
||||
extern GenericLogger Debug;
|
||||
extern GenericLogger Error;
|
||||
}
|
@@ -3,6 +3,8 @@
|
||||
#include <J3ML/J3ML.hpp>
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
#include <glad/glad.h>
|
||||
#include <Color4.hpp>
|
||||
#include <Color3.hpp>
|
||||
|
||||
namespace JGL {
|
||||
class Shader;
|
||||
@@ -33,7 +35,7 @@ namespace JGL {
|
||||
class JGL::Uniform {
|
||||
public:
|
||||
std::string name;
|
||||
GLint location = NULL;
|
||||
GLint location = 0;
|
||||
};
|
||||
|
||||
class JGL::Uniform_Float : public Uniform {
|
||||
@@ -82,6 +84,7 @@ public:
|
||||
Matrix4x4 value;
|
||||
};
|
||||
|
||||
//TODO attributes.
|
||||
class JGL::Shader {
|
||||
private:
|
||||
///Shader program.
|
||||
@@ -118,19 +121,27 @@ public:
|
||||
[[nodiscard]] GLuint GetGLShaderProgramHandle() const;
|
||||
[[nodiscard]] ShaderType GetShaderType() 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 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 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 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 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 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);
|
||||
|
||||
/// 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);
|
||||
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);
|
||||
|
2
main.cpp
2
main.cpp
@@ -5,7 +5,7 @@
|
||||
#include <chrono>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <JGL/types/Font.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
#include <JGL/Logger.h>
|
||||
#include <ReTexture/Texture.h>
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
62
src/JGL.cpp
62
src/JGL.cpp
@@ -5,9 +5,10 @@
|
||||
#include <JGL/JGL.h>
|
||||
#include <glad/glad.h>
|
||||
#include <Color3.hpp>
|
||||
#include <jlog/jlog.hpp>
|
||||
#include <jlog/Logger.hpp>
|
||||
#include <J3ML/Algorithm/Bezier.hpp>
|
||||
|
||||
JGL::Shader* j2d_shader_program = nullptr;
|
||||
GLfloat oldColor[4] = {0, 0, 0, 1};
|
||||
GLfloat baseColor[4] = {1, 1, 1, 1};
|
||||
bool inJ2D = false;
|
||||
@@ -30,6 +31,24 @@ namespace JGL {
|
||||
glViewport(0, 0, wS.x, wS.y);
|
||||
}
|
||||
|
||||
void J2D::UseShaderProgram(Shader& shader) {
|
||||
j2d_shader_program = &shader;
|
||||
glUseProgram(shader.GetGLShaderProgramHandle());
|
||||
}
|
||||
|
||||
void J2D::UseShaderProgram(Shader* shader) {
|
||||
j2d_shader_program = shader;
|
||||
glUseProgram(shader->GetGLShaderProgramHandle());
|
||||
}
|
||||
|
||||
void J2D::UseFixedFunction() {
|
||||
j2d_shader_program = nullptr;
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
bool J2D::IsUsingShaderProgram() {
|
||||
return (j2d_shader_program);
|
||||
}
|
||||
|
||||
void J2D::Begin() {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
@@ -47,6 +66,7 @@ namespace JGL {
|
||||
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE,& activeTextureUnit);
|
||||
activeTextureUnit = activeTextureUnit - GL_TEXTURE0;
|
||||
|
||||
if (activeTextureUnit != 0)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
@@ -89,7 +109,7 @@ namespace JGL {
|
||||
|
||||
if (!inJ3D)
|
||||
inJ2D = true;
|
||||
else { ERROR("Attempt to Begin J2D inside of J3D context.") }
|
||||
else { jlog::Error("Attempt to Begin J2D inside of J3D context."); }
|
||||
}
|
||||
|
||||
void J2D::End() {
|
||||
@@ -130,7 +150,7 @@ namespace JGL {
|
||||
|
||||
void J2D::DrawSprite(const Texture& texture, const Vector2& pos, const Vector2& origin, const Vector2& scale, const Color4& color, Inversion inversion) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
|
||||
const Vector2 size = texture.GetDimensions();
|
||||
@@ -182,7 +202,7 @@ namespace JGL {
|
||||
|
||||
void J2D::DrawPartialSprite(const Texture& texture, const Vector2& position, const Vector2& sub_texture_position, const Vector2& sub_texture_size, const Vector2& origin, const Vector2& scale, const Color4& color, Inversion inversion) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.");
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
const Vector2 textureSize = texture.GetDimensions();
|
||||
|
||||
@@ -238,7 +258,7 @@ namespace JGL {
|
||||
|
||||
void J2D::FillQuad(const Color4& color, const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {v1, v2, v3, v4};
|
||||
glColor4f(color.RedChannelNormalized(),
|
||||
@@ -256,7 +276,7 @@ namespace JGL {
|
||||
|
||||
void J2D::OutlineQuad(const Color4& color, const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float thickness) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {v1, v2, v3, v4};
|
||||
glLineWidth(thickness);
|
||||
@@ -277,7 +297,7 @@ namespace JGL {
|
||||
|
||||
void J2D::FillRect(const Color4& color, const Vector2& pos, const Vector2& size) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {{pos.x, pos.y}, {pos.x, pos.y + size.y}, {pos.x + size.x, pos.y + size.y}, {pos.x + size.x, pos.y}};
|
||||
glColor4f(color.RedChannelNormalized(),
|
||||
@@ -295,7 +315,7 @@ namespace JGL {
|
||||
|
||||
void J2D::FillGradientRect(const Color4& color1, const Color4& color2, const Gradient& gradient, const Vector2& pos, const Vector2& size) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {{pos.x, pos.y}, {pos.x, pos.y + size.y}, {pos.x + size.x, pos.y + size.y}, {pos.x + size.x, pos.y}};
|
||||
std::vector<GLfloat> colors = {};
|
||||
@@ -332,7 +352,7 @@ namespace JGL {
|
||||
|
||||
void J2D::FillRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, unsigned int subdivisions) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
J2D::FillRect(color, {pos.x + radius, pos.y}, {size.x - 2 * radius, size.y});
|
||||
J2D::FillRect(color, {pos.x, pos.y + radius}, {size.x, size.y - 2 * radius});
|
||||
@@ -349,7 +369,7 @@ namespace JGL {
|
||||
|
||||
void J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {{pos.x, pos.y}, {pos.x, pos.y + size.y}, {pos.x + size.x, pos.y + size.y}, {pos.x + size.x, pos.y}};
|
||||
|
||||
@@ -369,7 +389,7 @@ namespace JGL {
|
||||
|
||||
void J2D::DrawLine(const Color4& color, const Vector2& A, const Vector2& B, float thickness) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.");
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {A, B};
|
||||
|
||||
@@ -397,7 +417,7 @@ namespace JGL {
|
||||
|
||||
void J2D::DrawGradientLine(const Color4& color1, const Color4& color2, const Vector2& A, const Vector2& B, float thickness) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.");
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {A, B};
|
||||
GLfloat colors[8] = {color1.RedChannelNormalized(), color1.GreenChannelNormalized(), color1.BlueChannelNormalized(), color1.AlphaChannelNormalized(),
|
||||
@@ -425,7 +445,7 @@ namespace JGL {
|
||||
|
||||
void J2D::OutlinePolygon(const Color4 &color, const std::vector<Vector2>& points, float thickness) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.");
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
if (points.front() != points.back())
|
||||
throw std::runtime_error("J2D::OutlinePolygon: The first point and the last point must connect.");
|
||||
@@ -439,7 +459,7 @@ namespace JGL {
|
||||
|
||||
void J2D::DrawPoint(const Color4& color, const Vector2& coordinates, float radius) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.");
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {coordinates};
|
||||
|
||||
@@ -467,7 +487,7 @@ namespace JGL {
|
||||
|
||||
void J2D::OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions, float thickness) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
float step = (2.f * Math::Pi) / (float) subdivisions;
|
||||
std::vector<Vector2> vertices{};
|
||||
@@ -495,7 +515,7 @@ namespace JGL {
|
||||
|
||||
void J2D::FillCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
GLfloat angle, x, y;
|
||||
float step = (2.f * Math::Pi) / (float) subdivisions;
|
||||
@@ -518,7 +538,7 @@ namespace JGL {
|
||||
|
||||
void J2D::OutlineTriangle(const Color4& color, const Triangle2D& tri, float thickness) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {{tri.A.x, tri.A.y}, {tri.B.x, tri.B.y}, {tri.C.x, tri.C.y}};
|
||||
|
||||
@@ -535,7 +555,7 @@ namespace JGL {
|
||||
|
||||
void J2D::FillTriangle(const Color4& color, const Triangle2D& tri) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {{tri.A.x, tri.A.y}, {tri.B.x, tri.B.y}, {tri.C.x, tri.C.y}};
|
||||
|
||||
@@ -547,7 +567,7 @@ namespace JGL {
|
||||
|
||||
void J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Triangle2D& tri) {
|
||||
if (!inJ2D)
|
||||
ERROR("Drawing J2D element before J2D begin.")
|
||||
jlog::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {{tri.A.x, tri.A.y}, {tri.B.x, tri.B.y}, {tri.C.x, tri.C.y}};
|
||||
GLfloat colors[] = {a_color.r / 255.f, a_color.g / 255.f, a_color.b / 255.f, a_color.a / 255.f,b_color.r / 255.f,
|
||||
@@ -676,7 +696,7 @@ namespace JGL {
|
||||
|
||||
if (!inJ2D)
|
||||
inJ3D = true;
|
||||
else { ERROR("Attempt to Begin J3D inside of J2D context.")}
|
||||
else { jlog::Error("Attempt to Begin J3D inside of J2D context."); }
|
||||
}
|
||||
|
||||
void J3D::End() {
|
||||
@@ -703,7 +723,7 @@ namespace JGL {
|
||||
|
||||
void J3D::DrawLine(const Color4& color, const Vector3& A, const Vector3& B, float thickness) {
|
||||
if (!inJ3D)
|
||||
ERROR("Attempt to Render J3D element before J3D begin.")
|
||||
jlog::Error("Attempt to Render J3D element before J3D begin.");
|
||||
|
||||
Vector3 vertices[] = {A, B};
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
#include <JGL/types/Font.h>
|
||||
#include <JGL/types/FontCache.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
#include <JGL/Logger.h>
|
||||
|
||||
namespace JGL {
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace JGL {
|
||||
|
||||
//If the font doesn't exist in the cache yet.
|
||||
if (!cachedFont) {
|
||||
DEBUG("Caching font data...");
|
||||
jlog::Debug("Caching font data...");
|
||||
GLuint texture_id;
|
||||
glGenTextures(1, &texture_id);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
|
@@ -3,6 +3,8 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <Color3.hpp>
|
||||
#include "Color4.hpp"
|
||||
|
||||
void checkCompilationError(GLuint shader) {
|
||||
GLint success;
|
||||
@@ -131,13 +133,13 @@ void JGL::Shader::link() {
|
||||
|
||||
|
||||
else if (type == GL_FLOAT_MAT2)
|
||||
matrix2x2_uniforms.push_back(Uniform_Matrix2x2({uniform_name, location}));
|
||||
matrix2x2_uniforms.push_back(Uniform_Matrix2x2({uniform_name, location}, {}));
|
||||
|
||||
else if (type == GL_FLOAT_MAT3)
|
||||
matrix3x3_uniforms.push_back(Uniform_Matrix3x3({uniform_name, location}));
|
||||
matrix3x3_uniforms.push_back(Uniform_Matrix3x3({uniform_name, location}, {}));
|
||||
|
||||
else if (type == GL_FLOAT_MAT4)
|
||||
matrix4x4_uniforms.push_back(Uniform_Matrix4x4({uniform_name, location}));
|
||||
matrix4x4_uniforms.push_back(Uniform_Matrix4x4({uniform_name, location}, {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +157,7 @@ JGL::Shader::Shader(const std::string& vertex_shader_text, const std::string& fr
|
||||
link();
|
||||
}
|
||||
|
||||
void JGL::Shader::ResetUniforms() {
|
||||
void JGL::Shader::ResetLocalUniforms() {
|
||||
for (auto& u : float_uniforms)
|
||||
u.value = 0;
|
||||
|
||||
@@ -182,11 +184,17 @@ void JGL::Shader::ResetUniforms() {
|
||||
for (auto& u : matrix3x3_uniforms)
|
||||
u.value = {};
|
||||
|
||||
//TODO J3ML Matrix4x4 empty braced initializer list does not result in a Matrix4x4 filled with zeroes.
|
||||
for (auto& u : matrix4x4_uniforms)
|
||||
u.value = {0.0f};
|
||||
u.value = Matrix4x4();
|
||||
}
|
||||
|
||||
void JGL::Shader::SetFloat(const std::string& uniform_name, float value) {
|
||||
void JGL::Shader::ResetUniforms() {
|
||||
ResetLocalUniforms();
|
||||
SubmitUniforms();
|
||||
}
|
||||
|
||||
void JGL::Shader::SetUF(const std::string& uniform_name, float value) {
|
||||
for (auto& u : float_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -195,7 +203,7 @@ void JGL::Shader::SetFloat(const std::string& uniform_name, float value) {
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetInt(const std::string& uniform_name, int value) {
|
||||
void JGL::Shader::SetUI(const std::string& uniform_name, int value) {
|
||||
for (auto& u : int_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -204,7 +212,7 @@ void JGL::Shader::SetInt(const std::string& uniform_name, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetBool(const std::string& uniform_name, bool value) {
|
||||
void JGL::Shader::SetUB(const std::string& uniform_name, bool value) {
|
||||
for (auto& u : bool_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -214,7 +222,7 @@ void JGL::Shader::SetBool(const std::string& uniform_name, bool value) {
|
||||
}
|
||||
|
||||
|
||||
void JGL::Shader::SetVector2(const std::string& uniform_name, const Vector2& value) {
|
||||
void JGL::Shader::SetUV2(const std::string& uniform_name, const Vector2& value) {
|
||||
for (auto& u : vector2_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -223,7 +231,7 @@ void JGL::Shader::SetVector2(const std::string& uniform_name, const Vector2& val
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetVector3(const std::string& uniform_name, const Vector3& value) {
|
||||
void JGL::Shader::SetUV3(const std::string& uniform_name, const Vector3& value) {
|
||||
for (auto& u : vector3_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -232,7 +240,16 @@ void JGL::Shader::SetVector3(const std::string& uniform_name, const Vector3& val
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetVector4(const std::string& uniform_name, const Vector4& value) {
|
||||
void JGL::Shader::SetUV3(const std::string& uniform_name, const Color3& value) {
|
||||
for (auto& u : vector3_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = {value.RedChannelNormalized(), value.BlueChannelNormalized(), value.RedChannelNormalized()};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetUV4(const std::string& uniform_name, const Vector4& value) {
|
||||
for (auto& u : vector4_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -241,8 +258,16 @@ void JGL::Shader::SetVector4(const std::string& uniform_name, const Vector4& val
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetUV4(const std::string& uniform_name, const Color4& value) {
|
||||
for (auto& u : vector4_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = {value.RedChannelNormalized(), value.BlueChannelNormalized(), value.RedChannelNormalized(), value.AlphaChannelNormalized()};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetMatrix2x2(const std::string& uniform_name, const Matrix2x2& value) {
|
||||
void JGL::Shader::SetUMat2(const std::string& uniform_name, const Matrix2x2& value) {
|
||||
for (auto& u : matrix2x2_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -251,7 +276,7 @@ void JGL::Shader::SetMatrix2x2(const std::string& uniform_name, const Matrix2x2&
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetMatrix3x3(const std::string& uniform_name, const Matrix3x3& value) {
|
||||
void JGL::Shader::SetUMat3(const std::string& uniform_name, const Matrix3x3& value) {
|
||||
for (auto& u : matrix3x3_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -260,7 +285,7 @@ void JGL::Shader::SetMatrix3x3(const std::string& uniform_name, const Matrix3x3&
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SetMatrix4x4(const std::string& uniform_name, const Matrix4x4& value) {
|
||||
void JGL::Shader::SetUMat4(const std::string& uniform_name, const Matrix4x4& value) {
|
||||
for (auto& u : matrix4x4_uniforms) {
|
||||
if (u.name == uniform_name) {
|
||||
u.value = value;
|
||||
@@ -269,6 +294,50 @@ void JGL::Shader::SetMatrix4x4(const std::string& uniform_name, const Matrix4x4&
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::Shader::SubmitUniforms(bool clear_uniforms_from_local_store) {
|
||||
// Make sure "this" is the shader we submit to.
|
||||
GLuint current_program;
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*) ¤t_program);
|
||||
|
||||
if (current_program != shader_program_handle)
|
||||
glUseProgram(shader_program_handle);
|
||||
|
||||
for (const auto& u : float_uniforms)
|
||||
glUniform1f(u.location, u.value);
|
||||
|
||||
for (const auto& u : int_uniforms)
|
||||
glUniform1i(u.location, u.value);
|
||||
|
||||
for (const auto& u : bool_uniforms)
|
||||
glUniform1i(u.location, (int) u.value);
|
||||
|
||||
|
||||
for (const auto& u : vector2_uniforms)
|
||||
glUniform2fv(u.location, 1, u.value.ptr());
|
||||
|
||||
for (const auto& u : vector3_uniforms)
|
||||
glUniform3fv(u.location, 1, u.value.ptr());
|
||||
|
||||
for (const auto& u : vector4_uniforms)
|
||||
glUniform4fv(u.location, 1, u.value.ptr());
|
||||
|
||||
for (const auto& u : matrix2x2_uniforms)
|
||||
glUniformMatrix2fv(u.location, 1, GL_FALSE, u.value.ptr());
|
||||
|
||||
for (const auto& u : matrix3x3_uniforms)
|
||||
glUniformMatrix3fv(u.location, 1, GL_FALSE, u.value.ptr());
|
||||
|
||||
for (const auto& u : matrix4x4_uniforms)
|
||||
glUniformMatrix4fv(u.location, 1, GL_FALSE, u.value.ptr());
|
||||
|
||||
if (clear_uniforms_from_local_store)
|
||||
ResetLocalUniforms();
|
||||
|
||||
// Change back if they were using a different shader before.
|
||||
if (current_program != shader_program_handle)
|
||||
glUseProgram(current_program);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user