-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathquad.cpp
More file actions
131 lines (106 loc) · 3.84 KB
/
quad.cpp
File metadata and controls
131 lines (106 loc) · 3.84 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
#include <fea/rendering/quad.hpp>
#include <fea/assert.hpp>
namespace fea
{
Quad::Quad() : Quad(glm::vec2(1.0f, 1.0f))
{
}
Quad::Quad(const glm::vec2& size):
mHFlip(1.0f),
mVFlip(1.0f),
mTexture(nullptr),
mSize(size)
{
FEA_ASSERT(size.x > 0.0f && size.y > 0.0f, "Size of quads must be bigger than zero in all dimensions! " + std::to_string(size.x) + " " + std::to_string(size.y) + " provided.");
float xnum = size.x;
float ynum = size.y;
mVertices = {0.0f, 0.0f,
0.0f, ynum,
xnum, 0.0f,
xnum, 0.0f,
0.0f, ynum,
xnum, ynum};
glm::vec2 texCoordsX = glm::vec2(0.0f, 1.0f);
glm::vec2 texCoordsY = glm::vec2(0.0f, 1.0f);
mTexCoords = {texCoordsX[0], texCoordsY[0],
texCoordsX[0], texCoordsY[1],
texCoordsX[1], texCoordsY[0],
texCoordsX[1], texCoordsY[0],
texCoordsX[0], texCoordsY[1],
texCoordsX[1], texCoordsY[1]};
mVertexColors = {1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f};
mDrawMode = GL_TRIANGLES;
mConstraints = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f);
}
void Quad::setSize(const glm::vec2& size)
{
FEA_ASSERT(size.x > 0.0f && size.y > 0.0f, "Size of quads must be bigger than zero in all dimensions! " + std::to_string(size.x) + " " + std::to_string(size.y) + " provided.");
float xnum = size.x;
float ynum = size.y;
mVertices = {0.0f, 0.0f,
0.0f, ynum,
xnum, 0.0f,
xnum, 0.0f,
0.0f, ynum,
xnum, ynum};
mSize = size;
}
const glm::vec2& Quad::getSize() const
{
return mSize;
}
void Quad::setTexture(const Texture& tex)
{
mTexture = &tex;
}
const Texture& Quad::getTexture() const
{
return *mTexture;
}
void Quad::setHFlip(bool enabled)
{
if(enabled)
mHFlip = -1.0f;
else
mHFlip = 1.0f;
glm::vec2 texCoordsX = glm::vec2(0.0f, 1.0f) * mHFlip;
glm::vec2 texCoordsY = glm::vec2(0.0f, 1.0f) * mVFlip;
mTexCoords = {texCoordsX[0], texCoordsY[0],
texCoordsX[0], texCoordsY[1],
texCoordsX[1], texCoordsY[0],
texCoordsX[1], texCoordsY[0],
texCoordsX[0], texCoordsY[1],
texCoordsX[1], texCoordsY[1]};
//Make nice
}
void Quad::setVFlip(bool enabled)
{
if(enabled)
mVFlip = -1.0f;
else
mVFlip = 1.0f;
glm::vec2 texCoordsX = glm::vec2(0.0f, 1.0f) * mHFlip;
glm::vec2 texCoordsY = glm::vec2(0.0f, 1.0f) * mVFlip;
mTexCoords = {texCoordsX[0], texCoordsY[0],
texCoordsX[0], texCoordsY[1],
texCoordsX[1], texCoordsY[0],
texCoordsX[1], texCoordsY[0],
texCoordsX[0], texCoordsY[1],
texCoordsX[1], texCoordsY[1]};
}
std::vector<RenderEntity> Quad::getRenderInfo() const
{
std::vector<RenderEntity> temp = Drawable2D::getRenderInfo();
if(mTexture != nullptr)
{
temp[0].mUniforms.emplace_back("texture", TEXTURE, getTexture().getId());
}
temp[0].mUniforms.emplace_back("constraints", VEC4, mConstraints);
return temp;
}
}