forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShader.cpp
More file actions
89 lines (78 loc) · 2.04 KB
/
Copy pathShader.cpp
File metadata and controls
89 lines (78 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "pch.h"
#include "Shader.h"
namespace sh::render
{
Shader::Shader(int id, ShaderType type) :
id(id), type(type)
{
AddAttribute<glm::vec3>("vertex", 0);
}
Shader::Shader(Shader&& other) noexcept :
id(other.id), type(other.type),
attrs(std::move(other.attrs)), attridx(std::move(other.attridx)),
uniformBindings(std::move(other.uniformBindings)),
vertexUniforms(std::move(other.vertexUniforms)),
fragmentUniforms(std::move(other.fragmentUniforms)),
samplerUniforms(std::move(other.samplerUniforms))
{
}
auto Shader::GetShaderType() const -> ShaderType
{
return type;
}
void Shader::operator=(Shader&& other) noexcept
{
id = other.id;
attrs = std::move(other.attrs);
attridx = std::move(other.attridx);
uniformBindings = std::move(other.uniformBindings);
vertexUniforms = std::move(other.vertexUniforms);
fragmentUniforms = std::move(other.fragmentUniforms);
samplerUniforms = std::move(other.samplerUniforms);
}
auto Shader::operator==(const Shader& other) -> bool
{
return id == other.id;
}
auto Shader::GetId() const -> int
{
return id;
}
bool Shader::HasAttribute(const std::string& name) const
{
auto it = attridx.find(name);
if (it == attridx.end())
return false;
return true;
}
auto Shader::GetAttribute(const std::string& name) const -> std::optional<Data>
{
auto it = attridx.find(name);
if (it == attridx.end())
return {};
return attrs[it->second];
}
auto Shader::GetAttributes() const -> const std::vector<Data>&
{
return attrs;
}
auto Shader::GetVertexUniforms() const -> const std::vector<UniformBlock>&
{
return vertexUniforms;
}
auto Shader::GetFragmentUniforms() const -> const std::vector<UniformBlock>&
{
return fragmentUniforms;
}
auto Shader::GetSamplerUniforms() const -> const std::vector<UniformData>&
{
return samplerUniforms;
}
auto Shader::GetUniformBinding(std::string_view name) const -> std::optional<uint32_t>
{
auto it = uniformBindings.find(std::string{ name });
if (it == uniformBindings.end())
return {};
return it->second;
}
}