23 return "GL_INVALID_ENUM";
24 case GL_INVALID_VALUE:
25 return "GL_INVALID_VALUE";
26 case GL_INVALID_OPERATION:
27 return "GL_INVALID_OPERATION";
28 case GL_INVALID_FRAMEBUFFER_OPERATION:
29 return "GL_INVALID_FRAMEBUFFER_OPERATION";
30 case GL_FRAMEBUFFER_COMPLETE:
31 return "GL_FRAMEBUFFER_COMPLETE";
32 case GL_OUT_OF_MEMORY:
33 return "GL_OUT_OF_MEMORY";
43 case GL_INVALID_VALUE:
44 case GL_INVALID_OPERATION:
45 case GL_INVALID_FRAMEBUFFER_OPERATION:
46 case GL_OUT_OF_MEMORY:
54 return [resolver](
const char* function_name) ->
void* {
55 auto resolved = resolver(function_name);
61 auto function = std::string{function_name};
62 if (
function.find(
"KHR",
function.size() - 3) != std::string::npos) {
63 auto truncated =
function.substr(0u,
function.size() - 3);
64 return resolver(truncated.c_str());
66 if (
function.find(
"EXT",
function.size() - 3) != std::string::npos) {
67 auto truncated =
function.substr(0u,
function.size() - 3);
68 return resolver(truncated.c_str());
85 auto error_fn =
reinterpret_cast<PFNGLGETERRORPROC
>(resolver(
"glGetError"));
91 #define IMPELLER_PROC(proc_ivar) \
92 if (auto fn_ptr = resolver(proc_ivar.name)) { \
93 proc_ivar.function = \
94 reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
95 proc_ivar.error_fn = error_fn; \
97 VALIDATION_LOG << "Could not resolve " << proc_ivar.name; \
103 description_ = std::make_unique<DescriptionGLES>(*
this);
105 if (!description_->IsValid()) {
109 if (description_->IsES()) {
117 #define IMPELLER_PROC(proc_ivar) \
118 if (auto fn_ptr = resolver(proc_ivar.name)) { \
119 proc_ivar.function = \
120 reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
121 proc_ivar.error_fn = error_fn; \
124 if (description_->GetGlVersion().IsAtLeast(
Version(3))) {
133 PushDebugGroupKHR.Reset();
134 PopDebugGroupKHR.Reset();
135 ObjectLabelKHR.Reset();
137 GetIntegerv(GL_MAX_LABEL_LENGTH_KHR, &debug_label_max_length_);
140 if (!description_->HasExtension(
"GL_EXT_discard_framebuffer")) {
141 DiscardFramebufferEXT.Reset();
144 capabilities_ = std::make_shared<CapabilitiesGLES>(*
this);
157 const fml::Mapping& mapping,
158 const std::vector<Scalar>& defines)
const {
159 if (defines.empty()) {
160 const GLchar* sources[] = {
161 reinterpret_cast<const GLchar*
>(mapping.GetMapping())};
162 const GLint lengths[] = {
static_cast<GLint
>(mapping.GetSize())};
163 ShaderSource(shader, 1u, sources, lengths);
167 if (!shader_source.has_value()) {
172 const GLchar* sources[] = {
173 reinterpret_cast<const GLchar*
>(shader_source->c_str())};
174 const GLint lengths[] = {
static_cast<GLint
>(shader_source->size())};
175 ShaderSource(shader, 1u, sources, lengths);
180 const fml::Mapping& mapping,
181 const std::vector<Scalar>& defines)
const {
182 std::string shader_source = std::string{
183 reinterpret_cast<const char*
>(mapping.GetMapping()), mapping.GetSize()};
187 size_t index = shader_source.find(
'\n');
188 if (index == std::string::npos) {
193 std::stringstream ss;
195 for (
auto i = 0u; i < defines.size(); i++) {
196 ss <<
"#define SPIRV_CROSS_CONSTANT_ID_" << i <<
" " << defines[i] <<
'\n';
198 auto define_string = ss.str();
199 shader_source.insert(index + 1, define_string);
200 return shader_source;
204 return description_.get();
209 return capabilities_;
214 case GL_FRAMEBUFFER_COMPLETE:
215 return "GL_FRAMEBUFFER_COMPLETE";
216 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
217 return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
218 #if GL_ES_VERSION_2_0
219 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
220 return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
222 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
223 return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
224 case GL_FRAMEBUFFER_UNSUPPORTED:
225 return "GL_FRAMEBUFFER_UNSUPPORTED";
226 case GL_INVALID_ENUM:
227 return "GL_INVALID_ENUM";
230 return "Unknown FBO Error Status";
235 case GL_RENDERBUFFER:
236 return "GL_RENDERBUFFER";
243 return "Unknown Type";
248 GLint
type = GL_NONE;
249 gl.GetFramebufferAttachmentParameteriv(
252 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
256 if (
type != GL_NONE) {
257 GLint
object = GL_NONE;
258 gl.GetFramebufferAttachmentParameteriv(
261 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
264 std::stringstream stream;
269 return "No Attachment";
273 GLint framebuffer = GL_NONE;
274 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
275 if (framebuffer == GL_NONE) {
276 return "The default framebuffer (FBO0) was bound.";
278 if (IsFramebuffer(framebuffer) == GL_FALSE) {
279 return SPrintF(
"The framebuffer binding (%d) was not a valid framebuffer.",
283 GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
284 std::stringstream stream;
286 << ((framebuffer == GL_NONE) ?
"(Default)"
287 : std::to_string(framebuffer))
290 stream <<
"Framebuffer is complete." << std::endl;
292 stream <<
"Framebuffer is incomplete." << std::endl;
294 stream <<
"Description: " << std::endl;
295 stream <<
"Color Attachment: "
298 stream <<
"Depth Attachment: "
301 stream <<
"Stencil Attachment: "
308 GLint framebuffer = GL_NONE;
309 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
310 if (IsFramebuffer(framebuffer) == GL_FALSE) {
314 GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
315 return status == GL_FRAMEBUFFER_COMPLETE;
323 return GL_BUFFER_KHR;
325 return GL_PROGRAM_KHR;
327 return GL_SHADER_KHR;
329 return GL_RENDERBUFFER;
331 return GL_FRAMEBUFFER;
333 return GL_SYNC_FENCE;
343 return gl.IsTexture(name);
345 return gl.IsBuffer(name);
347 return gl.IsProgram(name);
349 return gl.IsShader(name);
351 return gl.IsRenderbuffer(name);
353 return gl.IsFramebuffer(name);
361 if (debug_label_max_length_ <= 0) {
364 if (!ObjectLabelKHR.IsAvailable()) {
372 std::string_view label)
const {
380 const auto label_length =
381 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
382 if (!identifier.has_value()) {
385 ObjectLabelKHR(identifier.value(),
394 #ifdef IMPELLER_DEBUG
395 if (debug_label_max_length_ <= 0) {
400 const auto label_length =
401 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
402 PushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR,
403 static_cast<GLuint
>(
id.
id),
411 #ifdef IMPELLER_DEBUG
412 if (debug_label_max_length_ <= 0) {
422 GetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
427 length = std::min<GLint>(length, 1024);
432 GetProgramInfoLog(program,
435 reinterpret_cast<GLchar*
>(allocation.
GetBuffer())
440 return std::string{
reinterpret_cast<const char*
>(allocation.
GetBuffer()),
441 static_cast<size_t>(length)};
Describes an allocation on the heap.
uint8_t * GetBuffer() const
Gets the pointer to the start of the allocation.
bool Truncate(Bytes length, bool npot=true)
Resize the underlying allocation to at least given number of bytes.
FOR_EACH_IMPELLER_ES_ONLY_PROC(IMPELLER_PROC)
std::optional< std::string > ComputeShaderWithDefines(const fml::Mapping &mapping, const std::vector< Scalar > &defines) const
void PopDebugGroup() const
bool SetDebugLabel(DebugResourceType type, GLint name, std::string_view label) const
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC)
std::function< void *(const char *function_name)> Resolver
void ShaderSourceMapping(GLuint shader, const fml::Mapping &mapping, const std::vector< Scalar > &defines={}) const
Set the source for the attached [shader].
FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(IMPELLER_PROC)
std::string GetProgramInfoLogString(GLuint program) const
bool SupportsDebugLabels() const
std::string DescribeCurrentFramebuffer() const
const std::shared_ptr< const CapabilitiesGLES > & GetCapabilities() const
bool IsCurrentFramebufferComplete() const
ProcTableGLES(Resolver resolver)
FOR_EACH_IMPELLER_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC)
void PushDebugGroup(const std::string &string) const
const DescriptionGLES * GetDescription() const
ProcTableGLES::Resolver WrappedResolver(const ProcTableGLES::Resolver &resolver)
static const char * AttachmentTypeString(GLint type)
bool GLErrorIsFatal(GLenum value)
std::string SPrintF(const char *format,...)
const char * GLErrorToString(GLenum value)
static const char * FramebufferStatusToString(GLenum status)
static std::optional< GLenum > ToDebugIdentifier(DebugResourceType type)
static bool ResourceIsLive(const ProcTableGLES &gl, DebugResourceType type, GLint name)
static std::string DescribeFramebufferAttachment(const ProcTableGLES &gl, GLenum attachment)
#define IMPELLER_PROC(proc_ivar)
#define IP_ENABLE_GLES_LABELING
Enable to allow GLES to push/pop labels for usage in GPU traces.