Commit ba7f8913 by Jamie Madill Committed by Commit Bot

Samples: Enable Debug callback.

This moves the debug callback code into a common location. For ease of access it's in shader_utils since that file has access to the GL API. Bug: angleproject:5040 Change-Id: Iab9de47c2d520a5618ea6825852f8afa63565c8a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2408715 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent b3c7d39a
......@@ -10,7 +10,9 @@
#include "util/EGLWindow.h"
#include "util/gles_loader_autogen.h"
#include "util/random_utils.h"
#include "util/shader_utils.h"
#include "util/test_utils.h"
#include "util/util_gl.h"
#include <string.h>
#include <iostream>
......@@ -64,6 +66,12 @@ EGLint GetDeviceTypeFromArg(const char *displayTypeArg)
return EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE;
}
}
ANGLE_MAYBE_UNUSED bool IsGLExtensionEnabled(const std::string &extName)
{
return angle::CheckExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
extName);
}
} // anonymous namespace
SampleApplication::SampleApplication(std::string name,
......@@ -207,6 +215,13 @@ int SampleApplication::run()
mRunning = true;
int result = 0;
#if defined(ANGLE_ENABLE_ASSERTS)
if (IsGLExtensionEnabled("GL_KHR_debug"))
{
EnableDebugCallback(this);
}
#endif
if (!initialize())
{
mRunning = false;
......
......@@ -159,20 +159,6 @@ void DumpTraceEventsToJSONFile(const std::vector<TraceEvent> &traceEvents,
outFile.close();
}
ANGLE_MAYBE_UNUSED void KHRONOS_APIENTRY DebugMessageCallback(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar *message,
const void *userParam)
{
std::string sourceText = gl::GetDebugMessageSourceString(source);
std::string typeText = gl::GetDebugMessageTypeString(type);
std::string severityText = gl::GetDebugMessageSeverityString(severity);
std::cerr << sourceText << ", " << typeText << ", " << severityText << ": " << message << "\n";
}
} // anonymous namespace
TraceEvent::TraceEvent(char phaseIn,
......@@ -584,22 +570,7 @@ void ANGLERenderTest::SetUp()
#if defined(ANGLE_ENABLE_ASSERTS)
if (IsGLExtensionEnabled("GL_KHR_debug"))
{
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
// Enable medium and high priority messages.
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr,
GL_TRUE);
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr,
GL_TRUE);
// Disable low and notification priority messages.
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, nullptr,
GL_FALSE);
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0,
nullptr, GL_FALSE);
// Disable performance messages to reduce spam.
glDebugMessageControlKHR(GL_DONT_CARE, GL_DEBUG_TYPE_PERFORMANCE, GL_DONT_CARE, 0, nullptr,
GL_FALSE);
glDebugMessageCallbackKHR(DebugMessageCallback, this);
EnableDebugCallback(this);
}
#endif
......
......@@ -11,6 +11,7 @@
#include <iostream>
#include <vector>
#include "common/utilities.h"
#include "util/test_utils.h"
namespace
......@@ -75,6 +76,20 @@ GLuint CompileProgramInternal(const char *vsSource,
return CheckLinkStatusAndReturnProgram(program, true);
}
void KHRONOS_APIENTRY DebugMessageCallback(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar *message,
const void *userParam)
{
std::string sourceText = gl::GetDebugMessageSourceString(source);
std::string typeText = gl::GetDebugMessageTypeString(type);
std::string severityText = gl::GetDebugMessageSeverityString(severity);
std::cerr << sourceText << ", " << typeText << ", " << severityText << ": " << message << "\n";
}
} // namespace
GLuint CompileShader(GLenum type, const char *source)
......@@ -282,6 +297,26 @@ bool LinkAttachedProgram(GLuint program)
return (CheckLinkStatusAndReturnProgram(program, true) != 0);
}
void EnableDebugCallback(const void *userParam)
{
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
// Enable medium and high priority messages.
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr,
GL_TRUE);
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr,
GL_TRUE);
// Disable low and notification priority messages.
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, nullptr,
GL_FALSE);
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, nullptr,
GL_FALSE);
// Disable performance messages to reduce spam.
glDebugMessageControlKHR(GL_DONT_CARE, GL_DEBUG_TYPE_PERFORMANCE, GL_DONT_CARE, 0, nullptr,
GL_FALSE);
glDebugMessageCallbackKHR(DebugMessageCallback, userParam);
}
namespace angle
{
......
......@@ -45,6 +45,8 @@ ANGLE_UTIL_EXPORT GLuint LoadBinaryProgramOES(const std::vector<uint8_t> &binary
ANGLE_UTIL_EXPORT GLuint LoadBinaryProgramES3(const std::vector<uint8_t> &binary,
GLenum binaryFormat);
ANGLE_UTIL_EXPORT void EnableDebugCallback(const void *userParam);
namespace angle
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment