/// <summary>
        /// Creates a context.
        /// </summary>
        /// <param name="sharedContext">
        /// A <see cref="IntPtr"/> that specify a context that will share objects with the returned one. If
        /// it is IntPtr.Zero, no sharing is performed.
        /// </param>
        /// <returns>
        /// A <see cref="IntPtr"/> that represents the handle of the created context. If the context cannot be
        /// created, it returns IntPtr.Zero.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown in the case <paramref name="sharedContext"/> is different from IntPtr.Zero, and the objects
        /// cannot be shared with it.
        /// </exception>
        public override IntPtr CreateContext(IntPtr sharedContext)
        {
            IntPtr renderContext = IntPtr.Zero;

            if (Wgl.CurrentExtensions == null || Wgl.CurrentExtensions.CreateContext_ARB == false)
            {
                try {
                    renderContext = Wgl.CreateContext(_DeviceContext);
                    if ((renderContext != IntPtr.Zero) && (sharedContext != IntPtr.Zero))
                    {
                        bool res = Wgl.ShareLists(renderContext, sharedContext);
                        Debug.Assert(res);
                    }

                    return(renderContext);
                } catch {
                    if (renderContext != IntPtr.Zero)
                    {
                        bool res = Wgl.DeleteContext(renderContext);
                        Debug.Assert(res);
                    }

                    throw;
                }
            }
            else
            {
                return(CreateContextAttrib(sharedContext, new int[] { Gl.NONE }));
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a context.
        /// </summary>
        /// <param name="sharedContext">
        /// A <see cref="IntPtr"/> that specify a context that will share objects with the returned one. If
        /// it is IntPtr.Zero, no sharing is performed.
        /// </param>
        /// <returns>
        /// A <see cref="IntPtr"/> that represents the handle of the created context. If the context cannot be
        /// created, it returns IntPtr.Zero.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown in the case <paramref name="sharedContext"/> is different from IntPtr.Zero, and the objects
        /// cannot be shared with it.
        /// </exception>
        public override IntPtr CreateContext(IntPtr sharedContext)
        {
            IntPtr renderContext = IntPtr.Zero;

            try {
                renderContext = Wgl.CreateContext(DeviceContext);
                if ((renderContext != IntPtr.Zero) && (sharedContext != IntPtr.Zero))
                {
                    bool res = Wgl.ShareLists(renderContext, sharedContext);
                    Debug.Assert(res);
                }

                return(renderContext);
            } catch {
                if (renderContext != IntPtr.Zero)
                {
                    bool res = Wgl.DeleteContext(renderContext);
                    Debug.Assert(res);
                }

                throw;
            }
        }