// 生成と終了 public Effekseer(SharpDX.Direct3D11.Device1 d3dDevice1, SharpDX.Direct3D11.DeviceContext d3ddc, float width, float height) { Renderer = EffekseerRendererDX11NET.Renderer.Create(d3dDevice1.NativePointer, d3ddc.NativePointer, squareMaxCount: 8000); Manager = EffekseerNET.Manager.Create(instance_max: 8000); Manager.SetSpriteRenderer(Renderer.CreateSpriteRenderer()); Manager.SetRibbonRenderer(Renderer.CreateRibbonRenderer()); Manager.SetRingRenderer(Renderer.CreateRingRenderer()); Manager.SetTrackRenderer(Renderer.CreateTrackRenderer()); Manager.SetModelRenderer(Renderer.CreateModelRenderer()); Manager.SetTextureLoader(Renderer.CreateTextureLoader()); Manager.SetModelLoader(Renderer.CreateModelLoader()); Manager.SetMaterialLoader(Renderer.CreateMaterialLoader()); Renderer.SetProjectionMatrix( new EffekseerNET.Matrix44().PerspectiveFovRH( 10.0f / 180.0f * MathF.PI, // 視野角10°;2Dにあわせるため、なるべく小さくして歪みを少なくする。 width / height, 1.0f, 500.0f)); Renderer.SetCameraMatrix( new EffekseerNET.Matrix44().LookAtRH( eye: new EffekseerNET.Vector3D(0.0f, 0f, 50.0f), at: new EffekseerNET.Vector3D(0.0f, 0.0f, 0.0f), up: new EffekseerNET.Vector3D(0.0f, 1.0f, 0.0f))); this._前回の更新時刻 = QPCTimer.生カウント; }
/// <summary> /// Creates device resources. /// </summary> /// <remarks> /// This method is called at the initialization of this instance. /// </remarks> protected virtual void CreateDeviceResources() { // Dispose previous references and set to null SafeDispose(ref d3dDevice); SafeDispose(ref d3dContext); SafeDispose(ref d2dDevice); SafeDispose(ref d2dContext); // Allocate new references // Enable compatibility with Direct2D // Retrieve the Direct3D 11.1 device amd device context var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; #if DEBUG creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug; #endif using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags)) d3dDevice = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>(); featureLevel = d3dDevice.FeatureLevel; // Get Direct3D 11.1 context d3dContext = ToDispose(d3dDevice.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>()); // Create Direct2D device using (var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device>()) d2dDevice = ToDispose(new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice)); // Create Direct2D context d2dContext = ToDispose(new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None)); }
/// <summary> /// Creates device resources. /// </summary> /// <remarks> /// This method is called at the initialization of this instance. /// </remarks> protected virtual void CreateDeviceResources() { // Dispose previous references and set to null if (d3dDevice != null) { RemoveAndDispose(ref d3dDevice); } if (d3dContext != null) { RemoveAndDispose(ref d3dContext); } if (d2dDevice != null) { RemoveAndDispose(ref d2dDevice); } if (d2dContext != null) { RemoveAndDispose(ref d2dContext); } // Allocate new references // Enable compatibility with Direct2D // Retrieve the Direct3D 11.1 device amd device context var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; // Decomment this line to have Debug. Unfortunately, debug is sometimes crashing applications, so it is disable by default try { // Try to create it with Video Support // If it is not working, we just use BGRA // Force to FeatureLevel.Level_9_1 using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags)) d3dDevice = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>(); } catch (Exception) { creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags)) d3dDevice = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>(); } featureLevel = d3dDevice.FeatureLevel; // Get Direct3D 11.1 context d3dContext = Collect(d3dDevice.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>()); // Create Direct2D device using (var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device>()) d2dDevice = Collect(new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice)); // Create Direct2D context d2dContext = Collect(new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None)); }
public void Run() { Debug.WriteLine("Run"); // First, create the Direct3D device. // This flag is required in order to enable compatibility with Direct2D. var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; #if DEBUG // If the project is in a debug build, enable debugging via SDK Layers with this flag. creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug; #endif // This array defines the ordering of feature levels that D3D should attempt to create. var featureLevels = new SharpDX.Direct3D.FeatureLevel[] { SharpDX.Direct3D.FeatureLevel.Level_11_1, SharpDX.Direct3D.FeatureLevel.Level_11_0, }; using (var d3dDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware , creationFlags, featureLevels)) { m_d3dDevice = d3dDevice.QueryInterface <SharpDX.Direct3D11.Device1>(); } m_d3dDeviceContext = m_d3dDevice.ImmediateContext1; // After the D3D device is created, create additional application resources. CreateWindowSizeDependentResources(); // Enter the render loop. Note that Windows Store apps should never exit. while (true) { // Process events incoming to the window. m_window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent); // Specify the render target we created as the output target. m_d3dDeviceContext.OutputMerger.SetRenderTargets(null, m_renderTargetView ); // Clear the render target to a solid color. m_d3dDeviceContext.ClearRenderTargetView( m_renderTargetView, new SharpDX.Color4(0.071f, 0.04f, 0.561f, 1.0f) ); // Present the rendered image to the window. Because the maximum frame latency is set to 1, // the render loop will generally be throttled to the screen refresh rate, typically around // 60Hz, by sleeping the application on Present until the screen is refreshed. m_swapChain.Present(1, 0); } }
private void OnLoaded(object sender, RoutedEventArgs e) { ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia | ManipulationModes.Scale; tileBackground.ImageSource = "Assets/bgline.JPG"; onePointWait.Visibility = Visibility.Collapsed; twoPointWait.Visibility = Visibility.Collapsed; double val = -Math.PI / 2; foreach (UIElement child in colorSelect.Children) { child.SetValue(Canvas.LeftProperty, Math.Cos(val) * 70); child.SetValue(Canvas.TopProperty, Math.Sin(val) * 70); val += Math.PI / 5; } var debugLevel = SharpDX.Direct2D1.DebugLevel.None; d2dFactory = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.SingleThreaded, debugLevel); var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; using (var defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, creationFlags)) d3dDevice = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>(); d3dContext = d3dDevice.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>(); using (dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device2>()) d2dDevice = new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice); d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None); DisplayProperties.LogicalDpiChanged += LogicalDpiChanged; }
/// <summary> /// Creates the swap chain. /// </summary> /// <param name="factory">The DXGI factory</param> /// <param name="device">The D3D11 device</param> /// <param name="desc">The swap chain description</param> /// <returns>An instance of swap chain</returns> protected abstract SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc);
private void OnLoaded(object sender, RoutedEventArgs e) { ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia | ManipulationModes.Scale; tileBackground.ImageSource = "Assets/bgline.JPG"; onePointWait.Visibility = Visibility.Collapsed; twoPointWait.Visibility = Visibility.Collapsed; double val = -Math.PI / 2; foreach (UIElement child in colorSelect.Children) { child.SetValue(Canvas.LeftProperty, Math.Cos(val) * 70); child.SetValue(Canvas.TopProperty, Math.Sin(val) * 70); val += Math.PI / 5; } var debugLevel = SharpDX.Direct2D1.DebugLevel.None; d2dFactory = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.SingleThreaded, debugLevel); var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; using (var defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, creationFlags)) d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>(); d3dContext = d3dDevice.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>(); using (dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device2>()) d2dDevice = new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice); d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None); DisplayProperties.LogicalDpiChanged += LogicalDpiChanged; }
void CreateDevice() { // d3d11 var flags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; #if DEBUG // error on Windows10(Geforce435M) //flags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug; #endif using (var device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware , flags , SharpDX.Direct3D.FeatureLevel.Level_10_0 )) { D3DDevice = device.QueryInterfaceOrNull<SharpDX.Direct3D11.Device1>(); } // DXGIDevice DXGIDevice = D3DDevice.QueryInterface<SharpDX.DXGI.Device2>(); DXGIDevice.MaximumFrameLatency = 1; }
protected override SharpDX.DXGI.SwapChain2 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { // Creates the swap chain for XAML composition using (var swapChain1 = new SwapChain1(factory, device, ref desc)) { var swapChain2 = swapChain1.QueryInterface<SwapChain2>(); // Associate the SwapChainPanel with the swap chain nativePanel.SwapChain = swapChain2; // Returns the new swap chain return swapChain2; } }
public static DrawingBackend FromFactoryAndDevice(Factory factory, Device1 device) { return new DrawingBackend(factory, device, false); }
protected override SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { // Creates the swap chain for the Window's Hwnd return(new SwapChain1(factory, device, Window.Handle, ref desc, CreateFullScreenDescription(), null)); }
protected override SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { // Creates a SwapChain from a CoreWindow pointer SwapChainFullScreenDescription scFullScreenDesc = new SwapChainFullScreenDescription() { Windowed = deviceManager.Settings.IsWindowed, RefreshRate = new Rational(120, 1) }; #if DIRECTX11_1 return(new SwapChain1(factory, device, form.Handle, ref desc)); #else return(factory.CreateSwapChainForHwnd(device, form.Handle, ref desc, scFullScreenDesc, null)); #endif }
//public override int Width //{ // get // { // return 0; // use size of CoreWindow // } //} //public override int Height //{ // get // { // return 0; // use size of CoreWindow // } //} protected override SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { // Creates the swap chain for the CoreWindow using (var coreWindow = new ComObject(_window)) return(new SwapChain1(factory, device, coreWindow, ref desc)); }
protected override SharpDX.DXGI.SwapChain2 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { // Creates a SwapChain from a CoreWindow pointer using (var comWindow = new ComObject(window)) using (var swapChain1 = new SwapChain1(factory, device, comWindow, ref desc)) return(swapChain1.QueryInterface <SwapChain2>()); }
protected override SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { // Creates the swap chain for XAML composition var swapChain = new SwapChain1(factory, device, ref desc); // Associate the SwapChainPanel with the swap chain nativePanel.SwapChain = swapChain; // Returns the new swap chain return(swapChain); }
DrawingBackend(Factory factory, Device1 device, bool ownsIt) { Factory = factory; Device = device; _owningFactoryAndDevice = ownsIt; }
/// <summary> /// Creates device resources. /// </summary> /// <remarks> /// This method is called at the initialization of this instance. /// </remarks> protected virtual void CreateDeviceResources() { // Dispose previous references and set to null SafeDispose(ref d3dDevice); SafeDispose(ref d3dContext); SafeDispose(ref d2dDevice); SafeDispose(ref d2dContext); // Allocate new references // Enable compatibility with Direct2D // Retrieve the Direct3D 11.1 device amd device context var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; #if DEBUG creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug; #endif using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags)) d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>(); featureLevel = d3dDevice.FeatureLevel; // Get Direct3D 11.1 context d3dContext = ToDispose(d3dDevice.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>()); // Create Direct2D device using (var dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>()) d2dDevice = ToDispose(new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice)); // Create Direct2D context d2dContext = ToDispose(new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None)); }
protected override SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { // Creates a SwapChain from a CoreWindow pointer using (var comWindow = new ComObject(window)) return(factory.CreateSwapChainForCoreWindow(device, comWindow, ref desc, null)); }
protected override SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { // Create the swap chain for XAML composition var swapChain = new SwapChain1(factory, device, ref desc); // Attach swap chain to SwapChainPanel nativePanel.SwapChain = swapChain; return(swapChain); }
/// <summary> /// Creates device resources. /// </summary> /// <remarks> /// This method is called at the initialization of this instance. /// </remarks> protected virtual void CreateDeviceResources() { // Dispose previous references and set to null RemoveAndDispose(ref d3dDevice); RemoveAndDispose(ref d3dContext); RemoveAndDispose(ref d2dDevice); RemoveAndDispose(ref d2dContext); // Allocate new references // Enable compatibility with Direct2D // Retrieve the Direct3D 11.1 device amd device context var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; // Decomment this line to have Debug. Unfortunately, debug is sometimes crashing applications, so it is disable by default try { // Try to create it with Video Support // If it is not working, we just use BGRA // Force to FeatureLevel.Level_9_1 using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags)) d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>(); } catch (Exception) { creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags)) d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>(); } featureLevel = d3dDevice.FeatureLevel; // Get Direct3D 11.1 context d3dContext = ToDispose(d3dDevice.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>()); // Create Direct2D device using (var dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>()) d2dDevice = ToDispose(new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice)); // Create Direct2D context d2dContext = ToDispose(new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None)); }
// Protected implementation of Dispose pattern. protected virtual void Dispose(bool disposing) { if (disposed) return; if (disposing) { if (SwapChain != null) { SwapChain.Dispose(); SwapChain = null; } // Free any other managed objects here. if (DXGIDevice != null) { DXGIDevice.Dispose(); DXGIDevice = null; } if (D3DDevice != null) { D3DDevice.Dispose(); D3DDevice = null; } } // Free any unmanaged objects here. // disposed = true; }