Debugger.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using OpenTK.Graphics.OpenGL;
  2. using Ryujinx.Common.Logging;
  3. using System;
  4. using System.Runtime.InteropServices;
  5. namespace Ryujinx.Graphics.OpenGL
  6. {
  7. public static class Debugger
  8. {
  9. private static DebugProc _debugCallback;
  10. public static void Initialize()
  11. {
  12. GL.Enable(EnableCap.DebugOutputSynchronous);
  13. GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, (int[])null, true);
  14. _debugCallback = GLDebugHandler;
  15. GL.DebugMessageCallback(_debugCallback, IntPtr.Zero);
  16. }
  17. private static void GLDebugHandler(
  18. DebugSource source,
  19. DebugType type,
  20. int id,
  21. DebugSeverity severity,
  22. int length,
  23. IntPtr message,
  24. IntPtr userParam)
  25. {
  26. string fullMessage = $"{type} {severity} {source} {Marshal.PtrToStringAnsi(message)}";
  27. switch (type)
  28. {
  29. case DebugType.DebugTypeError:
  30. Logger.PrintError(LogClass.Gpu, fullMessage);
  31. break;
  32. case DebugType.DebugTypePerformance:
  33. Logger.PrintWarning(LogClass.Gpu, fullMessage);
  34. break;
  35. default:
  36. Logger.PrintDebug(LogClass.Gpu, fullMessage);
  37. break;
  38. }
  39. }
  40. }
  41. }