Ryujinx/Ryujinx.Graphics.OpenGL/Debugger.cs

49 lines
1.4 KiB
C#
Raw Normal View History

2019-10-13 08:02:07 +02:00
using OpenTK.Graphics.OpenGL;
2019-12-29 00:45:33 +01:00
using Ryujinx.Common.Logging;
2019-10-13 08:02:07 +02:00
using System;
using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.OpenGL
{
public static class Debugger
{
private static DebugProc _debugCallback;
public static void Initialize()
{
GL.Enable(EnableCap.DebugOutputSynchronous);
2019-12-29 00:45:33 +01:00
GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, (int[])null, true);
2019-10-13 08:02:07 +02:00
2019-12-29 00:45:33 +01:00
_debugCallback = GLDebugHandler;
2019-10-13 08:02:07 +02:00
GL.DebugMessageCallback(_debugCallback, IntPtr.Zero);
}
2019-12-29 00:45:33 +01:00
private static void GLDebugHandler(
2019-10-13 08:02:07 +02:00
DebugSource source,
DebugType type,
int id,
DebugSeverity severity,
int length,
IntPtr message,
IntPtr userParam)
{
2019-12-29 00:45:33 +01:00
string fullMessage = $"{type} {severity} {source} {Marshal.PtrToStringAnsi(message)}";
2019-10-13 08:02:07 +02:00
2019-12-29 00:45:33 +01:00
switch (type)
2019-10-13 08:02:07 +02:00
{
2019-12-29 00:45:33 +01:00
case DebugType.DebugTypeError:
Logger.PrintError(LogClass.Gpu, fullMessage);
2019-12-29 00:45:33 +01:00
break;
case DebugType.DebugTypePerformance:
Logger.PrintWarning(LogClass.Gpu, fullMessage);
break;
default:
Logger.PrintDebug(LogClass.Gpu, fullMessage);
break;
2019-10-13 08:02:07 +02:00
}
}
}
}