Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
formats_gles.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7// Compressed texture internal formats. ETC2/EAC are core in OpenGL ES 3.0, but
8// the S3TC (BC1/BC3), RGTC (BC5), BPTC (BC7), and ASTC enums come from
9// extension headers that are not present on every platform, so they are
10// guarded here.
11#ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
12#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
13#endif
14#ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
15#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
16#endif
17#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
18#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
19#endif
20#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
21#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
22#endif
23#ifndef GL_COMPRESSED_RG_RGTC2
24#define GL_COMPRESSED_RG_RGTC2 0x8DBD
25#endif
26#ifndef GL_COMPRESSED_RGBA_BPTC_UNORM
27#define GL_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C
28#endif
29#ifndef GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
30#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM 0x8E8D
31#endif
32#ifndef GL_COMPRESSED_RGB8_ETC2
33#define GL_COMPRESSED_RGB8_ETC2 0x9274
34#endif
35#ifndef GL_COMPRESSED_SRGB8_ETC2
36#define GL_COMPRESSED_SRGB8_ETC2 0x9275
37#endif
38#ifndef GL_COMPRESSED_RGBA8_ETC2_EAC
39#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
40#endif
41#ifndef GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
42#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279
43#endif
44#ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR
45#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
46#endif
47#ifndef GL_COMPRESSED_RGBA_ASTC_8x8_KHR
48#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
49#endif
50#ifndef GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
51#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0
52#endif
53#ifndef GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
54#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7
55#endif
56
57namespace impeller {
58
59std::string DebugToFramebufferError(int status) {
60 switch (status) {
61 case GL_FRAMEBUFFER_UNDEFINED:
62 return "GL_FRAMEBUFFER_UNDEFINED";
63 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
64 return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
65 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
66 return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
67 case GL_FRAMEBUFFER_UNSUPPORTED:
68 return "GL_FRAMEBUFFER_UNSUPPORTED";
69 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
70 return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
71 default:
72 return "Unknown error code: " + std::to_string(status);
73 }
74}
75
76std::optional<PixelFormatGLES> ToPixelFormatGLES(PixelFormat pixel_format,
77 bool supports_bgra) {
79
80 switch (pixel_format) {
82 format.internal_format = GL_ALPHA;
83 format.external_format = GL_ALPHA;
84 format.type = GL_UNSIGNED_BYTE;
85 break;
87 format.internal_format = GL_RED;
88 format.external_format = GL_RED;
89 format.type = GL_UNSIGNED_BYTE;
90 break;
93 format.internal_format = GL_RGBA;
94 format.external_format = GL_RGBA;
95 format.type = GL_UNSIGNED_BYTE;
96 break;
99 if (supports_bgra) {
100 format.internal_format = GL_BGRA_EXT;
101 format.external_format = GL_BGRA_EXT;
102 } else {
103 format.internal_format = GL_RGBA;
104 format.external_format = GL_RGBA;
105 }
106 format.type = GL_UNSIGNED_BYTE;
107 break;
109 format.internal_format = GL_RGBA32F;
110 format.external_format = GL_RGBA;
111 format.type = GL_FLOAT;
112 break;
114 format.internal_format = GL_R32F;
115 format.external_format = GL_RED;
116 format.type = GL_FLOAT;
117 break;
119 format.internal_format = GL_RGBA16F;
120 format.external_format = GL_RGBA;
121 format.type = GL_HALF_FLOAT;
122 break;
124 // Pure stencil textures are only available in OpenGL 4.4+, which is
125 // ~0% of mobile devices. Instead, we use a depth-stencil texture and
126 // only use the stencil component.
127 //
128 // https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml
130 format.internal_format = GL_DEPTH_STENCIL;
131 format.external_format = GL_DEPTH_STENCIL;
132 format.type = GL_UNSIGNED_INT_24_8;
133 break;
134 // Block-compressed formats. Only the internal format is meaningful; the
135 // data is uploaded with glCompressedTexImage2D rather than glTexImage2D.
138 format.is_compressed = true;
139 break;
142 format.is_compressed = true;
143 break;
146 format.is_compressed = true;
147 break;
150 format.is_compressed = true;
151 break;
153 format.internal_format = GL_COMPRESSED_RG_RGTC2;
154 format.is_compressed = true;
155 break;
157 format.internal_format = GL_COMPRESSED_RGBA_BPTC_UNORM;
158 format.is_compressed = true;
159 break;
162 format.is_compressed = true;
163 break;
165 format.internal_format = GL_COMPRESSED_RGB8_ETC2;
166 format.is_compressed = true;
167 break;
169 format.internal_format = GL_COMPRESSED_SRGB8_ETC2;
170 format.is_compressed = true;
171 break;
173 format.internal_format = GL_COMPRESSED_RGBA8_ETC2_EAC;
174 format.is_compressed = true;
175 break;
178 format.is_compressed = true;
179 break;
181 format.internal_format = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
182 format.is_compressed = true;
183 break;
186 format.is_compressed = true;
187 break;
189 format.internal_format = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
190 format.is_compressed = true;
191 break;
194 format.is_compressed = true;
195 break;
196 // ASTC HDR uses the same internal formats as LDR; the HDR profile is
197 // selected by the GL_KHR_texture_compression_astc_hdr extension.
199 format.internal_format = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
200 format.is_compressed = true;
201 break;
203 format.internal_format = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
204 format.is_compressed = true;
205 break;
212 return std::nullopt;
213 }
214 return format;
215}
216
217} // namespace impeller
uint32_t uint32_t * format
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
#define GL_COMPRESSED_RGB8_ETC2
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
#define GL_COMPRESSED_RG_RGTC2
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
#define GL_COMPRESSED_RGBA8_ETC2_EAC
#define GL_COMPRESSED_SRGB8_ETC2
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR
#define GL_COMPRESSED_RGBA_BPTC_UNORM
#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
std::string DebugToFramebufferError(int status)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:99