/// <summary>
			/// Construct a NativePBuffer with a specific pixel format and size.
			/// </summary>
			/// <param name="pixelFormat">
			/// A <see cref="DevicePixelFormat"/> that specifies the pixel format and the ancillary buffers required.
			/// </param>
			/// <param name="width">
			/// A <see cref="UInt32"/> that specifies the width of the P-Buffer, in pixels.
			/// </param>
			/// <param name="height">
			/// A <see cref="UInt32"/> that specifies the height of the P-Buffer, in pixels.
			/// </param>
			public NativePBuffer(DevicePixelFormat pixelFormat, uint width, uint height)
			{
				if (pixelFormat == null)
					throw new ArgumentNullException("pixelFormat");

				if (!Wgl.CurrentExtensions.Pbuffer_ARB && !Wgl.CurrentExtensions.Pbuffer_EXT)
					throw new NotSupportedException("WGL_(ARB|EXT)_pbuffer not implemented");
				if (Gl._NativeWindow == null)
					throw new InvalidOperationException("no underlying native window", Gl._InitializationException);

				try {
					// Uses screen device context
					_DeviceContext = Wgl.GetDC(Gl._NativeWindow.Handle);

					// Choose appropriate pixel format
					pixelFormat.RenderWindow = false;	// XXX
					pixelFormat.RenderPBuffer = true;
					pixelFormat.DoubleBuffer = true;

					int pixelFormatIndex = ChoosePixelFormat(_DeviceContext, pixelFormat);

					if (Wgl.CurrentExtensions.Pbuffer_ARB)
						_Handle = Wgl.CreatePbufferARB(_DeviceContext, pixelFormatIndex, (int)width, (int)height, new int[] { 0 });
					else
						_Handle = Wgl.CreatePbufferEXT(_DeviceContext, pixelFormatIndex, (int)width, (int)height, new int[] { 0 });
					if (_Handle == IntPtr.Zero)
						throw new InvalidOperationException("unable to create P-Buffer", GetPlatformExceptionCore());
				} catch {
					Dispose();
					throw;
				}
			}
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceContextWGL"/> class.
        /// </summary>
        /// <param name='windowHandle'>
        /// A <see cref="IntPtr"/> that specifies the window handle used to create the device context.
        /// </param>
        /// <exception cref='InvalidOperationException'>
        /// Is thrown when an operation cannot be performed.
        /// </exception>
        /// <remarks>
        /// The created instance will be bound to the (hidden) window used for initializing <see cref="Gl"/>. The device contextes
        /// created by using this constructor are meant to render on framebuffer objects.
        /// </remarks>
        public DeviceContextWGL()
        {
            _WindowHandle   = Gl._NativeWindow.Handle;
            _PixelFormatSet = true;                     // We do not want to reset pixel format

            _DeviceContext = Wgl.GetDC(_WindowHandle);
            if (_DeviceContext == IntPtr.Zero)
            {
                throw new InvalidOperationException("unable to get device context");
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="DeviceContextWGL"/> class.
		/// </summary>
		/// <param name='windowHandle'>
		/// A <see cref="IntPtr"/> that specifies the window handle used to create the device context.
		/// </param>
		/// <exception cref="ArgumentException">
		/// Exception thrown if <paramref name="windowHandle"/> is <see cref="IntPtr.Zero"/>.
		/// </exception>
		/// <exception cref='InvalidOperationException'>
		/// Is thrown when an operation cannot be performed.
		/// </exception>
		/// <remarks>
		/// The <paramref name="windowHandle"/> must be an handle to a native window. It is normally created by calling
		/// CreateWindow(Ex)? methods.
		/// </remarks>
		public DeviceContextWGL(IntPtr windowHandle)
		{
			if (windowHandle == IntPtr.Zero)
				throw new ArgumentException("null handle", "windowHandle");

			_WindowHandle = windowHandle;

			_DeviceContext = Wgl.GetDC(_WindowHandle);
			if (_DeviceContext == IntPtr.Zero)
				throw new InvalidOperationException("unable to get device context");
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="DeviceContextWGL"/> class.
		/// </summary>
		/// <param name='windowHandle'>
		/// A <see cref="IntPtr"/> that specifies the window handle used to create the device context.
		/// </param>
		/// <exception cref='InvalidOperationException'>
		/// Is thrown when an operation cannot be performed.
		/// </exception>
		/// <remarks>
		/// The created instance will be bound to the (hidden) window used for initializing <see cref="Gl"/>. The device contextes
		/// created by using this constructor are meant to render on framebuffer objects.
		/// </remarks>
		public DeviceContextWGL()
		{
			if (Gl._NativeWindow == null)
				throw new InvalidOperationException("no underlying native window", Gl._InitializationException);

			_WindowHandle = Gl._NativeWindow.Handle;

			IsPixelFormatSet = true;		// We do not want to reset pixel format

			_DeviceContext = Wgl.GetDC(_WindowHandle);
			if (_DeviceContext == IntPtr.Zero)
				throw new InvalidOperationException("unable to get device context");
		}
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowsDeviceContext"/> class.
        /// </summary>
        /// <param name='window'>
        /// Window.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        /// <exception cref='InvalidOperationException'>
        /// Is thrown when an operation cannot be performed.
        /// </exception>
        public WindowsDeviceContext(Control window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            // "Force" handle creation
            if (!window.IsHandleCreated && window.Handle != IntPtr.Zero)
            {
                throw new InvalidOperationException("invalid handle");
            }

            _WindowHandle  = window.Handle;
            _DeviceContext = Wgl.GetDC(window.Handle);

            if (DeviceContext == IntPtr.Zero)
            {
                throw new InvalidOperationException("unable to get any video device context");
            }
        }