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_
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:178
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:92
impeller::StencilOperation::kKeep
@ kKeep
Don't modify the current stencil value.
impeller::TextureType
TextureType
Definition: formats.h:262
impeller::ShaderType::kSignedInt64
@ kSignedInt64
impeller::StencilOperation::kIncrementClamp
@ kIncrementClamp
Increment the current stencil value by 1. Clamp it to the maximum.
impeller::ShaderType::kImage
@ kImage
formats.h
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:571
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:35
impeller::StencilOperation::kDecrementWrap
@ kDecrementWrap
Decrement the current stencil value by 1. If at zero, set to maximum.
impeller::CompareFunction
CompareFunction
Definition: formats.h:552
impeller::BlendFactor::kOneMinusDestinationColor
@ kOneMinusDestinationColor
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:352
impeller::ToCompareFunction
constexpr GLenum ToCompareFunction(CompareFunction func)
Definition: formats_gles.h:70
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:17
impeller::BlendOperation::kAdd
@ kAdd
impeller::ShaderType::kSampler
@ kSampler
impeller::BlendFactor::kBlendColor
@ kBlendColor
impeller::IndexType
IndexType
Definition: formats.h:343
type
GLenum type
Definition: blit_command_gles.cc:127
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:171
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:140
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:196
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:128
impeller::ToTextureTarget
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:185
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:48
shader_types.h
impeller::CompareFunction::kLess
@ kLess
Comparison test passes if new_value < current_value.
impeller
Definition: allocation.cc:12
impeller::BlendOperation::kSubtract
@ kSubtract
impeller::IndexType::kUnknown
@ kUnknown
impeller::PrimitiveType::kTriangleFan
@ kTriangleFan
impeller::DebugToFramebufferError
std::string DebugToFramebufferError(int status)
Definition: formats_gles.cc:9
impeller::BlendFactor::kOneMinusDestinationAlpha
@ kOneMinusDestinationAlpha