Ejemplo 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);
                    }
                }
            }
        }
Ejemplo 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()));
            }
        }
Ejemplo 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);
        }
Ejemplo n.º 4
0
 int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd)
 {
     unsafe
     {
         fixed (PixelFormatDescriptor* pPfd_ptr = &pPfd)
         {
             return Delegates.wglChoosePixelFormat((IntPtr)hDc, (PixelFormatDescriptor*)pPfd_ptr);
         }
     }
 }
Ejemplo 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);
         }
     }
 }
Ejemplo 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));
         }
     }
 }
Ejemplo 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);
                }
            }
        }
Ejemplo 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());
            }
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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.");
            }
        }
Ejemplo 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()));
            }
        }
Ejemplo n.º 15
0
 internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);
Ejemplo n.º 16
0
 internal extern static Boolean SetPixelFormat(IntPtr hdc, int ipfd, ref PixelFormatDescriptor ppfd);
Ejemplo n.º 17
0
 internal extern static unsafe int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd);
Ejemplo 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;
                }
            }
        }
Ejemplo 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);
 }
Ejemplo n.º 20
0
Archivo: Wgl.cs Proyecto: Zeludon/FEZ
 internal static bool SetPixelFormat(IntPtr hdc, int ipfd, PixelFormatDescriptor* ppfd);
Ejemplo n.º 21
0
 internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, UInt32 cjpfd, PixelFormatDescriptor* ppfd);
Ejemplo n.º 22
0
Archivo: Wgl.cs Proyecto: Roku97/opentk
 internal extern static unsafe int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd);
Ejemplo 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));
 }
Ejemplo n.º 24
0
Archivo: Wgl.cs Proyecto: Zeludon/FEZ
 public static unsafe int ChoosePixelFormat(IntPtr hDc, PixelFormatDescriptor* pPfd)
 {
     return Wgl.Delegates.wglChoosePixelFormat(hDc, pPfd);
 }
Ejemplo n.º 25
0
Archivo: Wgl.cs Proyecto: Zeludon/FEZ
 public static unsafe int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd)
 {
     fixed (PixelFormatDescriptor* pPfd1 = &pPfd)
     return Wgl.Delegates.wglChoosePixelFormat(hDc, pPfd1);
 }
Ejemplo n.º 26
0
Archivo: Wgl.cs Proyecto: Zeludon/FEZ
 public static unsafe bool SetPixelFormat(IntPtr hdc, int ipfd, PixelFormatDescriptor* ppfd)
 {
     return Wgl.Delegates.wglSetPixelFormat(hdc, ipfd, ppfd);
 }
Ejemplo n.º 27
0
Archivo: Wgl.cs Proyecto: 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);
 }
Ejemplo n.º 28
0
 internal static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd);
Ejemplo n.º 29
0
 internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);
Ejemplo n.º 30
0
 internal extern static unsafe Boolean SetPixelFormat(IntPtr hdc, int ipfd, PixelFormatDescriptor* ppfd);
Ejemplo n.º 31
0
Archivo: Wgl.cs Proyecto: 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);
 }
Ejemplo 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()));
 }
Ejemplo 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);
         }
     }
 }
Ejemplo 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;
 }
Ejemplo n.º 35
0
Archivo: Wgl.cs Proyecto: Roku97/opentk
 internal extern static Boolean SetPixelFormat(IntPtr hdc, int ipfd, ref PixelFormatDescriptor ppfd);
Ejemplo 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);
        }
Ejemplo n.º 37
0
 internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor ppfd);
Ejemplo n.º 38
0
Archivo: Wgl.cs Proyecto: Zeludon/FEZ
 internal static int ChoosePixelFormat(IntPtr hDc, PixelFormatDescriptor* pPfd);
Ejemplo 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;
            }
        }
Ejemplo 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);
                }
        }
Ejemplo n.º 41
0
Archivo: Wgl.cs Proyecto: Zeludon/FEZ
 public static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, PixelFormatDescriptor* ppfd)
 {
     return Wgl.Delegates.wglDescribePixelFormat(hdc, ipfd, (uint) cjpfd, ppfd);
 }
Ejemplo 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;
        }
Ejemplo n.º 43
0
 internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat);
Ejemplo n.º 44
0
Archivo: Wgl.cs Proyecto: 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);
 }
Ejemplo 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));
        }
Ejemplo n.º 47
0
 internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat);
Ejemplo n.º 48
0
Archivo: Wgl.cs Proyecto: Zeludon/FEZ
 internal static int DescribePixelFormat(IntPtr hdc, int ipfd, uint cjpfd, PixelFormatDescriptor* ppfd);
Ejemplo 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;
 }
Ejemplo n.º 50
0
Archivo: Wgl.cs Proyecto: Roku97/opentk
 internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor ppfd);
Ejemplo 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);