1 //
2 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // angletypes.h : Defines a variety of structures and enum types that are used throughout libGLESv2
8
9 #include "libANGLE/angletypes.h"
10 #include "libANGLE/Program.h"
11 #include "libANGLE/VertexAttribute.h"
12 #include "libANGLE/State.h"
13 #include "libANGLE/VertexArray.h"
14
15 namespace gl
16 {
17
GetPrimitiveType(GLenum drawMode)18 PrimitiveType GetPrimitiveType(GLenum drawMode)
19 {
20 switch (drawMode)
21 {
22 case GL_POINTS:
23 return PRIMITIVE_POINTS;
24 case GL_LINES:
25 return PRIMITIVE_LINES;
26 case GL_LINE_STRIP:
27 return PRIMITIVE_LINE_STRIP;
28 case GL_LINE_LOOP:
29 return PRIMITIVE_LINE_LOOP;
30 case GL_TRIANGLES:
31 return PRIMITIVE_TRIANGLES;
32 case GL_TRIANGLE_STRIP:
33 return PRIMITIVE_TRIANGLE_STRIP;
34 case GL_TRIANGLE_FAN:
35 return PRIMITIVE_TRIANGLE_FAN;
36 default:
37 UNREACHABLE();
38 return PRIMITIVE_TYPE_MAX;
39 }
40 }
41
RasterizerState()42 RasterizerState::RasterizerState()
43 {
44 memset(this, 0, sizeof(RasterizerState));
45
46 rasterizerDiscard = false;
47 cullFace = false;
48 cullMode = CullFaceMode::Back;
49 frontFace = GL_CCW;
50 polygonOffsetFill = false;
51 polygonOffsetFactor = 0.0f;
52 polygonOffsetUnits = 0.0f;
53 pointDrawMode = false;
54 multiSample = false;
55 }
56
operator ==(const RasterizerState & a,const RasterizerState & b)57 bool operator==(const RasterizerState &a, const RasterizerState &b)
58 {
59 return memcmp(&a, &b, sizeof(RasterizerState)) == 0;
60 }
61
operator !=(const RasterizerState & a,const RasterizerState & b)62 bool operator!=(const RasterizerState &a, const RasterizerState &b)
63 {
64 return !(a == b);
65 }
66
BlendState()67 BlendState::BlendState()
68 {
69 memset(this, 0, sizeof(BlendState));
70
71 blend = false;
72 sourceBlendRGB = GL_ONE;
73 sourceBlendAlpha = GL_ONE;
74 destBlendRGB = GL_ZERO;
75 destBlendAlpha = GL_ZERO;
76 blendEquationRGB = GL_FUNC_ADD;
77 blendEquationAlpha = GL_FUNC_ADD;
78 sampleAlphaToCoverage = false;
79 dither = true;
80 }
81
BlendState(const BlendState & other)82 BlendState::BlendState(const BlendState &other)
83 {
84 memcpy(this, &other, sizeof(BlendState));
85 }
86
operator ==(const BlendState & a,const BlendState & b)87 bool operator==(const BlendState &a, const BlendState &b)
88 {
89 return memcmp(&a, &b, sizeof(BlendState)) == 0;
90 }
91
operator !=(const BlendState & a,const BlendState & b)92 bool operator!=(const BlendState &a, const BlendState &b)
93 {
94 return !(a == b);
95 }
96
DepthStencilState()97 DepthStencilState::DepthStencilState()
98 {
99 memset(this, 0, sizeof(DepthStencilState));
100
101 depthTest = false;
102 depthFunc = GL_LESS;
103 depthMask = true;
104 stencilTest = false;
105 stencilFunc = GL_ALWAYS;
106 stencilMask = static_cast<GLuint>(-1);
107 stencilWritemask = static_cast<GLuint>(-1);
108 stencilBackFunc = GL_ALWAYS;
109 stencilBackMask = static_cast<GLuint>(-1);
110 stencilBackWritemask = static_cast<GLuint>(-1);
111 stencilFail = GL_KEEP;
112 stencilPassDepthFail = GL_KEEP;
113 stencilPassDepthPass = GL_KEEP;
114 stencilBackFail = GL_KEEP;
115 stencilBackPassDepthFail = GL_KEEP;
116 stencilBackPassDepthPass = GL_KEEP;
117 }
118
DepthStencilState(const DepthStencilState & other)119 DepthStencilState::DepthStencilState(const DepthStencilState &other)
120 {
121 memcpy(this, &other, sizeof(DepthStencilState));
122 }
123
operator ==(const DepthStencilState & a,const DepthStencilState & b)124 bool operator==(const DepthStencilState &a, const DepthStencilState &b)
125 {
126 return memcmp(&a, &b, sizeof(DepthStencilState)) == 0;
127 }
128
operator !=(const DepthStencilState & a,const DepthStencilState & b)129 bool operator!=(const DepthStencilState &a, const DepthStencilState &b)
130 {
131 return !(a == b);
132 }
133
SamplerState()134 SamplerState::SamplerState()
135 {
136 memset(this, 0, sizeof(SamplerState));
137
138 minFilter = GL_NEAREST_MIPMAP_LINEAR;
139 magFilter = GL_LINEAR;
140 wrapS = GL_REPEAT;
141 wrapT = GL_REPEAT;
142 wrapR = GL_REPEAT;
143 maxAnisotropy = 1.0f;
144 minLod = -1000.0f;
145 maxLod = 1000.0f;
146 compareMode = GL_NONE;
147 compareFunc = GL_LEQUAL;
148 sRGBDecode = GL_DECODE_EXT;
149 }
150
151 SamplerState::SamplerState(const SamplerState &other) = default;
152
153 // static
CreateDefaultForTarget(GLenum target)154 SamplerState SamplerState::CreateDefaultForTarget(GLenum target)
155 {
156 SamplerState state;
157
158 // According to OES_EGL_image_external and ARB_texture_rectangle: For external textures, the
159 // default min filter is GL_LINEAR and the default s and t wrap modes are GL_CLAMP_TO_EDGE.
160 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ANGLE)
161 {
162 state.minFilter = GL_LINEAR;
163 state.wrapS = GL_CLAMP_TO_EDGE;
164 state.wrapT = GL_CLAMP_TO_EDGE;
165 }
166
167 return state;
168 }
169
ImageUnit()170 ImageUnit::ImageUnit()
171 : texture(), level(0), layered(false), layer(0), access(GL_READ_ONLY), format(GL_R32UI)
172 {
173 }
174
175 ImageUnit::ImageUnit(const ImageUnit &other) = default;
176
177 ImageUnit::~ImageUnit() = default;
178
MinMax(int a,int b,int * minimum,int * maximum)179 static void MinMax(int a, int b, int *minimum, int *maximum)
180 {
181 if (a < b)
182 {
183 *minimum = a;
184 *maximum = b;
185 }
186 else
187 {
188 *minimum = b;
189 *maximum = a;
190 }
191 }
192
ClipRectangle(const Rectangle & source,const Rectangle & clip,Rectangle * intersection)193 bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *intersection)
194 {
195 int minSourceX, maxSourceX, minSourceY, maxSourceY;
196 MinMax(source.x, source.x + source.width, &minSourceX, &maxSourceX);
197 MinMax(source.y, source.y + source.height, &minSourceY, &maxSourceY);
198
199 int minClipX, maxClipX, minClipY, maxClipY;
200 MinMax(clip.x, clip.x + clip.width, &minClipX, &maxClipX);
201 MinMax(clip.y, clip.y + clip.height, &minClipY, &maxClipY);
202
203 if (minSourceX >= maxClipX || maxSourceX <= minClipX || minSourceY >= maxClipY || maxSourceY <= minClipY)
204 {
205 if (intersection)
206 {
207 intersection->x = minSourceX;
208 intersection->y = maxSourceY;
209 intersection->width = maxSourceX - minSourceX;
210 intersection->height = maxSourceY - minSourceY;
211 }
212
213 return false;
214 }
215 else
216 {
217 if (intersection)
218 {
219 intersection->x = std::max(minSourceX, minClipX);
220 intersection->y = std::max(minSourceY, minClipY);
221 intersection->width = std::min(maxSourceX, maxClipX) - std::max(minSourceX, minClipX);
222 intersection->height = std::min(maxSourceY, maxClipY) - std::max(minSourceY, minClipY);
223 }
224
225 return true;
226 }
227 }
228
operator ==(const Box & other) const229 bool Box::operator==(const Box &other) const
230 {
231 return (x == other.x && y == other.y && z == other.z &&
232 width == other.width && height == other.height && depth == other.depth);
233 }
234
operator !=(const Box & other) const235 bool Box::operator!=(const Box &other) const
236 {
237 return !(*this == other);
238 }
239
operator ==(const Offset & a,const Offset & b)240 bool operator==(const Offset &a, const Offset &b)
241 {
242 return a.x == b.x && a.y == b.y && a.z == b.z;
243 }
244
operator !=(const Offset & a,const Offset & b)245 bool operator!=(const Offset &a, const Offset &b)
246 {
247 return !(a == b);
248 }
249
operator ==(const Extents & lhs,const Extents & rhs)250 bool operator==(const Extents &lhs, const Extents &rhs)
251 {
252 return lhs.width == rhs.width && lhs.height == rhs.height && lhs.depth == rhs.depth;
253 }
254
operator !=(const Extents & lhs,const Extents & rhs)255 bool operator!=(const Extents &lhs, const Extents &rhs)
256 {
257 return !(lhs == rhs);
258 }
259 } // namespace gl
260