| Flutter Impeller |

Public Types | Public Member Functions | List of all members
impeller::ProcTableGLES Class Reference

`#include <proc_table_gles.h>`

## Public Types
using | Resolver = std::function< void *(const char *function_name)>

## Public Member Functions
| ProcTableGLES (Resolver resolver)
| ProcTableGLES (ProcTableGLES &&other)=default
| ~ProcTableGLES ()
| FOR_EACH_IMPELLER_PROC (IMPELLER_PROC)
| FOR_EACH_IMPELLER_GLES3_PROC (IMPELLER_PROC)
| FOR_EACH_IMPELLER_EXT_PROC (IMPELLER_PROC)
bool | IsValid () const
void | ShaderSourceMapping (GLuint shader, const fml::Mapping &mapping, const std::vector< Scalar > &defines={}) const
| Set the source for the attached [shader]. More...
const DescriptionGLES * | GetDescription () const
const std::shared_ptr< const CapabilitiesGLES > & | GetCapabilities () const
std::string | DescribeCurrentFramebuffer () const
std::string | GetProgramInfoLogString (GLuint program) const
bool | IsCurrentFramebufferComplete () const
bool | SetDebugLabel (DebugResourceType type, GLint name, const std::string &label) const
void | PushDebugGroup (const std::string &string) const
void | PopDebugGroup () const
std::optional< std::string > | ComputeShaderWithDefines (const fml::Mapping &mapping, const std::vector< Scalar > &defines) const

## Detailed Description

Definition at line 217 of file proc_table_gles.h.

## Member Typedef Documentation

## ◆ Resolver

using impeller::ProcTableGLES::Resolver = std::function<void*(const char* function_name)>

Definition at line 219 of file proc_table_gles.h.

## Constructor & Destructor Documentation

## ◆ ProcTableGLES() [1/2]

impeller::ProcTableGLES::ProcTableGLES | ( | Resolver | resolver | ) |
| explicit

Definition at line 74 of file proc_table_gles.cc.

74 {
75 if (!resolver) {
76 return;
77 }
78
79 resolver = WrappedResolver(resolver);
80
81 auto error_fn = reinterpret_cast<PFNGLGETERRORPROC>(resolver("glGetError"));
82 if (!error_fn) {
83 VALIDATION_LOG << "Could not resolve "
84 << "glGetError";
85 return;
86 }
87
88 #define IMPELLER_PROC(proc_ivar) \
89 if (auto fn_ptr = resolver(proc_ivar.name)) { \
90 proc_ivar.function = \
91 reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
92 proc_ivar.error_fn = error_fn; \
93 } else { \
94 VALIDATION_LOG << "Could not resolve " << proc_ivar.name; \
95 return; \
96 }
97
98 FOR_EACH_IMPELLER_PROC(IMPELLER_PROC);
99
100 #undef IMPELLER_PROC
101
102 #define IMPELLER_PROC(proc_ivar) \
103 if (auto fn_ptr = resolver(proc_ivar.name)) { \
104 proc_ivar.function = \
105 reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
106 proc_ivar.error_fn = error_fn; \
107 }
108 FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC);
109 FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC);
110
111 #undef IMPELLER_PROC
112
113 description_ = std::make_unique<DescriptionGLES>(*this);
114
115 if (!description_->IsValid()) {
116 return;
117 }
118
119 if (!description_->HasDebugExtension()) {
120 PushDebugGroupKHR.Reset();
121 PopDebugGroupKHR.Reset();
122 ObjectLabelKHR.Reset();
123 } else {
124 GetIntegerv(GL_MAX_LABEL_LENGTH_KHR, &debug_label_max_length_);
125 }
126
127 if (!description_->HasExtension("GL_EXT_discard_framebuffer")) {
128 DiscardFramebufferEXT.Reset();
129 }
130
131 capabilities_ = std::make_shared<CapabilitiesGLES>(*this);
132
133 is_valid_ = true;
134 }

References FOR_EACH_IMPELLER_EXT_PROC(), FOR_EACH_IMPELLER_GLES3_PROC(), FOR_EACH_IMPELLER_PROC(), IMPELLER_PROC, VALIDATION_LOG, and impeller::WrappedResolver().

## ◆ ProcTableGLES() [2/2]

impeller::ProcTableGLES::ProcTableGLES | ( | ProcTableGLES && | other | ) |
| default

## ◆ ~ProcTableGLES()

impeller::ProcTableGLES::~ProcTableGLES | ( |  | ) |
| default

## Member Function Documentation

## ◆ ComputeShaderWithDefines()

std::optional< std::string > impeller::ProcTableGLES::ComputeShaderWithDefines | ( | const fml::Mapping & | mapping,
|  | const std::vector< Scalar > & | defines
| ) |  | const

Definition at line 166 of file proc_table_gles.cc.

168 {
169 auto shader_source = std::string{
170 reinterpret_cast<const char*>(mapping.GetMapping()), mapping.GetSize()};
171
172 // Look for the first newline after the '#version' header, which impellerc
173 // will always emit as the first line of a compiled shader.
174 auto index = shader_source.find('\n');
175 if (index == std::string::npos) {
176 VALIDATION_LOG << "Failed to append constant data to shader";
177 return std::nullopt;
178 }
179
180 std::stringstream ss;
181 ss << std::fixed;
182 for (auto i = 0u; i < defines.size(); i++) {
183 ss << "#define SPIRV_CROSS_CONSTANT_ID_" << i << " " << defines[i] << '\n';
184 }
185 auto define_string = ss.str();
186 shader_source.insert(index + 1, define_string);
187 return shader_source;
188 }

References VALIDATION_LOG.

Referenced by ShaderSourceMapping().

## ◆ DescribeCurrentFramebuffer()

std::string impeller::ProcTableGLES::DescribeCurrentFramebuffer | ( |  | ) | const

Definition at line 259 of file proc_table_gles.cc.

259 {
260 GLint framebuffer = GL_NONE;
261 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
262 if (IsFramebuffer(framebuffer) == GL_FALSE) {
263 return "No framebuffer or the default window framebuffer is bound.";
264 }
265
266 GLenum status = CheckFramebufferStatus(framebuffer);
267 std::stringstream stream;
268 stream << "FBO "
269 << ((framebuffer == GL_NONE) ? "(Default)"
270 : std::to_string(framebuffer))
271 << ": " << FramebufferStatusToString(status) << std::endl;
272 if (IsCurrentFramebufferComplete()) {
273 stream << "Framebuffer is complete." << std::endl;
274 } else {
275 stream << "Framebuffer is incomplete." << std::endl;
276 }
277 stream << "Description: " << std::endl;
278 stream << "Color Attachment: "
279 << DescribeFramebufferAttachment(*this, GL_COLOR_ATTACHMENT0)
280 << std::endl;
281 stream << "Color Attachment: "
282 << DescribeFramebufferAttachment(*this, GL_DEPTH_ATTACHMENT)
283 << std::endl;
284 stream << "Color Attachment: "
285 << DescribeFramebufferAttachment(*this, GL_STENCIL_ATTACHMENT)
286 << std::endl;
287 return stream.str();
288 }

References impeller::DescribeFramebufferAttachment(), impeller::FramebufferStatusToString(), and IsCurrentFramebufferComplete().

## ◆ FOR_EACH_IMPELLER_EXT_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_EXT_PROC | ( | IMPELLER_PROC |  | ) |

Referenced by ProcTableGLES().

## ◆ FOR_EACH_IMPELLER_GLES3_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_GLES3_PROC | ( | IMPELLER_PROC |  | ) |

Referenced by ProcTableGLES().

## ◆ FOR_EACH_IMPELLER_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_PROC | ( | IMPELLER_PROC |  | ) |

Referenced by ProcTableGLES().

## ◆ GetCapabilities()

const std::shared_ptr< const CapabilitiesGLES > & impeller::ProcTableGLES::GetCapabilities | ( |  | ) | const

Definition at line 194 of file proc_table_gles.cc.

195 {
196 return capabilities_;
197 }

Referenced by impeller::SamplerGLES::ConfigureBoundTexture().

## ◆ GetDescription()

const DescriptionGLES * impeller::ProcTableGLES::GetDescription | ( |  | ) | const

Definition at line 190 of file proc_table_gles.cc.

190 {
191 return description_.get();
192 }

Referenced by impeller::CapabilitiesGLES::CapabilitiesGLES(), and impeller::GPUTracerGLES::GPUTracerGLES().

## ◆ GetProgramInfoLogString()

std::string impeller::ProcTableGLES::GetProgramInfoLogString | ( | GLuint | program | ) | const

Definition at line 392 of file proc_table_gles.cc.

392 {
393 GLint length = 0;
394 GetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
395 if (length <= 0) {
396 return "";
397 }
398
399 length = std::min<GLint>(length, 1024);
400 Allocation allocation;
401 if (!allocation.Truncate(length, false)) {
402 return "";
403 }
404 GetProgramInfoLog(program, // program
405 length, // max length
406 &length, // length written (excluding NULL terminator)
407 reinterpret_cast<GLchar*>(allocation.GetBuffer()) // buffer
408 );
409 if (length <= 0) {
410 return "";
411 }
412 return std::string{reinterpret_cast<const char*>(allocation.GetBuffer()),
413 static_cast<size_t>(length)};
414 }

References impeller::Allocation::GetBuffer(), and impeller::Allocation::Truncate().

## ◆ IsCurrentFramebufferComplete()

bool impeller::ProcTableGLES::IsCurrentFramebufferComplete | ( |  | ) | const

Definition at line 290 of file proc_table_gles.cc.

290 {
291 GLint framebuffer = GL_NONE;
292 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
293 if (IsFramebuffer(framebuffer) == GL_FALSE) {
294 // The default framebuffer is always complete.
295 return true;
296 }
297 GLenum status = CheckFramebufferStatus(framebuffer);
298 return status == GL_FRAMEBUFFER_COMPLETE;
299 }

Referenced by DescribeCurrentFramebuffer().

## ◆ IsValid()

bool impeller::ProcTableGLES::IsValid | ( |  | ) | const

Definition at line 138 of file proc_table_gles.cc.

138 {
139 return is_valid_;
140 }

## ◆ PopDebugGroup()

void impeller::ProcTableGLES::PopDebugGroup | ( |  | ) | const

Definition at line 382 of file proc_table_gles.cc.

382 {
383 #ifdef IMPELLER_DEBUG
384 if (debug_label_max_length_ <= 0) {
385 return;
386 }
387
388 PopDebugGroupKHR();
389 #endif // IMPELLER_DEBUG
390 }

## ◆ PushDebugGroup()

void impeller::ProcTableGLES::PushDebugGroup | ( | const std::string & | string | ) | const

Definition at line 365 of file proc_table_gles.cc.

365 {
366 #ifdef IMPELLER_DEBUG
367 if (debug_label_max_length_ <= 0) {
368 return;
369 }
370
371 UniqueID id;
372 const auto label_length =
373 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
374 PushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, // source
375 static_cast<GLuint>(id.id), // id
376 label_length, // length
377 label.data() // message
378 );
379 #endif // IMPELLER_DEBUG
380 }

Referenced by impeller::EncodeCommandsInReactor().

## ◆ SetDebugLabel()

bool impeller::ProcTableGLES::SetDebugLabel | ( | DebugResourceType | type,
|  | GLint | name,
|  | const std::string & | label
| ) |  | const

Definition at line 339 of file proc_table_gles.cc.

341 {
342 if (debug_label_max_length_ <= 0) {
343 return true;
344 }
345 if (!ObjectLabelKHR.IsAvailable()) {
346 return true;
347 }
348 if (!ResourceIsLive(*this, type, name)) {
349 return false;
350 }
351 const auto identifier = ToDebugIdentifier(type);
352 const auto label_length =
353 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
354 if (!identifier.has_value()) {
355 return true;
356 }
357 ObjectLabelKHR(identifier.value(), // identifier
358 name, // name
359 label_length, // length
360 label.data() // label
361 );
362 return true;
363 }

References impeller::ResourceIsLive(), and impeller::ToDebugIdentifier().

## ◆ ShaderSourceMapping()

void impeller::ProcTableGLES::ShaderSourceMapping | ( | GLuint | shader,
|  | const fml::Mapping & | mapping,
|  | const std::vector< Scalar > & | defines = `{}`
| ) |  | const

Set the source for the attached [shader].

Optionally, [defines] may contain a string value that will be append to the shader source after the version marker. This can be used to support static specialization. For example, setting "#define Foo 1".

Definition at line 142 of file proc_table_gles.cc.

145 {
146 if (defines.empty()) {
147 const GLchar* sources[] = {
148 reinterpret_cast<const GLchar*>(mapping.GetMapping())};
149 const GLint lengths[] = {static_cast<GLint>(mapping.GetSize())};
150 ShaderSource(shader, 1u, sources, lengths);
151 return;
152 }
153 const auto& shader_source = ComputeShaderWithDefines(mapping, defines);
154 if (!shader_source.has_value()) {
155 VALIDATION_LOG << "Failed to append constant data to shader";
156 return;
157 }
158
159 const GLchar* sources[] = {
160 reinterpret_cast<const GLchar*>(shader_source->c_str())};
161 const GLint lengths[] = {static_cast<GLint>(shader_source->size())};
162 ShaderSource(shader, 1u, sources, lengths);
163 }

References ComputeShaderWithDefines(), and VALIDATION_LOG.

The documentation for this class was generated from the following files:

- impeller/renderer/backend/gles/proc_table_gles.h
- impeller/renderer/backend/gles/proc_table_gles.cc

impeller::DescribeFramebufferAttachment
static std::string DescribeFramebufferAttachment(const ProcTableGLES &gl, GLenum attachment)
Definition: proc_table_gles.cc:233
impeller::ProcTableGLES::FOR_EACH_IMPELLER_PROC
FOR_EACH_IMPELLER_PROC(IMPELLER_PROC)
impeller::ProcTableGLES::FOR_EACH_IMPELLER_GLES3_PROC
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC)
IMPELLER_PROC
#define IMPELLER_PROC(proc_ivar)
impeller::ResourceIsLive
static bool ResourceIsLive(const ProcTableGLES &gl, DebugResourceType type, GLint name)
Definition: proc_table_gles.cc:319
impeller::WrappedResolver
ProcTableGLES::Resolver WrappedResolver(const ProcTableGLES::Resolver &resolver)
Definition: proc_table_gles.cc:52
impeller::ProcTableGLES::FOR_EACH_IMPELLER_EXT_PROC
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC)
impeller::FramebufferStatusToString
static const char * FramebufferStatusToString(GLenum status)
Definition: proc_table_gles.cc:199
impeller::ProcTableGLES::ComputeShaderWithDefines
std::optional< std::string > ComputeShaderWithDefines(const fml::Mapping &mapping, const std::vector< Scalar > &defines) const
Definition: proc_table_gles.cc:166
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::ProcTableGLES::IsCurrentFramebufferComplete
bool IsCurrentFramebufferComplete() const
Definition: proc_table_gles.cc:290
impeller::ToDebugIdentifier
static std::optional< GLenum > ToDebugIdentifier(DebugResourceType type)
Definition: proc_table_gles.cc:301