rjx-mirror/Ryujinx.Graphics.OpenGL/Debugger.cs

49 lines
1.4 KiB
C#
Raw Normal View History

2019-10-13 06:02:07 +00:00
using OpenTK.Graphics.OpenGL;
2019-12-28 23:45:33 +00:00
using Ryujinx.Common.Logging;
2019-10-13 06:02:07 +00: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-28 23:45:33 +00:00
GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, (int[])null, true);
2019-10-13 06:02:07 +00:00
2019-12-28 23:45:33 +00:00
_debugCallback = GLDebugHandler;
2019-10-13 06:02:07 +00:00
GL.DebugMessageCallback(_debugCallback, IntPtr.Zero);
}
2019-12-28 23:45:33 +00:00
private static void GLDebugHandler(
2019-10-13 06:02:07 +00:00
DebugSource source,
DebugType type,
int id,
DebugSeverity severity,
int length,
IntPtr message,
IntPtr userParam)
{
2019-12-28 23:45:33 +00:00
string fullMessage = $"{type} {severity} {source} {Marshal.PtrToStringAnsi(message)}";
2019-10-13 06:02:07 +00:00
2019-12-28 23:45:33 +00:00
switch (type)
2019-10-13 06:02:07 +00:00
{
2019-12-28 23:45:33 +00:00
case DebugType.DebugTypeError:
Logger.PrintDebug(LogClass.Gpu, fullMessage);
2019-12-28 23:45:33 +00:00
break;
case DebugType.DebugTypePerformance:
Logger.PrintWarning(LogClass.Gpu, fullMessage);
break;
default:
Logger.PrintDebug(LogClass.Gpu, fullMessage);
break;
2019-10-13 06:02:07 +00:00
}
}
}
}