GLContext.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. Console.WriteLine("Trying win32 API");
  54. useWGLContext = true;
  55. }
  56. return CreateContext(attrs, share, gdkDrawable);
  57. } else {
  58. return new W32GLContext(attrs,
  59. (W32GLContext) share, gdkDrawable);
  60. }
  61. }
  62. public abstract bool MakeCurrent (IntPtr gdkDrawable);
  63. public abstract void SwapBuffers (IntPtr gdkDrawable);
  64. }
  65. }