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