void InitializeSharedBackBuffer(IntPtr resourcePtr) { // convert native pointer to DXGI shared resource Resource resource = CppObject.FromPointer <Resource>(resourcePtr).QueryInterface <Resource>(); // convert shared resource to D3D11 Texture D3D11.Texture2D sharedBackbuffer = device.OpenSharedResource <D3D11.Texture2D>(resource.SharedHandle); // release reference resource.Dispose(); // use D3D11 Texture as render target D3D11.RenderTargetViewDescription desc = new D3D11.RenderTargetViewDescription(); desc.Format = Format.B8G8R8A8_UNorm; desc.Dimension = D3D11.RenderTargetViewDimension.Texture2D; desc.Texture2D.MipSlice = 0; renderTargetView = new D3D11.RenderTargetView(device, sharedBackbuffer, desc); deviceContext.OutputMerger.SetRenderTargets(renderTargetView); // release reference sharedBackbuffer.Dispose(); // setup viewport Size size = Utils.WpfSizeToPixels(ImageGrid); deviceContext.Rasterizer.SetViewport(new Viewport(0, 0, (int)size.Width, (int)size.Height, 0.0f, 1.0f)); }
private void PlatformPlay() { // Cleanup the last song first. if (State != MediaState.Stopped) { _session.Stop(); _volumeController.Dispose(); _clock.Dispose(); } // Set the new song. _session.SetTopology(0, _currentVideo.Topology); _volumeController = CppObject.FromPointer <SimpleAudioVolume>(GetVolumeObj(_session)); _volumeController.Mute = IsMuted; _volumeController.MasterVolume = _volume; // Get the clock. _clock = _session.Clock.QueryInterface <PresentationClock>(); //create the callback if it hasn't been created yet if (_callback == null) { _callback = new Callback(); _session.BeginGetEvent(_callback, null); } // Start playing. var varStart = new Variant(); _session.Start(null, varStart); }
/// <summary> /// Opens a handle for a shared fence by using resourceHandle. /// </summary> /// <param name="resourceHandle">The handle that was returned by a call to ID3D11Fence::CreateSharedHandle or ID3D12Device::CreateSharedHandle</param> /// <returns>Fence</returns> public Fence OpenSharedFence(IntPtr resourceHandle) { IntPtr temp; OpenSharedFence(resourceHandle, Utilities.GetGuidFromType(typeof(Fence)), out temp); return(CppObject.FromPointer <Fence>(temp)); }
private static void PlatformPlaySong(Song song) { // Cleanup the last song first. if (State != MediaState.Stopped) { _session.Stop(); _session.ClearTopologies(); _session.Close(); _volumeController.Dispose(); _clock.Dispose(); } // Set the new song. _session.SetTopology(SessionSetTopologyFlags.Immediate, song.Topology); // Get the volume interface. _volumeController = CppObject.FromPointer <AudioStreamVolume>(MediaPlayer.GetVolumeObj(_session)); SetChannelVolumes(); // Get the clock. _clock = _session.Clock.QueryInterface <PresentationClock>(); //create the callback if it hasn't been created yet if (_callback == null) { _callback = new Callback(); _session.BeginGetEvent(_callback, null); } // Start playing. var varStart = new Variant(); _session.Start(null, varStart); }
private static void PlaySong(Song song) { #if WINDOWS_MEDIA_ENGINE _mediaEngineEx.Source = song.FilePath; _mediaEngineEx.Load(); _mediaEngineEx.Play(); #elif WINDOWS_MEDIA_SESSION // Cleanup the last song first. if (State != MediaState.Stopped) { _session.Stop(); _volumeController.Dispose(); _clock.Dispose(); } // Set the new song. _session.SetTopology(0, song.GetTopology()); // Get the volume interface. IntPtr volumeObj; try { MediaFactory.GetService(_session, MRPolicyVolumeService, SimpleAudioVolumeGuid, out volumeObj); } catch (Exception e) { MediaFactory.GetService(_session, MRPolicyVolumeService, SimpleAudioVolumeGuid, out volumeObj); } _volumeController = CppObject.FromPointer <SimpleAudioVolume>(volumeObj); _volumeController.Mute = _isMuted; _volumeController.MasterVolume = _volume; // Get the clock. _clock = _session.Clock.QueryInterface <PresentationClock>(); // Start playing. var varStart = new Variant(); _session.Start(null, varStart); #elif WINDOWS_PHONE Deployment.Current.Dispatcher.BeginInvoke(() => { _mediaElement.Source = new Uri(song.FilePath, UriKind.Relative); _mediaElement.Play(); // Ensure only one subscribe _mediaElement.MediaEnded -= OnSongFinishedPlaying; _mediaElement.MediaEnded += OnSongFinishedPlaying; }); #else song.SetEventHandler(OnSongFinishedPlaying); song.Volume = _isMuted ? 0.0f : _volume; song.Play(); #endif State = MediaState.Playing; }
internal unsafe MarkerNotification(RawNotification *rawNotification) : base(rawNotification) { CueIndex = rawNotification->Data.Marker.CueIndex; SoundBank = CppObject.FromPointer <SoundBank>(rawNotification->Data.Marker.SoundBankPointer); Cue = CppObject.FromPointer <Cue>(rawNotification->Data.Marker.CuePointer); Marker = rawNotification->Data.Marker.Marker; }
private static void OnTopologyReady() { IntPtr volumeObjectPtr; MediaFactory.GetService(_session, MediaServiceKeys.StreamVolume, AudioStreamVolumeGuid, out volumeObjectPtr); _volumeController = CppObject.FromPointer <AudioStreamVolume>(volumeObjectPtr); SetChannelVolumes(); }
/// <summary> /// Update D3DImage for WPF /// </summary> /// <param name="surface">Pointer to Surface from FFMpeg</param> /// <param name="surfaceIndex">Index to subsufaace from the current update</param> private void UpdateImage(IntPtr surface, uint surfaceIndex) { if (Shutdown == false) { if (surface != IntPtr.Zero) { //Access ffmpeg d3d device using (var ffmpegSrc = CppObject.FromPointer <Texture2D>(surface)) { if (FFmpegD3DDevice == null) { FFmpegD3DDevice = ffmpegSrc.Device; FFmpegD3DContext = FFmpegD3DDevice.ImmediateContext; } //Need to Create a Transfer Texture on the ffmpeg device to allow shared access from wpf d3ddevice //Only Create Once if (TransferTexture == null) { var tempDesc = ffmpegSrc.Description; tempDesc.ArraySize = 1; tempDesc.BindFlags |= BindFlags.ShaderResource; tempDesc.OptionFlags = ResourceOptionFlags.Shared; tempDesc.Usage = ResourceUsage.Default; TransferTexture = new Texture2D(FFmpegD3DDevice, tempDesc); } ////Copy the ffmpegTexture to Transfer Texture, Also select the correct sub texture index to a single texture for transfer FFmpegD3DContext.CopySubresourceRegion(ffmpegSrc, Convert.ToInt32(surfaceIndex), null, TransferTexture, 0); } //Hack to create D3D Device so we dont miss the first frame if (D3DDevice == null) { RequestD3DRender(); } if (D3DDevice != null && TransferTexture != null && DisplayTexture == null) { //Convert transfer texture thru to DXGI resource Object using (var resource = TransferTexture.QueryInterface <SharpDX.DXGI.Resource>()) { //Get shared handle from DXGI resource using (var sharedResource = D3DDevice.OpenSharedResource <SharpDX.DXGI.Resource>(resource.SharedHandle)) { //Convert back to Texture2D Object using (var sharedTexture = sharedResource.QueryInterface <SharpDX.Direct3D11.Texture2D>()) { DisplayTexture = sharedResource.QueryInterface <SharpDX.Direct3D11.Texture2D>(); } } } } //Request a render evey time we have a new frame from FFMpeg RequestD3DRender(); } } }
internal unsafe VariableNotification(RawNotification *rawNotification) : base(rawNotification) { CueIndex = rawNotification->Data.Variable.CueIndex; SoundBank = CppObject.FromPointer <SoundBank>(rawNotification->Data.Variable.SoundBankPointer); Cue = CppObject.FromPointer <Cue>(rawNotification->Data.Variable.CuePointer); VariableIndex = rawNotification->Data.Variable.VariableIndex; VariableValue = rawNotification->Data.Variable.VariableValue; IsLocal = rawNotification->Data.Variable.Local; }
internal unsafe WaveNotification(RawNotification *rawNotification) : base(rawNotification) { WaveBank = CppObject.FromPointer <WaveBank>(rawNotification->Data.Wave.WaveBankPointer); WaveIndex = rawNotification->Data.Wave.WaveIndex; CueIndex = rawNotification->Data.Wave.CueIndex; SoundBank = CppObject.FromPointer <SoundBank>(rawNotification->Data.Wave.SoundBankPointer); Cue = CppObject.FromPointer <Cue>(rawNotification->Data.Wave.CuePointer); Wave = CppObject.FromPointer <Wave>(rawNotification->Data.Wave.WavePointer); }
/// <summary> /// Try to create new instance of <see cref="IDXGIFactory1"/>. /// </summary> /// <returns>Return an instance of <see cref="IDXGIFactory1"/> or null if failed.</returns> public static T CreateDXGIFactory1 <T>() where T : IDXGIFactory1 { var result = CreateDXGIFactory1(typeof(T).GUID, out var nativePtr); if (result.Success) { return(CppObject.FromPointer <T>(nativePtr)); } return(default);
public void ResizeBackbuffer(IntPtr newBackbuffer) { // Unbind the old RTV and DSV from the pipeline by binding null // Then Dispose them immediateContext.OutputMerger.SetRenderTargets(null, renderTargetView: null); depthStencilView?.Dispose(); depthBuffer?.Dispose(); backbufferRTV?.Dispose(); // Query to get to the DX11 version of the backbuffer // (The backbuffer is shared between DX9 and DX11) var surface = CppObject.FromPointer <Surface>(newBackbuffer); var resourceDXGI = surface.QueryInterface <SharpDX.DXGI.Resource>(); var sharedHandle = resourceDXGI.SharedHandle; resourceDXGI.Dispose(); var resourceDX11 = device.OpenSharedResource <SharpDX.Direct3D11.Resource>(sharedHandle); var texture2D = resourceDX11.QueryInterface <Texture2D>(); resourceDX11.Dispose(); // Create a new RTV var rtvDesc = new RenderTargetViewDescription { Format = Format.B8G8R8A8_UNorm, Dimension = RenderTargetViewDimension.Texture2D, Texture2D = { MipSlice = 0 } }; backbufferRTV = new RenderTargetView(device, texture2D, rtvDesc); // Create the new Depth buffer and bind it var texture2DDesc = texture2D.Description; immediateContext.Rasterizer.SetViewport(new Viewport(0, 0, texture2DDesc.Width, texture2DDesc.Height, 0.0f, 1.0f)); depthBuffer = new Texture2D(device, new Texture2DDescription { Format = Format.D32_Float, ArraySize = 1, MipLevels = 1, Width = texture2DDesc.Width, Height = texture2DDesc.Height, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }); depthStencilView = new DepthStencilView(this.device, this.depthBuffer); immediateContext.OutputMerger.SetRenderTargets(depthStencilView, backbufferRTV); // Set up the viewport and projection matrix immediateContext.Rasterizer.SetViewport(0.0f, 0.0f, texture2DDesc.Width, texture2DDesc.Height); Camera.UpdateProjectionMatrix(texture2DDesc.Width, texture2DDesc.Height, 100000.0f, 1.0f); }
/// <summary> /// 指定された型のインターフェースを取得する。 /// </summary> /// <typeparam name="T">希望する型。</typeparam> /// <param name="unknownObject">取得元のオブジェクト。</param> /// <returns> /// 取得されたオブジェクト。クエリに失敗した場合は null 。 /// </returns> public static T QueryInterface <T>(this IUnknown unknownObject) where T : ComObject { if (null == unknownObject) { return(null); } var guid = SharpDX.Utilities.GetGuidFromType(typeof(T)); var resuult = unknownObject.QueryInterface(ref guid, out IntPtr comObject); return((resuult.Failure) ? null : CppObject.FromPointer <T>(comObject)); }
/// <summary> /// Try to create new instance of <see cref="IDWriteFactory"/>. /// </summary> /// <typeparam name="T">Type based on <see cref="IDWriteFactory"/>.</typeparam> /// <param name="factoryType">The type of factory.</param> /// <param name="factory">The <see cref="IDWriteFactory"/> being created.</param> /// <returns>Return the <see cref="Result"/>.</returns> public static Result DWriteCreateFactory <T>(FactoryType factoryType, out T factory) where T : IDWriteFactory { var result = DWriteCreateFactory(factoryType, typeof(IDWriteFactory).GUID, out var nativePtr); if (result.Failure) { factory = null; return(result); } factory = CppObject.FromPointer <T>(nativePtr); return(result); }
public static Result DxcCreateInstance <T>(Guid classGuid, out T instance) where T : ComObject { Result result = DxcCreateInstance(classGuid, typeof(T).GUID, out IntPtr nativePtr); if (result.Success) { instance = CppObject.FromPointer <T>(nativePtr); return(result); } instance = null; return(result); }
private void OnTopologyReady() { if (_session.IsDisposed) { return; } // Get the volume interface. MediaFactory.GetService(_session, MediaServiceKeys.StreamVolume, AudioStreamVolumeGuid, out IntPtr volumeObjectPtr); _volumeController = CppObject.FromPointer <AudioStreamVolume>(volumeObjectPtr); SetChannelVolumes(); }
public static Result D3D12CreateDevice <T>(IDXGIAdapter adapter, FeatureLevel minFeatureLevel, out T device) where T : ID3D12Device { Result result = D3D12CreateDevice(adapter, minFeatureLevel, typeof(T).GUID, out IntPtr nativePtr); if (result.Failure) { device = default; return(result); } device = CppObject.FromPointer <T>(nativePtr); return(result); }
/// <summary> /// Try to create new instance of <see cref="IDXGIFactory1"/>. /// </summary> /// <param name="factory">The <see cref="IDXGIFactory1"/> being created.</param> /// <returns>Return the <see cref="Result"/>.</returns> public static Result CreateDXGIFactory1 <T>(out T factory) where T : IDXGIFactory1 { var result = CreateDXGIFactory1(typeof(T).GUID, out var nativePtr); if (result.Success) { factory = CppObject.FromPointer <T>(nativePtr); return(result); } factory = null; return(result); }
/// <summary> /// Creates a new DirectComposition device object, which can be used to create other DirectComposition objects. /// </summary> /// <typeparam name="T">A generic type of <see cref="IDCompositionDevice"/>.</typeparam> /// <param name="renderingDevice">An optional instance to a DirectX device to be used to create DirectComposition surface objects. Must be a instance of an object implementing the <see cref="IDXGIDevice"/> or <see cref="ID2D1Device"/> interfaces.</param> /// <param name="compositionDevice">An instance of <see cref="IDCompositionDevice"/> interface or null if failure</param> /// <returns>The <see cref="Result"/> code.</returns> public static Result DCompositionCreateDevice3 <T>(IUnknown renderingDevice, out T compositionDevice) where T : IDCompositionDevice { Result result = DCompositionCreateDevice3(renderingDevice, typeof(T).GUID, out IntPtr nativePtr); if (result.Failure) { compositionDevice = default; return(result); } compositionDevice = CppObject.FromPointer <T>(nativePtr); return(result); }
/// <summary> /// Try to create new instance of <see cref="IDXCoreAdapterFactory"/>. /// </summary> /// <param name="factory">The <see cref="IDXCoreAdapterFactory"/> being created.</param> /// <returns>Return the <see cref="Result"/>.</returns> public static Result DXCoreCreateAdapterFactory <T>(out T factory) where T : IDXCoreAdapterFactory { Result result = DXCoreCreateAdapterFactory(typeof(T).GUID, out IntPtr nativePtr); if (result.Success) { factory = CppObject.FromPointer <T>(nativePtr); return(result); } factory = null; return(result); }
/// <summary> /// Try to create new instance of <see cref="ID2D1Factory"/>. /// </summary> /// <param name="factoryType">The type of factory.</param> /// <param name="options">The <see cref="FactoryOptions"/>.</param> /// <param name="factory">The <see cref="ID2D1Factory"/> being created.</param> /// <returns>Return the <see cref="Result"/>.</returns> public static Result D2D1CreateFactory <T>(FactoryType factoryType, FactoryOptions options, out T factory) where T : ID2D1Factory { var result = D2D1CreateFactory(factoryType, typeof(T).GUID, options, out var nativePtr); if (result.Success) { factory = CppObject.FromPointer <T>(nativePtr); return(result); } factory = null; return(result); }
public static Result D3D12GetDebugInterface <T>(out T debugInterface) where T : ComObject { var result = D3D12GetDebugInterface(typeof(T).GUID, out var nativePtr); if (result.Failure) { debugInterface = null; return(result); } debugInterface = CppObject.FromPointer <T>(nativePtr); return(result); }
/// <summary> /// Try to create new instance of <see cref="IDXGIFactory2"/>. /// </summary> /// <param name="debug">Whether to enable debug callback.</param> /// <param name="factory">The <see cref="IDXGIFactory2"/> being created.</param> /// <returns>Return the <see cref="Result"/>.</returns> public static Result CreateDXGIFactory2 <T>(bool debug, out T factory) where T : IDXGIFactory2 { int flags = debug ? CreateFactoryDebug : 0x00; var result = CreateDXGIFactory2(flags, typeof(T).GUID, out var nativePtr); if (result.Success) { factory = CppObject.FromPointer <T>(nativePtr); return(result); } factory = null; return(result); }
private static void OnTopologyReady() { IntPtr volumeObjectPtr; MediaFactory.GetService(_session, MediaServiceKeys.StreamVolume, AudioStreamVolumeGuid, out volumeObjectPtr); _volumeController = CppObject.FromPointer <AudioStreamVolume>(volumeObjectPtr); SetChannelVolumes(); if (_desiredPosition.HasValue) { StartSession(_desiredPosition.Value); _desiredPosition = null; } }
private static void PlatformPlaySong(Song song) { // Cleanup the last song first. if (State != MediaState.Stopped) { _session.Stop(); _session.ClearTopologies(); _session.Close(); _volumeController.Dispose(); _clock.Dispose(); } // Set the new song. _session.SetTopology(SessionSetTopologyFlags.Immediate, song.Topology); // Get the volume interface. IntPtr volumeObj; try { MediaFactory.GetService(_session, MRPolicyVolumeService, SimpleAudioVolumeGuid, out volumeObj); } catch { MediaFactory.GetService(_session, MRPolicyVolumeService, SimpleAudioVolumeGuid, out volumeObj); } _volumeController = CppObject.FromPointer <SimpleAudioVolume>(volumeObj); _volumeController.Mute = _isMuted; _volumeController.MasterVolume = _volume; // Get the clock. _clock = _session.Clock.QueryInterface <PresentationClock>(); //create the callback if it hasn't been created yet if (_callback == null) { _callback = new Callback(); _session.BeginGetEvent(_callback, null); } // Start playing. var varStart = new Variant(); _session.Start(null, varStart); }
public static Result CreateAudioReverb <T>(out T reverb) where T : ComObject { unsafe { var nativePtr = IntPtr.Zero; Result result = s_CreateAudioReverb(&nativePtr); if (result.Success) { reverb = CppObject.FromPointer <T>(nativePtr); return(result); } reverb = null; return(result); } }
/// <summary> /// Try to create new instance of <see cref="IDXGIFactory"/>. /// </summary> /// <param name="factory">The <see cref="IDXGIFactory"/> being created.</param> /// <returns>Return the <see cref="Result"/>.</returns> public static Result CreateDXGIFactory <T>(out T factory) where T : IDXGIFactory { if (PlatformDetection.IsUAP) { throw new NotSupportedException(); } var result = CreateDXGIFactory(typeof(T).GUID, out var nativePtr); if (result.Success) { factory = CppObject.FromPointer <T>(nativePtr); return(result); } factory = null; return(result); }
public static Result Reflect <T>(byte[] shaderBytecode, out T reflection) where T : ComObject { var interfaceGuid = typeof(T).GUID; fixed(void *shaderBytecodePtr = shaderBytecode) { PointerSize srcDataSize = shaderBytecode.Length; var result = Reflect(new IntPtr(shaderBytecodePtr), srcDataSize, interfaceGuid, out var nativePtr); if (result.Success) { reflection = CppObject.FromPointer <T>(nativePtr); return(result); } reflection = null; return(result); } }
/// <summary> /// Gets debug interface for given type. /// </summary> /// <typeparam name="T">The <see cref="ComObject"/> to get.</typeparam> /// <param name="debugInterface">Instance of T.</param> /// <returns>The result code.</returns> public static Result DXGIGetDebugInterface <T>(out T debugInterface) where T : ComObject { try { var result = DXGIGetDebugInterface(typeof(T).GUID, out var nativePtr); if (result.Failure) { debugInterface = null; return(result); } debugInterface = CppObject.FromPointer <T>(nativePtr); return(result); } catch { debugInterface = default; return(ResultCode.NotFound); } }
private static void PlaySong(Song song) { #if WINDOWS_MEDIA_ENGINE _mediaEngineEx.Source = song.FilePath; _mediaEngineEx.Load(); _mediaEngineEx.Play(); #elif WINDOWS_MEDIA_SESSION // Cleanup the last song first. if (State != MediaState.Stopped) { _session.Stop(); _volumeController.Dispose(); _clock.Dispose(); } // Set the new song. _session.SetTopology(0, song.GetTopology()); // Get the volume interface. IntPtr volumeObj; MediaFactory.GetService(_session, MRPolicyVolumeService, SimpleAudioVolumeGuid, out volumeObj); _volumeController = CppObject.FromPointer <SimpleAudioVolume>(volumeObj); _volumeController.Mute = _isMuted; _volumeController.MasterVolume = _volume; // Get the clock. _clock = _session.Clock.QueryInterface <PresentationClock>(); // Start playing. var varStart = new Variant(); _session.Start(null, varStart); #else song.SetEventHandler(OnSongFinishedPlaying); song.Volume = _isMuted ? 0.0f : _volume; song.Play(); #endif State = MediaState.Playing; }