OglExtension.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using OpenTK.Graphics.OpenGL;
  2. using Ryujinx.Common.Logging;
  3. using System;
  4. namespace Ryujinx.Graphics.Gal.OpenGL
  5. {
  6. static class OglExtension
  7. {
  8. // Private lazy backing variables
  9. private static Lazy<bool> _enhancedLayouts = new Lazy<bool>(() => HasExtension("GL_ARB_enhanced_layouts"));
  10. private static Lazy<bool> _textureMirrorClamp = new Lazy<bool>(() => HasExtension("GL_EXT_texture_mirror_clamp"));
  11. private static Lazy<bool> _viewportArray = new Lazy<bool>(() => HasExtension("GL_ARB_viewport_array"));
  12. private static Lazy<bool> _nvidiaDriver = new Lazy<bool>(() => IsNvidiaDriver());
  13. // Public accessors
  14. public static bool EnhancedLayouts => _enhancedLayouts.Value;
  15. public static bool TextureMirrorClamp => _textureMirrorClamp.Value;
  16. public static bool ViewportArray => _viewportArray.Value;
  17. public static bool NvidiaDriver => _nvidiaDriver.Value;
  18. private static bool HasExtension(string name)
  19. {
  20. int numExtensions = GL.GetInteger(GetPName.NumExtensions);
  21. for (int extension = 0; extension < numExtensions; extension++)
  22. {
  23. if (GL.GetString(StringNameIndexed.Extensions, extension) == name)
  24. {
  25. return true;
  26. }
  27. }
  28. Logger.PrintInfo(LogClass.Gpu, $"OpenGL extension {name} unavailable. You may experience some performance degradation");
  29. return false;
  30. }
  31. private static bool IsNvidiaDriver()
  32. {
  33. return GL.GetString(StringName.Vendor).Equals("NVIDIA Corporation");
  34. }
  35. public static class Required
  36. {
  37. // Public accessors
  38. public static bool EnhancedLayouts => _enhancedLayoutsRequired.Value;
  39. public static bool TextureMirrorClamp => _textureMirrorClampRequired.Value;
  40. public static bool ViewportArray => _viewportArrayRequired.Value;
  41. // Private lazy backing variables
  42. private static Lazy<bool> _enhancedLayoutsRequired = new Lazy<bool>(() => HasExtensionRequired(OglExtension.EnhancedLayouts, "GL_ARB_enhanced_layouts"));
  43. private static Lazy<bool> _textureMirrorClampRequired = new Lazy<bool>(() => HasExtensionRequired(OglExtension.TextureMirrorClamp, "GL_EXT_texture_mirror_clamp"));
  44. private static Lazy<bool> _viewportArrayRequired = new Lazy<bool>(() => HasExtensionRequired(OglExtension.ViewportArray, "GL_ARB_viewport_array"));
  45. private static bool HasExtensionRequired(bool value, string name)
  46. {
  47. if (value)
  48. {
  49. return true;
  50. }
  51. Logger.PrintWarning(LogClass.Gpu, $"Required OpenGL extension {name} unavailable. You may experience some rendering issues");
  52. return false;
  53. }
  54. }
  55. }
  56. }