wglDeleteContext() приватный Метод

private wglDeleteContext ( IntPtr hrc ) : int
hrc IntPtr
Результат int
        /// <summary>
        /// Only valid to be called after the render context is created, this function attempts to
        /// move the render context to the OpenGL version originally requested. If this is &gt; 2.1, this
        /// means building a new context. If this fails, we'll have to make do with 2.1.
        /// </summary>
        protected void UpdateContextVersion()
        {
            //  If the request version number is anything up to and including 2.1, standard render contexts
            //  will provide what we need (as long as the graphics card drivers are up to date).

            //  Now the none-trivial case. We must use the WGL_ARB_create_context extension to
            //  attempt to create a 3.0+ context.
            try
            {
                int[] attributes =
                {
                    OpenGL.WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
                    OpenGL.WGL_CONTEXT_MINOR_VERSION_ARB, 1,
                    OpenGL.WGL_CONTEXT_FLAGS_ARB,         OpenGL.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, // compatible profile
#if DEBUG
                    OpenGL.WGL_CONTEXT_FLAGS_ARB,         OpenGL.WGL_CONTEXT_DEBUG_BIT_ARB,              // this is a debug context
#endif
                    0
                };
                IntPtr hrc = OpenGL.GetDelegateFor <OpenGL.wglCreateContextAttribsARB>()(this.DeviceContextHandle, IntPtr.Zero, attributes);
                Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
                Win32.wglDeleteContext(this.RenderContextHandle);
                Win32.wglMakeCurrent(this.DeviceContextHandle, hrc);
                this.RenderContextHandle = hrc;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
 /// <summary>
 ///
 /// </summary>
 protected virtual void DisposeUnmanagedResources()
 {
     // If we have a render context, destroy it.
     if (this.RenderContextHandle != IntPtr.Zero)
     {
         Win32.wglDeleteContext(this.RenderContextHandle);
         this.RenderContextHandle = IntPtr.Zero;
     }
 }
Пример #3
0
 /// <summary>
 /// Destroys the render context provider instance.
 /// </summary>
 public virtual void Destroy()
 {
     //  If we have a render context, destroy it.
     if (RenderContextHandle != IntPtr.Zero)
     {
         Win32.wglDeleteContext(RenderContextHandle);
         RenderContextHandle = IntPtr.Zero;
     }
 }
        /// <summary>
        /// Destroys the render context provider instance.
        /// </summary>
        protected override void DisposeUnmanagedResources()
        {
            //	Release the device context.
            Win32.ReleaseDC(windowHandle, this.DeviceContextHandle);

            //	Destroy the window.
            Win32.DestroyWindow(windowHandle);

            // If we have a render context, destroy it.
            if (this.RenderContextHandle != IntPtr.Zero)
            {
                Win32.wglDeleteContext(this.RenderContextHandle);
                this.RenderContextHandle = IntPtr.Zero;
            }
        }
Пример #5
0
        /// <summary>
        /// Only valid to be called after the render context is created, this function attempts to
        /// move the render context to the OpenGL version originally requested. If this is &gt; 2.1, this
        /// means building a new context. If this fails, we'll have to make do with 2.1.
        /// </summary>
        protected void UpdateContextVersion()
        {
            //  If the request version number is anything up to and including 2.1, standard render contexts
            //  will provide what we need (as long as the graphics card drivers are up to date).

            //  Now the none-trivial case. We must use the WGL_create_context extension to
            //  attempt to create a 3.0+ context.
            int major, minor;

            GetHighestVersion(out major, out minor);
            if ((major > 2) || (major == 2 && minor > 1))
            {
                try
                {
                    //OpenGL.WGL_CONTEXT_MAJOR_VERSION_ARB, requestedVersionNumber.Major,  kw
                    //OpenGL.WGL_CONTEXT_MINOR_VERSION_ARB, requestedVersionNumber.Minor,
                    //OpenGL.WGL_CONTEXT_FLAGS_ARB, OpenGL.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,

                    int[] attributes =
                    {
                        GL.WGL_CONTEXT_MAJOR_VERSION, major,
                        GL.WGL_CONTEXT_MINOR_VERSION, minor,
                        GL.WGL_CONTEXT_FLAGS,         GL.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT,// compatible profile
//#if DEBUG
//                        GL.WGL_CONTEXT_FLAGS, GL.WGL_CONTEXT_DEBUG_BIT,// this is a debug context
//#endif
                        0
                    };
                    var    wglCreateContextAttribs = GL.Instance.GetDelegateFor("wglCreateContextAttribsARB", GLDelegates.typeof_IntPtr_IntPtr_IntPtr_intN) as GLDelegates.IntPtr_IntPtr_IntPtr_intN;
                    IntPtr hrc = wglCreateContextAttribs(this.DeviceContextHandle, IntPtr.Zero, attributes);
                    Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
                    Win32.wglDeleteContext(this.RenderContextHandle);
                    Win32.wglMakeCurrent(this.DeviceContextHandle, hrc);
                    this.RenderContextHandle = hrc;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }
        /// <summary>
        /// Only valid to be called after the render context is created, this function attempts to
        /// move the render context to the OpenGL version originally requested. If this is &gt; 2.1, this
        /// means building a new context. If this fails, we'll have to make do with 2.1.
        /// </summary>
        protected void UpdateContextVersion()
        {
            //  If the request version number is anything up to and including 2.1, standard render contexts
            //  will provide what we need (as long as the graphics card drivers are up to date).
            var requestedVersionNumber = VersionAttribute.GetVersionAttribute(this.RequestedGLVersion);

            if (requestedVersionNumber.IsAtLeastVersion(3, 0) == false)
            {
                this.CreatedGLVersion = this.RequestedGLVersion;
                return;
            }

            //  Now the none-trivial case. We must use the WGL_ARB_create_context extension to
            //  attempt to create a 3.0+ context.
            try
            {
                int[] attributes =
                {
                    OpenGL.WGL_CONTEXT_MAJOR_VERSION_ARB, requestedVersionNumber.Major,
                    OpenGL.WGL_CONTEXT_MINOR_VERSION_ARB, requestedVersionNumber.Minor,
                    OpenGL.WGL_CONTEXT_FLAGS_ARB,         OpenGL.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, // compatible profile
#if DEBUG
                    OpenGL.WGL_CONTEXT_FLAGS_ARB,         OpenGL.WGL_CONTEXT_DEBUG_BIT_ARB,              // this is a debug context
#endif
                    0
                };
                IntPtr hrc = OpenGL.GetDelegateFor <OpenGL.wglCreateContextAttribsARB>()(this.DeviceContextHandle, IntPtr.Zero, attributes);
                Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
                Win32.wglDeleteContext(this.RenderContextHandle);
                Win32.wglMakeCurrent(this.DeviceContextHandle, hrc);
                this.RenderContextHandle = hrc;
            }
            catch (Exception)
            {
                //  TODO: can we actually get the real version?
                this.CreatedGLVersion = GLVersion.OpenGL2_1;
            }
        }
        /// <summary>
        /// Only valid to be called after the render context is created, this function attempts to
        /// move the render context to the OpenGL version originally requested. If this is &gt; 2.1, this
        /// means building a new context. If this fails, we'll have to make do with 2.1.
        /// </summary>
        /// <param name="parameters"></param>
        protected bool UpdateContextVersion(ContextGenerationParams parameters)
        {
            //  If the request version number is anything up to and including 2.1, standard render contexts
            //  will provide what we need (as long as the graphics card drivers are up to date).

            //  Now the none-trivial case. We must use the WGL_create_context extension to
            //  attempt to create a 3.0+ context.
            try
            {
                var wglChoosePixelFormatARB = GL.Instance.GetDelegateFor("wglChoosePixelFormatARB", GLDelegates.typeof_bool_IntPtr_intN_floatN_uint_intN_uintN) as GLDelegates.bool_IntPtr_intN_floatN_uint_intN_uintN;
                if (wglChoosePixelFormatARB == null)
                {
                    return(false);
                }
                var wglCreateContextAttribs = GL.Instance.GetDelegateFor("wglCreateContextAttribsARB", GLDelegates.typeof_IntPtr_IntPtr_IntPtr_intN) as GLDelegates.IntPtr_IntPtr_IntPtr_intN;
                if (wglCreateContextAttribs == null)
                {
                    return(false);
                }

                int major, minor;
                GetHighestVersion(out major, out minor);
                if ((major > 2) || (major == 2 && minor > 1))
                {
                    int[] attribList = new int[]
                    {
                        WinGL.WGL_SUPPORT_OPENGL_ARB, (int)GL.GL_TRUE,
                        WinGL.WGL_DRAW_TO_WINDOW_ARB, (int)GL.GL_TRUE,
                        WinGL.WGL_DOUBLE_BUFFER_ARB, (int)GL.GL_TRUE,
                        WinGL.WGL_ACCELERATION_ARB, WinGL.WGL_FULL_ACCELERATION_ARB,
                        WinGL.WGL_PIXEL_TYPE_ARB, WinGL.WGL_TYPE_RGBA_ARB,
                        WinGL.WGL_COLOR_BITS_ARB, parameters.ColorBits,
                        WinGL.WGL_ACCUM_BITS_ARB, parameters.AccumBits,
                        WinGL.WGL_ACCUM_RED_BITS_ARB, parameters.AccumRedBits,
                        WinGL.WGL_ACCUM_GREEN_BITS_ARB, parameters.AccumGreenBits,
                        WinGL.WGL_ACCUM_BLUE_BITS_ARB, parameters.AccumBlueBits,
                        WinGL.WGL_ACCUM_ALPHA_BITS_ARB, parameters.AccumAlphaBits,
                        WinGL.WGL_DEPTH_BITS_ARB, parameters.DepthBits,
                        WinGL.WGL_STENCIL_BITS_ARB, parameters.StencilBits,
                        0,        //End
                    };

                    IntPtr dc = this.DeviceContextHandle;
                    //	Match an appropriate pixel format
                    int[]  pixelFormat = new int[1];
                    uint[] numFormats  = new uint[1];
                    if (false == wglChoosePixelFormatARB(dc, attribList, null, 1, pixelFormat, numFormats))
                    {
                        return(false);
                    }
                    //	Sets the pixel format
                    if (false == Win32.SetPixelFormat(dc, pixelFormat[0], new PixelFormatDescriptor()))
                    {
                        return(false);
                    }

                    int[] attributes =
                    {
                        WinGL.WGL_CONTEXT_MAJOR_VERSION_ARB,
                        major,
                        WinGL.WGL_CONTEXT_MINOR_VERSION_ARB,
                        minor,
                        WinGL.WGL_CONTEXT_PROFILE_MASK_ARB,
                        WinGL.WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
//#if DEBUG
//                        GL.WGL_CONTEXT_FLAGS, GL.WGL_CONTEXT_DEBUG_BIT,// this is a debug context
//#endif
                        0
                    };
                    IntPtr hrc = wglCreateContextAttribs(dc, IntPtr.Zero, attributes);
                    Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
                    Win32.wglDeleteContext(this.RenderContextHandle);
                    Win32.wglMakeCurrent(dc, hrc);
                    this.RenderContextHandle = hrc;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Log.Write(ex);
            }

            return(true);
        }