| 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 "flutter/fml/macros.h"
12 #include "impeller/core/formats.h"
13 #include "impeller/core/shader_types.h"
14 #include "impeller/renderer/backend/gles/gles.h"
15
16 namespace impeller {
17
18 constexpr GLenum ToMode(PrimitiveType primitive_type) {
19 switch (primitive_type) {
20 case PrimitiveType::kTriangle:
21 return GL_TRIANGLES;
22 case PrimitiveType::kTriangleStrip:
23 return GL_TRIANGLE_STRIP;
24 case PrimitiveType::kLine:
25 return GL_LINES;
26 case PrimitiveType::kLineStrip:
27 return GL_LINE_STRIP;
28 case PrimitiveType::kPoint:
29 return GL_POINTS;
30 }
31 FML_UNREACHABLE();
32 }
33
34 constexpr GLenum ToIndexType(IndexType type) {
35 switch (type) {
36 case IndexType::kUnknown:
37 case IndexType::kNone:
38 FML_UNREACHABLE();
39 case IndexType::k16bit:
40 return GL_UNSIGNED_SHORT;
41 case IndexType::k32bit:
42 return GL_UNSIGNED_INT;
43 }
44 FML_UNREACHABLE();
45 }
46
47 constexpr GLenum ToStencilOp(StencilOperation op) {
48 switch (op) {
49 case StencilOperation::kKeep:
50 return GL_KEEP;
51 case StencilOperation::kZero:
52 return GL_ZERO;
53 case StencilOperation::kSetToReferenceValue:
54 return GL_REPLACE;
55 case StencilOperation::kIncrementClamp:
56 return GL_INCR;
57 case StencilOperation::kDecrementClamp:
58 return GL_DECR;
59 case StencilOperation::kInvert:
60 return GL_INVERT;
61 case StencilOperation::kIncrementWrap:
62 return GL_INCR_WRAP;
63 case StencilOperation::kDecrementWrap:
64 return GL_DECR_WRAP;
65 }
66 FML_UNREACHABLE();
67 }
68
69 constexpr GLenum ToCompareFunction(CompareFunction func) {
70 switch (func) {
71 case CompareFunction::kNever:
72 return GL_NEVER;
73 case CompareFunction::kAlways:
74 return GL_ALWAYS;
75 case CompareFunction::kLess:
76 return GL_LESS;
77 case CompareFunction::kEqual:
78 return GL_EQUAL;
79 case CompareFunction::kLessEqual:
80 return GL_LEQUAL;
81 case CompareFunction::kGreater:
82 return GL_GREATER;
83 case CompareFunction::kNotEqual:
84 return GL_NOTEQUAL;
85 case CompareFunction::kGreaterEqual:
86 return GL_GEQUAL;
87 }
88 FML_UNREACHABLE();
89 }
90
91 constexpr GLenum ToBlendFactor(BlendFactor factor) {
92 switch (factor) {
93 case BlendFactor::kZero:
94 return GL_ZERO;
95 case BlendFactor::kOne:
96 return GL_ONE;
97 case BlendFactor::kSourceColor:
98 return GL_SRC_COLOR;
99 case BlendFactor::kOneMinusSourceColor:
100 return GL_ONE_MINUS_SRC_COLOR;
101 case BlendFactor::kSourceAlpha:
102 return GL_SRC_ALPHA;
103 case BlendFactor::kOneMinusSourceAlpha:
104 return GL_ONE_MINUS_SRC_ALPHA;
105 case BlendFactor::kDestinationColor:
106 return GL_DST_COLOR;
107 case BlendFactor::kOneMinusDestinationColor:
108 return GL_ONE_MINUS_DST_COLOR;
109 case BlendFactor::kDestinationAlpha:
110 return GL_DST_ALPHA;
111 case BlendFactor::kOneMinusDestinationAlpha:
112 return GL_ONE_MINUS_DST_ALPHA;
113 case BlendFactor::kSourceAlphaSaturated:
114 return GL_SRC_ALPHA_SATURATE;
115 case BlendFactor::kBlendColor:
116 return GL_CONSTANT_COLOR;
117 case BlendFactor::kOneMinusBlendColor:
118 return GL_ONE_MINUS_CONSTANT_COLOR;
119 case BlendFactor::kBlendAlpha:
120 return GL_CONSTANT_ALPHA;
121 case BlendFactor::kOneMinusBlendAlpha:
122 return GL_ONE_MINUS_CONSTANT_ALPHA;
123 }
124 FML_UNREACHABLE();
125 }
126
127 constexpr GLenum ToBlendOperation(BlendOperation op) {
128 switch (op) {
129 case BlendOperation::kAdd:
130 return GL_FUNC_ADD;
131 case BlendOperation::kSubtract:
132 return GL_FUNC_SUBTRACT;
133 case BlendOperation::kReverseSubtract:
134 return GL_FUNC_REVERSE_SUBTRACT;
135 }
136 FML_UNREACHABLE();
137 }
138
139 constexpr std::optional<GLenum> ToVertexAttribType(ShaderType type) {
140 switch (type) {
141 case ShaderType::kSignedByte:
142 return GL_BYTE;
143 case ShaderType::kUnsignedByte:
144 return GL_UNSIGNED_BYTE;
145 case ShaderType::kSignedShort:
146 return GL_SHORT;
147 case ShaderType::kUnsignedShort:
148 return GL_UNSIGNED_SHORT;
149 case ShaderType::kFloat:
150 return GL_FLOAT;
151 case ShaderType::kUnknown:
152 case ShaderType::kVoid:
153 case ShaderType::kBoolean:
154 case ShaderType::kSignedInt:
155 case ShaderType::kUnsignedInt:
156 case ShaderType::kSignedInt64:
157 case ShaderType::kUnsignedInt64:
158 case ShaderType::kAtomicCounter:
159 case ShaderType::kHalfFloat:
160 case ShaderType::kDouble:
161 case ShaderType::kStruct:
162 case ShaderType::kImage:
163 case ShaderType::kSampledImage:
164 case ShaderType::kSampler:
165 return std::nullopt;
166 }
167 FML_UNREACHABLE();
168 }
169
170 constexpr GLenum ToTextureType(TextureType type) {
171 switch (type) {
172 case TextureType::kTexture2D:
173 return GL_TEXTURE_2D;
174 case TextureType::kTexture2DMultisample:
175 return GL_TEXTURE_2D_MULTISAMPLE;
176 case TextureType::kTextureCube:
177 return GL_TEXTURE_CUBE_MAP;
178 case TextureType::kTextureExternalOES:
179 return GL_TEXTURE_EXTERNAL_OES;
180 }
181 FML_UNREACHABLE();
182 }
183
184 constexpr std::optional<GLenum> ToTextureTarget(TextureType type) {
185 switch (type) {
186 case TextureType::kTexture2D:
187 return GL_TEXTURE_2D;
188 case TextureType::kTexture2DMultisample:
189 return GL_TEXTURE_2D;
190 case TextureType::kTextureCube:
191 return GL_TEXTURE_CUBE_MAP;
192 case TextureType::kTextureExternalOES:
193 return GL_TEXTURE_EXTERNAL_OES;
194 }
195 FML_UNREACHABLE();
196 }
197
198 std::string DebugToFramebufferError(int status);
199
200 } // namespace impeller
201
202 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_FORMATS_GLES_H_
impeller::TextureType::kTextureExternalOES
@ kTextureExternalOES
impeller::CompareFunction::kGreater
@ kGreater
Comparison test passes if new_value > current_value.
impeller::PrimitiveType::kLineStrip
@ kLineStrip
impeller::StencilOperation::kDecrementClamp
@ kDecrementClamp
Decrement the current stencil value by 1. Clamp it to zero.
impeller::ShaderType::kAtomicCounter
@ kAtomicCounter
impeller::IndexType::k16bit
@ k16bit
impeller::ShaderType::kDouble
@ kDouble
impeller::ShaderType
ShaderType
Definition: shader_types.h:41
impeller::BlendFactor::kSourceAlphaSaturated
@ kSourceAlphaSaturated
impeller::BlendFactor
BlendFactor
Definition: formats.h:179
impeller::CompareFunction::kEqual
@ kEqual
Comparison test passes if new_value == current_value.
impeller::BlendFactor::kOneMinusSourceAlpha
@ kOneMinusSourceAlpha
impeller::CompareFunction::kGreaterEqual
@ kGreaterEqual
Comparison test passes if new_value >= current_value.
impeller::ToBlendFactor
constexpr GLenum ToBlendFactor(BlendFactor factor)
Definition: formats_gles.h:91
impeller::StencilOperation::kKeep
@ kKeep
Don't modify the current stencil value.
impeller::TextureType
TextureType
Definition: formats.h:263
impeller::ShaderType::kSignedInt64
@ kSignedInt64
formats.h
impeller::StencilOperation::kIncrementClamp
@ kIncrementClamp
Increment the current stencil value by 1. Clamp it to the maximum.
impeller::ShaderType::kImage
@ kImage
impeller::ShaderType::kVoid
@ kVoid
impeller::StencilOperation::kInvert
@ kInvert
Perform a logical bitwise invert on the current stencil value.
impeller::BlendFactor::kDestinationAlpha
@ kDestinationAlpha
impeller::ShaderType::kSignedByte
@ kSignedByte
impeller::IndexType::k32bit
@ k32bit
impeller::ShaderType::kUnsignedShort
@ kUnsignedShort
impeller::StencilOperation
StencilOperation
Definition: formats.h:553
impeller::StencilOperation::kSetToReferenceValue
@ kSetToReferenceValue
Reset the stencil value to the reference value.
impeller::BlendFactor::kSourceColor
@ kSourceColor
impeller::ShaderType::kUnsignedInt64
@ kUnsignedInt64
impeller::PrimitiveType::kLine
@ kLine
impeller::BlendFactor::kDestinationColor
@ kDestinationColor
impeller::ShaderType::kUnsignedByte
@ kUnsignedByte
impeller::ShaderType::kFloat
@ kFloat
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::BlendFactor::kZero
@ kZero
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::ToIndexType
constexpr GLenum ToIndexType(IndexType type)
Definition: formats_gles.h:34
impeller::StencilOperation::kDecrementWrap
@ kDecrementWrap
Decrement the current stencil value by 1. If at zero, set to maximum.
impeller::CompareFunction
CompareFunction
Definition: formats.h:534
impeller::BlendFactor::kOneMinusDestinationColor
@ kOneMinusDestinationColor
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:353
impeller::ToCompareFunction
constexpr GLenum ToCompareFunction(CompareFunction func)
Definition: formats_gles.h:69
impeller::BlendOperation::kReverseSubtract
@ kReverseSubtract
impeller::ShaderType::kBoolean
@ kBoolean
impeller::BlendFactor::kBlendAlpha
@ kBlendAlpha
impeller::PrimitiveType::kPoint
@ kPoint
Draws a point at each input vertex.
impeller::ToMode
constexpr GLenum ToMode(PrimitiveType primitive_type)
Definition: formats_gles.h:18
impeller::BlendOperation::kAdd
@ kAdd
impeller::ShaderType::kSampler
@ kSampler
impeller::BlendFactor::kBlendColor
@ kBlendColor
impeller::IndexType
IndexType
Definition: formats.h:344
impeller::BlendFactor::kOneMinusBlendColor
@ kOneMinusBlendColor
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::ShaderType::kSampledImage
@ kSampledImage
impeller::StencilOperation::kIncrementWrap
@ kIncrementWrap
Increment the current stencil value by 1. If at maximum, set to zero.
impeller::TextureType::kTextureCube
@ kTextureCube
impeller::ToTextureType
constexpr GLenum ToTextureType(TextureType type)
Definition: formats_gles.h:170
impeller::CompareFunction::kLessEqual
@ kLessEqual
Comparison test passes if new_value <= current_value.
impeller::BlendFactor::kOne
@ kOne
impeller::BlendFactor::kOneMinusBlendAlpha
@ kOneMinusBlendAlpha
impeller::CompareFunction::kAlways
@ kAlways
Comparison test passes always passes.
impeller::ToVertexAttribType
constexpr std::optional< GLenum > ToVertexAttribType(ShaderType type)
Definition: formats_gles.h:139
gles.h
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::StencilOperation::kZero
@ kZero
Reset the stencil value to zero.
impeller::ShaderType::kUnsignedInt
@ kUnsignedInt
impeller::CompareFunction::kNever
@ kNever
Comparison test never passes.
impeller::ShaderType::kStruct
@ kStruct
impeller::BlendOperation
BlendOperation
Definition: formats.h:197
impeller::ShaderType::kSignedShort
@ kSignedShort
impeller::ShaderType::kHalfFloat
@ kHalfFloat
impeller::ShaderType::kSignedInt
@ kSignedInt
impeller::BlendFactor::kOneMinusSourceColor
@ kOneMinusSourceColor
impeller::ToBlendOperation
constexpr GLenum ToBlendOperation(BlendOperation op)
Definition: formats_gles.h:127
impeller::ToTextureTarget
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:184
impeller::ShaderType::kUnknown
@ kUnknown
impeller::CompareFunction::kNotEqual
@ kNotEqual
Comparison test passes if new_value != current_value.
impeller::BlendFactor::kSourceAlpha
@ kSourceAlpha
impeller::ToStencilOp
constexpr GLenum ToStencilOp(StencilOperation op)
Definition: formats_gles.h:47
shader_types.h
impeller::CompareFunction::kLess
@ kLess
Comparison test passes if new_value < current_value.
impeller
Definition: aiks_blur_unittests.cc:20
impeller::BlendOperation::kSubtract
@ kSubtract
impeller::IndexType::kUnknown
@ kUnknown
impeller::DebugToFramebufferError
std::string DebugToFramebufferError(int status)
Definition: formats_gles.cc:9
impeller::BlendFactor::kOneMinusDestinationAlpha
@ kOneMinusDestinationAlpha