1 #include "precompiled.h"
3 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
8 // angletypes.h : Defines a variety of structures and enum types that are used throughout libGLESv2
10 #include "libGLESv2/angletypes.h"
11 #include "libGLESv2/ProgramBinary.h"
12 #include "libGLESv2/VertexAttribute.h"
17 SamplerState::SamplerState()
18 : minFilter(GL_NEAREST_MIPMAP_LINEAR),
29 compareFunc(GL_LEQUAL),
31 swizzleGreen(GL_GREEN),
33 swizzleAlpha(GL_ALPHA)
36 bool SamplerState::swizzleRequired() const
38 return swizzleRed != GL_RED || swizzleGreen != GL_GREEN ||
39 swizzleBlue != GL_BLUE || swizzleAlpha != GL_ALPHA;
42 static void MinMax(int a, int b, int *minimum, int *maximum)
56 bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *intersection)
58 int minSourceX, maxSourceX, minSourceY, maxSourceY;
59 MinMax(source.x, source.x + source.width, &minSourceX, &maxSourceX);
60 MinMax(source.y, source.y + source.height, &minSourceY, &maxSourceY);
62 int minClipX, maxClipX, minClipY, maxClipY;
63 MinMax(clip.x, clip.x + clip.width, &minClipX, &maxClipX);
64 MinMax(clip.y, clip.y + clip.height, &minClipY, &maxClipY);
66 if (minSourceX >= maxClipX || maxSourceX <= minClipX || minSourceY >= maxClipY || maxSourceY <= minClipY)
70 intersection->x = minSourceX;
71 intersection->y = maxSourceY;
72 intersection->width = maxSourceX - minSourceX;
73 intersection->height = maxSourceY - minSourceY;
82 intersection->x = std::max(minSourceX, minClipX);
83 intersection->y = std::max(minSourceY, minClipY);
84 intersection->width = std::min(maxSourceX, maxClipX) - std::max(minSourceX, minClipX);
85 intersection->height = std::min(maxSourceY, maxClipY) - std::max(minSourceY, minClipY);
92 VertexFormat::VertexFormat()
94 mNormalized(GL_FALSE),
99 VertexFormat::VertexFormat(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
101 mNormalized(normalized),
102 mComponents(components),
103 mPureInteger(pureInteger)
105 // Float data can not be normalized, so ignore the user setting
106 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
108 mNormalized = GL_FALSE;
112 VertexFormat::VertexFormat(const VertexAttribute &attrib)
113 : mType(attrib.type),
114 mNormalized(attrib.normalized ? GL_TRUE : GL_FALSE),
115 mComponents(attrib.size),
116 mPureInteger(attrib.pureInteger)
118 // Ensure we aren't initializing a vertex format which should be using
119 // the current-value type
120 ASSERT(attrib.enabled);
122 // Float data can not be normalized, so ignore the user setting
123 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
125 mNormalized = GL_FALSE;
129 VertexFormat::VertexFormat(const VertexAttribute &attrib, GLenum currentValueType)
130 : mType(attrib.type),
131 mNormalized(attrib.normalized ? GL_TRUE : GL_FALSE),
132 mComponents(attrib.size),
133 mPureInteger(attrib.pureInteger)
137 mType = currentValueType;
138 mNormalized = GL_FALSE;
140 mPureInteger = (currentValueType != GL_FLOAT);
143 // Float data can not be normalized, so ignore the user setting
144 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
146 mNormalized = GL_FALSE;
150 void VertexFormat::GetInputLayout(VertexFormat *inputLayout,
151 ProgramBinary *programBinary,
152 const VertexAttribute *attributes,
153 const gl::VertexAttribCurrentValueData *currentValues)
155 for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
157 int semanticIndex = programBinary->getSemanticIndex(attributeIndex);
159 if (semanticIndex != -1)
161 inputLayout[semanticIndex] = VertexFormat(attributes[attributeIndex], currentValues[attributeIndex].Type);
166 bool VertexFormat::operator==(const VertexFormat &other) const
168 return (mType == other.mType &&
169 mComponents == other.mComponents &&
170 mNormalized == other.mNormalized &&
171 mPureInteger == other.mPureInteger );
174 bool VertexFormat::operator!=(const VertexFormat &other) const
176 return !(*this == other);
179 bool VertexFormat::operator<(const VertexFormat& other) const
181 if (mType != other.mType)
183 return mType < other.mType;
185 if (mNormalized != other.mNormalized)
187 return mNormalized < other.mNormalized;
189 if (mComponents != other.mComponents)
191 return mComponents < other.mComponents;
193 return mPureInteger < other.mPureInteger;