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.
7 // angletypes.h : Defines a variety of structures and enum types that are used throughout libGLESv2
9 #include "libGLESv2/angletypes.h"
10 #include "libGLESv2/ProgramBinary.h"
11 #include "libGLESv2/VertexAttribute.h"
12 #include "libGLESv2/State.h"
13 #include "libGLESv2/VertexArray.h"
18 SamplerState::SamplerState()
19 : minFilter(GL_NEAREST_MIPMAP_LINEAR),
30 compareFunc(GL_LEQUAL),
32 swizzleGreen(GL_GREEN),
34 swizzleAlpha(GL_ALPHA)
37 bool SamplerState::swizzleRequired() const
39 return swizzleRed != GL_RED || swizzleGreen != GL_GREEN ||
40 swizzleBlue != GL_BLUE || swizzleAlpha != GL_ALPHA;
43 static void MinMax(int a, int b, int *minimum, int *maximum)
57 bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *intersection)
59 int minSourceX, maxSourceX, minSourceY, maxSourceY;
60 MinMax(source.x, source.x + source.width, &minSourceX, &maxSourceX);
61 MinMax(source.y, source.y + source.height, &minSourceY, &maxSourceY);
63 int minClipX, maxClipX, minClipY, maxClipY;
64 MinMax(clip.x, clip.x + clip.width, &minClipX, &maxClipX);
65 MinMax(clip.y, clip.y + clip.height, &minClipY, &maxClipY);
67 if (minSourceX >= maxClipX || maxSourceX <= minClipX || minSourceY >= maxClipY || maxSourceY <= minClipY)
71 intersection->x = minSourceX;
72 intersection->y = maxSourceY;
73 intersection->width = maxSourceX - minSourceX;
74 intersection->height = maxSourceY - minSourceY;
83 intersection->x = std::max(minSourceX, minClipX);
84 intersection->y = std::max(minSourceY, minClipY);
85 intersection->width = std::min(maxSourceX, maxClipX) - std::max(minSourceX, minClipX);
86 intersection->height = std::min(maxSourceY, maxClipY) - std::max(minSourceY, minClipY);
93 VertexFormat::VertexFormat()
95 mNormalized(GL_FALSE),
100 VertexFormat::VertexFormat(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
102 mNormalized(normalized),
103 mComponents(components),
104 mPureInteger(pureInteger)
106 // Float data can not be normalized, so ignore the user setting
107 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
109 mNormalized = GL_FALSE;
113 VertexFormat::VertexFormat(const VertexAttribute &attrib)
114 : mType(attrib.type),
115 mNormalized(attrib.normalized ? GL_TRUE : GL_FALSE),
116 mComponents(attrib.size),
117 mPureInteger(attrib.pureInteger)
119 // Ensure we aren't initializing a vertex format which should be using
120 // the current-value type
121 ASSERT(attrib.enabled);
123 // Float data can not be normalized, so ignore the user setting
124 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
126 mNormalized = GL_FALSE;
130 VertexFormat::VertexFormat(const VertexAttribute &attrib, GLenum currentValueType)
131 : mType(attrib.type),
132 mNormalized(attrib.normalized ? GL_TRUE : GL_FALSE),
133 mComponents(attrib.size),
134 mPureInteger(attrib.pureInteger)
138 mType = currentValueType;
139 mNormalized = GL_FALSE;
141 mPureInteger = (currentValueType != GL_FLOAT);
144 // Float data can not be normalized, so ignore the user setting
145 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
147 mNormalized = GL_FALSE;
151 void VertexFormat::GetInputLayout(VertexFormat *inputLayout,
152 ProgramBinary *programBinary,
155 const VertexAttribute *vertexAttributes = state.getVertexArray()->getVertexAttributes();
156 for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
158 int semanticIndex = programBinary->getSemanticIndex(attributeIndex);
160 if (semanticIndex != -1)
162 inputLayout[semanticIndex] = VertexFormat(vertexAttributes[attributeIndex], state.getVertexAttribCurrentValue(attributeIndex).Type);
167 bool VertexFormat::operator==(const VertexFormat &other) const
169 return (mType == other.mType &&
170 mComponents == other.mComponents &&
171 mNormalized == other.mNormalized &&
172 mPureInteger == other.mPureInteger );
175 bool VertexFormat::operator!=(const VertexFormat &other) const
177 return !(*this == other);
180 bool VertexFormat::operator<(const VertexFormat& other) const
182 if (mType != other.mType)
184 return mType < other.mType;
186 if (mNormalized != other.mNormalized)
188 return mNormalized < other.mNormalized;
190 if (mComponents != other.mComponents)
192 return mComponents < other.mComponents;
194 return mPureInteger < other.mPureInteger;
197 bool Box::operator==(const Box &other) const
199 return (x == other.x && y == other.y && z == other.z &&
200 width == other.width && height == other.height && depth == other.depth);
203 bool Box::operator!=(const Box &other) const
205 return !(*this == other);