Debugger.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using OpenTK.Graphics.OpenGL;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace Ryujinx.Graphics.OpenGL
  5. {
  6. public static class Debugger
  7. {
  8. private static DebugProc _debugCallback;
  9. public static void Initialize()
  10. {
  11. GL.Enable(EnableCap.DebugOutputSynchronous);
  12. int[] array = null;
  13. GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, array, true);
  14. _debugCallback = PrintDbg;
  15. GL.DebugMessageCallback(_debugCallback, IntPtr.Zero);
  16. }
  17. private static void PrintDbg(
  18. DebugSource source,
  19. DebugType type,
  20. int id,
  21. DebugSeverity severity,
  22. int length,
  23. IntPtr message,
  24. IntPtr userParam)
  25. {
  26. string msg = Marshal.PtrToStringAnsi(message);
  27. if (type == DebugType.DebugTypeError && !msg.Contains("link"))
  28. {
  29. throw new Exception(msg);
  30. }
  31. System.Console.WriteLine("GL message: " + source + " " + type + " " + severity + " " + msg);
  32. }
  33. }
  34. }