GLContext.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * $Id$
  3. *
  4. * GtkGL# - OpenGL Graphics Library for the Gtk# Toolkit
  5. *
  6. * Copyright (c) 2002-2004 The Olympum Group, http://www.olympum.com/
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. *
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * - Neither the name of The Olympum Group nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  29. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  33. * DAMAGE.
  34. */
  35. namespace Gdk
  36. {
  37. using System;
  38. using System.Runtime.InteropServices;
  39. internal abstract class GLContext
  40. {
  41. private static bool useWGLContext;
  42. public static GLContext CreateContext (int[] attrs,
  43. GLContext share, IntPtr gdkDrawable)
  44. {
  45. if(!useWGLContext) {
  46. try {
  47. return new X11GLContext(attrs,
  48. (X11GLContext) share, gdkDrawable);
  49. } catch(DllNotFoundException e) {
  50. Console.WriteLine("Failed setting up X11 opengl context: " + e.Message);
  51. Console.WriteLine(" (If you run Windows this is normal, on any other OS it would be bad)");
  52. Console.WriteLine(e.StackTrace);
  53. useWGLContext = true;
  54. }
  55. return CreateContext(attrs, share, gdkDrawable);
  56. } else {
  57. PlatformID operatingSystem = Environment.OSVersion.Platform;
  58. if (operatingSystem == PlatformID.Win32Windows) {
  59. Console.WriteLine("Trying win32 API");
  60. return new W32GLContext (attrs,
  61. (W32GLContext)share, gdkDrawable);
  62. } else {
  63. Console.WriteLine("Trying OS X API");
  64. return new MacGLContext (attrs,
  65. (MacGLContext)share, gdkDrawable);
  66. }
  67. }
  68. }
  69. public abstract bool MakeCurrent (IntPtr gdkDrawable);
  70. public abstract void SwapBuffers (IntPtr gdkDrawable);
  71. }
  72. }