OSDN Git Service

ウィンドウのリサイズ時に異常終了する不具合を修正。
[strokestylet/CsWin10Desktop3.git] / FDK24 / メディア / デバイスリソース.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.Linq;
5
6 namespace FDK.メディア
7 {
8         public class デバイスリソース
9         {
10                 public SharpDX.Size2F 設計画面サイズdpx = new SharpDX.Size2F( 1920f, 1080f );    // 設計サイズ。
11                 public SharpDX.Size2F 物理画面サイズpx = new SharpDX.Size2F( 0, 0 );   // (0, 0) は、サイズ依存リソース無効の印。
12                 public IntPtr ウィンドウハンドル = IntPtr.Zero;
13                 public float 視野角deg { get; set; } = 45f;
14                 public SharpDX.Matrix ビュー変換行列
15                 {
16                         get
17                         {
18                                 var カメラの位置 = new SharpDX.Vector3( 0f, 0f, ( -2f * this.dz( this.設計画面サイズdpx.Height, this.視野角deg ) ) );
19                                 var カメラの注視点 = new SharpDX.Vector3( 0f, 0f, 0f );
20                                 var カメラの上方向 = new SharpDX.Vector3( 0f, 1f, 0f );
21                                 var mat = SharpDX.Matrix.LookAtLH( カメラの位置, カメラの注視点, カメラの上方向 );
22                                 mat.Transpose();  // 転置
23                                 return mat;
24                         }
25                 }
26                 public SharpDX.Matrix 射影変換行列
27                 {
28                         get
29                         {
30                                 float dz = this.dz( this.設計画面サイズdpx.Height, this.視野角deg );
31                                 var mat = SharpDX.Matrix.PerspectiveFovLH(
32                                         SharpDX.MathUtil.DegreesToRadians( 視野角deg ),
33                                         設計画面サイズdpx.Width / 設計画面サイズdpx.Height,  // アスペクト比
34                                         -dz,  // 前方投影面までの距離
35                                         dz ); // 後方投影面までの距離
36                                 mat.Transpose();  // 転置
37                                 return mat;
38                         }
39                 }
40                 public SharpDX.MediaFoundation.DXGIDeviceManager DXGIDeviceManager => this.bs_DXGIDeviceManager;
41                 public SharpDX.DXGI.SwapChain SwapChain => this.bs_SwapChain;
42                 public SharpDX.Direct3D11.RenderTargetView D3DRenderTargetView => this.bs_D3DRenderTargetView;
43                 public SharpDX.Mathematics.Interop.RawViewportF[] D3DViewPort => this.bs_D3DViewPort;
44                 public SharpDX.Direct3D11.Texture2D D3DDepthStencil => this.bs_D3DDepthStencil;
45                 public SharpDX.Direct3D11.DepthStencilView D3DDepthStencilView => this.bs_D3DDepthStencilView;
46                 public SharpDX.Direct3D11.DepthStencilState D3DDepthStencilState => this.bs_D3DDepthStencilState;
47                 public SharpDX.Direct2D1.Factory2 D2DFactory2 => this.bs_D2DFactory2;
48                 public SharpDX.DirectWrite.Factory DWriteFactory => this.bs_DWriteFactory;
49                 public SharpDX.WIC.ImagingFactory2 WicImagingFactory2 => this.bs_WicImagingFactory2;
50                 public SharpDX.Direct2D1.Device1 D2DDevice1 => this.bs_D2DDevice1;
51                 public SharpDX.Direct2D1.DeviceContext1 D2DContext1 => this.bs_D2DContext1;
52                 public SharpDX.Direct2D1.Bitmap1 D2DRenderTargetBitmap => this.bs_D2DRenderTargetBitmap;
53
54                 public float 拡大率DPXtoPX横方法 => ( this.物理画面サイズpx.Width / this.設計画面サイズdpx.Width );
55                 public float 拡大率DPXtoPX縦方向 => ( this.物理画面サイズpx.Height / this.設計画面サイズdpx.Height );
56                 public float 拡大率PXtoDPX横方法 => ( 1f / this.拡大率DPXtoPX横方法 );
57                 public float 拡大率PXtoDPX縦方法 => ( 1f / this.拡大率DPXtoPX縦方向 );
58                 public SharpDX.Matrix3x2 拡大行列DPXtoPX => SharpDX.Matrix3x2.Scaling( this.拡大率DPXtoPX横方法, this.拡大率DPXtoPX縦方向 );
59                 public SharpDX.Matrix3x2 拡大行列PXtoDPX => SharpDX.Matrix3x2.Scaling( this.拡大率PXtoDPX横方法, this.拡大率PXtoDPX縦方法 );
60                 public SharpDX.Matrix3x2 行列を単位変換するDPXtoPX( SharpDX.Matrix3x2 行列dpx ) => 行列dpx * 拡大行列DPXtoPX;
61                 public SharpDX.Matrix3x2 行列を単位変換するPXtoDPX( SharpDX.Matrix3x2 行列px ) => 行列px * 拡大行列PXtoDPX;
62
63                 public void すべてのリソースを作成する( System.Drawing.Size バックバッファサイズ, IntPtr ウィンドウハンドル )
64                 {
65                         this.物理画面サイズpx = new SharpDX.Size2F( バックバッファサイズ.Width, バックバッファサイズ.Height );
66                         this.ウィンドウハンドル = ウィンドウハンドル;
67
68                         this.すべてのリソースを作成する();
69                 }
70                 protected void すべてのリソースを作成する()
71                 {
72                         // これらが呼び出し前に設定されていること。
73                         Debug.Assert( ( 0f < this.物理画面サイズpx.Width ) && ( 0f < this.物理画面サイズpx.Height ) );
74                         Debug.Assert( IntPtr.Zero != this.ウィンドウハンドル );
75
76                         #region " D2DFactory2 を作成する。"
77                         //-----------------
78                         {
79                                 var デバッグレベル = SharpDX.Direct2D1.DebugLevel.None;
80 #if DEBUG
81                                 // プロジェクトがデバッグビルドに含まれている場合は、Direct2D デバッグレイヤーを SDK レイヤーを介して有効にする。
82                                 デバッグレベル = SharpDX.Direct2D1.DebugLevel.Information;
83 #endif
84                                 this.bs_D2DFactory2 = new SharpDX.Direct2D1.Factory2(
85                                         SharpDX.Direct2D1.FactoryType.SingleThreaded,
86                                         デバッグレベル );
87                         }
88                         //-----------------
89                         #endregion
90                         #region " DWriteFactory を作成する。"
91                         //-----------------
92                         this.bs_DWriteFactory = new SharpDX.DirectWrite.Factory(
93                                 SharpDX.DirectWrite.FactoryType.Shared );
94                         //-----------------
95                         #endregion
96                         #region " WicImagingFactory2 を作成する。"
97                         //-----------------
98                         this.bs_WicImagingFactory2 = new SharpDX.WIC.ImagingFactory2();
99                         //-----------------
100                         #endregion
101
102                         var d3dDevice = (SharpDX.Direct3D11.Device) null;
103
104                         #region " DXGIDeviceManager を作成する。"
105                         //-----------------
106                         this.bs_DXGIDeviceManager = new SharpDX.MediaFoundation.DXGIDeviceManager();
107                         //-----------------
108                         #endregion
109                         #region " D3Dデバイス、スワップチェーンを作成する。"
110                         //----------------
111                         // スワップチェーン desc
112                         var swapChainDesc = new SharpDX.DXGI.SwapChainDescription() {
113                                 BufferCount = 2,
114                                 ModeDescription = new SharpDX.DXGI.ModeDescription() {
115                                         Width = (int) this.物理画面サイズpx.Width,
116                                         Height = (int) this.物理画面サイズpx.Height,
117                                         RefreshRate = new SharpDX.DXGI.Rational( 60, 1 ),
118                                         Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,  // D2D をサポートするなら B8G8R8A8 で。
119                                         Scaling = SharpDX.DXGI.DisplayModeScaling.Stretched,
120                                         ScanlineOrdering = SharpDX.DXGI.DisplayModeScanlineOrder.Progressive,
121                                 },
122                                 IsWindowed = true,
123                                 OutputHandle = ウィンドウハンドル,
124                                 SampleDescription = new SharpDX.DXGI.SampleDescription( 1, 0 ),
125                                 SwapEffect = SharpDX.DXGI.SwapEffect.Discard,
126                                 Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
127                         };
128                         // 機能レベル
129                         var featureLevels = new SharpDX.Direct3D.FeatureLevel[] {
130                                 SharpDX.Direct3D.FeatureLevel.Level_11_0,
131                                 SharpDX.Direct3D.FeatureLevel.Level_10_1,
132                                 SharpDX.Direct3D.FeatureLevel.Level_10_0,
133                         };
134                         var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport; // D2Dをサポートするなら必須。
135 #if DEBUG
136                         creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug;
137 #endif
138                         // デバイスとスワップチェーンを作成する。
139                         SharpDX.Direct3D11.Device.CreateWithSwapChain(
140                                 SharpDX.Direct3D.DriverType.Hardware,
141                                 creationFlags,
142                                 featureLevels,
143                                 swapChainDesc,
144                                 out d3dDevice,
145                                 out this.bs_SwapChain );
146
147                         FDK.Log.Info( "D3Dデバイスとスワップチェーンを生成しました。" );
148                         FDK.Log.Info( $"機能レベル: {d3dDevice.FeatureLevel.ToString()}" );
149                         //----------------
150                         #endregion
151
152                         using( d3dDevice )
153                         {
154                                 // D3D 関連
155                                 #region " D3DDevice が ID3D11VideoDevice を実装してないならエラー。(Win8以降のPCでは実装されているはず。) "
156                                 //-----------------
157                                 using( var videoDevice = d3dDevice.QueryInterfaceOrNull<SharpDX.Direct3D11.VideoDevice>() )
158                                 {
159                                         if( null == videoDevice )
160                                                 throw new FDKException( "Direct3D11デバイスが、ID3D11VideoDevice をサポートしていません。" );
161                                 }
162                                 //-----------------
163                                 #endregion
164                                 #region " マルチスレッドモードを ON に設定する。DXVAを使う場合は必須。"
165                                 //-----------------
166                                 using( var multithread = d3dDevice.QueryInterfaceOrNull<SharpDX.Direct3D.DeviceMultithread>() )
167                                 {
168                                         if( null == multithread )
169                                                 throw new FDKException( "Direct3D11デバイスが、ID3D10Multithread をサポートしていません。" );
170
171                                         multithread.SetMultithreadProtected( true );
172                                 }
173                                 //-----------------
174                                 #endregion
175                                 #region " DXGIデバイスマネージャに D3Dデバイスを登録する。"
176                                 //-----------------
177                                 this.DXGIDeviceManager.ResetDevice( d3dDevice );
178                                 //-----------------
179                                 #endregion
180                                 #region " すべての Windows イベントを無視する。具体的には PrintScreen と Alt+Enter 。"
181                                 //----------------
182                                 using( var factory = this.bs_SwapChain.GetParent<SharpDX.DXGI.Factory>() )
183                                 {
184                                         factory.MakeWindowAssociation( ウィンドウハンドル, SharpDX.DXGI.WindowAssociationFlags.IgnoreAll );
185                                 }
186                                 //----------------
187                                 #endregion
188                                 #region " 深度ステンシルステートを作成する。"
189                                 //----------------
190                                 var DepthSencil = new SharpDX.Direct3D11.DepthStencilStateDescription() {
191                                         IsDepthEnabled = true,  // 深度テストあり
192                                         DepthWriteMask = SharpDX.Direct3D11.DepthWriteMask.All,     // 書き込む
193                                         DepthComparison = SharpDX.Direct3D11.Comparison.Less,   // 手前の物体を描画
194                                         IsStencilEnabled = false,   // ステンシルテストなし。
195                                         StencilReadMask = 0,    // ステンシル読み込みマスク。
196                                         StencilWriteMask = 0,   // ステンシル書き込みマスク。
197
198                                         // 面が表を向いている場合のステンシル・テストの設定
199                                         FrontFace = new SharpDX.Direct3D11.DepthStencilOperationDescription() {
200                                                 FailOperation = SharpDX.Direct3D11.StencilOperation.Keep,   // 維持
201                                                 DepthFailOperation = SharpDX.Direct3D11.StencilOperation.Keep,  // 維持
202                                                 PassOperation = SharpDX.Direct3D11.StencilOperation.Keep,   // 維持
203                                                 Comparison = SharpDX.Direct3D11.Comparison.Never,   // 常に失敗
204                                         },
205
206                                         // 面が裏を向いている場合のステンシル・テストの設定
207                                         BackFace = new SharpDX.Direct3D11.DepthStencilOperationDescription() {
208                                                 FailOperation = SharpDX.Direct3D11.StencilOperation.Keep,   // 維持
209                                                 DepthFailOperation = SharpDX.Direct3D11.StencilOperation.Keep,  // 維持
210                                                 PassOperation = SharpDX.Direct3D11.StencilOperation.Keep,   // 維持
211                                                 Comparison = SharpDX.Direct3D11.Comparison.Always,  // 常に成功
212                                         },
213                                 };
214                                 this.bs_D3DDepthStencilState = new SharpDX.Direct3D11.DepthStencilState( d3dDevice, DepthSencil );
215                                 //----------------
216                                 #endregion
217                         }
218
219                         this.サイズに依存するリソースを作成する();
220                 }
221                 public void すべてのリソースを解放する()
222                 {
223                         FDK.Utilities.解放する( ref this.bs_WicImagingFactory2 );
224                         FDK.Utilities.解放する( ref this.bs_DWriteFactory );
225                         FDK.Utilities.解放する( ref this.bs_D2DFactory2 );
226
227                         // D3D 関連
228                         var d3dDevice = (SharpDX.Direct3D11.Device) null;
229                         using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.DXGIDeviceManager, out d3dDevice ) )
230                         {
231                                 d3dDevice.ImmediateContext?.ClearState();   // デバイスステートをクリアする。
232                         }
233                         this.bs_SwapChain?.SetFullscreenState( fullscreen: false, targetRef: null );    // スワップチェインをウインドウモードにする。
234                         this.サイズに依存するリソースを解放する();
235                         FDK.Utilities.解放する( ref this.bs_D3DDepthStencilState );
236                         FDK.Utilities.解放する( ref this.bs_SwapChain );
237                         FDK.Utilities.解放する( ref this.bs_DXGIDeviceManager );
238                 }
239                 public void サイズに依存するリソースを作成する()
240                 {
241                         #region " スワップチェーンのサイズを変更する。"
242                         //----------------
243                         Debug.Assert( null != this.SwapChain ); // スワップチェーンは、デバイスとともに、すでに生成される。
244                         this.SwapChain.ResizeBuffers(
245                                 bufferCount: 2,
246                                 width: (int) this.物理画面サイズpx.Width,
247                                 height: (int) this.物理画面サイズpx.Height,
248                                 newFormat: SharpDX.DXGI.Format.Unknown, // 以前のフォーマットを維持する。
249                                 swapChainFlags: SharpDX.DXGI.SwapChainFlags.None );
250                         //----------------
251                         #endregion
252
253                         // D3D 関連
254                         using( var backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>( this.bs_SwapChain, 0 ) )
255                         {
256                                 var d3dDevice = (SharpDX.Direct3D11.Device) null;
257                                 using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.DXGIDeviceManager, out d3dDevice ) )
258                                 {
259                                         #region " RenderTargetView の作成 "
260                                         //----------------
261                                         this.bs_D3DRenderTargetView = new SharpDX.Direct3D11.RenderTargetView( d3dDevice, backBuffer );
262                                         //----------------
263                                         #endregion
264                                         #region " 深度ステンシルテクスチャの作成 "
265                                         //----------------
266                                         var descDepth = backBuffer.Description;
267                                         //descDepth.Width = backBuffer.Description.Width;       → backBuffer に同じ
268                                         //descDepth.Height = backBuffer.Description.Height;     → 同上
269                                         descDepth.MipLevels = 1;    // ミップマップレベル数
270                                         descDepth.ArraySize = 1;    // 配列サイズ
271                                         descDepth.Format = SharpDX.DXGI.Format.D32_Float;   // フォーマット(深度のみ)
272                                         descDepth.Usage = SharpDX.Direct3D11.ResourceUsage.Default; // デフォルト使用法
273                                         descDepth.BindFlags = SharpDX.Direct3D11.BindFlags.DepthStencil;    // 深度ステンシル
274                                         descDepth.CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None;  // CPUからはアクセスしない
275                                         descDepth.OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None;    // その他の設定なし
276                                         this.bs_D3DDepthStencil = new SharpDX.Direct3D11.Texture2D( d3dDevice, descDepth );
277                                         //----------------
278                                         #endregion
279                                         #region " 深度ステンシルビューの作成 "
280                                         //----------------
281                                         var descDSV = new SharpDX.Direct3D11.DepthStencilViewDescription() {
282                                                 Format = descDepth.Format,
283                                                 Dimension = SharpDX.Direct3D11.DepthStencilViewDimension.Texture2D,
284                                                 Flags = SharpDX.Direct3D11.DepthStencilViewFlags.None,
285                                         };
286                                         descDSV.Texture2D.MipSlice = 0;
287                                         this.bs_D3DDepthStencilView = new SharpDX.Direct3D11.DepthStencilView( d3dDevice, this.bs_D3DDepthStencil, descDSV );
288                                         //----------------
289                                         #endregion
290                                         #region " ビューポートの設定 "
291                                         //----------------
292                                         this.bs_D3DViewPort[ 0 ] = new SharpDX.Mathematics.Interop.RawViewportF() {
293                                                 X = 0.0f,
294                                                 Y = 0.0f,
295                                                 Width = (float) backBuffer.Description.Width,
296                                                 Height = (float) backBuffer.Description.Height,
297                                                 MinDepth = 0.0f,
298                                                 MaxDepth = 1.0f,
299                                         };
300                                         //----------------
301                                         #endregion
302                                         #region " テクスチャの共有リソースの作成 "
303                                         //----------------
304                                         FDK.メディア.テクスチャ.共有リソースを作成する( this );
305                                         //----------------
306                                         #endregion
307                                 }
308
309                                 // D2D 関連
310                                 using( var backbuffer = SharpDX.DXGI.Surface.FromSwapChain( this.bs_SwapChain, 0 ) )
311                                 {
312                                         #region " D2DDevice を作成する。"
313                                         //-----------------
314                                         using( var dxgiDevice = d3dDevice.QueryInterfaceOrNull<SharpDX.DXGI.Device>() )
315                                         {
316                                                 if( null == dxgiDevice )
317                                                         throw new FDKException( "Direct3D11デバイスが、IDXGIDevice3 をサポートしていません。" );
318
319                                                 this.bs_D2DDevice1 = new SharpDX.Direct2D1.Device1( this.D2DFactory2, dxgiDevice );
320                                         }
321                                         //-----------------
322                                         #endregion
323                                         #region " D2Dの既定のコンテキスト D2DContext1 を作成する。"
324                                         //-----------------
325                                         this.bs_D2DContext1 = new SharpDX.Direct2D1.DeviceContext1( this.D2DDevice1, SharpDX.Direct2D1.DeviceContextOptions.None );
326
327                                         // 現在のディスプレイDPI を取得し、D2DContext に設定する。
328                                         this.D2DContext1.DotsPerInch = this.D2DFactory2.DesktopDpi;
329                                         //-----------------
330                                         #endregion
331                                         #region " D2Dの既定のレンダーターゲットビットマップを作成する。"
332                                         //-----------------
333                                         var dpi = this.D2DContext1.DotsPerInch;
334
335                                         // DXGIスワップチェーンのバックバッファとデータを共有するD2Dターゲットビットマップを作成する。ビューではなく共有リソース。
336                                         this.bs_D2DRenderTargetBitmap = new SharpDX.Direct2D1.Bitmap1(
337                                                 this.D2DContext1,   // このコンテキストを通じて、
338                                                 backbuffer, // バックバッファとデータを共有する。
339                                                 new SharpDX.Direct2D1.BitmapProperties1(
340                                                         new SharpDX.Direct2D1.PixelFormat( backbuffer.Description.Format, SharpDX.Direct2D1.AlphaMode.Premultiplied ),
341                                                         dpi.Width,
342                                                         dpi.Height,
343                                                         SharpDX.Direct2D1.BitmapOptions.Target | SharpDX.Direct2D1.BitmapOptions.CannotDraw ) );
344                                         //-----------------
345                                         #endregion
346                                         #region " テキストのアンチエイリアシングを設定する。Grayscale が、すべての Windows ストアアプリで推奨される。"
347                                         //-----------------
348                                         this.D2DContext1.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Grayscale;
349                                         //-----------------
350                                         #endregion
351                                 }
352                         }
353                 }
354                 public void サイズに依存するリソースを解放する()
355                 {
356                         // D2D 関連
357                         FDK.Utilities.解放する( ref this.bs_D2DRenderTargetBitmap );
358                         FDK.Utilities.解放する( ref this.bs_D2DContext1 );
359                         FDK.Utilities.解放する( ref this.bs_D2DDevice1 );
360
361                         // D3D 関連
362                         var d3dDevice = (SharpDX.Direct3D11.Device) null;
363                         using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.DXGIDeviceManager, out d3dDevice ) )
364                         {
365                                 // 描画ターゲットを解除する。
366                                 d3dDevice.ImmediateContext.OutputMerger.ResetTargets();
367
368                                 FDK.メディア.テクスチャ.共有リソースを解放する();
369                                 FDK.Utilities.解放する( ref this.bs_D3DDepthStencilView );
370                                 FDK.Utilities.解放する( ref this.bs_D3DDepthStencil );
371                                 FDK.Utilities.解放する( ref this.bs_D3DRenderTargetView );
372                                 //FDK.Utilities.解放する( ref this.bs_SwapChain ); → スワップチェーンは解放しない(生成・解放はデバイスとセット)。
373
374                                 // (0,0)は、サイズ依存リソース無効の印。
375                                 this.物理画面サイズpx = new SharpDX.Size2F( 0, 0 );
376                         }
377                 }
378                 public void D3Dデバイスが消失していれば再構築する( out bool 異常状態なのでアプリを終了せよ )
379                 {
380                         var d3dDevice = (SharpDX.Direct3D11.Device) null;
381                         using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.DXGIDeviceManager, out d3dDevice ) )
382                         {
383                                 異常状態なのでアプリを終了せよ = false;
384
385                                 var 削除理由 = d3dDevice.DeviceRemovedReason;
386                                 if( 削除理由.Success )
387                                         return;
388
389                                 var エラー詳細 = new[] {
390                                         new { Code = SharpDX.DXGI.ResultCode.DeviceHung.Code, Info = SharpDX.DXGI.ResultCode.DeviceHung.ApiCode, Rebuild = true },
391                                         new { Code = SharpDX.DXGI.ResultCode.DeviceReset.Code, Info = SharpDX.DXGI.ResultCode.DeviceReset.ApiCode, Rebuild = true },
392                                         new { Code = SharpDX.DXGI.ResultCode.DeviceRemoved.Code, Info = SharpDX.DXGI.ResultCode.DeviceRemoved.ApiCode, Rebuild = false },
393                                         new { Code = SharpDX.DXGI.ResultCode.DriverInternalError.Code, Info = SharpDX.DXGI.ResultCode.DriverInternalError.ApiCode, Rebuild = false },
394                                         new { Code = SharpDX.DXGI.ResultCode.InvalidCall.Code, Info = SharpDX.DXGI.ResultCode.InvalidCall.ApiCode, Rebuild = false },
395                                 }.First( ( エラー ) => エラー.Code == 削除理由.Code );  // 見つからないなら System.InvalidOperationException 。
396
397                                 Trace.WriteLine( $"D3Dデバイスが消失しました: {エラー詳細.Info}" );
398
399                                 if( エラー詳細.Rebuild )
400                                 {
401                                         this.すべてのリソースを解放する();
402                                         this.すべてのリソースを作成する();
403                                 }
404                                 else
405                                 {
406                                         異常状態なのでアプリを終了せよ = true;
407                                 }
408                         }
409                 }
410
411                 private float dz( float 高さdpx, float 視野角deg )
412                 {
413                         return (float) ( 高さdpx / ( 4.0 * Math.Tan( SharpDX.MathUtil.DegreesToRadians( 視野角deg / 2.0f ) ) ) );
414                 }
415
416                 #region " バックストア。"
417                 //----------------
418                 private SharpDX.Direct2D1.Factory2 bs_D2DFactory2 = null;
419                 private SharpDX.DirectWrite.Factory bs_DWriteFactory = null;
420                 private SharpDX.WIC.ImagingFactory2 bs_WicImagingFactory2 = null;
421                 private SharpDX.MediaFoundation.DXGIDeviceManager bs_DXGIDeviceManager = null;
422                 private SharpDX.DXGI.SwapChain bs_SwapChain = null;
423                 private SharpDX.Mathematics.Interop.RawViewportF[] bs_D3DViewPort = new SharpDX.Mathematics.Interop.RawViewportF[ 1 ];
424                 private SharpDX.Direct3D11.DepthStencilState bs_D3DDepthStencilState = null;
425                 private SharpDX.Direct3D11.RenderTargetView bs_D3DRenderTargetView = null;
426                 private SharpDX.Direct3D11.Texture2D bs_D3DDepthStencil = null;
427                 private SharpDX.Direct3D11.DepthStencilView bs_D3DDepthStencilView = null;
428                 private SharpDX.Direct2D1.Device1 bs_D2DDevice1 = null;
429                 private SharpDX.Direct2D1.DeviceContext1 bs_D2DContext1 = null;
430                 private SharpDX.Direct2D1.Bitmap1 bs_D2DRenderTargetBitmap = null;
431                 //----------------
432                 #endregion
433         }
434 }