瀏覽代碼

gpu: implement GL debug context logging.

legacy
Sam Hocevar 5 年之前
父節點
當前提交
4d58c015f9
共有 4 個檔案被更改,包括 106 行新增4 行删除
  1. +10
    -2
      src/application/sdl-app.cpp
  2. +88
    -0
      src/gpu/debug.cpp
  3. +7
    -2
      src/gpu/renderer.cpp
  4. +1
    -0
      src/lol/gpu/debug.h

+ 10
- 2
src/application/sdl-app.cpp 查看文件

@@ -48,10 +48,18 @@ sdl::app_display::app_display(char const *title, ivec2 res)
}
}

/* This seems to fix the swap context bug.
* However, perfs warning have been may occur. */
// This seems to fix a bug we used to have at context swap. Maybe remove one day.
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);

#if 0
// Ask for GL 3.2 at least
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#endif
#if LOL_BUILD_DEBUG
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
#endif

int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
if (window_size == ivec2(0))
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;


+ 88
- 0
src/gpu/debug.cpp 查看文件

@@ -17,6 +17,94 @@
namespace lol
{

static std::map<GLenum, char const *> gl_dbg_source_to_str
{
{ GL_DEBUG_SOURCE_API, "API" },
{ GL_DEBUG_SOURCE_WINDOW_SYSTEM, "Window System" },
{ GL_DEBUG_SOURCE_SHADER_COMPILER, "Shader Compiler" },
{ GL_DEBUG_SOURCE_THIRD_PARTY, "Third Party" },
{ GL_DEBUG_SOURCE_APPLICATION, "Application" },
{ GL_DEBUG_SOURCE_OTHER, "Other" },
};

static std::map<GLenum, char const *> gl_dbg_type_to_str
{
{ GL_DEBUG_TYPE_ERROR, "Error" },
{ GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, "Deprecated Behaviour" },
{ GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR, "Undefined Behaviour" },
{ GL_DEBUG_TYPE_PORTABILITY, "Portability" },
{ GL_DEBUG_TYPE_PERFORMANCE, "Performance" },
{ GL_DEBUG_TYPE_MARKER, "Marker" },
{ GL_DEBUG_TYPE_PUSH_GROUP, "Push Group" },
{ GL_DEBUG_TYPE_POP_GROUP, "Pop Group" },
{ GL_DEBUG_TYPE_OTHER, "Other" },
};

static std::map<GLenum, char const *> gl_dbg_severity_to_str
{
{ GL_DEBUG_SEVERITY_HIGH, "High" },
{ GL_DEBUG_SEVERITY_MEDIUM, "Medium" },
{ GL_DEBUG_SEVERITY_LOW, "Low" },
{ GL_DEBUG_SEVERITY_NOTIFICATION, "Notification" },
};

static void gl_debug(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length,
const GLchar *message, const void *user_param)
{
switch (id)
{
default:
msg::debug("GL debug: %s\n", message);
if (gl_dbg_source_to_str.count(source) == 1)
msg::debug(" source: %s\n", gl_dbg_source_to_str[source]);
if (gl_dbg_type_to_str.count(type) == 1)
msg::debug(" type: %s\n", gl_dbg_type_to_str[type]);
msg::debug(" ID: %d\n", id);
if (gl_dbg_severity_to_str.count(severity) == 1)
msg::debug(" severity: %s\n", gl_dbg_severity_to_str[severity]);
break;
// Some debug messages are just annoying informational messages
case 131185: // glBufferData
case 131169: // glFramebufferRenderbuffer
break;
}
}

static void gl_debug_amd(GLuint id, GLenum category, GLenum severity,
GLsizei length, const GLchar* message,
GLvoid* user_param)
{
gl_debug(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, id,
severity, length, message, user_param);
}

void gpu::setup_debug()
{
#if LOL_BUILD_DEBUG
GLint glflags;
glGetIntegerv(GL_CONTEXT_FLAGS, &glflags);

if (glflags & GL_CONTEXT_FLAG_DEBUG_BIT)
{
// Debug Output available

glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
#if defined LOL_USE_GLEW && !defined __APPLE__
if (GLEW_ARB_debug_output)
glDebugMessageCallbackARB(gl_debug, NULL);
else if (GLEW_AMD_debug_output)
glDebugMessageCallbackAMD(gl_debug_amd, NULL);
else if (GLEW_KHR_debug)
#endif
glDebugMessageCallback(gl_debug, NULL);

glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
}
#endif
}

void gpu::error(char const *msg, int error)
{
msg::error("%s: GL error 0x%04x\n", msg, error);


+ 7
- 2
src/gpu/renderer.cpp 查看文件

@@ -62,7 +62,8 @@ Renderer::Renderer(ivec2 size)
: m_data(new RendererData())
{
#if defined LOL_USE_GLEW && !defined __APPLE__
/* Initialise GLEW if necessary */
// Initialise GLEW if necessary
// FIXME: move this somewhere else
GLenum glerr = glewInit();
if (glerr != GLEW_OK)
{
@@ -71,6 +72,8 @@ Renderer::Renderer(ivec2 size)
}
#endif

gpu::setup_debug();

/* Initialise rendering states */
m_data->m_viewport = ibox2(0, 0, 0, 0);
SetViewport(ibox2(ivec2::zero, size));
@@ -109,7 +112,7 @@ Renderer::Renderer(ivec2 size)
SetPolygonMode(PolygonMode::Fill);

/* Add some rendering states that we don't export to the user */
#if defined HAVE_GL_2X && !defined __APPLE__
#if defined HAVE_GL_2X && !defined GL_VERSION_3_1
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
#endif
}
@@ -218,6 +221,8 @@ void Renderer::SetAlphaFunc(AlphaFunc func, float alpha)

#if defined HAVE_GLES_2X
/* not supported */
#elif defined GL_VERSION_3_1
/* deprecated */
#elif defined GL_VERSION_1_1
switch (func)
{


+ 1
- 0
src/lol/gpu/debug.h 查看文件

@@ -18,6 +18,7 @@ namespace lol
namespace gpu
{

void setup_debug();
void error(char const *msg, int error);

} // namespace gpu


Loading…
取消
儲存