GLHelper.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Collections.Generic;
  4. namespace OpenGl
  5. {
  6. public static class GlHelper
  7. {
  8. private static HashSet<string> extensions = null;
  9. public static HashSet<string> Extensions {
  10. get {
  11. if (extensions == null) {
  12. IntPtr extstr = gl.GetString(gl.EXTENSIONS);
  13. if (extstr.Equals(IntPtr.Zero)) {
  14. LogManager.Log(LogLevel.Warning, "Couldn't receive a list of gl extensions (no context?)");
  15. return null;
  16. } else {
  17. string exts = Marshal.PtrToStringAuto(extstr);
  18. extensions = new HashSet<string>(exts.Split(' '));
  19. return extensions;
  20. }
  21. } else {
  22. return extensions;
  23. }
  24. }
  25. }
  26. /// <summary>
  27. /// Wrapper around glGetString(GL_EXTENSIONS)
  28. /// </summary>
  29. /// <returns>
  30. /// <c>true</c> if the specified extension is available; otherwise, <c>false</c>.
  31. /// </returns>
  32. public static bool HasExtension(string name) {
  33. if (Extensions != null) {
  34. return Extensions.Contains(name);
  35. } else {
  36. return false;
  37. }
  38. }
  39. }
  40. }