Flutter Impeller
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 namespace impeller {
8 
9 std::string DebugToFramebufferError(int status) {
10  switch (status) {
11  case GL_FRAMEBUFFER_UNDEFINED:
12  return "GL_FRAMEBUFFER_UNDEFINED";
13  case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
14  return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
15  case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
16  return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
17  case GL_FRAMEBUFFER_UNSUPPORTED:
18  return "GL_FRAMEBUFFER_UNSUPPORTED";
19  case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
20  return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
21  default:
22  return "Unknown error code: " + std::to_string(status);
23  }
24 }
25 
26 std::optional<PixelFormatGLES> ToPixelFormatGLES(PixelFormat pixel_format,
27  bool supports_bgra) {
28  PixelFormatGLES format;
29 
30  switch (pixel_format) {
32  format.internal_format = GL_ALPHA;
33  format.external_format = GL_ALPHA;
34  format.type = GL_UNSIGNED_BYTE;
35  break;
37  format.internal_format = GL_RED;
38  format.external_format = GL_RED;
39  format.type = GL_UNSIGNED_BYTE;
40  break;
43  format.internal_format = GL_RGBA;
44  format.external_format = GL_RGBA;
45  format.type = GL_UNSIGNED_BYTE;
46  break;
49  if (supports_bgra) {
50  format.internal_format = GL_BGRA_EXT;
51  format.external_format = GL_BGRA_EXT;
52  } else {
53  format.internal_format = GL_RGBA;
54  format.external_format = GL_RGBA;
55  }
56  format.type = GL_UNSIGNED_BYTE;
57  break;
59  format.internal_format = GL_RGBA32F;
60  format.external_format = GL_RGBA;
61  format.type = GL_FLOAT;
62  break;
64  format.internal_format = GL_R32F;
65  format.external_format = GL_RED;
66  format.type = GL_FLOAT;
67  break;
69  format.internal_format = GL_RGBA16F;
70  format.external_format = GL_RGBA;
71  format.type = GL_HALF_FLOAT;
72  break;
74  // Pure stencil textures are only available in OpenGL 4.4+, which is
75  // ~0% of mobile devices. Instead, we use a depth-stencil texture and
76  // only use the stencil component.
77  //
78  // https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml
80  format.internal_format = GL_DEPTH_STENCIL;
81  format.external_format = GL_DEPTH_STENCIL;
82  format.type = GL_UNSIGNED_INT_24_8;
83  break;
90  return std::nullopt;
91  }
92  return format;
93 }
94 
95 } // namespace impeller
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
Definition: formats_gles.cc:26
std::string DebugToFramebufferError(int status)
Definition: formats_gles.cc:9
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99