}
}
public SharpDX.MediaFoundation.DXGIDeviceManager DXGIDeviceManager => ( this.bs_DXGIDeviceManager );
- public SharpDX.DXGI.SwapChain SwapChain => ( this.bs_SwapChain );
+ public SharpDX.DXGI.SwapChain1 SwapChain1 => ( this.bs_SwapChain1 );
public SharpDX.Direct3D11.RenderTargetView D3DRenderTargetView => ( this.bs_D3DRenderTargetView );
public SharpDX.Mathematics.Interop.RawViewportF[] D3DViewPort => ( this.bs_D3DViewPort );
public SharpDX.Direct3D11.Texture2D D3DDepthStencil => ( this.bs_D3DDepthStencil );
var デバッグレベル = SharpDX.Direct2D1.DebugLevel.None;
#if DEBUG
// プロジェクトがデバッグビルドに含まれている場合は、Direct2D デバッグレイヤーを SDK レイヤーを介して有効にする。
- //デバッグレベル = SharpDX.Direct2D1.DebugLevel.Information;
+ デバッグレベル = SharpDX.Direct2D1.DebugLevel.Information;
#endif
this.bs_D2DFactory2 = new SharpDX.Direct2D1.Factory2( SharpDX.Direct2D1.FactoryType.MultiThreaded, デバッグレベル );
}
this.bs_DXGIDeviceManager = new SharpDX.MediaFoundation.DXGIDeviceManager();
//-----------------
#endregion
- #region " D3Dã\83\87ã\83\90ã\82¤ã\82¹ã\80\81ã\82¹ã\83¯ã\83\83ã\83\97ã\83\81ã\82§ã\83¼ã\83³ã\82\92ä½\9cæ\88\90ã\81\99ã\82\8bã\80\82"
+ #region " D3Dデバイスを作成する。"
//----------------
- // スワップチェーン desc
- var swapChainDesc = new SharpDX.DXGI.SwapChainDescription() {
- BufferCount = 2,
- ModeDescription = new SharpDX.DXGI.ModeDescription() {
- Width = (int) this.物理画面サイズpx.Width,
- Height = (int) this.物理画面サイズpx.Height,
- RefreshRate = new SharpDX.DXGI.Rational( 60, 1 ),
- Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, // D2D をサポートするなら B8G8R8A8 を使う必要がある。
- Scaling = SharpDX.DXGI.DisplayModeScaling.Stretched,
- ScanlineOrdering = SharpDX.DXGI.DisplayModeScanlineOrder.Progressive,
- },
- IsWindowed = true,
- OutputHandle = ウィンドウハンドル,
- SampleDescription = new SharpDX.DXGI.SampleDescription( 1, 0 ),
- SwapEffect = SharpDX.DXGI.SwapEffect.Discard,
- Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
- Flags = SharpDX.DXGI.SwapChainFlags.AllowModeSwitch,
- };
- // 機能レベル
- var featureLevels = new SharpDX.Direct3D.FeatureLevel[] {
- SharpDX.Direct3D.FeatureLevel.Level_11_0,
- SharpDX.Direct3D.FeatureLevel.Level_10_1,
- SharpDX.Direct3D.FeatureLevel.Level_10_0,
- };
+ // 作成フラグ
var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; // D2Dをサポートするなら BgraSupport フラグが必須。
#if DEBUG
// D3D11 Debugメッセージは、プロジェクトプロパティで「ネイティブコードのデバッグを有効にする」を ON にしないと表示されないので注意。
creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug;
#endif
- // デバイスとスワップチェーンを作成する。
- SharpDX.Direct3D11.Device.CreateWithSwapChain(
+ d3dDevice = new SharpDX.Direct3D11.Device(
SharpDX.Direct3D.DriverType.Hardware,
creationFlags,
- featureLevels,
- swapChainDesc,
- out d3dDevice,
- out this.bs_SwapChain );
+ new SharpDX.Direct3D.FeatureLevel[] {
+ SharpDX.Direct3D.FeatureLevel.Level_11_1,
+ SharpDX.Direct3D.FeatureLevel.Level_11_0,
+ } );
- FDK.Log.Info( "D3Dã\83\87ã\83\90ã\82¤ã\82¹ã\81¨ã\82¹ã\83¯ã\83\83ã\83\97ã\83\81ã\82§ã\83¼ã\83³ã\82\92ç\94\9fæ\88\90ã\81\97ã\81¾ã\81\97ã\81\9fã\80\82" );
+ FDK.Log.Info( "D3Dデバイスを生成しました。" );
FDK.Log.Info( $"機能レベル: {d3dDevice.FeatureLevel.ToString()}" );
//----------------
#endregion
{
// D3D 関連
+ #region " スワップチェーンを作成する。"
+ //----------------
+ using( var dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>() )
+ using( var dxgiAdapter = dxgiDevice.Adapter )
+ using( var dxgiFactory2 = dxgiAdapter.GetParent<SharpDX.DXGI.Factory2>() )
+ {
+ var swapChainDesc1 = new SharpDX.DXGI.SwapChainDescription1() {
+ BufferCount = 2,
+ Width = (int) this.物理画面サイズpx.Width,
+ Height = (int) this.物理画面サイズpx.Height,
+ Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, // D2D をサポートするなら B8G8R8A8 を使う必要がある。
+ Scaling = SharpDX.DXGI.Scaling.Stretch,
+ SampleDescription = new SharpDX.DXGI.SampleDescription( 1, 0 ),
+ SwapEffect = SharpDX.DXGI.SwapEffect.FlipDiscard, // Windowsストアアプリはこれが必須。
+ Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
+ //Flags = SharpDX.DXGI.SwapChainFlags.None,
+ Flags = SharpDX.DXGI.SwapChainFlags.AllowModeSwitch,
+ };
+ this.bs_SwapChain1 = new SharpDX.DXGI.SwapChain1(
+ dxgiFactory2,
+ d3dDevice,
+ this.ウィンドウハンドル,
+ ref swapChainDesc1 );
+ }
+ //----------------
+ #endregion
#region " デバイスからデバッグオブジェクトを取得する。"
//----------------
this.bs_D3DDeviceDebug = d3dDevice.QueryInterfaceOrNull<SharpDX.Direct3D11.DeviceDebug>();
#endregion
#region " すべての Windows イベントを無視する。具体的には PrintScreen と Alt+Enter 。"
//----------------
- using( var factory = this.bs_SwapChain.GetParent<SharpDX.DXGI.Factory>() )
+ using( var factory = this.bs_SwapChain1.GetParent<SharpDX.DXGI.Factory>() )
{
factory.MakeWindowAssociation( ウィンドウハンドル, SharpDX.DXGI.WindowAssociationFlags.IgnoreAll );
}
FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
// D3D 関連
- this.bs_SwapChain?.SetFullscreenState( fullscreen: false, targetRef: null ); // スワップチェインをウインドウモードにする。
+ this.bs_SwapChain1?.SetFullscreenState( fullscreen: false, targetRef: null ); // スワップチェインをウインドウモードにする。
this.サイズに依存するリソースを解放する();
- FDK.Utilities.解放する( ref this.bs_SwapChain );
+ FDK.Utilities.解放する( ref this.bs_SwapChain1 );
FDK.Utilities.解放する( ref this.bs_DXGIDeviceManager );
// その他
#region " スワップチェーンのサイズを変更する。"
//----------------
- Debug.Assert( null != this.SwapChain ); // スワップチェーンは(デバイスとともに)すでに生成されていること。
-
- this.SwapChain.ResizeBuffers(
+ Debug.Assert( null != this.SwapChain1 ); // スワップチェーンは(デバイスとともに)すでに生成されていること。
+
+ // ResizeTarget は、全画面モードにしたとき、モニタ画面の解像度も変更する。
+ //var mode = new SharpDX.DXGI.ModeDescription(
+ // width: (int) this.物理画面サイズpx.Width,
+ // height: (int) this.物理画面サイズpx.Height,
+ // refreshRate: new SharpDX.DXGI.Rational( 60000, 1001 ), // 多くのモニタは(60,1)じゃない;一致しないとFlipじゃなくBlitになるので注意(MSDN)。
+ // format: SharpDX.DXGI.Format.B8G8R8A8_UNorm );
+ //this.SwapChain.ResizeTarget( ref mode );
+
+ // ResizeBuffers は、全画面モードにしたとき、モニタの解像度を変更しない。
+ // ただし、swapChainFlags に AllowModeSwitch を指定すると変更される(ResizeTargetと同じ挙動になる)。
+ this.SwapChain1.ResizeBuffers(
bufferCount: 2,
width: (int) this.物理画面サイズpx.Width,
height: (int) this.物理画面サイズpx.Height,
newFormat: SharpDX.DXGI.Format.B8G8R8A8_UNorm,
+ //swapChainFlags: SharpDX.DXGI.SwapChainFlags.None );
swapChainFlags: SharpDX.DXGI.SwapChainFlags.AllowModeSwitch );
//----------------
#endregion
// バックバッファを使って、D3D / D2D 関連のリソースを作成する。
- using( var backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>( this.bs_SwapChain, 0 ) )
+ using( var backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>( this.bs_SwapChain1, 0 ) )
{
var d3dDevice = (SharpDX.Direct3D11.Device) null;
using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.DXGIDeviceManager, out d3dDevice ) )
#endregion
// D2D 関連
- using( var backsurface = SharpDX.DXGI.Surface.FromSwapChain( this.bs_SwapChain, 0 ) )
+ using( var backsurface = SharpDX.DXGI.Surface.FromSwapChain( this.bs_SwapChain1, 0 ) )
{
#region " D2DDevice を作成する。"
//-----------------
private SharpDX.DirectWrite.Factory bs_DWriteFactory = null;
private SharpDX.WIC.ImagingFactory2 bs_WicImagingFactory2 = null;
private SharpDX.MediaFoundation.DXGIDeviceManager bs_DXGIDeviceManager = null;
- private SharpDX.DXGI.SwapChain bs_SwapChain = null;
+ private SharpDX.DXGI.SwapChain1 bs_SwapChain1 = null;
private SharpDX.Mathematics.Interop.RawViewportF[] bs_D3DViewPort = new SharpDX.Mathematics.Interop.RawViewportF[ 1 ];
private SharpDX.Direct3D11.DepthStencilState bs_D3DDepthStencilState = null;
private SharpDX.Direct3D11.RenderTargetView bs_D3DRenderTargetView = null;