-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathuniform.cpp
More file actions
149 lines (137 loc) · 4.27 KB
/
uniform.cpp
File metadata and controls
149 lines (137 loc) · 4.27 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <fea/rendering/uniform.hpp>
#define GLM_FORCE_RADIANS
#include <glm/gtc/type_ptr.hpp>
namespace fea
{
Uniform::Uniform()
{
mType = NO_TYPE;
}
Uniform::Uniform(const std::string& name, UniformType t, const float val)
{
mName = name;
mType = t;
mFloatVal = val;
}
Uniform::Uniform(const std::string& name, UniformType t, const glm::vec2& val)
{
mName = name;
mType = t;
mVec2Val[0] = val[0];
mVec2Val[1] = val[1];
}
Uniform::Uniform(const std::string& name, UniformType t, const glm::vec3& val)
{
mName = name;
mType = t;
mVec3Val[0] = val[0];
mVec3Val[1] = val[1];
mVec3Val[2] = val[2];
}
Uniform::Uniform(const std::string& name, UniformType t, const glm::vec4& val)
{
mName = name;
mType = t;
mVec4Val[0] = val[0];
mVec4Val[1] = val[1];
mVec4Val[2] = val[2];
mVec4Val[3] = val[3];
}
Uniform::Uniform(const std::string& name, UniformType t, const glm::mat2x2& val)
{
mName = name;
mType = t;
const float* mat = glm::value_ptr(val);
mMat2x2Val[0] = mat[0];
mMat2x2Val[1] = mat[1];
mMat2x2Val[2] = mat[2];
mMat2x2Val[3] = mat[3];
}
Uniform::Uniform(const std::string& name, UniformType t, const glm::mat4x4& val)
{
mName = name;
mType = t;
const float* mat = glm::value_ptr(val);
mMat4x4Val[0] = mat[0];
mMat4x4Val[1] = mat[1];
mMat4x4Val[2] = mat[2];
mMat4x4Val[3] = mat[3];
mMat4x4Val[4] = mat[4];
mMat4x4Val[5] = mat[5];
mMat4x4Val[6] = mat[6];
mMat4x4Val[7] = mat[7];
mMat4x4Val[8] = mat[8];
mMat4x4Val[9] = mat[9];
mMat4x4Val[10] = mat[10];
mMat4x4Val[11] = mat[11];
mMat4x4Val[12] = mat[12];
mMat4x4Val[13] = mat[13];
mMat4x4Val[14] = mat[14];
mMat4x4Val[15] = mat[15];
}
Uniform::Uniform(const std::string& name, UniformType t, const GLuint val)
{
mName = name;
mType = t;
mTextureVal = val;
}
Uniform::Uniform(const Uniform& other)
{
mName = other.mName;
mType = other.mType;
switch(mType)
{
case FLOAT:
mFloatVal = other.mFloatVal;
break;
case VEC2:
std::copy(other.mVec2Val, other.mVec2Val + 2, mVec2Val);
break;
case VEC3:
std::copy(other.mVec3Val, other.mVec3Val + 3, mVec3Val);
break;
case VEC4:
std::copy(other.mVec4Val, other.mVec4Val + 4, mVec4Val);
break;
case MAT2X2:
std::copy(other.mMat2x2Val, other.mMat2x2Val + 4, mMat2x2Val);
break;
case MAT4X4:
std::copy(other.mMat4x4Val, other.mMat4x4Val + 16, mMat4x4Val);
break;
case TEXTURE:
mTextureVal = other.mTextureVal;
break;
case NO_TYPE:
break;
}
}
bool Uniform::operator==(const Uniform& other) const
{
if(!(mType == other.mType && mName == other.mName))
return false;
else
{
std::equal(mMat4x4Val, mMat4x4Val + 16, other.mMat4x4Val) && mName == other.mName;
switch(mType)
{
case FLOAT:
return mFloatVal == other.mFloatVal;
case VEC2:
return std::equal(other.mVec2Val, other.mVec2Val + 2, mVec2Val);
case VEC3:
return std::equal(other.mVec3Val, other.mVec3Val + 3, mVec3Val);
case VEC4:
return std::equal(other.mVec4Val, other.mVec4Val + 4, mVec4Val);
case MAT2X2:
return std::equal(other.mMat2x2Val, other.mMat2x2Val + 4, mMat2x2Val);
case MAT4X4:
return std::equal(other.mMat4x4Val, other.mMat4x4Val + 16, mMat4x4Val);
case TEXTURE:
return mTextureVal == other.mTextureVal;
case NO_TYPE:
return true;
}
}
}
}