Vivid
Loading...
Searching...
No Matches
Shader.h
1#pragma once
2
3#include "glm/glm.hpp"
4#include "VertexBuffer.h"
5#include "common/maths/Vec.h"
6#include <string>
7#include <unordered_map>
8
9namespace Vivid
10{
12 {
13 std::string VertexSource;
14 std::string PixelSource;
15 };
16
17 // Shader should contain all the uniforms that are required by it to run.
18 // We can bind those uniforms to the shader and then use them automatically. Or we can have them Statically Bind them, which doesn;t put them into the shader's object. Just binds them for some time.
24 class Shader
25 {
26 private:
27 std::string m_FilePathVS;
28 std::string m_FilePathPS;
29 unsigned int m_RendererID;
30 std::unordered_map<std::string, int> m_UniformLocationCache;
31
32 public:
33 Shader(const String& filepathVertexShader, const String& filepathPixelShader);
34 ~Shader();
35
36 static Ref<Shader> Create(const std::string& filepathVertexShader, const std::string& filepathPixelShader);
37
38 void Bind() const;
39 void Unbind() const;
40
41 // Set uniforms
42 void SetUniform4f(const std::string& name, float f0, float f1, float f2, float f3);
43 void SetUniform4f(const std::string& name, const glm::vec4& matrix);
44 void SetUniform3f(const std::string& name, float f0, float f1, float f2);
45 void SetUniform3f(const std::string& name, Maths::Vec3& value);
46 void SetUniform1f(const std::string& name, float value);
47 void SetUniform1i(const std::string& name, int value);
48 void SetUniformMat4f(const std::string& name, const glm::mat4& matrix);
49
50 String GetVertexShaderPath() { return m_FilePathVS; }
51 String GetPixelShaderPath() { return m_FilePathPS; }
52
53 unsigned int GetRendererID() { return m_RendererID; }
54
55 private:
56 int getUniformLocation(const std::string& name);
57 struct ShaderProgramSource parseShader(const std::string& filepathVertexShader, const std::string& filepathPixelShader);
58 unsigned int compileShader(unsigned int type, const std::string& source);
59 unsigned int createShader(const std::string& vertexShader, const std::string& fragmentShader);
60 };
61}
A class for the Shader.
Definition: Shader.h:25
Contains a 3D vector.
Definition: Vec.h:51