Flutter Impeller
formats_gles.h
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 
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_FORMATS_GLES_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_FORMATS_GLES_H_
7 
8 #include <optional>
9 
10 #include "flutter/fml/logging.h"
11 #include "impeller/core/formats.h"
14 
15 namespace impeller {
16 
17 constexpr GLenum ToMode(PrimitiveType primitive_type) {
18  switch (primitive_type) {
20  return GL_TRIANGLES;
22  return GL_TRIANGLE_STRIP;
24  return GL_LINES;
26  return GL_LINE_STRIP;
28  return GL_POINTS;
30  return GL_TRIANGLE_FAN;
31  }
32  FML_UNREACHABLE();
33 }
34 
35 constexpr GLenum ToIndexType(IndexType type) {
36  switch (type) {
38  case IndexType::kNone:
39  FML_UNREACHABLE();
40  case IndexType::k16bit:
41  return GL_UNSIGNED_SHORT;
42  case IndexType::k32bit:
43  return GL_UNSIGNED_INT;
44  }
45  FML_UNREACHABLE();
46 }
47 
48 constexpr GLenum ToStencilOp(StencilOperation op) {
49  switch (op) {
51  return GL_KEEP;
53  return GL_ZERO;
55  return GL_REPLACE;
57  return GL_INCR;
59  return GL_DECR;
61  return GL_INVERT;
63  return GL_INCR_WRAP;
65  return GL_DECR_WRAP;
66  }
67  FML_UNREACHABLE();
68 }
69 
70 constexpr GLenum ToCompareFunction(CompareFunction func) {
71  switch (func) {
73  return GL_NEVER;
75  return GL_ALWAYS;
77  return GL_LESS;
79  return GL_EQUAL;
81  return GL_LEQUAL;
83  return GL_GREATER;
85  return GL_NOTEQUAL;
87  return GL_GEQUAL;
88  }
89  FML_UNREACHABLE();
90 }
91 
92 constexpr GLenum ToBlendFactor(BlendFactor factor) {
93  switch (factor) {
94  case BlendFactor::kZero:
95  return GL_ZERO;
96  case BlendFactor::kOne:
97  return GL_ONE;
99  return GL_SRC_COLOR;
101  return GL_ONE_MINUS_SRC_COLOR;
103  return GL_SRC_ALPHA;
105  return GL_ONE_MINUS_SRC_ALPHA;
107  return GL_DST_COLOR;
109  return GL_ONE_MINUS_DST_COLOR;
111  return GL_DST_ALPHA;
113  return GL_ONE_MINUS_DST_ALPHA;
115  return GL_SRC_ALPHA_SATURATE;
117  return GL_CONSTANT_COLOR;
119  return GL_ONE_MINUS_CONSTANT_COLOR;
121  return GL_CONSTANT_ALPHA;
123  return GL_ONE_MINUS_CONSTANT_ALPHA;
124  }
125  FML_UNREACHABLE();
126 }
127 
128 constexpr GLenum ToBlendOperation(BlendOperation op) {
129  switch (op) {
131  return GL_FUNC_ADD;
133  return GL_FUNC_SUBTRACT;
135  return GL_FUNC_REVERSE_SUBTRACT;
136  }
137  FML_UNREACHABLE();
138 }
139 
140 /// Returns the GL scalar type for a vertex attribute, or `std::nullopt` when
141 /// the format cannot be consumed as a vertex attribute on this backend. The
142 /// component count is supplied separately to `glVertexAttribPointer`, so only
143 /// the scalar kind matters here. Half-float and 32-bit integer attributes are
144 /// not available on the GLES 2.0 floor.
145 constexpr std::optional<GLenum> ToVertexAttribType(VertexAttributeFormat type) {
146  switch (type) {
151  return GL_BYTE;
156  return GL_UNSIGNED_BYTE;
161  return GL_SHORT;
166  return GL_UNSIGNED_SHORT;
171  return GL_FLOAT;
185  return std::nullopt;
186  }
187  FML_UNREACHABLE();
188 }
189 
190 constexpr GLenum ToTextureType(TextureType type) {
191  switch (type) {
193  return GL_TEXTURE_2D;
195  return GL_TEXTURE_2D_MULTISAMPLE;
197  return GL_TEXTURE_CUBE_MAP;
199  return GL_TEXTURE_EXTERNAL_OES;
200  }
201  FML_UNREACHABLE();
202 }
203 
204 constexpr std::optional<GLenum> ToTextureTarget(TextureType type) {
205  switch (type) {
207  return GL_TEXTURE_2D;
209  return GL_TEXTURE_2D;
211  return GL_TEXTURE_CUBE_MAP;
213  return GL_TEXTURE_EXTERNAL_OES;
214  }
215  FML_UNREACHABLE();
216 }
217 
219  GLint internal_format = 0;
220  GLenum external_format = GL_NONE;
221  GLenum type = GL_NONE;
222  // When true, the data must be uploaded with glCompressedTexImage2D and only
223  // `internal_format` is meaningful.
224  bool is_compressed = false;
225 };
226 
227 std::optional<PixelFormatGLES> ToPixelFormatGLES(PixelFormat format,
228  bool supports_bgra);
229 
230 std::string DebugToFramebufferError(int status);
231 
232 } // namespace impeller
233 
234 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_FORMATS_GLES_H_
BlendFactor
Definition: formats.h:366
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:529
@ kPoint
Draws a point at each input vertex.
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
Definition: formats_gles.cc:76
@ kNone
Does not use the index buffer.
constexpr GLenum ToIndexType(IndexType type)
Definition: formats_gles.h:35
constexpr std::optional< GLenum > ToVertexAttribType(VertexAttributeFormat type)
Definition: formats_gles.h:145
constexpr GLenum ToCompareFunction(CompareFunction func)
Definition: formats_gles.h:70
std::string DebugToFramebufferError(int status)
Definition: formats_gles.cc:59
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
VertexAttributeFormat
The format of a single vertex attribute, combining its scalar kind, bit width, and component count.
Definition: shader_types.h:175
CompareFunction
Definition: formats.h:804
@ kEqual
Comparison test passes if new_value == current_value.
@ kLessEqual
Comparison test passes if new_value <= current_value.
@ kGreaterEqual
Comparison test passes if new_value >= current_value.
@ kAlways
Comparison test passes always passes.
@ kLess
Comparison test passes if new_value < current_value.
@ kGreater
Comparison test passes if new_value > current_value.
@ kNotEqual
Comparison test passes if new_value != current_value.
@ kNever
Comparison test never passes.
constexpr GLenum ToTextureType(TextureType type)
Definition: formats_gles.h:190
constexpr GLenum ToStencilOp(StencilOperation op)
Definition: formats_gles.h:48
constexpr GLenum ToMode(PrimitiveType primitive_type)
Definition: formats_gles.h:17
StencilOperation
Definition: formats.h:823
@ kDecrementWrap
Decrement the current stencil value by 1. If at zero, set to maximum.
@ kSetToReferenceValue
Reset the stencil value to the reference value.
@ kDecrementClamp
Decrement the current stencil value by 1. Clamp it to zero.
@ kZero
Reset the stencil value to zero.
@ kIncrementClamp
Increment the current stencil value by 1. Clamp it to the maximum.
@ kIncrementWrap
Increment the current stencil value by 1. If at maximum, set to zero.
@ kInvert
Perform a logical bitwise invert on the current stencil value.
@ kKeep
Don't modify the current stencil value.
TextureType
Definition: formats.h:450
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:204
constexpr GLenum ToBlendFactor(BlendFactor factor)
Definition: formats_gles.h:92
BlendOperation
Definition: formats.h:384
constexpr GLenum ToBlendOperation(BlendOperation op)
Definition: formats_gles.h:128