Flutter Engine
The Flutter Engine
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"
14
15namespace impeller {
16
17constexpr 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;
29 }
31}
32
33constexpr GLenum ToIndexType(IndexType type) {
34 switch (type) {
39 return GL_UNSIGNED_SHORT;
41 return GL_UNSIGNED_INT;
42 }
44}
45
46constexpr GLenum ToStencilOp(StencilOperation op) {
47 switch (op) {
49 return GL_KEEP;
51 return GL_ZERO;
53 return GL_REPLACE;
55 return GL_INCR;
57 return GL_DECR;
59 return GL_INVERT;
61 return GL_INCR_WRAP;
63 return GL_DECR_WRAP;
64 }
66}
67
68constexpr GLenum ToCompareFunction(CompareFunction func) {
69 switch (func) {
71 return GL_NEVER;
73 return GL_ALWAYS;
75 return GL_LESS;
77 return GL_EQUAL;
79 return GL_LEQUAL;
81 return GL_GREATER;
83 return GL_NOTEQUAL;
85 return GL_GEQUAL;
86 }
88}
89
90constexpr GLenum ToBlendFactor(BlendFactor factor) {
91 switch (factor) {
93 return GL_ZERO;
95 return GL_ONE;
97 return GL_SRC_COLOR;
99 return GL_ONE_MINUS_SRC_COLOR;
101 return GL_SRC_ALPHA;
103 return GL_ONE_MINUS_SRC_ALPHA;
105 return GL_DST_COLOR;
107 return GL_ONE_MINUS_DST_COLOR;
109 return GL_DST_ALPHA;
111 return GL_ONE_MINUS_DST_ALPHA;
113 return GL_SRC_ALPHA_SATURATE;
115 return GL_CONSTANT_COLOR;
117 return GL_ONE_MINUS_CONSTANT_COLOR;
119 return GL_CONSTANT_ALPHA;
121 return GL_ONE_MINUS_CONSTANT_ALPHA;
122 }
124}
125
126constexpr GLenum ToBlendOperation(BlendOperation op) {
127 switch (op) {
129 return GL_FUNC_ADD;
131 return GL_FUNC_SUBTRACT;
133 return GL_FUNC_REVERSE_SUBTRACT;
134 }
136}
137
138constexpr std::optional<GLenum> ToVertexAttribType(ShaderType type) {
139 switch (type) {
141 return GL_BYTE;
143 return GL_UNSIGNED_BYTE;
145 return GL_SHORT;
147 return GL_UNSIGNED_SHORT;
149 return GL_FLOAT;
164 return std::nullopt;
165 }
167}
168
169constexpr GLenum ToTextureType(TextureType type) {
170 switch (type) {
172 return GL_TEXTURE_2D;
174 return GL_TEXTURE_2D_MULTISAMPLE;
176 return GL_TEXTURE_CUBE_MAP;
178 return GL_TEXTURE_EXTERNAL_OES;
179 }
181}
182
183constexpr std::optional<GLenum> ToTextureTarget(TextureType type) {
184 switch (type) {
186 return GL_TEXTURE_2D;
188 return GL_TEXTURE_2D;
190 return GL_TEXTURE_CUBE_MAP;
192 return GL_TEXTURE_EXTERNAL_OES;
193 }
195}
196
197std::string DebugToFramebufferError(int status);
198
199} // namespace impeller
200
201#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_FORMATS_GLES_H_
GLenum type
#define FML_UNREACHABLE()
Definition: logging.h:109
@ 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 std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:183
constexpr GLenum ToIndexType(IndexType type)
Definition: formats_gles.h:33
constexpr GLenum ToCompareFunction(CompareFunction func)
Definition: formats_gles.h:68
std::string DebugToFramebufferError(int status)
Definition: formats_gles.cc:9
CompareFunction
Definition: formats.h:546
@ 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:169
constexpr GLenum ToStencilOp(StencilOperation op)
Definition: formats_gles.h:46
constexpr GLenum ToMode(PrimitiveType primitive_type)
Definition: formats_gles.h:17
StencilOperation
Definition: formats.h:565
@ 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.
TextureType
Definition: formats.h:262
constexpr std::optional< GLenum > ToVertexAttribType(ShaderType type)
Definition: formats_gles.h:138
constexpr GLenum ToBlendFactor(BlendFactor factor)
Definition: formats_gles.h:90
BlendOperation
Definition: formats.h:196
constexpr GLenum ToBlendOperation(BlendOperation op)
Definition: formats_gles.h:126