Esempio n. 1
0
        private IEnumerable <GraphicsMode> GetModesPFD(INativeWindow native)
        {
            WinWindowInfo         window        = native.WindowInfo as WinWindowInfo;
            IntPtr                deviceContext = window.DeviceContext;
            PixelFormatDescriptor pfd           = new PixelFormatDescriptor();

            pfd.Size    = API.PixelFormatDescriptorSize;
            pfd.Version = API.PixelFormatDescriptorVersion;
            pfd.Flags   = PixelFormatDescriptorFlags.DRAW_TO_WINDOW | PixelFormatDescriptorFlags.SUPPORT_OPENGL;
            if (Environment.OSVersion.Version.Major >= 6)
            {
                pfd.Flags |= PixelFormatDescriptorFlags.SUPPORT_COMPOSITION;
            }
            // ISSUE: reference to a compiler-generated field
            this.\u003C\u003E7__wrapc = new bool[2]
            {
                false,
                true
            };
            bool[] flagArray;
            for (int index = 0; index < flagArray.Length; ++index)
            {
                bool generic_allowed = flagArray[index];
                int  pixel           = 0;
                while (WinGraphicsMode.DescribePixelFormat(deviceContext, ++pixel, (int)API.PixelFormatDescriptorSize, ref pfd) != 0)
                {
                    if (generic_allowed || (pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) == (PixelFormatDescriptorFlags)0)
                    {
                        GraphicsMode fmt = new GraphicsMode(new IntPtr?((IntPtr)pixel), new ColorFormat((int)pfd.RedBits, (int)pfd.GreenBits, (int)pfd.BlueBits, (int)pfd.AlphaBits), (int)pfd.DepthBits, (int)pfd.StencilBits, 0, new ColorFormat((int)pfd.AccumBits), (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != (PixelFormatDescriptorFlags)0 ? 2 : 1, (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != (PixelFormatDescriptorFlags)0);
                        yield return(fmt);
                    }
                }
            }
        }
Esempio n. 2
0
        // Note: there is no relevant ARB function.
        internal static void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
        {
            Debug.Write("Setting pixel format... ");

            if (!mode.Index.HasValue)
            {
                throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
            }

            if (window == null)
            {
                throw new ArgumentNullException("window", "Must point to a valid window.");
            }

            PixelFormatDescriptor pfd = new PixelFormatDescriptor();

            Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index.Value,
                                          API.PixelFormatDescriptorSize, ref pfd);
            Debug.WriteLine(mode.Index.ToString());
            if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd))
            {
                throw new GraphicsContextException(String.Format(
                                                       "Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error()));
            }
        }
Esempio n. 3
0
        // Note: there is no relevant ARB function.
        internal static GraphicsMode SetGraphicsModePFD(WinGraphicsMode mode_selector,
                                                        GraphicsMode mode, WinWindowInfo window)
        {
            Debug.Write("Setting pixel format... ");
            if (window == null)
            {
                throw new ArgumentNullException("window", "Must point to a valid window.");
            }

            if (!mode.Index.HasValue)
            {
                mode = mode_selector.SelectGraphicsMode(
                    mode.ColorFormat, mode.Depth, mode.Stencil,
                    mode.Samples, mode.AccumulatorFormat,
                    mode.Buffers, mode.Stereo);
            }

            PixelFormatDescriptor pfd = new PixelFormatDescriptor();

            Functions.DescribePixelFormat(
                window.DeviceContext, (int)mode.Index.Value,
                API.PixelFormatDescriptorSize, ref pfd);

            Debug.WriteLine(mode.Index.ToString());

            if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd))
            {
                throw new GraphicsContextException(String.Format(
                                                       "Requested GraphicsMode not available. SetPixelFormat error: {0}",
                                                       Marshal.GetLastWin32Error()));
            }

            return(mode);
        }
Esempio n. 4
0
 int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd)
 {
     unsafe
     {
         fixed (PixelFormatDescriptor* pPfd_ptr = &pPfd)
         {
             return Delegates.wglChoosePixelFormat((IntPtr)hDc, (PixelFormatDescriptor*)pPfd_ptr);
         }
     }
 }
Esempio n. 5
0
 int DescribePixelFormat(IntPtr hdc, int ipfd, UInt32 cjpfd, PixelFormatDescriptor[] ppfd)
 {
     unsafe
     {
         fixed (PixelFormatDescriptor* ppfd_ptr = ppfd)
         {
             return Delegates.wglDescribePixelFormat((IntPtr)hdc, (int)ipfd, (UInt32)cjpfd, (PixelFormatDescriptor*)ppfd_ptr);
         }
     }
 }
Esempio n. 6
0
 static int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor pfd)
 {
     unsafe
     {
         fixed(PixelFormatDescriptor *ppfd = &pfd)
         {
             // Note: DescribePixelFormat found in gdi32 is extremely slow
             // on nvidia, for some reason.
             return(Wgl.Imports.DescribePixelFormat(hdc, ipfd, (uint)cjpfd, ppfd));
         }
     }
 }
Esempio n. 7
0
        IEnumerable <GraphicsMode> GetModesPFD(INativeWindow native)
        {
            WinWindowInfo window        = native.WindowInfo as WinWindowInfo;
            IntPtr        deviceContext = ((WinWindowInfo)window).DeviceContext;

            Debug.WriteLine(String.Format("Device context: {0}", deviceContext));

            Debug.WriteLine("Retrieving PFD pixel formats... ");
            PixelFormatDescriptor pfd = new PixelFormatDescriptor();

            pfd.Size    = API.PixelFormatDescriptorSize;
            pfd.Version = API.PixelFormatDescriptorVersion;
            pfd.Flags   =
                PixelFormatDescriptorFlags.SUPPORT_OPENGL |
                PixelFormatDescriptorFlags.DRAW_TO_WINDOW;

            // Make sure we don't turn off Aero on Vista and newer.
            if (Environment.OSVersion.Version.Major >= 6)
            {
                pfd.Flags |= PixelFormatDescriptorFlags.SUPPORT_COMPOSITION;
            }

            foreach (bool generic_allowed in new bool[] { false, true })
            {
                // Iterate through all accelerated formats first. Afterwards, iterate through non-accelerated formats.
                // This should fix issue #2224, which causes OpenTK to fail on VMs without hardware acceleration.
                int pixel = 0;
                while (DescribePixelFormat(deviceContext, ++pixel, API.PixelFormatDescriptorSize, ref pfd) != 0)
                {
                    // Ignore non-accelerated formats.
                    if (!generic_allowed && (pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0)
                    {
                        continue;
                    }

                    GraphicsMode fmt = new GraphicsMode((IntPtr)pixel,
                                                        new ColorFormat(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
                                                        pfd.DepthBits,
                                                        pfd.StencilBits,
                                                        0,
                                                        new ColorFormat(pfd.AccumBits),
                                                        (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
                                                        (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);

                    yield return(fmt);
                }
            }
        }
Esempio n. 8
0
        void SetGraphicsModePFD(GraphicsMode mode, WinWindow window)
        {
            // Find out what we really got as a format:
            IntPtr deviceContext      = window.DeviceContext;
            PixelFormatDescriptor pfd = new PixelFormatDescriptor();

            pfd.Size    = PixelFormatDescriptor.DefaultSize;
            pfd.Version = PixelFormatDescriptor.DefaultVersion;
            API.DescribePixelFormat(deviceContext, modeIndex, pfd.Size, ref pfd);

            Debug.Print("WGL mode index: " + modeIndex.ToString());
            if (!API.SetPixelFormat(window.DeviceContext, modeIndex, ref pfd))
            {
                throw new GraphicsContextException("SetPixelFormat failed. " +
                                                   "Error: " + Marshal.GetLastWin32Error());
            }
        }
Esempio n. 9
0
        static AccelerationType GetAccelerationType(ref PixelFormatDescriptor pfd)
        {
            AccelerationType type = AccelerationType.ICD;

            if ((pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0)
            {
                if ((pfd.Flags & PixelFormatDescriptorFlags.GENERIC_ACCELERATED) != 0)
                {
                    type = AccelerationType.MCD;
                }
                else
                {
                    type = AccelerationType.None;
                }
            }
            return(type);
        }
Esempio n. 10
0
        private void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
        {
            if (!mode.Index.HasValue)
            {
                throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
            }
            if (window == null)
            {
                throw new ArgumentNullException("window", "Must point to a valid window.");
            }
            PixelFormatDescriptor formatDescriptor = new PixelFormatDescriptor();

            Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index.Value, (int)API.PixelFormatDescriptorSize, ref formatDescriptor);
            if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref formatDescriptor))
            {
                throw new GraphicsContextException(string.Format("Requested GraphicsMode not available. SetPixelFormat error: {0}", (object)Marshal.GetLastWin32Error()));
            }
        }
        private static AccelerationType GetAccelerationType(ref PixelFormatDescriptor pfd)
        {
            var type = AccelerationType.ICD;

            if ((pfd.Flags & PixelFormatDescriptorFlags.GenericFormat) != 0)
            {
                if ((pfd.Flags & PixelFormatDescriptorFlags.GenericAccelerated) != 0)
                {
                    type = AccelerationType.MCD;
                }
                else
                {
                    type = AccelerationType.None;
                }
            }

            return(type);
        }
Esempio n. 12
0
        static GraphicsMode DescribePixelFormatPFD(IntPtr device, ref PixelFormatDescriptor pfd,
                                                   int pixelformat)
        {
            GraphicsMode created_mode = null;

            if (Functions.DescribePixelFormat(device, pixelformat, pfd.Size, ref pfd) > 0)
            {
                created_mode = new GraphicsMode(
                    new IntPtr(pixelformat),
                    new ColorFormat(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
                    pfd.DepthBits,
                    pfd.StencilBits,
                    0, // MSAA not supported when using PixelFormatDescriptor
                    new ColorFormat(pfd.AccumRedBits, pfd.AccumGreenBits, pfd.AccumBlueBits, pfd.AccumAlphaBits),
                    (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
                    (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);
            }
            return(created_mode);
        }
Esempio n. 13
0
        void SelectGraphicsModePFD(GraphicsMode format, WinWindowInfo window)
        {
            IntPtr deviceContext = window.DeviceContext;

            Debug.Print("Device context: {0}", deviceContext);
            ColorFormat color = format.ColorFormat;

            Debug.Print("Selecting pixel format PFD... ");
            PixelFormatDescriptor pfd = new PixelFormatDescriptor();

            pfd.Size    = PixelFormatDescriptor.DefaultSize;
            pfd.Version = PixelFormatDescriptor.DefaultVersion;
            pfd.Flags   =
                PixelFormatDescriptorFlags.SUPPORT_OPENGL |
                PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
            pfd.ColorBits = (byte)(color.Red + color.Green + color.Blue);

            pfd.PixelType = color.IsIndexed ? PixelType.INDEXED : PixelType.RGBA;
            pfd.RedBits   = (byte)color.Red;
            pfd.GreenBits = (byte)color.Green;
            pfd.BlueBits  = (byte)color.Blue;
            pfd.AlphaBits = (byte)color.Alpha;

            pfd.DepthBits   = (byte)format.Depth;
            pfd.StencilBits = (byte)format.Stencil;

            if (format.Depth <= 0)
            {
                pfd.Flags |= PixelFormatDescriptorFlags.DEPTH_DONTCARE;
            }
            if (format.Buffers > 1)
            {
                pfd.Flags |= PixelFormatDescriptorFlags.DOUBLEBUFFER;
            }

            modeIndex = API.ChoosePixelFormat(deviceContext, ref pfd);
            if (modeIndex == 0)
            {
                throw new GraphicsModeException("The requested GraphicsMode is not available.");
            }
        }
Esempio n. 14
0
        void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
        {
            // Find out what we really got as a format:
            IntPtr deviceContext      = window.DeviceContext;
            PixelFormatDescriptor pfd = new PixelFormatDescriptor();

            pfd.Size    = PixelFormatDescriptor.DefaultSize;
            pfd.Version = PixelFormatDescriptor.DefaultVersion;
            API.DescribePixelFormat(deviceContext, modeIndex, pfd.Size, ref pfd);

            Mode = new GraphicsMode(
                new ColorFormat(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
                pfd.DepthBits, pfd.StencilBits,
                (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1);

            Debug.Print("WGL mode index: " + modeIndex.ToString());
            if (!API.SetPixelFormat(window.DeviceContext, modeIndex, ref pfd))
            {
                throw new GraphicsContextException(String.Format(
                                                       "Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error()));
            }
        }
Esempio n. 15
0
 internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);
Esempio n. 16
0
 internal extern static Boolean SetPixelFormat(IntPtr hdc, int ipfd, ref PixelFormatDescriptor ppfd);
Esempio n. 17
0
 internal extern static unsafe int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd);
Esempio n. 18
0
        IEnumerable<GraphicsMode> GetModesPFD(INativeWindow native)
        {
            WinWindowInfo window = native.WindowInfo as WinWindowInfo;
            IntPtr deviceContext = ((WinWindowInfo)window).DeviceContext;
            Debug.WriteLine(String.Format("Device context: {0}", deviceContext));

            Debug.WriteLine("Retrieving PFD pixel formats... ");
            PixelFormatDescriptor pfd = new PixelFormatDescriptor();
            pfd.Size = API.PixelFormatDescriptorSize;
            pfd.Version = API.PixelFormatDescriptorVersion;
            pfd.Flags =
                PixelFormatDescriptorFlags.SUPPORT_OPENGL |
                PixelFormatDescriptorFlags.DRAW_TO_WINDOW;

            // Make sure we don't turn off Aero on Vista and newer.
            if (Environment.OSVersion.Version.Major >= 6)
            {
                pfd.Flags |= PixelFormatDescriptorFlags.SUPPORT_COMPOSITION;
            }

            foreach (bool generic_allowed in new bool[] { false, true })
            {
                // Iterate through all accelerated formats first. Afterwards, iterate through non-accelerated formats.
                // This should fix issue #2224, which causes OpenTK to fail on VMs without hardware acceleration.
                int pixel = 0;
                while (DescribePixelFormat(deviceContext, ++pixel, API.PixelFormatDescriptorSize, ref pfd) != 0)
                {
                    // Ignore non-accelerated formats.
                    if (!generic_allowed && (pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0)
                        continue;

                    GraphicsMode fmt = new GraphicsMode((IntPtr)pixel,
                        new ColorFormat(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
                        pfd.DepthBits,
                        pfd.StencilBits,
                        0,
                        new ColorFormat(pfd.AccumBits),
                        (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
                        (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);

                    yield return fmt;
                }
            }
        }
Esempio n. 19
0
 private static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor pfd)
 {
     fixed (PixelFormatDescriptor* ppfd = &pfd)
     return Wgl.Imports.DescribePixelFormat(hdc, ipfd, (uint) cjpfd, ppfd);
 }
Esempio n. 20
0
File: Wgl.cs Progetto: Zeludon/FEZ
 internal static bool SetPixelFormat(IntPtr hdc, int ipfd, PixelFormatDescriptor* ppfd);
Esempio n. 21
0
 internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, UInt32 cjpfd, PixelFormatDescriptor* ppfd);
Esempio n. 22
0
File: Wgl.cs Progetto: Roku97/opentk
 internal extern static unsafe int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd);
Esempio n. 23
0
 private static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor pfd)
 {
     fixed(PixelFormatDescriptor *ppfd = &pfd)
     return(Wgl.Imports.DescribePixelFormat(hdc, ipfd, (uint)cjpfd, ppfd));
 }
Esempio n. 24
0
File: Wgl.cs Progetto: Zeludon/FEZ
 public static unsafe int ChoosePixelFormat(IntPtr hDc, PixelFormatDescriptor* pPfd)
 {
     return Wgl.Delegates.wglChoosePixelFormat(hDc, pPfd);
 }
Esempio n. 25
0
File: Wgl.cs Progetto: Zeludon/FEZ
 public static unsafe int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd)
 {
     fixed (PixelFormatDescriptor* pPfd1 = &pPfd)
     return Wgl.Delegates.wglChoosePixelFormat(hDc, pPfd1);
 }
Esempio n. 26
0
File: Wgl.cs Progetto: Zeludon/FEZ
 public static unsafe bool SetPixelFormat(IntPtr hdc, int ipfd, PixelFormatDescriptor* ppfd)
 {
     return Wgl.Delegates.wglSetPixelFormat(hdc, ipfd, ppfd);
 }
Esempio n. 27
0
File: Wgl.cs Progetto: Zeludon/FEZ
 public static unsafe bool SetPixelFormat(IntPtr hdc, int ipfd, ref PixelFormatDescriptor ppfd)
 {
     fixed (PixelFormatDescriptor* ppfd1 = &ppfd)
     return Wgl.Delegates.wglSetPixelFormat(hdc, ipfd, ppfd1);
 }
Esempio n. 28
0
 internal static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd);
Esempio n. 29
0
 internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);
Esempio n. 30
0
 internal extern static unsafe Boolean SetPixelFormat(IntPtr hdc, int ipfd, PixelFormatDescriptor* ppfd);
Esempio n. 31
0
File: Wgl.cs Progetto: Zeludon/FEZ
 public static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, uint cjpfd, PixelFormatDescriptor[] ppfd)
 {
     fixed (PixelFormatDescriptor* ppfd1 = ppfd)
     return Wgl.Delegates.wglDescribePixelFormat(hdc, ipfd, cjpfd, ppfd1);
 }
Esempio n. 32
0
 private void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
 {
     if (!mode.Index.HasValue)
     throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
       if (window == null)
     throw new ArgumentNullException("window", "Must point to a valid window.");
       PixelFormatDescriptor formatDescriptor = new PixelFormatDescriptor();
       Functions.DescribePixelFormat(window.DeviceContext, (int) mode.Index.Value, (int) API.PixelFormatDescriptorSize, ref formatDescriptor);
       if (!Functions.SetPixelFormat(window.DeviceContext, (int) mode.Index.Value, ref formatDescriptor))
     throw new GraphicsContextException(string.Format("Requested GraphicsMode not available. SetPixelFormat error: {0}", (object) Marshal.GetLastWin32Error()));
 }
Esempio n. 33
0
 static int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor pfd)
 {
     unsafe
     {
         fixed (PixelFormatDescriptor* ppfd = &pfd)
         {
             // Note: DescribePixelFormat found in gdi32 is extremely slow
             // on nvidia, for some reason.
             return Wgl.Imports.DescribePixelFormat(hdc, ipfd, (uint)cjpfd, ppfd);
         }
     }
 }
Esempio n. 34
0
 static AccelerationType GetAccelerationType(ref PixelFormatDescriptor pfd)
 {
     AccelerationType type = AccelerationType.ICD;
     if ((pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0)
     {
         if ((pfd.Flags & PixelFormatDescriptorFlags.GENERIC_ACCELERATED) != 0)
         {
             type = AccelerationType.MCD;
         }
         else
         {
             type = AccelerationType.None;
         }
     }
     return type;
 }
Esempio n. 35
0
File: Wgl.cs Progetto: Roku97/opentk
 internal extern static Boolean SetPixelFormat(IntPtr hdc, int ipfd, ref PixelFormatDescriptor ppfd);
Esempio n. 36
0
        GraphicsMode ChoosePixelFormatPFD(IntPtr device, GraphicsMode mode, AccelerationType requested_acceleration_type)
        {
            PixelFormatDescriptor pfd = new PixelFormatDescriptor();
            PixelFormatDescriptorFlags flags = 0;
            flags |= PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
            flags |= PixelFormatDescriptorFlags.SUPPORT_OPENGL;

            if (mode.Stereo)
            {
                flags |= PixelFormatDescriptorFlags.STEREO;
            }

            if (System.Environment.OSVersion.Version.Major >= 6 &&
                requested_acceleration_type != AccelerationType.None)
            {
                // Request a compositor-capable mode when running on
                // Vista+ and using hardware acceleration. Without this,
                // some modes will cause the compositor to turn off,
                // which is very annoying to the user.
                // Note: compositor-capable modes require hardware
                // acceleration. Don't set this flag when running
                // with software acceleration (e.g. over Remote Desktop
                // as described in bug https://github.com/opentk/opentk/issues/35)
                flags |= PixelFormatDescriptorFlags.SUPPORT_COMPOSITION;
            }

            int count = Functions.DescribePixelFormat(device, 1, API.PixelFormatDescriptorSize, ref pfd);

            int best = 0;
            int best_dist = int.MaxValue;
            for (int index = 1; index <= count; index++)
            {
                int dist = 0;
                bool valid = Functions.DescribePixelFormat(device, index, API.PixelFormatDescriptorSize, ref pfd) != 0;
                valid &= GetAccelerationType(ref pfd) == requested_acceleration_type;
                valid &= (pfd.Flags & flags) == flags;
                valid &= pfd.PixelType == PixelType.RGBA; // indexed modes not currently supported
                // heavily penalize single-buffered modes when the user requests double buffering
                if ((pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) == 0 && mode.Buffers > 1)
                    dist += 1000;
                valid &= Compare(pfd.ColorBits, mode.ColorFormat.BitsPerPixel, ref dist);
                valid &= Compare(pfd.RedBits, mode.ColorFormat.Red, ref dist);
                valid &= Compare(pfd.GreenBits, mode.ColorFormat.Green, ref dist);
                valid &= Compare(pfd.BlueBits, mode.ColorFormat.Blue, ref dist);
                valid &= Compare(pfd.AlphaBits, mode.ColorFormat.Alpha, ref dist);
                valid &= Compare(pfd.AccumBits, mode.AccumulatorFormat.BitsPerPixel, ref dist);
                valid &= Compare(pfd.AccumRedBits, mode.AccumulatorFormat.Red, ref dist);
                valid &= Compare(pfd.AccumGreenBits, mode.AccumulatorFormat.Green, ref dist);
                valid &= Compare(pfd.AccumBlueBits, mode.AccumulatorFormat.Blue, ref dist);
                valid &= Compare(pfd.AccumAlphaBits, mode.AccumulatorFormat.Alpha, ref dist);
                valid &= Compare(pfd.DepthBits, mode.Depth, ref dist);
                valid &= Compare(pfd.StencilBits, mode.Stencil, ref dist);

                if (valid && dist < best_dist)
                {
                    best = index;
                    best_dist = dist;
                }
            }

            return DescribePixelFormatPFD(device, ref pfd, best);
        }
Esempio n. 37
0
 internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor ppfd);
Esempio n. 38
0
File: Wgl.cs Progetto: Zeludon/FEZ
 internal static int ChoosePixelFormat(IntPtr hDc, PixelFormatDescriptor* pPfd);
Esempio n. 39
0
        GraphicsMode SelectGraphicsModePFD(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum,
            int buffers, bool stereo)
        {
            using (Control native_window = new Control())
            using (WinWindowInfo window = new WinWindowInfo(native_window.Handle, null))
            {
                IntPtr deviceContext = ((WinWindowInfo)window).DeviceContext;
                Debug.WriteLine(String.Format("Device context: {0}", deviceContext));

                Debug.Write("Selecting pixel format... ");
                PixelFormatDescriptor pixelFormat = new PixelFormatDescriptor();
                pixelFormat.Size = API.PixelFormatDescriptorSize;
                pixelFormat.Version = API.PixelFormatDescriptorVersion;
                pixelFormat.Flags =
                    PixelFormatDescriptorFlags.SUPPORT_OPENGL |
                    PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
                pixelFormat.ColorBits = (byte)(color.Red + color.Green + color.Blue);

                pixelFormat.PixelType = color.IsIndexed ? PixelType.INDEXED : PixelType.RGBA;
                pixelFormat.RedBits = (byte)color.Red;
                pixelFormat.GreenBits = (byte)color.Green;
                pixelFormat.BlueBits = (byte)color.Blue;
                pixelFormat.AlphaBits = (byte)color.Alpha;

                if (accum.BitsPerPixel > 0)
                {
                    pixelFormat.AccumBits = (byte)(accum.Red + accum.Green + accum.Blue);
                    pixelFormat.AccumRedBits = (byte)accum.Red;
                    pixelFormat.AccumGreenBits = (byte)accum.Green;
                    pixelFormat.AccumBlueBits = (byte)accum.Blue;
                    pixelFormat.AccumAlphaBits = (byte)accum.Alpha;
                }

                pixelFormat.DepthBits = (byte)depth;
                pixelFormat.StencilBits = (byte)stencil;

                if (depth <= 0) pixelFormat.Flags |= PixelFormatDescriptorFlags.DEPTH_DONTCARE;
                if (stereo) pixelFormat.Flags |= PixelFormatDescriptorFlags.STEREO;
                if (buffers > 1) pixelFormat.Flags |= PixelFormatDescriptorFlags.DOUBLEBUFFER;

                int pixel = Functions.ChoosePixelFormat(deviceContext, ref pixelFormat);
                if (pixel == 0)
                    throw new GraphicsModeException("The requested GraphicsMode is not available.");

                // Find out what we really got as a format:
                PixelFormatDescriptor pfd = new PixelFormatDescriptor();
                pixelFormat.Size = API.PixelFormatDescriptorSize;
                pixelFormat.Version = API.PixelFormatDescriptorVersion;
                Functions.DescribePixelFormat(deviceContext, pixel, API.PixelFormatDescriptorSize, ref pfd);
                GraphicsMode fmt = new GraphicsMode((IntPtr)pixel,
                    new ColorDepth(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
                    pfd.DepthBits,
                    pfd.StencilBits,
                    0,
                    new ColorDepth(pfd.AccumBits),
                    (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
                    (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);

                return fmt;
            }
        }
Esempio n. 40
0
        GraphicsMode SelectGraphicsModePFD(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum,
                                           int buffers, bool stereo)
        {
            using (Control native_window = new Control())
                using (WinWindowInfo window = new WinWindowInfo(native_window.Handle, null))
                {
                    IntPtr deviceContext = ((WinWindowInfo)window).DeviceContext;
                    Debug.WriteLine(String.Format("Device context: {0}", deviceContext));

                    Debug.Write("Selecting pixel format... ");
                    PixelFormatDescriptor pixelFormat = new PixelFormatDescriptor();
                    pixelFormat.Size    = API.PixelFormatDescriptorSize;
                    pixelFormat.Version = API.PixelFormatDescriptorVersion;
                    pixelFormat.Flags   =
                        PixelFormatDescriptorFlags.SUPPORT_OPENGL |
                        PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
                    pixelFormat.ColorBits = (byte)(color.Red + color.Green + color.Blue);

                    pixelFormat.PixelType = color.IsIndexed ? PixelType.INDEXED : PixelType.RGBA;
                    pixelFormat.RedBits   = (byte)color.Red;
                    pixelFormat.GreenBits = (byte)color.Green;
                    pixelFormat.BlueBits  = (byte)color.Blue;
                    pixelFormat.AlphaBits = (byte)color.Alpha;

                    if (accum.BitsPerPixel > 0)
                    {
                        pixelFormat.AccumBits      = (byte)(accum.Red + accum.Green + accum.Blue);
                        pixelFormat.AccumRedBits   = (byte)accum.Red;
                        pixelFormat.AccumGreenBits = (byte)accum.Green;
                        pixelFormat.AccumBlueBits  = (byte)accum.Blue;
                        pixelFormat.AccumAlphaBits = (byte)accum.Alpha;
                    }

                    pixelFormat.DepthBits   = (byte)depth;
                    pixelFormat.StencilBits = (byte)stencil;

                    if (depth <= 0)
                    {
                        pixelFormat.Flags |= PixelFormatDescriptorFlags.DEPTH_DONTCARE;
                    }
                    if (stereo)
                    {
                        pixelFormat.Flags |= PixelFormatDescriptorFlags.STEREO;
                    }
                    if (buffers > 1)
                    {
                        pixelFormat.Flags |= PixelFormatDescriptorFlags.DOUBLEBUFFER;
                    }

                    int pixel = Functions.ChoosePixelFormat(deviceContext, ref pixelFormat);
                    if (pixel == 0)
                    {
                        throw new GraphicsModeException("The requested GraphicsMode is not available.");
                    }

                    // Find out what we really got as a format:
                    PixelFormatDescriptor pfd = new PixelFormatDescriptor();
                    pixelFormat.Size    = API.PixelFormatDescriptorSize;
                    pixelFormat.Version = API.PixelFormatDescriptorVersion;
                    Functions.DescribePixelFormat(deviceContext, pixel, API.PixelFormatDescriptorSize, ref pfd);
                    GraphicsMode fmt = new GraphicsMode((IntPtr)pixel,
                                                        new ColorDepth(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
                                                        pfd.DepthBits,
                                                        pfd.StencilBits,
                                                        0,
                                                        new ColorDepth(pfd.AccumBits),
                                                        (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
                                                        (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);

                    return(fmt);
                }
        }
Esempio n. 41
0
File: Wgl.cs Progetto: Zeludon/FEZ
 public static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, PixelFormatDescriptor* ppfd)
 {
     return Wgl.Delegates.wglDescribePixelFormat(hdc, ipfd, (uint) cjpfd, ppfd);
 }
Esempio n. 42
0
        // Note: there is no relevant ARB function.
        internal static GraphicsMode SetGraphicsModePFD(WinGraphicsMode mode_selector,
            GraphicsMode mode, WinWindowInfo window)
        {
            Debug.Write("Setting pixel format... ");
            if (window == null)
                throw new ArgumentNullException("window", "Must point to a valid window.");

            if (!mode.Index.HasValue)
            {
                mode = mode_selector.SelectGraphicsMode(
                    mode.ColorFormat, mode.Depth, mode.Stencil,
                    mode.Samples, mode.AccumulatorFormat,
                    mode.Buffers, mode.Stereo);
            }

            PixelFormatDescriptor pfd = new PixelFormatDescriptor();
            Functions.DescribePixelFormat(
                window.DeviceContext, (int)mode.Index.Value,
                API.PixelFormatDescriptorSize, ref pfd);
            
            Debug.WriteLine(mode.Index.ToString());
            
            if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd))
            {
                throw new GraphicsContextException(String.Format(
                    "Requested GraphicsMode not available. SetPixelFormat error: {0}",
                    Marshal.GetLastWin32Error()));
            }

            return mode;
        }
Esempio n. 43
0
 internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat);
Esempio n. 44
0
File: Wgl.cs Progetto: Zeludon/FEZ
 public static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor ppfd)
 {
     fixed (PixelFormatDescriptor* ppfd1 = &ppfd)
     return Wgl.Delegates.wglDescribePixelFormat(hdc, ipfd, (uint) cjpfd, ppfd1);
 }
Esempio n. 45
0
 internal static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd);
        private GraphicsMode ChoosePixelFormatPFD(IntPtr device, GraphicsMode mode,
                                                  AccelerationType requested_acceleration_type)
        {
            var pfd = new PixelFormatDescriptor();
            PixelFormatDescriptorFlags flags = 0;

            flags |= PixelFormatDescriptorFlags.DrawToWindow;
            flags |= PixelFormatDescriptorFlags.SupportOpenGL;

            if (mode.Stereo)
            {
                flags |= PixelFormatDescriptorFlags.Stereo;
            }

            if (Environment.OSVersion.Version.Major >= 6 &&
                requested_acceleration_type != AccelerationType.None)
            {
                // Request a compositor-capable mode when running on
                // Vista+ and using hardware acceleration. Without this,
                // some modes will cause the compositor to turn off,
                // which is very annoying to the user.
                // Note: compositor-capable modes require hardware
                // acceleration. Don't set this flag when running
                // with software acceleration (e.g. over Remote Desktop
                // as described in bug https://github.com/opentk/opentk/issues/35)
                flags |= PixelFormatDescriptorFlags.SupportComposition;
            }

            var count = Gdi32.DescribePixelFormat(device, 1, PixelFormatDescriptor.SizeInBytes, ref pfd);

            var best      = 0;
            var best_dist = int.MaxValue;

            for (var index = 1; index <= count; index++)
            {
                var dist  = 0;
                var valid = Gdi32.DescribePixelFormat(device, index, PixelFormatDescriptor.SizeInBytes, ref pfd) != 0;
                valid &= GetAccelerationType(ref pfd) == requested_acceleration_type;
                valid &= (pfd.Flags & flags) == flags;
                valid &= pfd.PixelType == PixelFormatDescriptorPixelTypes.Rgba; // indexed modes not currently supported
                // heavily penalize single-buffered modes when the user requests double buffering
                if ((pfd.Flags & PixelFormatDescriptorFlags.DoubleBuffer) == 0 && mode.Buffers > 1)
                {
                    dist += 1000;
                }

                valid &= Compare(pfd.ColorBits, mode.ColorFormat.BitsPerPixel, ref dist);
                valid &= Compare(pfd.RedBits, mode.ColorFormat.Red, ref dist);
                valid &= Compare(pfd.GreenBits, mode.ColorFormat.Green, ref dist);
                valid &= Compare(pfd.BlueBits, mode.ColorFormat.Blue, ref dist);
                valid &= Compare(pfd.AlphaBits, mode.ColorFormat.Alpha, ref dist);
                valid &= Compare(pfd.AccumBits, mode.AccumulatorFormat.BitsPerPixel, ref dist);
                valid &= Compare(pfd.AccumRedBits, mode.AccumulatorFormat.Red, ref dist);
                valid &= Compare(pfd.AccumGreenBits, mode.AccumulatorFormat.Green, ref dist);
                valid &= Compare(pfd.AccumBlueBits, mode.AccumulatorFormat.Blue, ref dist);
                valid &= Compare(pfd.AccumAlphaBits, mode.AccumulatorFormat.Alpha, ref dist);
                valid &= Compare(pfd.DepthBits, mode.Depth, ref dist);
                valid &= Compare(pfd.StencilBits, mode.Stencil, ref dist);

                if (valid && dist < best_dist)
                {
                    best      = index;
                    best_dist = dist;
                }
            }

            return(DescribePixelFormatPFD(device, ref pfd, best));
        }
Esempio n. 47
0
 internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat);
Esempio n. 48
0
File: Wgl.cs Progetto: Zeludon/FEZ
 internal static int DescribePixelFormat(IntPtr hdc, int ipfd, uint cjpfd, PixelFormatDescriptor* ppfd);
Esempio n. 49
0
 static GraphicsMode DescribePixelFormatPFD(IntPtr device, ref PixelFormatDescriptor pfd,
     int pixelformat)
 {
     GraphicsMode created_mode = null;
     if (Functions.DescribePixelFormat(device, pixelformat, pfd.Size, ref pfd) > 0)
     {
         created_mode = new GraphicsMode(
             new IntPtr(pixelformat),
             new ColorFormat(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
             pfd.DepthBits,
             pfd.StencilBits,
             0, // MSAA not supported when using PixelFormatDescriptor
             new ColorFormat(pfd.AccumRedBits, pfd.AccumGreenBits, pfd.AccumBlueBits, pfd.AccumAlphaBits),
             (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
             (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);
     }
     return created_mode;
 }
Esempio n. 50
0
File: Wgl.cs Progetto: Roku97/opentk
 internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor ppfd);
Esempio n. 51
0
        GraphicsMode ChoosePixelFormatPFD(IntPtr device, GraphicsMode mode, AccelerationType requested_acceleration_type)
        {
            PixelFormatDescriptor      pfd   = new PixelFormatDescriptor();
            PixelFormatDescriptorFlags flags = 0;

            flags |= PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
            flags |= PixelFormatDescriptorFlags.SUPPORT_OPENGL;

            if (mode.Stereo)
            {
                flags |= PixelFormatDescriptorFlags.STEREO;
            }

            if (System.Environment.OSVersion.Version.Major >= 6 &&
                requested_acceleration_type != AccelerationType.None)
            {
                // Request a compositor-capable mode when running on
                // Vista+ and using hardware acceleration. Without this,
                // some modes will cause the compositor to turn off,
                // which is very annoying to the user.
                // Note: compositor-capable modes require hardware
                // acceleration. Don't set this flag when running
                // with software acceleration (e.g. over Remote Desktop
                // as described in bug https://github.com/opentk/opentk/issues/35)
                flags |= PixelFormatDescriptorFlags.SUPPORT_COMPOSITION;
            }

            int count = Functions.DescribePixelFormat(device, 1, API.PixelFormatDescriptorSize, ref pfd);

            int best      = 0;
            int best_dist = int.MaxValue;

            for (int index = 1; index <= count; index++)
            {
                int  dist  = 0;
                bool valid = Functions.DescribePixelFormat(device, index, API.PixelFormatDescriptorSize, ref pfd) != 0;
                valid &= GetAccelerationType(ref pfd) == requested_acceleration_type;
                valid &= (pfd.Flags & flags) == flags;
                valid &= pfd.PixelType == PixelType.RGBA; // indexed modes not currently supported
                // heavily penalize single-buffered modes when the user requests double buffering
                if ((pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) == 0 && mode.Buffers > 1)
                {
                    dist += 1000;
                }
                valid &= Compare(pfd.ColorBits, mode.ColorFormat.BitsPerPixel, ref dist);
                valid &= Compare(pfd.RedBits, mode.ColorFormat.Red, ref dist);
                valid &= Compare(pfd.GreenBits, mode.ColorFormat.Green, ref dist);
                valid &= Compare(pfd.BlueBits, mode.ColorFormat.Blue, ref dist);
                valid &= Compare(pfd.AlphaBits, mode.ColorFormat.Alpha, ref dist);
                valid &= Compare(pfd.AccumBits, mode.AccumulatorFormat.BitsPerPixel, ref dist);
                valid &= Compare(pfd.AccumRedBits, mode.AccumulatorFormat.Red, ref dist);
                valid &= Compare(pfd.AccumGreenBits, mode.AccumulatorFormat.Green, ref dist);
                valid &= Compare(pfd.AccumBlueBits, mode.AccumulatorFormat.Blue, ref dist);
                valid &= Compare(pfd.AccumAlphaBits, mode.AccumulatorFormat.Alpha, ref dist);
                valid &= Compare(pfd.DepthBits, mode.Depth, ref dist);
                valid &= Compare(pfd.StencilBits, mode.Stencil, ref dist);

                if (valid && dist < best_dist)
                {
                    best      = index;
                    best_dist = dist;
                }
            }

            return(DescribePixelFormatPFD(device, ref pfd, best));
        }
 internal static extern bool SetPixelFormat(IntPtr hdc, int ipfd, ref PixelFormatDescriptor ppfd);
        // Note: there is no relevant ARB function.
        void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
        {
            Debug.Write("Setting pixel format... ");

            if (!mode.Index.HasValue)
                throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");

            if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");

            PixelFormatDescriptor pfd = new PixelFormatDescriptor();
            Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index.Value,
                API.PixelFormatDescriptorSize, ref pfd);
            Debug.WriteLine(mode.Index.ToString());
            if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd))
                throw new GraphicsContextException(String.Format(
                    "Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error()));
        }
 internal static extern int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor ppfd);