GlEntryPointAttribute.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. namespace Avalonia.OpenGL
  3. {
  4. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
  5. class GlMinVersionEntryPoint : Attribute
  6. {
  7. public GlMinVersionEntryPoint(string entry, int minVersionMajor, int minVersionMinor)
  8. {
  9. }
  10. public GlMinVersionEntryPoint(string entry, int minVersionMajor, int minVersionMinor, GlProfileType profile)
  11. {
  12. }
  13. public static IntPtr GetProcAddress(Func<string, IntPtr> getProcAddress, GlInterface.GlContextInfo context,
  14. string entry, int minVersionMajor, int minVersionMinor, GlProfileType? profile = null)
  15. {
  16. if(profile.HasValue && context.Version.Type != profile)
  17. return IntPtr.Zero;
  18. if(context.Version.Major<minVersionMajor)
  19. return IntPtr.Zero;
  20. if (context.Version.Major == minVersionMajor && context.Version.Minor < minVersionMinor)
  21. return IntPtr.Zero;
  22. return getProcAddress(entry);
  23. }
  24. }
  25. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
  26. class GlExtensionEntryPoint : Attribute
  27. {
  28. public GlExtensionEntryPoint(string entry, string extension)
  29. {
  30. }
  31. public GlExtensionEntryPoint(string entry, string extension, GlProfileType profile)
  32. {
  33. }
  34. public static IntPtr GetProcAddress(Func<string, IntPtr> getProcAddress, GlInterface.GlContextInfo context,
  35. string entry, string extension, GlProfileType? profile = null)
  36. {
  37. // Ignore different profile type
  38. if (profile.HasValue && profile != context.Version.Type)
  39. return IntPtr.Zero;
  40. // Check if extension is supported by the current context
  41. if (!context.Extensions.Contains(extension))
  42. return IntPtr.Zero;
  43. return getProcAddress(entry);
  44. }
  45. }
  46. }