/// <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; } }