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