public WinGLContext(ContextHandle handle, WinWindowInfo window, IGraphicsContext sharedContext,
                     int major, int minor, GraphicsContextFlags flags, DesktopBackend backEnd)
     : base(backEnd)
 {
     if (handle == ContextHandle.Zero)
     {
         throw new ArgumentException("handle");
     }
     if (window == null)
     {
         throw new ArgumentNullException("window");
     }
     Handle = handle;
 }
 public ExternalGraphicsContext(DesktopBackend desktopBackEnd)
 {
     this.desktopBackEnd = desktopBackEnd;
 }
Example #3
0
 public DesktopGraphicsContext(DesktopBackend desktopBackEnd)
 {
     this.desktopBackEnd = desktopBackEnd;
 }
Example #4
0
 public ExternalGraphicsContext(DesktopBackend desktopBackEnd)
 {
     this.desktopBackEnd = desktopBackEnd;
 }
        public WinGLContext(GraphicsMode format, WinWindowInfo window, IGraphicsContext sharedContext,
                            int major, int minor, GraphicsContextFlags flags, DesktopBackend backEnd)
            : base(backEnd)
        {
            // There are many ways this code can break when accessed by multiple threads. The biggest offender is
            // the sharedContext stuff, which will only become valid *after* this constructor returns.
            // The easiest solution is to serialize all context construction - hence the big lock, below.
            lock (SyncRoot)
            {
                if (window == null)
                {
                    throw new ArgumentNullException("window", "Must point to a valid window.");
                }
                if (window.WindowHandle == IntPtr.Zero)
                {
                    throw new ArgumentException("window", "Must be a valid window.");
                }
                Mode = format;
                Debug.Print("OpenGL will be bound to handle: {0}", window.WindowHandle);
                Debug.Write("Setting pixel format... ");
                this.SetGraphicsModePFD(format, (WinWindowInfo)window);
                if (!wgl_loaded)
                {
                    // We need to create a temp context in order to load wgl extensions (e.g. for multisampling or GL3).
                    // We cannot rely on OpenTK.Platform.Wgl until we create the context and call Wgl.LoadAll().
                    Debug.Print("Creating temporary context for wgl extensions.");
                    ContextHandle temp_context = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
                    Wgl.Imports.MakeCurrent(window.DeviceContext, temp_context.Handle);
                    Wgl.LoadAll();
                    Wgl.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
                    Wgl.DeleteContext(temp_context.Handle);
                    wgl_loaded = true;
                }

                if (Wgl.Delegates.wglCreateContextAttribsARB != null)
                {
                    try
                    {
                        Debug.Write("Using WGL_ARB_create_context... ");
                        List <int> attributes = new List <int>();
                        attributes.Add((int)ArbCreateContext.MajorVersion);
                        attributes.Add(major);
                        attributes.Add((int)ArbCreateContext.MinorVersion);
                        attributes.Add(minor);
                        if (flags != 0)
                        {
                            attributes.Add((int)ArbCreateContext.Flags);
#warning "This is not entirely correct: Embedded is not a valid flag! We need to add a GetARBContextFlags(GraphicsContextFlags) method."
                            attributes.Add((int)flags);
                        }
                        // According to the docs, " <attribList> specifies a list of attributes for the context.
                        // The list consists of a sequence of <name,value> pairs terminated by the
                        // value 0. [...]"
                        // Is this a single 0, or a <0, 0> pair? (Defensive coding: add two zeroes just in case).
                        attributes.Add(0);
                        attributes.Add(0);
                        Handle = new ContextHandle(
                            Wgl.Arb.CreateContextAttribs(
                                window.DeviceContext,
                                sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero,
                                attributes.ToArray()));
                        if (Handle == ContextHandle.Zero)
                        {
                            Debug.Print("failed. (Error: {0})", Marshal.GetLastWin32Error());
                        }
                        else
                        {
                            Debug.Print("success!");
                        }
                    }
                    catch (EntryPointNotFoundException e) { Debug.Print(e.ToString()); }
                    catch (NullReferenceException e) { Debug.Print(e.ToString()); }
                }

                if (Handle == ContextHandle.Zero)
                {
                    // Failed to create GL3-level context, fall back to GL2.
                    Debug.Write("Falling back to GL2... ");
                    Handle = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
                    if (Handle == ContextHandle.Zero)
                    {
                        Handle = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
                    }
                    if (Handle == ContextHandle.Zero)
                    {
                        throw new GraphicsContextException(
                                  String.Format("Context creation failed. Wgl.CreateContext() error: {0}.",
                                                Marshal.GetLastWin32Error()));
                    }
                }

                Debug.WriteLine(String.Format("success! (id: {0})", Handle));
                if (sharedContext != null)
                {
                    Marshal.GetLastWin32Error();
                    Debug.Write("Sharing state with context {0}: ", sharedContext.ToString());
                    bool result = Wgl.Imports.ShareLists((sharedContext as IGraphicsContextInternal).Context.Handle, Handle.Handle);
                    Debug.WriteLine(result ? "success!" : "failed with win32 error " + Marshal.GetLastWin32Error());
                }
            }
        }
Example #6
0
 public WinFactory(DesktopBackend desktopBackEnd)
 {
     this.desktopBackEnd = desktopBackEnd;
 }
Example #7
0
 public WinFactory(DesktopBackend desktopBackEnd)
 {
     this.desktopBackEnd = desktopBackEnd;
 }
Example #8
0
        public WinGLContext(GraphicsMode format, WinWindowInfo window, IGraphicsContext sharedContext,
            int major, int minor, GraphicsContextFlags flags, DesktopBackend backEnd)
            : base(backEnd)
        {
            // There are many ways this code can break when accessed by multiple threads. The biggest offender is
            // the sharedContext stuff, which will only become valid *after* this constructor returns.
            // The easiest solution is to serialize all context construction - hence the big lock, below.
            lock (SyncRoot)
            {
                if (window == null)
                    throw new ArgumentNullException("window", "Must point to a valid window.");
                if (window.WindowHandle == IntPtr.Zero)
                    throw new ArgumentException("window", "Must be a valid window.");
                Mode = format;
                Debug.Print("OpenGL will be bound to handle: {0}", window.WindowHandle);
                Debug.Write("Setting pixel format... ");
                this.SetGraphicsModePFD(format, (WinWindowInfo)window);
                if (!wgl_loaded)
                {
                    // We need to create a temp context in order to load wgl extensions (e.g. for multisampling or GL3).
                    // We cannot rely on OpenTK.Platform.Wgl until we create the context and call Wgl.LoadAll().
                    Debug.Print("Creating temporary context for wgl extensions.");
                    ContextHandle temp_context = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
                    Wgl.Imports.MakeCurrent(window.DeviceContext, temp_context.Handle);
                    Wgl.LoadAll();
                    Wgl.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
                    Wgl.DeleteContext(temp_context.Handle);
                    wgl_loaded = true;
                }

                if (Wgl.Delegates.wglCreateContextAttribsARB != null)
                {
                    try
                    {
                        Debug.Write("Using WGL_ARB_create_context... ");
                        List<int> attributes = new List<int>();
                        attributes.Add((int)ArbCreateContext.MajorVersion);
                        attributes.Add(major);
                        attributes.Add((int)ArbCreateContext.MinorVersion);
                        attributes.Add(minor);
                        if (flags != 0)
                        {
                            attributes.Add((int)ArbCreateContext.Flags);
#warning "This is not entirely correct: Embedded is not a valid flag! We need to add a GetARBContextFlags(GraphicsContextFlags) method."
                            attributes.Add((int)flags);
                        }
                        // According to the docs, " <attribList> specifies a list of attributes for the context.
                        // The list consists of a sequence of <name,value> pairs terminated by the
                        // value 0. [...]"
                        // Is this a single 0, or a <0, 0> pair? (Defensive coding: add two zeroes just in case).
                        attributes.Add(0);
                        attributes.Add(0);
                        Handle = new ContextHandle(
                            Wgl.Arb.CreateContextAttribs(
                                window.DeviceContext,
                                sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero,
                                attributes.ToArray()));
                        if (Handle == ContextHandle.Zero)
                            Debug.Print("failed. (Error: {0})", Marshal.GetLastWin32Error());
                        else
                            Debug.Print("success!");
                    }
                    catch (EntryPointNotFoundException e) { Debug.Print(e.ToString()); }
                    catch (NullReferenceException e) { Debug.Print(e.ToString()); }
                }

                if (Handle == ContextHandle.Zero)
                {
                    // Failed to create GL3-level context, fall back to GL2.
                    Debug.Write("Falling back to GL2... ");
                    Handle = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
                    if (Handle == ContextHandle.Zero)
                        Handle = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
                    if (Handle == ContextHandle.Zero)
                        throw new GraphicsContextException(
                            String.Format("Context creation failed. Wgl.CreateContext() error: {0}.",
                                Marshal.GetLastWin32Error()));
                }

                Debug.WriteLine(String.Format("success! (id: {0})", Handle));
                if (sharedContext != null)
                {
                    Marshal.GetLastWin32Error();
                    Debug.Write("Sharing state with context {0}: ", sharedContext.ToString());
                    bool result = Wgl.Imports.ShareLists((sharedContext as IGraphicsContextInternal).Context.Handle, Handle.Handle);
                    Debug.WriteLine(result ? "success!" : "failed with win32 error " + Marshal.GetLastWin32Error());
                }
            }
        }
Example #9
0
 public WinGLContext(ContextHandle handle, WinWindowInfo window, IGraphicsContext sharedContext,
     int major, int minor, GraphicsContextFlags flags, DesktopBackend backEnd)
     : base(backEnd)
 {
     if (handle == ContextHandle.Zero)
         throw new ArgumentException("handle");
     if (window == null)
         throw new ArgumentNullException("window");
     Handle = handle;
 }
 public DesktopGraphicsContext(DesktopBackend desktopBackEnd)
 {
     this.desktopBackEnd = desktopBackEnd;
 }