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 constexpr std::optional<GLenum> ToVertexAttribType(ShaderType type) {
141  switch (type) {
143  return GL_BYTE;
145  return GL_UNSIGNED_BYTE;
147  return GL_SHORT;
149  return GL_UNSIGNED_SHORT;
150  case ShaderType::kFloat:
151  return GL_FLOAT;
153  case ShaderType::kVoid:
161  case ShaderType::kDouble:
162  case ShaderType::kStruct:
163  case ShaderType::kImage:
166  return std::nullopt;
167  }
168  FML_UNREACHABLE();
169 }
170 
171 constexpr GLenum ToTextureType(TextureType type) {
172  switch (type) {
174  return GL_TEXTURE_2D;
176  return GL_TEXTURE_2D_MULTISAMPLE;
178  return GL_TEXTURE_CUBE_MAP;
180  return GL_TEXTURE_EXTERNAL_OES;
181  }
182  FML_UNREACHABLE();
183 }
184 
185 constexpr std::optional<GLenum> ToTextureTarget(TextureType type) {
186  switch (type) {
188  return GL_TEXTURE_2D;
190  return GL_TEXTURE_2D;
192  return GL_TEXTURE_CUBE_MAP;
194  return GL_TEXTURE_EXTERNAL_OES;
195  }
196  FML_UNREACHABLE();
197 }
198 
199 std::string DebugToFramebufferError(int status);
200 
201 } // namespace impeller
202 
203 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_FORMATS_GLES_H_
GLenum type
@ kNone
Does not use the index buffer.
BlendFactor
Definition: formats.h:178
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:352
@ kPoint
Draws a point at each input vertex.
constexpr GLenum ToIndexType(IndexType type)
Definition: formats_gles.h:35
constexpr GLenum ToCompareFunction(CompareFunction func)
Definition: formats_gles.h:70
std::string DebugToFramebufferError(int status)
Definition: formats_gles.cc:9
CompareFunction
Definition: formats.h:552
@ 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:171
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:571
@ 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.
constexpr std::optional< GLenum > ToVertexAttribType(ShaderType type)
Definition: formats_gles.h:140
TextureType
Definition: formats.h:262
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:185
constexpr GLenum ToBlendFactor(BlendFactor factor)
Definition: formats_gles.h:92
BlendOperation
Definition: formats.h:196
constexpr GLenum ToBlendOperation(BlendOperation op)
Definition: formats_gles.h:128