Esempio n. 1
0
        /// <summary>
        /// Create a simple context.
        /// </summary>
        /// <returns>
        /// A <see cref="IntPtr"/> that represents the handle of the created context. If the context cannot be
        /// created, it returns IntPtr.Zero.
        /// </returns>
        internal override IntPtr CreateSimpleContext()
        {
            IntPtr rContext;

            // Define most compatible pixel format
            Wgl.PIXELFORMATDESCRIPTOR pfd = new Wgl.PIXELFORMATDESCRIPTOR(24);
            int  pFormat;
            bool res;

            // Find pixel format match
            pfd.dwFlags |= Wgl.PixelFormatDescriptorFlags.DepthDontCare | Wgl.PixelFormatDescriptorFlags.DoublebufferDontCare | Wgl.PixelFormatDescriptorFlags.StereoDontCare;

            pFormat = Wgl.ChoosePixelFormat(_DeviceContext, ref pfd);
            Debug.Assert(pFormat != 0);

            // Get exact description of the pixel format
            res = Wgl.DescribePixelFormat(_DeviceContext, pFormat, (uint)pfd.nSize, ref pfd);
            Debug.Assert(res);

            // Set pixel format before creating OpenGL context
            res = Wgl.SetPixelFormat(_DeviceContext, pFormat, ref pfd);
            Debug.Assert(res);

            // Create a dummy OpenGL context to retrieve initial informations.
            rContext = CreateContext(IntPtr.Zero);
            Debug.Assert(rContext != IntPtr.Zero);

            return(rContext);
        }
Esempio n. 2
0
        /// <summary>
        /// Set the device pixel format.
        /// </summary>
        /// <param name="pixelFormat">
        /// A <see cref="DevicePixelFormat"/> that specifies the pixel format to set.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="pixelFormat"/> is null.
        /// </exception>
        public override void SetPixelFormat(DevicePixelFormat pixelFormat)
        {
            if (pixelFormat == null)
            {
                throw new ArgumentNullException("pixelFormat");
            }
            if (_PixelFormatSet == true)
            {
                throw new InvalidOperationException("pixel format already set");
            }

            Wgl.PIXELFORMATDESCRIPTOR pDescriptor = new Wgl.PIXELFORMATDESCRIPTOR();
            bool res;

            // Note (from MSDN): Setting the pixel format of a window more than once can lead to significant complications for the Window Manager
            // and for multithread applications, so it is not allowed. An application can only set the pixel format of a window one time. Once a
            // window's pixel format is set, it cannot be changed.

            res = Wgl.DescribePixelFormat(DeviceContext, pixelFormat.FormatIndex, (uint)pDescriptor.nSize, ref pDescriptor);
            Debug.Assert(res);

            // Set choosen pixel format
            res = Wgl.SetPixelFormat(DeviceContext, pixelFormat.FormatIndex, ref pDescriptor);
            Debug.Assert(res);

            // Unable to set pixel format again
            _PixelFormatSet = true;
        }
Esempio n. 3
0
		/// <summary>
		/// Set the device pixel format.
		/// </summary>
		/// <param name="pixelFormat">
		/// A <see cref="DevicePixelFormat"/> that specifies the pixel format to set.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// Exception thrown if <paramref name="pixelFormat"/> is null.
		/// </exception>
		public override void SetPixelFormat(DevicePixelFormat pixelFormat)
		{
			if (pixelFormat == null)
				throw new ArgumentNullException("pixelFormat");
			if (IsPixelFormatSet == true)
				throw new InvalidOperationException("pixel format already set");

#if CHOOSE_PIXEL_FORMAT_FALLBACK
			try {
#endif
				Wgl.PIXELFORMATDESCRIPTOR pDescriptor = new Wgl.PIXELFORMATDESCRIPTOR();

				// Note (from MSDN): Setting the pixel format of a window more than once can lead to significant complications for the Window Manager
				// and for multithread applications, so it is not allowed. An application can only set the pixel format of a window one time. Once a
				// window's pixel format is set, it cannot be changed.

				if (Wgl.DescribePixelFormat(_DeviceContext, pixelFormat.FormatIndex, (uint)pDescriptor.nSize, ref pDescriptor) == 0)
					throw new InvalidOperationException(String.Format("unable to describe pixel format {0}", pixelFormat.FormatIndex), GetPlatformException());

				// Set choosen pixel format
				if (!Wgl.SetPixelFormat(_DeviceContext, pixelFormat.FormatIndex, ref pDescriptor))
					throw new InvalidOperationException(String.Format("unable to set pixel format {0}: {1}", pixelFormat.FormatIndex), GetPlatformException());

#if CHOOSE_PIXEL_FORMAT_FALLBACK
			} catch (InvalidOperationException) {
				// Try using default ChoosePixelFormat*
				SetDisplayablePixelFormat(pixelFormat);
			}
#endif

			IsPixelFormatSet = true;
		}
        /// <summary>
        /// Set the device pixel format.
        /// </summary>
        /// <param name="pixelFormat">
        /// A <see cref="DevicePixelFormat"/> that specifies the pixel format to set.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="pixelFormat"/> is null.
        /// </exception>
        public override void SetPixelFormat(DevicePixelFormat pixelFormat)
        {
            if (pixelFormat == null)
            {
                throw new ArgumentNullException("pixelFormat");
            }
            if (_PixelFormatSet == true)
            {
                throw new InvalidOperationException("pixel format already set");
            }

            Wgl.PIXELFORMATDESCRIPTOR pDescriptor = new Wgl.PIXELFORMATDESCRIPTOR();

            // Note (from MSDN): Setting the pixel format of a window more than once can lead to significant complications for the Window Manager
            // and for multithread applications, so it is not allowed. An application can only set the pixel format of a window one time. Once a
            // window's pixel format is set, it cannot be changed.

            if (Wgl.DescribePixelFormat(DeviceContext, pixelFormat.FormatIndex, (uint)pDescriptor.nSize, ref pDescriptor) == false)
            {
                Win32Exception innerException = new Win32Exception(Marshal.GetLastWin32Error());
                throw new InvalidOperationException(String.Format("unable to describe pixel format, {0}", innerException.Message), innerException);
            }

            // Set choosen pixel format
            if (Wgl.SetPixelFormat(DeviceContext, pixelFormat.FormatIndex, ref pDescriptor) == false)
            {
                Win32Exception innerException = new Win32Exception(Marshal.GetLastWin32Error());
                throw new InvalidOperationException(String.Format("unable to set pixel format, {0}", innerException.Message), innerException);
            }

            // Unable to set pixel format again
            _PixelFormatSet = true;
        }
Esempio n. 5
0
		private DevicePixelFormatCollection GetPixelFormats_Win32()
		{
			DevicePixelFormatCollection pixelFormats = new DevicePixelFormatCollection();
			Wgl.PIXELFORMATDESCRIPTOR pixelDescr = new Wgl.PIXELFORMATDESCRIPTOR();
			int pixelFormatsCount = Wgl.DescribePixelFormat(_DeviceContext, 0, 0, ref pixelDescr);

			for (int i = 1; i <= pixelFormatsCount; i++) {
				Wgl.DescribePixelFormat(_DeviceContext, i, (uint)Marshal.SizeOf(typeof(Wgl.PIXELFORMATDESCRIPTOR)), ref pixelDescr);

				if ((pixelDescr.dwFlags & Wgl.PixelFormatDescriptorFlags.SupportOpenGL) == 0)
					continue;

				DevicePixelFormat pixelFormat = new DevicePixelFormat();

				pixelFormat.FormatIndex = i;

				pixelFormat.RgbaUnsigned = true;
				pixelFormat.RgbaFloat = false;

				pixelFormat.RenderWindow = true;
				pixelFormat.RenderBuffer = false;

				pixelFormat.DoubleBuffer = (pixelDescr.dwFlags & Wgl.PixelFormatDescriptorFlags.Doublebuffer) != 0;
				pixelFormat.SwapMethod = 0;
				pixelFormat.StereoBuffer = (pixelDescr.dwFlags & Wgl.PixelFormatDescriptorFlags.Stereo) != 0;

				pixelFormat.ColorBits = pixelDescr.cColorBits;
				pixelFormat.DepthBits = pixelDescr.cDepthBits;
				pixelFormat.StencilBits = pixelDescr.cStencilBits;

				pixelFormat.MultisampleBits = 0;

				pixelFormat.RenderPBuffer = false;

				pixelFormat.SRGBCapable = false;

				pixelFormats.Add(pixelFormat);
			}

			return (pixelFormats);
		}