| Flutter Impeller |

proc_table_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 <functional>
8 #include <string>
9
10 #include "flutter/fml/logging.h"
11 #include "flutter/fml/macros.h"
12 #include "flutter/fml/mapping.h"
13 #include "impeller/renderer/backend/gles/capabilities_gles.h"
14 #include "impeller/renderer/backend/gles/description_gles.h"
15 #include "impeller/renderer/backend/gles/gles.h"
16
17 namespace impeller {
18
19 const char* GLErrorToString(GLenum value);
20
21 struct AutoErrorCheck {
22 const PFNGLGETERRORPROC error_fn;
23 const char* name;
24
25 AutoErrorCheck(PFNGLGETERRORPROC error, const char* name)
26 : error_fn(error), name(name) {}
27
28 ~AutoErrorCheck() {
29 if (error_fn) {
30 auto error = error_fn();
31 FML_CHECK(error == GL_NO_ERROR)
32 << "GL Error " << GLErrorToString(error) << "(" << error << ")"
33 << " encountered on call to " << name;
34 }
35 }
36 };
37
38 template <class T>
39 struct GLProc {
40 using GLFunctionType = T;
41
42 //----------------------------------------------------------------------------
43 /// The name of the GL function.
44 ///
45 const char* name = nullptr;
46
47 //----------------------------------------------------------------------------
48 /// The pointer to the GL function.
49 ///
50 GLFunctionType* function = nullptr;
51
52 //----------------------------------------------------------------------------
53 /// An optional error function. If present, all calls will be followed by an
54 /// error check.
55 ///
56 PFNGLGETERRORPROC error_fn = nullptr;
57
58 //----------------------------------------------------------------------------
59 /// @brief Call the GL function with the appropriate parameters. Lookup
60 /// the documentation for the GL function being called to
61 /// understand the arguments and return types. The arguments
62 /// types must match and will be type checked.
63 ///
64 template <class... Args>
65 auto operator()(Args&&... args) const {
66 #ifdef IMPELLER_ERROR_CHECK_ALL_GL_CALLS
67 AutoErrorCheck error(error_fn, name);
68 #endif // IMPELLER_ERROR_CHECK_ALL_GL_CALLS
69 #ifdef IMPELLER_TRACE_ALL_GL_CALLS
70 TRACE_EVENT0("impeller", name);
71 #endif // IMPELLER_TRACE_ALL_GL_CALLS
72 return function(std::forward<Args>(args)...);
73 }
74
75 constexpr bool IsAvailable() const { return function != nullptr; }
76
77 void Reset() {
78 name = nullptr;
79 function = nullptr;
80 error_fn = nullptr;
81 }
82 };
83
84 #define FOR_EACH_IMPELLER_PROC(PROC) \
85 PROC(ActiveTexture); \
86 PROC(AttachShader); \
87 PROC(BindAttribLocation); \
88 PROC(BindBuffer); \
89 PROC(BindFramebuffer); \
90 PROC(BindRenderbuffer); \
91 PROC(BindTexture); \
92 PROC(BlendEquationSeparate); \
93 PROC(BlendFuncSeparate); \
94 PROC(BufferData); \
95 PROC(CheckFramebufferStatus); \
96 PROC(Clear); \
97 PROC(ClearColor); \
98 PROC(ClearDepthf); \
99 PROC(ClearStencil); \
100 PROC(ColorMask); \
101 PROC(CompileShader); \
102 PROC(CreateProgram); \
103 PROC(CreateShader); \
104 PROC(CullFace); \
105 PROC(DeleteBuffers); \
106 PROC(DeleteFramebuffers); \
107 PROC(DeleteProgram); \
108 PROC(DeleteRenderbuffers); \
109 PROC(DeleteShader); \
110 PROC(DeleteTextures); \
111 PROC(DepthFunc); \
112 PROC(DepthMask); \
113 PROC(DepthRangef); \
114 PROC(DetachShader); \
115 PROC(Disable); \
116 PROC(DisableVertexAttribArray); \
117 PROC(DrawArrays); \
118 PROC(DrawElements); \
119 PROC(Enable); \
120 PROC(EnableVertexAttribArray); \
121 PROC(Flush); \
122 PROC(FramebufferRenderbuffer); \
123 PROC(FramebufferTexture2D); \
124 PROC(FrontFace); \
125 PROC(GenBuffers); \
126 PROC(GenerateMipmap); \
127 PROC(GenFramebuffers); \
128 PROC(GenRenderbuffers); \
129 PROC(GenTextures); \
130 PROC(GetActiveUniform); \
131 PROC(GetBooleanv); \
132 PROC(GetFloatv); \
133 PROC(GetFramebufferAttachmentParameteriv); \
134 PROC(GetIntegerv); \
135 PROC(GetProgramInfoLog); \
136 PROC(GetProgramiv); \
137 PROC(GetShaderInfoLog); \
138 PROC(GetShaderiv); \
139 PROC(GetString); \
140 PROC(GetStringi); \
141 PROC(GetUniformLocation); \
142 PROC(IsBuffer); \
143 PROC(IsFramebuffer); \
144 PROC(IsProgram); \
145 PROC(IsRenderbuffer); \
146 PROC(IsShader); \
147 PROC(IsTexture); \
148 PROC(LinkProgram); \
149 PROC(RenderbufferStorage); \
150 PROC(Scissor); \
151 PROC(ShaderBinary); \
152 PROC(ShaderSource); \
153 PROC(StencilFuncSeparate); \
154 PROC(StencilMaskSeparate); \
155 PROC(StencilOpSeparate); \
156 PROC(TexImage2D); \
157 PROC(TexParameteri); \
158 PROC(Uniform1fv); \
159 PROC(Uniform1i); \
160 PROC(Uniform2fv); \
161 PROC(Uniform3fv); \
162 PROC(Uniform4fv); \
163 PROC(UniformMatrix4fv); \
164 PROC(UseProgram); \
165 PROC(VertexAttribPointer); \
166 PROC(Viewport); \
167 PROC(ReadPixels);
168
169 #define FOR_EACH_IMPELLER_GLES3_PROC(PROC) PROC(BlitFramebuffer);
170
171 #define FOR_EACH_IMPELLER_EXT_PROC(PROC) \
172 PROC(DiscardFramebufferEXT); \
173 PROC(FramebufferTexture2DMultisampleEXT) \
174 PROC(PushDebugGroupKHR); \
175 PROC(PopDebugGroupKHR); \
176 PROC(ObjectLabelKHR); \
177 PROC(RenderbufferStorageMultisampleEXT);
178
179 enum class DebugResourceType {
180 kTexture,
181 kBuffer,
182 kProgram,
183 kShader,
184 kRenderBuffer,
185 kFrameBuffer,
186 };
187
188 class ProcTableGLES {
189 public:
190 using Resolver = std::function<void*(const char* function_name)>;
191 explicit ProcTableGLES(Resolver resolver);
192
193 ~ProcTableGLES();
194
195 #define IMPELLER_PROC(name) \
196 GLProc<decltype(gl##name)> name = {"gl" #name, nullptr};
197
198 FOR_EACH_IMPELLER_PROC(IMPELLER_PROC);
199 FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC);
200 FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC);
201
202 #undef IMPELLER_PROC
203
204 bool IsValid() const;
205
206 void ShaderSourceMapping(GLuint shader, const fml::Mapping& mapping) const;
207
208 const DescriptionGLES* GetDescription() const;
209
210 const CapabilitiesGLES* GetCapabilities() const;
211
212 std::string DescribeCurrentFramebuffer() const;
213
214 std::string GetProgramInfoLogString(GLuint program) const;
215
216 bool IsCurrentFramebufferComplete() const;
217
218 bool SetDebugLabel(DebugResourceType type,
219 GLint name,
220 const std::string& label) const;
221
222 void PushDebugGroup(const std::string& string) const;
223
224 void PopDebugGroup() const;
225
226 private:
227 bool is_valid_ = false;
228 std::unique_ptr<DescriptionGLES> description_;
229 std::unique_ptr<CapabilitiesGLES> capabilities_;
230 GLint debug_label_max_length_ = 0;
231
232 FML_DISALLOW_COPY_AND_ASSIGN(ProcTableGLES);
233 };
234
235 } // namespace impeller
impeller::ProcTableGLES::FOR_EACH_IMPELLER_PROC
FOR_EACH_IMPELLER_PROC(IMPELLER_PROC)
impeller::ProcTableGLES::ProcTableGLES
ProcTableGLES(Resolver resolver)
Definition: proc_table_gles.cc:57
IMPELLER_PROC
#define IMPELLER_PROC(name)
Definition: proc_table_gles.h:195
impeller::ProcTableGLES::FOR_EACH_IMPELLER_GLES3_PROC
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC)
impeller::ProcTableGLES::PushDebugGroup
void PushDebugGroup(const std::string &string) const
Definition: proc_table_gles.cc:307
impeller::AutoErrorCheck::AutoErrorCheck
AutoErrorCheck(PFNGLGETERRORPROC error, const char *name)
Definition: proc_table_gles.h:25
impeller::AutoErrorCheck::name
const char * name
Definition: proc_table_gles.h:23
impeller::GLProc::IsAvailable
constexpr bool IsAvailable() const
Definition: proc_table_gles.h:75
impeller::DebugResourceType::kBuffer
@ kBuffer
impeller::ProcTableGLES::SetDebugLabel
bool SetDebugLabel(DebugResourceType type, GLint name, const std::string &label) const
Definition: proc_table_gles.cc:281
impeller::ProcTableGLES::IsValid
bool IsValid() const
Definition: proc_table_gles.cc:121
impeller::DebugResourceType::kProgram
@ kProgram
impeller::ProcTableGLES::FOR_EACH_IMPELLER_EXT_PROC
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC)
impeller::AutoErrorCheck
Definition: proc_table_gles.h:21
impeller::GLProc
Definition: proc_table_gles.h:39
impeller::ProcTableGLES::Resolver
std::function< void *(const char *function_name)> Resolver
Definition: proc_table_gles.h:190
impeller::DebugResourceType::kTexture
@ kTexture
impeller::ProcTableGLES
Definition: proc_table_gles.h:188
impeller::GLProc::error_fn
PFNGLGETERRORPROC error_fn
Definition: proc_table_gles.h:56
impeller::ProcTableGLES::GetProgramInfoLogString
std::string GetProgramInfoLogString(GLuint program) const
Definition: proc_table_gles.cc:328
impeller::DebugResourceType::kShader
@ kShader
impeller::DebugResourceType::kRenderBuffer
@ kRenderBuffer
gles.h
description_gles.h
impeller::ProcTableGLES::DescribeCurrentFramebuffer
std::string DescribeCurrentFramebuffer() const
Definition: proc_table_gles.cc:201
impeller::GLProc::GLFunctionType
T GLFunctionType
Definition: proc_table_gles.h:40
impeller::DebugResourceType
DebugResourceType
Definition: proc_table_gles.h:179
impeller::GLProc::operator()
auto operator()(Args &&... args) const
Call the GL function with the appropriate parameters. Lookup the documentation for the GL function be...
Definition: proc_table_gles.h:65
impeller::ProcTableGLES::IsCurrentFramebufferComplete
bool IsCurrentFramebufferComplete() const
Definition: proc_table_gles.cc:232
impeller::DebugResourceType::kFrameBuffer
@ kFrameBuffer
impeller::GLErrorToString
const char * GLErrorToString(GLenum value)
Definition: proc_table_gles.cc:15
impeller::AutoErrorCheck::~AutoErrorCheck
~AutoErrorCheck()
Definition: proc_table_gles.h:28
impeller::AutoErrorCheck::error_fn
const PFNGLGETERRORPROC error_fn
Definition: proc_table_gles.h:22
capabilities_gles.h
impeller::ProcTableGLES::GetCapabilities
const CapabilitiesGLES * GetCapabilities() const
Definition: proc_table_gles.cc:137
impeller::ProcTableGLES::ShaderSourceMapping
void ShaderSourceMapping(GLuint shader, const fml::Mapping &mapping) const
Definition: proc_table_gles.cc:125
impeller
Definition: aiks_context.cc:10
impeller::GLProc::name
const char * name
Definition: proc_table_gles.h:45
impeller::ProcTableGLES::PopDebugGroup
void PopDebugGroup() const
Definition: proc_table_gles.cc:321
impeller::GLProc::Reset
void Reset()
Definition: proc_table_gles.h:77
impeller::ProcTableGLES::GetDescription
const DescriptionGLES * GetDescription() const
Definition: proc_table_gles.cc:133
impeller::ProcTableGLES::~ProcTableGLES
~ProcTableGLES()