public DxGlContext([NotNull] GLWpfControlSettings settings) { DXInterop.Direct3DCreate9Ex(DXInterop.DefaultSdkVersion, out var dxContextHandle); DxContextHandle = dxContextHandle; var deviceParameters = new PresentationParameters { Windowed = 1, SwapEffect = SwapEffect.Discard, DeviceWindowHandle = IntPtr.Zero, PresentationInterval = 0, BackBufferFormat = Format.X8R8G8B8, // this is like A8 R8 G8 B8, but avoids issues with Gamma correction being applied twice. BackBufferWidth = 1, BackBufferHeight = 1, AutoDepthStencilFormat = Format.Unknown, BackBufferCount = 1, EnableAutoDepthStencil = 0, Flags = 0, FullScreen_RefreshRateInHz = 0, MultiSampleQuality = 0, MultiSampleType = MultisampleType.None }; DXInterop.CreateDeviceEx( dxContextHandle, 0, DeviceType.HAL, // use hardware rasterization IntPtr.Zero, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.PureDevice, ref deviceParameters, IntPtr.Zero, out var dxDeviceHandle); DxDeviceHandle = dxDeviceHandle; // if the graphics context is null, we use the shared context. if (settings.ContextToUse != null) { GraphicsContext = settings.ContextToUse; } else { GraphicsContext = GetOrCreateSharedOpenGLContext(settings); } GlDeviceHandle = Wgl.DXOpenDeviceNV(dxDeviceHandle); }
protected bool RegisterDxDevice() { // Device already registered? if (_glDeviceHandle != IntPtr.Zero) { return(true); } // No device or DXInterop not supported, fallback to base // implementation of rendering to a GL texture. if (_dxDevice == null || !Wgl.CurrentExtensions.DXInterop_NV) { _glDeviceHandle = IntPtr.Zero; return(false); } // Register the dx device _glDeviceHandle = Wgl.DXOpenDeviceNV(_dxDevice.NativePointer); return(_glDeviceHandle != IntPtr.Zero); }