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"
16 SamplerState::SamplerState()
17 : minFilter(GL_NEAREST_MIPMAP_LINEAR),
28 compareFunc(GL_LEQUAL),
30 swizzleGreen(GL_GREEN),
32 swizzleAlpha(GL_ALPHA)
35 bool SamplerState::swizzleRequired() const
37 return swizzleRed != GL_RED || swizzleGreen != GL_GREEN ||
38 swizzleBlue != GL_BLUE || swizzleAlpha != GL_ALPHA;
41 static void MinMax(int a, int b, int *minimum, int *maximum)
55 bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *intersection)
57 int minSourceX, maxSourceX, minSourceY, maxSourceY;
58 MinMax(source.x, source.x + source.width, &minSourceX, &maxSourceX);
59 MinMax(source.y, source.y + source.height, &minSourceY, &maxSourceY);
61 int minClipX, maxClipX, minClipY, maxClipY;
62 MinMax(clip.x, clip.x + clip.width, &minClipX, &maxClipX);
63 MinMax(clip.y, clip.y + clip.height, &minClipY, &maxClipY);
65 if (minSourceX >= maxClipX || maxSourceX <= minClipX || minSourceY >= maxClipY || maxSourceY <= minClipY)
69 intersection->x = minSourceX;
70 intersection->y = maxSourceY;
71 intersection->width = maxSourceX - minSourceX;
72 intersection->height = maxSourceY - minSourceY;
81 intersection->x = std::max(minSourceX, minClipX);
82 intersection->y = std::max(minSourceY, minClipY);
83 intersection->width = std::min(maxSourceX, maxClipX) - std::max(minSourceX, minClipX);
84 intersection->height = std::min(maxSourceY, maxClipY) - std::max(minSourceY, minClipY);
91 VertexFormat::VertexFormat()
93 mNormalized(GL_FALSE),
98 VertexFormat::VertexFormat(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
100 mNormalized(normalized),
101 mComponents(components),
102 mPureInteger(pureInteger)
104 // Float data can not be normalized, so ignore the user setting
105 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
107 mNormalized = GL_FALSE;
111 VertexFormat::VertexFormat(const VertexAttribute &attrib)
112 : mType(attrib.type),
113 mNormalized(attrib.normalized ? GL_TRUE : GL_FALSE),
114 mComponents(attrib.size),
115 mPureInteger(attrib.pureInteger)
117 // Ensure we aren't initializing a vertex format which should be using
118 // the current-value type
119 ASSERT(attrib.enabled);
121 // Float data can not be normalized, so ignore the user setting
122 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
124 mNormalized = GL_FALSE;
128 VertexFormat::VertexFormat(const VertexAttribute &attrib, GLenum currentValueType)
129 : mType(attrib.type),
130 mNormalized(attrib.normalized ? GL_TRUE : GL_FALSE),
131 mComponents(attrib.size),
132 mPureInteger(attrib.pureInteger)
136 mType = currentValueType;
137 mNormalized = GL_FALSE;
139 mPureInteger = (currentValueType != GL_FLOAT);
142 // Float data can not be normalized, so ignore the user setting
143 if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
145 mNormalized = GL_FALSE;
149 void VertexFormat::GetInputLayout(VertexFormat *inputLayout,
150 ProgramBinary *programBinary,
151 const VertexAttribute *attributes,
152 const gl::VertexAttribCurrentValueData *currentValues)
154 for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
156 int semanticIndex = programBinary->getSemanticIndex(attributeIndex);
158 if (semanticIndex != -1)
160 inputLayout[semanticIndex] = VertexFormat(attributes[attributeIndex], currentValues[attributeIndex].Type);
165 bool VertexFormat::operator==(const VertexFormat &other) const
167 return (mType == other.mType &&
168 mComponents == other.mComponents &&
169 mNormalized == other.mNormalized &&
170 mPureInteger == other.mPureInteger );
173 bool VertexFormat::operator!=(const VertexFormat &other) const
175 return !(*this == other);
178 bool VertexFormat::operator<(const VertexFormat& other) const
180 if (mType != other.mType)
182 return mType < other.mType;
184 if (mNormalized != other.mNormalized)
186 return mNormalized < other.mNormalized;
188 if (mComponents != other.mComponents)
190 return mComponents < other.mComponents;
192 return mPureInteger < other.mPureInteger;