1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2013 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker // formatutils.h: Queries for GL image formats.
8*8975f5c5SAndroid Build Coastguard Worker
9*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_FORMATUTILS_H_
10*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_FORMATUTILS_H_
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker #include <stdint.h>
13*8975f5c5SAndroid Build Coastguard Worker #include <cstddef>
14*8975f5c5SAndroid Build Coastguard Worker #include <ostream>
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard Worker #include "angle_gl.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "common/android_util.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "common/hash_containers.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Caps.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Config.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Error.h"
22*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Version.h"
23*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/VertexAttribute.h"
24*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/angletypes.h"
25*8975f5c5SAndroid Build Coastguard Worker
26*8975f5c5SAndroid Build Coastguard Worker namespace gl
27*8975f5c5SAndroid Build Coastguard Worker {
28*8975f5c5SAndroid Build Coastguard Worker struct VertexAttribute;
29*8975f5c5SAndroid Build Coastguard Worker
30*8975f5c5SAndroid Build Coastguard Worker struct FormatType final
31*8975f5c5SAndroid Build Coastguard Worker {
32*8975f5c5SAndroid Build Coastguard Worker FormatType();
33*8975f5c5SAndroid Build Coastguard Worker FormatType(GLenum format_, GLenum type_);
34*8975f5c5SAndroid Build Coastguard Worker FormatType(const FormatType &other) = default;
35*8975f5c5SAndroid Build Coastguard Worker FormatType &operator=(const FormatType &other) = default;
36*8975f5c5SAndroid Build Coastguard Worker
37*8975f5c5SAndroid Build Coastguard Worker bool operator<(const FormatType &other) const;
38*8975f5c5SAndroid Build Coastguard Worker
39*8975f5c5SAndroid Build Coastguard Worker GLenum format;
40*8975f5c5SAndroid Build Coastguard Worker GLenum type;
41*8975f5c5SAndroid Build Coastguard Worker };
42*8975f5c5SAndroid Build Coastguard Worker
43*8975f5c5SAndroid Build Coastguard Worker struct Type
44*8975f5c5SAndroid Build Coastguard Worker {
TypeType45*8975f5c5SAndroid Build Coastguard Worker Type() : bytes(0), bytesShift(0), specialInterpretation(0) {}
46*8975f5c5SAndroid Build Coastguard Worker
TypeType47*8975f5c5SAndroid Build Coastguard Worker explicit Type(uint32_t packedTypeInfo)
48*8975f5c5SAndroid Build Coastguard Worker : bytes(packedTypeInfo & 0xff),
49*8975f5c5SAndroid Build Coastguard Worker bytesShift((packedTypeInfo >> 8) & 0xff),
50*8975f5c5SAndroid Build Coastguard Worker specialInterpretation((packedTypeInfo >> 16) & 1)
51*8975f5c5SAndroid Build Coastguard Worker {}
52*8975f5c5SAndroid Build Coastguard Worker
53*8975f5c5SAndroid Build Coastguard Worker GLuint bytes;
54*8975f5c5SAndroid Build Coastguard Worker GLuint bytesShift; // Bit shift by this value to effectively divide/multiply by "bytes" in a
55*8975f5c5SAndroid Build Coastguard Worker // more optimal way
56*8975f5c5SAndroid Build Coastguard Worker bool specialInterpretation;
57*8975f5c5SAndroid Build Coastguard Worker };
58*8975f5c5SAndroid Build Coastguard Worker
59*8975f5c5SAndroid Build Coastguard Worker uint32_t GetPackedTypeInfo(GLenum type);
60*8975f5c5SAndroid Build Coastguard Worker
GetNonLinearFormat(const GLenum format)61*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE GLenum GetNonLinearFormat(const GLenum format)
62*8975f5c5SAndroid Build Coastguard Worker {
63*8975f5c5SAndroid Build Coastguard Worker switch (format)
64*8975f5c5SAndroid Build Coastguard Worker {
65*8975f5c5SAndroid Build Coastguard Worker case GL_BGRA8_EXT:
66*8975f5c5SAndroid Build Coastguard Worker return GL_BGRA8_SRGB_ANGLEX;
67*8975f5c5SAndroid Build Coastguard Worker case GL_RGBA8:
68*8975f5c5SAndroid Build Coastguard Worker return GL_SRGB8_ALPHA8;
69*8975f5c5SAndroid Build Coastguard Worker case GL_RGB8:
70*8975f5c5SAndroid Build Coastguard Worker return GL_SRGB8;
71*8975f5c5SAndroid Build Coastguard Worker case GL_BGRX8_ANGLEX:
72*8975f5c5SAndroid Build Coastguard Worker return GL_BGRX8_SRGB_ANGLEX;
73*8975f5c5SAndroid Build Coastguard Worker case GL_RGBX8_ANGLE:
74*8975f5c5SAndroid Build Coastguard Worker return GL_RGBX8_SRGB_ANGLEX;
75*8975f5c5SAndroid Build Coastguard Worker case GL_RGBA16F:
76*8975f5c5SAndroid Build Coastguard Worker return GL_RGBA16F;
77*8975f5c5SAndroid Build Coastguard Worker case GL_RGB10_A2_EXT:
78*8975f5c5SAndroid Build Coastguard Worker return GL_RGB10_A2_EXT;
79*8975f5c5SAndroid Build Coastguard Worker case GL_SRGB8:
80*8975f5c5SAndroid Build Coastguard Worker case GL_SRGB8_ALPHA8:
81*8975f5c5SAndroid Build Coastguard Worker case GL_SRGB_ALPHA_EXT:
82*8975f5c5SAndroid Build Coastguard Worker case GL_SRGB_EXT:
83*8975f5c5SAndroid Build Coastguard Worker return format;
84*8975f5c5SAndroid Build Coastguard Worker default:
85*8975f5c5SAndroid Build Coastguard Worker return GL_NONE;
86*8975f5c5SAndroid Build Coastguard Worker }
87*8975f5c5SAndroid Build Coastguard Worker }
88*8975f5c5SAndroid Build Coastguard Worker
GetLinearFormat(const GLenum format)89*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE GLenum GetLinearFormat(const GLenum format)
90*8975f5c5SAndroid Build Coastguard Worker {
91*8975f5c5SAndroid Build Coastguard Worker switch (format)
92*8975f5c5SAndroid Build Coastguard Worker {
93*8975f5c5SAndroid Build Coastguard Worker case GL_BGRA8_SRGB_ANGLEX:
94*8975f5c5SAndroid Build Coastguard Worker return GL_BGRA8_EXT;
95*8975f5c5SAndroid Build Coastguard Worker case GL_SRGB8_ALPHA8:
96*8975f5c5SAndroid Build Coastguard Worker return GL_RGBA8;
97*8975f5c5SAndroid Build Coastguard Worker case GL_SRGB8:
98*8975f5c5SAndroid Build Coastguard Worker return GL_RGB8;
99*8975f5c5SAndroid Build Coastguard Worker case GL_BGRX8_SRGB_ANGLEX:
100*8975f5c5SAndroid Build Coastguard Worker return GL_BGRX8_ANGLEX;
101*8975f5c5SAndroid Build Coastguard Worker case GL_RGBX8_SRGB_ANGLEX:
102*8975f5c5SAndroid Build Coastguard Worker return GL_RGBX8_ANGLE;
103*8975f5c5SAndroid Build Coastguard Worker default:
104*8975f5c5SAndroid Build Coastguard Worker return format;
105*8975f5c5SAndroid Build Coastguard Worker }
106*8975f5c5SAndroid Build Coastguard Worker }
107*8975f5c5SAndroid Build Coastguard Worker
ColorspaceFormatOverride(const EGLenum colorspace,GLenum * rendertargetformat)108*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool ColorspaceFormatOverride(const EGLenum colorspace, GLenum *rendertargetformat)
109*8975f5c5SAndroid Build Coastguard Worker {
110*8975f5c5SAndroid Build Coastguard Worker // Override the rendertargetformat based on colorpsace
111*8975f5c5SAndroid Build Coastguard Worker switch (colorspace)
112*8975f5c5SAndroid Build Coastguard Worker {
113*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_LINEAR: // linear colorspace no translation needed
114*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT: // linear colorspace no translation needed
115*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_BT2020_LINEAR_EXT: // linear colorspace no translation needed
116*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT: // linear colorspace no translation needed
117*8975f5c5SAndroid Build Coastguard Worker *rendertargetformat = GetLinearFormat(*rendertargetformat);
118*8975f5c5SAndroid Build Coastguard Worker return true;
119*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT: // App, not the HW, will specify the
120*8975f5c5SAndroid Build Coastguard Worker // transfer function
121*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_SCRGB_EXT: // App, not the HW, will specify the transfer function
122*8975f5c5SAndroid Build Coastguard Worker // No translation
123*8975f5c5SAndroid Build Coastguard Worker return true;
124*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_SRGB_KHR:
125*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_BT2020_PQ_EXT:
126*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_BT2020_HLG_EXT:
127*8975f5c5SAndroid Build Coastguard Worker case EGL_GL_COLORSPACE_DISPLAY_P3_EXT:
128*8975f5c5SAndroid Build Coastguard Worker {
129*8975f5c5SAndroid Build Coastguard Worker GLenum nonLinearFormat = GetNonLinearFormat(*rendertargetformat);
130*8975f5c5SAndroid Build Coastguard Worker if (nonLinearFormat != GL_NONE)
131*8975f5c5SAndroid Build Coastguard Worker {
132*8975f5c5SAndroid Build Coastguard Worker *rendertargetformat = nonLinearFormat;
133*8975f5c5SAndroid Build Coastguard Worker return true;
134*8975f5c5SAndroid Build Coastguard Worker }
135*8975f5c5SAndroid Build Coastguard Worker else
136*8975f5c5SAndroid Build Coastguard Worker {
137*8975f5c5SAndroid Build Coastguard Worker return false;
138*8975f5c5SAndroid Build Coastguard Worker }
139*8975f5c5SAndroid Build Coastguard Worker }
140*8975f5c5SAndroid Build Coastguard Worker break;
141*8975f5c5SAndroid Build Coastguard Worker default:
142*8975f5c5SAndroid Build Coastguard Worker UNREACHABLE();
143*8975f5c5SAndroid Build Coastguard Worker return false;
144*8975f5c5SAndroid Build Coastguard Worker }
145*8975f5c5SAndroid Build Coastguard Worker }
146*8975f5c5SAndroid Build Coastguard Worker
GetTypeInfo(GLenum type)147*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE const Type GetTypeInfo(GLenum type)
148*8975f5c5SAndroid Build Coastguard Worker {
149*8975f5c5SAndroid Build Coastguard Worker return Type(GetPackedTypeInfo(type));
150*8975f5c5SAndroid Build Coastguard Worker }
151*8975f5c5SAndroid Build Coastguard Worker
152*8975f5c5SAndroid Build Coastguard Worker // This helpers use tricks based on the assumption that the type has certain values.
153*8975f5c5SAndroid Build Coastguard Worker static_assert(static_cast<GLuint>(DrawElementsType::UnsignedByte) == 0, "Please update this code.");
154*8975f5c5SAndroid Build Coastguard Worker static_assert(static_cast<GLuint>(DrawElementsType::UnsignedShort) == 1,
155*8975f5c5SAndroid Build Coastguard Worker "Please update this code.");
156*8975f5c5SAndroid Build Coastguard Worker static_assert(static_cast<GLuint>(DrawElementsType::UnsignedInt) == 2, "Please update this code.");
GetDrawElementsTypeSize(DrawElementsType type)157*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE GLuint GetDrawElementsTypeSize(DrawElementsType type)
158*8975f5c5SAndroid Build Coastguard Worker {
159*8975f5c5SAndroid Build Coastguard Worker return (1 << static_cast<GLuint>(type));
160*8975f5c5SAndroid Build Coastguard Worker }
161*8975f5c5SAndroid Build Coastguard Worker
GetDrawElementsTypeShift(DrawElementsType type)162*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE GLuint GetDrawElementsTypeShift(DrawElementsType type)
163*8975f5c5SAndroid Build Coastguard Worker {
164*8975f5c5SAndroid Build Coastguard Worker return static_cast<GLuint>(type);
165*8975f5c5SAndroid Build Coastguard Worker }
166*8975f5c5SAndroid Build Coastguard Worker
167*8975f5c5SAndroid Build Coastguard Worker // Information about an OpenGL internal format. Can be keyed on the internalFormat and type
168*8975f5c5SAndroid Build Coastguard Worker // members.
169*8975f5c5SAndroid Build Coastguard Worker struct InternalFormat
170*8975f5c5SAndroid Build Coastguard Worker {
171*8975f5c5SAndroid Build Coastguard Worker InternalFormat();
172*8975f5c5SAndroid Build Coastguard Worker InternalFormat(const InternalFormat &other);
173*8975f5c5SAndroid Build Coastguard Worker InternalFormat &operator=(const InternalFormat &other);
174*8975f5c5SAndroid Build Coastguard Worker
175*8975f5c5SAndroid Build Coastguard Worker GLuint computePixelBytes(GLenum formatType) const;
176*8975f5c5SAndroid Build Coastguard Worker
177*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeBufferRowLength(uint32_t width, uint32_t *resultOut) const;
178*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeBufferImageHeight(uint32_t height, uint32_t *resultOut) const;
179*8975f5c5SAndroid Build Coastguard Worker
180*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeRowPitch(GLenum formatType,
181*8975f5c5SAndroid Build Coastguard Worker GLsizei width,
182*8975f5c5SAndroid Build Coastguard Worker GLint alignment,
183*8975f5c5SAndroid Build Coastguard Worker GLint rowLength,
184*8975f5c5SAndroid Build Coastguard Worker GLuint *resultOut) const;
185*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeDepthPitch(GLsizei height,
186*8975f5c5SAndroid Build Coastguard Worker GLint imageHeight,
187*8975f5c5SAndroid Build Coastguard Worker GLuint rowPitch,
188*8975f5c5SAndroid Build Coastguard Worker GLuint *resultOut) const;
189*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeDepthPitch(GLenum formatType,
190*8975f5c5SAndroid Build Coastguard Worker GLsizei width,
191*8975f5c5SAndroid Build Coastguard Worker GLsizei height,
192*8975f5c5SAndroid Build Coastguard Worker GLint alignment,
193*8975f5c5SAndroid Build Coastguard Worker GLint rowLength,
194*8975f5c5SAndroid Build Coastguard Worker GLint imageHeight,
195*8975f5c5SAndroid Build Coastguard Worker GLuint *resultOut) const;
196*8975f5c5SAndroid Build Coastguard Worker
197*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computePalettedImageRowPitch(GLsizei width, GLuint *resultOut) const;
198*8975f5c5SAndroid Build Coastguard Worker
199*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeCompressedImageRowPitch(GLsizei width, GLuint *resultOut) const;
200*8975f5c5SAndroid Build Coastguard Worker
201*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeCompressedImageDepthPitch(GLsizei height,
202*8975f5c5SAndroid Build Coastguard Worker GLuint rowPitch,
203*8975f5c5SAndroid Build Coastguard Worker GLuint *resultOut) const;
204*8975f5c5SAndroid Build Coastguard Worker
205*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeCompressedImageSize(const Extents &size, GLuint *resultOut) const;
206*8975f5c5SAndroid Build Coastguard Worker
207*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] std::pair<GLuint, GLuint> getCompressedImageMinBlocks() const;
208*8975f5c5SAndroid Build Coastguard Worker
209*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computeSkipBytes(GLenum formatType,
210*8975f5c5SAndroid Build Coastguard Worker GLuint rowPitch,
211*8975f5c5SAndroid Build Coastguard Worker GLuint depthPitch,
212*8975f5c5SAndroid Build Coastguard Worker const PixelStoreStateBase &state,
213*8975f5c5SAndroid Build Coastguard Worker bool is3D,
214*8975f5c5SAndroid Build Coastguard Worker GLuint *resultOut) const;
215*8975f5c5SAndroid Build Coastguard Worker
216*8975f5c5SAndroid Build Coastguard Worker [[nodiscard]] bool computePackUnpackEndByte(GLenum formatType,
217*8975f5c5SAndroid Build Coastguard Worker const Extents &size,
218*8975f5c5SAndroid Build Coastguard Worker const PixelStoreStateBase &state,
219*8975f5c5SAndroid Build Coastguard Worker bool is3D,
220*8975f5c5SAndroid Build Coastguard Worker GLuint *resultOut) const;
221*8975f5c5SAndroid Build Coastguard Worker
222*8975f5c5SAndroid Build Coastguard Worker bool isLUMA() const;
223*8975f5c5SAndroid Build Coastguard Worker GLenum getReadPixelsFormat(const Extensions &extensions) const;
224*8975f5c5SAndroid Build Coastguard Worker GLenum getReadPixelsType(const Version &version) const;
225*8975f5c5SAndroid Build Coastguard Worker
226*8975f5c5SAndroid Build Coastguard Worker // Support upload a portion of image?
227*8975f5c5SAndroid Build Coastguard Worker bool supportSubImage() const;
228*8975f5c5SAndroid Build Coastguard Worker
isChannelSizeCompatibleInternalFormat229*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool isChannelSizeCompatible(GLuint redSize,
230*8975f5c5SAndroid Build Coastguard Worker GLuint greenSize,
231*8975f5c5SAndroid Build Coastguard Worker GLuint blueSize,
232*8975f5c5SAndroid Build Coastguard Worker GLuint alphaSize) const
233*8975f5c5SAndroid Build Coastguard Worker {
234*8975f5c5SAndroid Build Coastguard Worker // We only check for equality in all channel sizes
235*8975f5c5SAndroid Build Coastguard Worker return ((redSize == redBits) && (greenSize == greenBits) && (blueSize == blueBits) &&
236*8975f5c5SAndroid Build Coastguard Worker (alphaSize == alphaBits));
237*8975f5c5SAndroid Build Coastguard Worker }
238*8975f5c5SAndroid Build Coastguard Worker
239*8975f5c5SAndroid Build Coastguard Worker // Return true if the format is a required renderbuffer format in the given version of the core
240*8975f5c5SAndroid Build Coastguard Worker // spec. Note that it isn't always clear whether all the rules that apply to core required
241*8975f5c5SAndroid Build Coastguard Worker // renderbuffer formats also apply to additional formats added by extensions. Because of this
242*8975f5c5SAndroid Build Coastguard Worker // extension formats are conservatively not included.
243*8975f5c5SAndroid Build Coastguard Worker bool isRequiredRenderbufferFormat(const Version &version) const;
244*8975f5c5SAndroid Build Coastguard Worker
245*8975f5c5SAndroid Build Coastguard Worker bool isInt() const;
246*8975f5c5SAndroid Build Coastguard Worker bool isDepthOrStencil() const;
247*8975f5c5SAndroid Build Coastguard Worker
248*8975f5c5SAndroid Build Coastguard Worker GLuint getEGLConfigBufferSize() const;
249*8975f5c5SAndroid Build Coastguard Worker
250*8975f5c5SAndroid Build Coastguard Worker bool operator==(const InternalFormat &other) const;
251*8975f5c5SAndroid Build Coastguard Worker bool operator!=(const InternalFormat &other) const;
252*8975f5c5SAndroid Build Coastguard Worker
253*8975f5c5SAndroid Build Coastguard Worker GLenum internalFormat;
254*8975f5c5SAndroid Build Coastguard Worker
255*8975f5c5SAndroid Build Coastguard Worker bool sized;
256*8975f5c5SAndroid Build Coastguard Worker GLenum sizedInternalFormat;
257*8975f5c5SAndroid Build Coastguard Worker
258*8975f5c5SAndroid Build Coastguard Worker GLuint redBits;
259*8975f5c5SAndroid Build Coastguard Worker GLuint greenBits;
260*8975f5c5SAndroid Build Coastguard Worker GLuint blueBits;
261*8975f5c5SAndroid Build Coastguard Worker
262*8975f5c5SAndroid Build Coastguard Worker GLuint luminanceBits;
263*8975f5c5SAndroid Build Coastguard Worker
264*8975f5c5SAndroid Build Coastguard Worker GLuint alphaBits;
265*8975f5c5SAndroid Build Coastguard Worker GLuint sharedBits;
266*8975f5c5SAndroid Build Coastguard Worker
267*8975f5c5SAndroid Build Coastguard Worker GLuint depthBits;
268*8975f5c5SAndroid Build Coastguard Worker GLuint stencilBits;
269*8975f5c5SAndroid Build Coastguard Worker
270*8975f5c5SAndroid Build Coastguard Worker GLuint pixelBytes;
271*8975f5c5SAndroid Build Coastguard Worker
272*8975f5c5SAndroid Build Coastguard Worker GLuint componentCount;
273*8975f5c5SAndroid Build Coastguard Worker
274*8975f5c5SAndroid Build Coastguard Worker bool compressed;
275*8975f5c5SAndroid Build Coastguard Worker GLuint compressedBlockWidth;
276*8975f5c5SAndroid Build Coastguard Worker GLuint compressedBlockHeight;
277*8975f5c5SAndroid Build Coastguard Worker GLuint compressedBlockDepth;
278*8975f5c5SAndroid Build Coastguard Worker
279*8975f5c5SAndroid Build Coastguard Worker bool paletted;
280*8975f5c5SAndroid Build Coastguard Worker GLuint paletteBits;
281*8975f5c5SAndroid Build Coastguard Worker
282*8975f5c5SAndroid Build Coastguard Worker GLenum format;
283*8975f5c5SAndroid Build Coastguard Worker GLenum type;
284*8975f5c5SAndroid Build Coastguard Worker
285*8975f5c5SAndroid Build Coastguard Worker GLenum componentType;
286*8975f5c5SAndroid Build Coastguard Worker GLenum colorEncoding;
287*8975f5c5SAndroid Build Coastguard Worker
288*8975f5c5SAndroid Build Coastguard Worker typedef bool (*SupportCheckFunction)(const Version &, const Extensions &);
289*8975f5c5SAndroid Build Coastguard Worker SupportCheckFunction textureSupport;
290*8975f5c5SAndroid Build Coastguard Worker SupportCheckFunction filterSupport;
291*8975f5c5SAndroid Build Coastguard Worker SupportCheckFunction textureAttachmentSupport; // glFramebufferTexture2D
292*8975f5c5SAndroid Build Coastguard Worker SupportCheckFunction renderbufferSupport; // glFramebufferRenderbuffer
293*8975f5c5SAndroid Build Coastguard Worker SupportCheckFunction blendSupport;
294*8975f5c5SAndroid Build Coastguard Worker };
295*8975f5c5SAndroid Build Coastguard Worker
296*8975f5c5SAndroid Build Coastguard Worker // A "Format" wraps an InternalFormat struct, querying it from either a sized internal format or
297*8975f5c5SAndroid Build Coastguard Worker // unsized internal format and type.
298*8975f5c5SAndroid Build Coastguard Worker // TODO(geofflang): Remove this, it doesn't add any more information than the InternalFormat object.
299*8975f5c5SAndroid Build Coastguard Worker struct Format
300*8975f5c5SAndroid Build Coastguard Worker {
301*8975f5c5SAndroid Build Coastguard Worker // Sized types only.
302*8975f5c5SAndroid Build Coastguard Worker explicit Format(GLenum internalFormat);
303*8975f5c5SAndroid Build Coastguard Worker
304*8975f5c5SAndroid Build Coastguard Worker // Sized or unsized types.
305*8975f5c5SAndroid Build Coastguard Worker explicit Format(const InternalFormat &internalFormat);
306*8975f5c5SAndroid Build Coastguard Worker Format(GLenum internalFormat, GLenum type);
307*8975f5c5SAndroid Build Coastguard Worker
308*8975f5c5SAndroid Build Coastguard Worker Format(const Format &other);
309*8975f5c5SAndroid Build Coastguard Worker Format &operator=(const Format &other);
310*8975f5c5SAndroid Build Coastguard Worker
311*8975f5c5SAndroid Build Coastguard Worker bool valid() const;
312*8975f5c5SAndroid Build Coastguard Worker
313*8975f5c5SAndroid Build Coastguard Worker static Format Invalid();
314*8975f5c5SAndroid Build Coastguard Worker static bool SameSized(const Format &a, const Format &b);
315*8975f5c5SAndroid Build Coastguard Worker static bool EquivalentForBlit(const Format &a, const Format &b);
316*8975f5c5SAndroid Build Coastguard Worker
317*8975f5c5SAndroid Build Coastguard Worker friend std::ostream &operator<<(std::ostream &os, const Format &fmt);
318*8975f5c5SAndroid Build Coastguard Worker
319*8975f5c5SAndroid Build Coastguard Worker // This is the sized info.
320*8975f5c5SAndroid Build Coastguard Worker const InternalFormat *info;
321*8975f5c5SAndroid Build Coastguard Worker };
322*8975f5c5SAndroid Build Coastguard Worker
323*8975f5c5SAndroid Build Coastguard Worker const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat);
324*8975f5c5SAndroid Build Coastguard Worker const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type);
325*8975f5c5SAndroid Build Coastguard Worker
326*8975f5c5SAndroid Build Coastguard Worker // Strip sizing information from an internal format. Doesn't necessarily validate that the internal
327*8975f5c5SAndroid Build Coastguard Worker // format is valid.
328*8975f5c5SAndroid Build Coastguard Worker GLenum GetUnsizedFormat(GLenum internalFormat);
329*8975f5c5SAndroid Build Coastguard Worker
330*8975f5c5SAndroid Build Coastguard Worker // Return whether the compressed format requires whole image/mip level to be uploaded to texture.
331*8975f5c5SAndroid Build Coastguard Worker bool CompressedFormatRequiresWholeImage(GLenum internalFormat);
332*8975f5c5SAndroid Build Coastguard Worker
333*8975f5c5SAndroid Build Coastguard Worker // In support of GetImage, check for LUMA formats and override with real format
334*8975f5c5SAndroid Build Coastguard Worker void MaybeOverrideLuminance(GLenum &format, GLenum &type, GLenum actualFormat, GLenum actualType);
335*8975f5c5SAndroid Build Coastguard Worker
336*8975f5c5SAndroid Build Coastguard Worker typedef std::set<GLenum> FormatSet;
337*8975f5c5SAndroid Build Coastguard Worker const FormatSet &GetAllSizedInternalFormats();
338*8975f5c5SAndroid Build Coastguard Worker
339*8975f5c5SAndroid Build Coastguard Worker typedef angle::HashMap<GLenum, angle::HashMap<GLenum, InternalFormat>> InternalFormatInfoMap;
340*8975f5c5SAndroid Build Coastguard Worker const InternalFormatInfoMap &GetInternalFormatMap();
341*8975f5c5SAndroid Build Coastguard Worker
342*8975f5c5SAndroid Build Coastguard Worker int GetAndroidHardwareBufferFormatFromChannelSizes(const egl::AttributeMap &attribMap);
343*8975f5c5SAndroid Build Coastguard Worker
344*8975f5c5SAndroid Build Coastguard Worker GLenum GetConfigColorBufferFormat(const egl::Config *config);
345*8975f5c5SAndroid Build Coastguard Worker GLenum GetConfigDepthStencilBufferFormat(const egl::Config *config);
346*8975f5c5SAndroid Build Coastguard Worker
GetNativeVisualID(const InternalFormat & internalFormat)347*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE int GetNativeVisualID(const InternalFormat &internalFormat)
348*8975f5c5SAndroid Build Coastguard Worker {
349*8975f5c5SAndroid Build Coastguard Worker int nativeVisualId = 0;
350*8975f5c5SAndroid Build Coastguard Worker #if defined(ANGLE_PLATFORM_ANDROID)
351*8975f5c5SAndroid Build Coastguard Worker nativeVisualId =
352*8975f5c5SAndroid Build Coastguard Worker angle::android::GLInternalFormatToNativePixelFormat(internalFormat.internalFormat);
353*8975f5c5SAndroid Build Coastguard Worker #endif
354*8975f5c5SAndroid Build Coastguard Worker #if defined(ANGLE_PLATFORM_LINUX) && defined(ANGLE_USES_GBM)
355*8975f5c5SAndroid Build Coastguard Worker nativeVisualId = angle::GLInternalFormatToGbmFourCCFormat(internalFormat.internalFormat);
356*8975f5c5SAndroid Build Coastguard Worker #endif
357*8975f5c5SAndroid Build Coastguard Worker
358*8975f5c5SAndroid Build Coastguard Worker return nativeVisualId;
359*8975f5c5SAndroid Build Coastguard Worker }
360*8975f5c5SAndroid Build Coastguard Worker
361*8975f5c5SAndroid Build Coastguard Worker // From the ESSL 3.00.4 spec:
362*8975f5c5SAndroid Build Coastguard Worker // Vertex shader inputs can only be float, floating-point vectors, matrices, signed and unsigned
363*8975f5c5SAndroid Build Coastguard Worker // integers and integer vectors. Vertex shader inputs cannot be arrays or structures.
364*8975f5c5SAndroid Build Coastguard Worker
365*8975f5c5SAndroid Build Coastguard Worker enum AttributeType
366*8975f5c5SAndroid Build Coastguard Worker {
367*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_FLOAT,
368*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_VEC2,
369*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_VEC3,
370*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_VEC4,
371*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_INT,
372*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_IVEC2,
373*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_IVEC3,
374*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_IVEC4,
375*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_UINT,
376*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_UVEC2,
377*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_UVEC3,
378*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_UVEC4,
379*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT2,
380*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT3,
381*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT4,
382*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT2x3,
383*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT2x4,
384*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT3x2,
385*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT3x4,
386*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT4x2,
387*8975f5c5SAndroid Build Coastguard Worker ATTRIBUTE_MAT4x3,
388*8975f5c5SAndroid Build Coastguard Worker };
389*8975f5c5SAndroid Build Coastguard Worker
390*8975f5c5SAndroid Build Coastguard Worker AttributeType GetAttributeType(GLenum enumValue);
391*8975f5c5SAndroid Build Coastguard Worker
392*8975f5c5SAndroid Build Coastguard Worker typedef std::vector<angle::FormatID> InputLayout;
393*8975f5c5SAndroid Build Coastguard Worker
394*8975f5c5SAndroid Build Coastguard Worker struct VertexFormat : private angle::NonCopyable
395*8975f5c5SAndroid Build Coastguard Worker {
396*8975f5c5SAndroid Build Coastguard Worker VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn);
397*8975f5c5SAndroid Build Coastguard Worker
398*8975f5c5SAndroid Build Coastguard Worker GLenum type;
399*8975f5c5SAndroid Build Coastguard Worker GLboolean normalized;
400*8975f5c5SAndroid Build Coastguard Worker GLuint components;
401*8975f5c5SAndroid Build Coastguard Worker bool pureInteger;
402*8975f5c5SAndroid Build Coastguard Worker };
403*8975f5c5SAndroid Build Coastguard Worker
404*8975f5c5SAndroid Build Coastguard Worker angle::FormatID GetVertexFormatID(VertexAttribType type,
405*8975f5c5SAndroid Build Coastguard Worker GLboolean normalized,
406*8975f5c5SAndroid Build Coastguard Worker GLuint components,
407*8975f5c5SAndroid Build Coastguard Worker bool pureInteger);
408*8975f5c5SAndroid Build Coastguard Worker
409*8975f5c5SAndroid Build Coastguard Worker angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, VertexAttribType currentValueType);
410*8975f5c5SAndroid Build Coastguard Worker angle::FormatID GetCurrentValueFormatID(VertexAttribType currentValueType);
411*8975f5c5SAndroid Build Coastguard Worker const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID);
412*8975f5c5SAndroid Build Coastguard Worker size_t GetVertexFormatSize(angle::FormatID vertexFormatID);
413*8975f5c5SAndroid Build Coastguard Worker angle::FormatID ConvertFormatSignedness(const angle::Format &format);
414*8975f5c5SAndroid Build Coastguard Worker
IsS3TCFormat(const GLenum format)415*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool IsS3TCFormat(const GLenum format)
416*8975f5c5SAndroid Build Coastguard Worker {
417*8975f5c5SAndroid Build Coastguard Worker switch (format)
418*8975f5c5SAndroid Build Coastguard Worker {
419*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
420*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
421*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
422*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
423*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
424*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
425*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
426*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
427*8975f5c5SAndroid Build Coastguard Worker return true;
428*8975f5c5SAndroid Build Coastguard Worker
429*8975f5c5SAndroid Build Coastguard Worker default:
430*8975f5c5SAndroid Build Coastguard Worker return false;
431*8975f5c5SAndroid Build Coastguard Worker }
432*8975f5c5SAndroid Build Coastguard Worker }
433*8975f5c5SAndroid Build Coastguard Worker
IsRGTCFormat(const GLenum format)434*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool IsRGTCFormat(const GLenum format)
435*8975f5c5SAndroid Build Coastguard Worker {
436*8975f5c5SAndroid Build Coastguard Worker switch (format)
437*8975f5c5SAndroid Build Coastguard Worker {
438*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RED_RGTC1_EXT:
439*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SIGNED_RED_RGTC1_EXT:
440*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RED_GREEN_RGTC2_EXT:
441*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT:
442*8975f5c5SAndroid Build Coastguard Worker return true;
443*8975f5c5SAndroid Build Coastguard Worker
444*8975f5c5SAndroid Build Coastguard Worker default:
445*8975f5c5SAndroid Build Coastguard Worker return false;
446*8975f5c5SAndroid Build Coastguard Worker }
447*8975f5c5SAndroid Build Coastguard Worker }
448*8975f5c5SAndroid Build Coastguard Worker
IsBPTCFormat(const GLenum format)449*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool IsBPTCFormat(const GLenum format)
450*8975f5c5SAndroid Build Coastguard Worker {
451*8975f5c5SAndroid Build Coastguard Worker switch (format)
452*8975f5c5SAndroid Build Coastguard Worker {
453*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT:
454*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:
455*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT:
456*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT:
457*8975f5c5SAndroid Build Coastguard Worker return true;
458*8975f5c5SAndroid Build Coastguard Worker
459*8975f5c5SAndroid Build Coastguard Worker default:
460*8975f5c5SAndroid Build Coastguard Worker return false;
461*8975f5c5SAndroid Build Coastguard Worker }
462*8975f5c5SAndroid Build Coastguard Worker }
463*8975f5c5SAndroid Build Coastguard Worker
IsASTC2DFormat(const GLenum format)464*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool IsASTC2DFormat(const GLenum format)
465*8975f5c5SAndroid Build Coastguard Worker {
466*8975f5c5SAndroid Build Coastguard Worker if ((format >= GL_COMPRESSED_RGBA_ASTC_4x4_KHR &&
467*8975f5c5SAndroid Build Coastguard Worker format <= GL_COMPRESSED_RGBA_ASTC_12x12_KHR) ||
468*8975f5c5SAndroid Build Coastguard Worker (format >= GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR &&
469*8975f5c5SAndroid Build Coastguard Worker format <= GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR))
470*8975f5c5SAndroid Build Coastguard Worker {
471*8975f5c5SAndroid Build Coastguard Worker return true;
472*8975f5c5SAndroid Build Coastguard Worker }
473*8975f5c5SAndroid Build Coastguard Worker return false;
474*8975f5c5SAndroid Build Coastguard Worker }
475*8975f5c5SAndroid Build Coastguard Worker
IsETC1Format(const GLenum format)476*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool IsETC1Format(const GLenum format)
477*8975f5c5SAndroid Build Coastguard Worker {
478*8975f5c5SAndroid Build Coastguard Worker switch (format)
479*8975f5c5SAndroid Build Coastguard Worker {
480*8975f5c5SAndroid Build Coastguard Worker case GL_ETC1_RGB8_OES:
481*8975f5c5SAndroid Build Coastguard Worker return true;
482*8975f5c5SAndroid Build Coastguard Worker
483*8975f5c5SAndroid Build Coastguard Worker default:
484*8975f5c5SAndroid Build Coastguard Worker return false;
485*8975f5c5SAndroid Build Coastguard Worker }
486*8975f5c5SAndroid Build Coastguard Worker }
487*8975f5c5SAndroid Build Coastguard Worker
IsETC2EACFormat(const GLenum format)488*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool IsETC2EACFormat(const GLenum format)
489*8975f5c5SAndroid Build Coastguard Worker {
490*8975f5c5SAndroid Build Coastguard Worker // ES 3.1, Table 8.19
491*8975f5c5SAndroid Build Coastguard Worker switch (format)
492*8975f5c5SAndroid Build Coastguard Worker {
493*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_R11_EAC:
494*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SIGNED_R11_EAC:
495*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RG11_EAC:
496*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SIGNED_RG11_EAC:
497*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGB8_ETC2:
498*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SRGB8_ETC2:
499*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
500*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
501*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_RGBA8_ETC2_EAC:
502*8975f5c5SAndroid Build Coastguard Worker case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
503*8975f5c5SAndroid Build Coastguard Worker return true;
504*8975f5c5SAndroid Build Coastguard Worker
505*8975f5c5SAndroid Build Coastguard Worker default:
506*8975f5c5SAndroid Build Coastguard Worker return false;
507*8975f5c5SAndroid Build Coastguard Worker }
508*8975f5c5SAndroid Build Coastguard Worker }
509*8975f5c5SAndroid Build Coastguard Worker
IsPVRTC1Format(const GLenum format)510*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE constexpr bool IsPVRTC1Format(const GLenum format)
511*8975f5c5SAndroid Build Coastguard Worker {
512*8975f5c5SAndroid Build Coastguard Worker // This function is called for all compressed texture uploads. The expression below generates
513*8975f5c5SAndroid Build Coastguard Worker // fewer instructions than a regular switch statement. Two groups of four consecutive values,
514*8975f5c5SAndroid Build Coastguard Worker // each group starts with two least significant bits unset.
515*8975f5c5SAndroid Build Coastguard Worker return ((format & ~3) == GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG) ||
516*8975f5c5SAndroid Build Coastguard Worker ((format & ~3) == GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT);
517*8975f5c5SAndroid Build Coastguard Worker }
518*8975f5c5SAndroid Build Coastguard Worker static_assert(IsPVRTC1Format(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG), "0x8C00");
519*8975f5c5SAndroid Build Coastguard Worker static_assert(IsPVRTC1Format(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG), "0x8C01");
520*8975f5c5SAndroid Build Coastguard Worker static_assert(IsPVRTC1Format(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG), "0x8C02");
521*8975f5c5SAndroid Build Coastguard Worker static_assert(IsPVRTC1Format(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG), "0x8C03");
522*8975f5c5SAndroid Build Coastguard Worker static_assert(IsPVRTC1Format(GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT), "0x8A54");
523*8975f5c5SAndroid Build Coastguard Worker static_assert(IsPVRTC1Format(GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT), "0x8A55");
524*8975f5c5SAndroid Build Coastguard Worker static_assert(IsPVRTC1Format(GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT), "0x8A56");
525*8975f5c5SAndroid Build Coastguard Worker static_assert(IsPVRTC1Format(GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT), "0x8A57");
526*8975f5c5SAndroid Build Coastguard Worker static_assert(!IsPVRTC1Format(0x8BFF) && !IsPVRTC1Format(0x8C04), "invalid");
527*8975f5c5SAndroid Build Coastguard Worker static_assert(!IsPVRTC1Format(0x8A53) && !IsPVRTC1Format(0x8A58), "invalid");
528*8975f5c5SAndroid Build Coastguard Worker
IsBGRAFormat(const GLenum internalFormat)529*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool IsBGRAFormat(const GLenum internalFormat)
530*8975f5c5SAndroid Build Coastguard Worker {
531*8975f5c5SAndroid Build Coastguard Worker switch (internalFormat)
532*8975f5c5SAndroid Build Coastguard Worker {
533*8975f5c5SAndroid Build Coastguard Worker case GL_BGRA8_EXT:
534*8975f5c5SAndroid Build Coastguard Worker case GL_BGRA4_ANGLEX:
535*8975f5c5SAndroid Build Coastguard Worker case GL_BGR5_A1_ANGLEX:
536*8975f5c5SAndroid Build Coastguard Worker case GL_BGRA8_SRGB_ANGLEX:
537*8975f5c5SAndroid Build Coastguard Worker case GL_BGRX8_ANGLEX:
538*8975f5c5SAndroid Build Coastguard Worker case GL_BGR565_ANGLEX:
539*8975f5c5SAndroid Build Coastguard Worker case GL_BGR10_A2_ANGLEX:
540*8975f5c5SAndroid Build Coastguard Worker return true;
541*8975f5c5SAndroid Build Coastguard Worker
542*8975f5c5SAndroid Build Coastguard Worker default:
543*8975f5c5SAndroid Build Coastguard Worker return false;
544*8975f5c5SAndroid Build Coastguard Worker }
545*8975f5c5SAndroid Build Coastguard Worker }
546*8975f5c5SAndroid Build Coastguard Worker
547*8975f5c5SAndroid Build Coastguard Worker // Check if an internal format is ever valid in ES3. Makes no checks about support for a specific
548*8975f5c5SAndroid Build Coastguard Worker // context.
549*8975f5c5SAndroid Build Coastguard Worker bool ValidES3InternalFormat(GLenum internalFormat);
550*8975f5c5SAndroid Build Coastguard Worker
551*8975f5c5SAndroid Build Coastguard Worker // Implemented in format_map_autogen.cpp
552*8975f5c5SAndroid Build Coastguard Worker bool ValidES3Format(GLenum format);
553*8975f5c5SAndroid Build Coastguard Worker bool ValidES3Type(GLenum type);
554*8975f5c5SAndroid Build Coastguard Worker bool ValidES3FormatCombination(GLenum format, GLenum type, GLenum internalFormat);
555*8975f5c5SAndroid Build Coastguard Worker
556*8975f5c5SAndroid Build Coastguard Worker // Implemented in es3_copy_conversion_table_autogen.cpp
557*8975f5c5SAndroid Build Coastguard Worker bool ValidES3CopyConversion(GLenum textureFormat, GLenum framebufferFormat);
558*8975f5c5SAndroid Build Coastguard Worker
GetVertexAttributeComponentType(bool pureInteger,VertexAttribType type)559*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE ComponentType GetVertexAttributeComponentType(bool pureInteger, VertexAttribType type)
560*8975f5c5SAndroid Build Coastguard Worker {
561*8975f5c5SAndroid Build Coastguard Worker if (pureInteger)
562*8975f5c5SAndroid Build Coastguard Worker {
563*8975f5c5SAndroid Build Coastguard Worker switch (type)
564*8975f5c5SAndroid Build Coastguard Worker {
565*8975f5c5SAndroid Build Coastguard Worker case VertexAttribType::Byte:
566*8975f5c5SAndroid Build Coastguard Worker case VertexAttribType::Short:
567*8975f5c5SAndroid Build Coastguard Worker case VertexAttribType::Int:
568*8975f5c5SAndroid Build Coastguard Worker return ComponentType::Int;
569*8975f5c5SAndroid Build Coastguard Worker
570*8975f5c5SAndroid Build Coastguard Worker case VertexAttribType::UnsignedByte:
571*8975f5c5SAndroid Build Coastguard Worker case VertexAttribType::UnsignedShort:
572*8975f5c5SAndroid Build Coastguard Worker case VertexAttribType::UnsignedInt:
573*8975f5c5SAndroid Build Coastguard Worker return ComponentType::UnsignedInt;
574*8975f5c5SAndroid Build Coastguard Worker
575*8975f5c5SAndroid Build Coastguard Worker default:
576*8975f5c5SAndroid Build Coastguard Worker UNREACHABLE();
577*8975f5c5SAndroid Build Coastguard Worker return ComponentType::NoType;
578*8975f5c5SAndroid Build Coastguard Worker }
579*8975f5c5SAndroid Build Coastguard Worker }
580*8975f5c5SAndroid Build Coastguard Worker else
581*8975f5c5SAndroid Build Coastguard Worker {
582*8975f5c5SAndroid Build Coastguard Worker return ComponentType::Float;
583*8975f5c5SAndroid Build Coastguard Worker }
584*8975f5c5SAndroid Build Coastguard Worker }
585*8975f5c5SAndroid Build Coastguard Worker
586*8975f5c5SAndroid Build Coastguard Worker constexpr std::size_t kMaxYuvPlaneCount = 3;
587*8975f5c5SAndroid Build Coastguard Worker template <typename T>
588*8975f5c5SAndroid Build Coastguard Worker using YuvPlaneArray = std::array<T, kMaxYuvPlaneCount>;
589*8975f5c5SAndroid Build Coastguard Worker
590*8975f5c5SAndroid Build Coastguard Worker struct YuvFormatInfo
591*8975f5c5SAndroid Build Coastguard Worker {
592*8975f5c5SAndroid Build Coastguard Worker // Sized types only.
593*8975f5c5SAndroid Build Coastguard Worker YuvFormatInfo(GLenum internalFormat, const Extents &yPlaneExtent);
594*8975f5c5SAndroid Build Coastguard Worker
595*8975f5c5SAndroid Build Coastguard Worker GLenum glInternalFormat;
596*8975f5c5SAndroid Build Coastguard Worker uint32_t planeCount;
597*8975f5c5SAndroid Build Coastguard Worker YuvPlaneArray<uint32_t> planeBpp;
598*8975f5c5SAndroid Build Coastguard Worker YuvPlaneArray<Extents> planeExtent;
599*8975f5c5SAndroid Build Coastguard Worker YuvPlaneArray<uint32_t> planePitch;
600*8975f5c5SAndroid Build Coastguard Worker YuvPlaneArray<uint32_t> planeSize;
601*8975f5c5SAndroid Build Coastguard Worker YuvPlaneArray<uint32_t> planeOffset;
602*8975f5c5SAndroid Build Coastguard Worker };
603*8975f5c5SAndroid Build Coastguard Worker
604*8975f5c5SAndroid Build Coastguard Worker bool IsYuvFormat(GLenum format);
605*8975f5c5SAndroid Build Coastguard Worker uint32_t GetPlaneCount(GLenum format);
606*8975f5c5SAndroid Build Coastguard Worker uint32_t GetYPlaneBpp(GLenum format);
607*8975f5c5SAndroid Build Coastguard Worker uint32_t GetChromaPlaneBpp(GLenum format);
608*8975f5c5SAndroid Build Coastguard Worker void GetSubSampleFactor(GLenum format,
609*8975f5c5SAndroid Build Coastguard Worker int *horizontalSubsampleFactor,
610*8975f5c5SAndroid Build Coastguard Worker int *verticalSubsampleFactor);
611*8975f5c5SAndroid Build Coastguard Worker } // namespace gl
612*8975f5c5SAndroid Build Coastguard Worker
613*8975f5c5SAndroid Build Coastguard Worker #endif // LIBANGLE_FORMATUTILS_H_
614