Brunot
Loading...
Searching...
No Matches
Shader.h
Go to the documentation of this file.
1// File: Shader.h
2// Description: Loads and handles shaers in OpenGL programs
3// Author(s): Aidan Hartman (aidan.hartman@digipen.edu) Pair progamming with Ori
4// Ori Balashov (ori.balashov@digipen.edu) Pair progamming with Aidan
5// Marcelo Escamilla (marcelo.escamilla@digipen.edu) JSON serialization
6// 2025 / 10 / 03
7// (C) Digipen 2025
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15#pragma once
16#include <string>
17#include "System/json.h"
18
19using GLuint = unsigned int;
20using Stream = sys::Json; // replace with whatever stream we are using
21
22class Shader
23{
24
25public:
26 Shader();
27 Shader(const std::string& vertexFile, const std::string& fragmentFile);
28 ~Shader();
29
30 Shader(const Shader& other);
31 Shader(Shader&& other) noexcept;
32 auto operator=(const Shader& other) -> Shader&;
33 auto operator=(Shader&& other) noexcept -> Shader&;
34
35 auto activate() const -> void;
36 auto deactivate() const -> void;
37
42 auto setCamera() const -> void;
43
44 auto ID() const -> GLuint
45 {
46 return shaderID;
47 }
48
49 auto loadFile(const std::string& vertexFile, const std::string& fragmentFile) -> void;
50
51 auto load(Stream& stream) -> void;
52 auto save(Stream& stream) const -> void;
53
58 [[nodiscard]] auto name() const -> const std::string&
59 {
60 return _name;
61 }
62
67 auto name(const std::string& name) -> void
68 {
69 this->_name = name;
70 }
71
72 friend auto to_json(json& j, const Shader& a) -> void;
73 friend auto from_json(const json& j, Shader& a) -> void;
74
75private:
76 std::string _name;
77 std::string vertexPath;
78 std::string fragmentPath;
80};
sys::Json Stream
Definition AudioObject.h:20
unsigned int GLuint
Definition IndexBuffer.h:17
nlohmann::json json
Definition Json.cpp:19
Definition Shader.h:23
auto deactivate() const -> void
Definition Shader.cpp:111
Shader()
Definition Shader.cpp:36
auto save(Stream &stream) const -> void
Definition Shader.cpp:271
auto name() const -> const std::string &
Definition Shader.h:58
auto loadFile(const std::string &vertexFile, const std::string &fragmentFile) -> void
Definition Shader.cpp:122
auto name(const std::string &name) -> void
Definition Shader.h:67
auto setCamera() const -> void
Sets the view and projection transforms for the shader The shader to be set must be currently loaded.
Definition Shader.cpp:117
friend auto to_json(json &j, const Shader &a) -> void
Definition Shader.cpp:276
std::string fragmentPath
Definition Shader.h:78
auto load(Stream &stream) -> void
Definition Shader.cpp:266
auto ID() const -> GLuint
Definition Shader.h:44
auto activate() const -> void
Definition Shader.cpp:105
GLuint shaderID
Definition Shader.h:79
std::string _name
Definition Shader.h:76
std::string vertexPath
Definition Shader.h:77
friend auto from_json(const json &j, Shader &a) -> void
Definition Shader.cpp:286
auto operator=(const Shader &other) -> Shader &
Definition Shader.cpp:76
~Shader()
Definition Shader.cpp:47
Definition Json.h:32