public void FrameResized(int width, int height) { lock (device) { if (textureRGB != null) { Utilities.Dispose(ref textureRGB); } textureRGB = new Texture2D(device, new Texture2DDescription() { Usage = ResourceUsage.Default, Format = Format.R8G8B8A8_UNorm, Width = width, Height = height, BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), ArraySize = 1, MipLevels = 1 }); srvRGB = new ShaderResourceView(device, textureRGB); } Utilities.Dispose(ref vpov); videoDevice1.CreateVideoProcessorOutputView((Resource)textureRGB, vpe, vpovd, out vpov); }
// Get's a handle to assosiate with the BackBuffer and Prepares Devices private void Initialize(IntPtr outputHandle) { // SwapChain Description var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(0, 0, new Rational(0, 0), Format.B8G8R8A8_UNorm), // RBGA | BGRA 32-bit IsWindowed = true, OutputHandle = outputHandle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; // Create Device, SwapChain & BackBuffer Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, desc, out _device, out _swapChain); _backBuffer = Texture2D.FromSwapChain <Texture2D>(_swapChain, 0); // Creates Association between outputHandle and BackBuffer var factory = _swapChain.GetParent <Factory>(); factory.MakeWindowAssociation(outputHandle, WindowAssociationFlags.IgnoreAll); // Video Device | Video Context videoDevice1 = _device.QueryInterface <VideoDevice1>(); videoContext1 = _device.ImmediateContext.QueryInterface <VideoContext1>(); // Creates Video Processor Enumerator vpcd = new VideoProcessorContentDescription() { Usage = VideoUsage.PlaybackNormal, InputFrameFormat = VideoFrameFormat.Progressive, InputFrameRate = new Rational(1, 1), OutputFrameRate = new Rational(1, 1), // We Set those later InputWidth = 1, OutputWidth = 1, InputHeight = 1, OutputHeight = 1 }; videoDevice1.CreateVideoProcessorEnumerator(ref vpcd, out vpe); videoDevice1.CreateVideoProcessor(vpe, 0, out videoProcessor); // Prepares Video Processor Input View Description for Video Processor Input View that we pass Shared NV12 Texture (nv12SharedResource) each time vpivd = new VideoProcessorInputViewDescription() { FourCC = 0, Dimension = VpivDimension.Texture2D, Texture2D = new Texture2DVpiv() { MipSlice = 0, ArraySlice = 0 } }; // Creates Video Processor Output to our BackBuffer vpovd = new VideoProcessorOutputViewDescription() { Dimension = VpovDimension.Texture2D }; videoDevice1.CreateVideoProcessorOutputView((Resource)_backBuffer, vpe, vpovd, out vpov); // Prepares Streams Array vpsa = new VideoProcessorStream[1]; }