OSDN Git Service

テストテクスチャの表示処理を、テクスチャクラスに委譲。
authorくまかみ工房 <kumakamikoubou@gmail.com>
Sat, 17 Sep 2016 14:06:32 +0000 (23:06 +0900)
committerくまかみ工房 <kumakamikoubou@gmail.com>
Sat, 17 Sep 2016 14:06:32 +0000 (23:06 +0900)
FDK24/ApplicationFormBase.cs
FDK24/メディア/テクスチャ.cs

index 4950e7b..7172d44 100644 (file)
@@ -59,6 +59,13 @@ namespace FDK
                        // 以下は、実装例。
                        //------------------
                        Debug.Assert( null == this.デバイスリソース );  // 解放された後であること。
+
+#warning " 最終的に削除すること。"
+                       if( null != this.testTexture )
+                       {
+                               this.testTexture.非活性化する( this.デバイスリソース );
+                               this.testTexture = null;
+                       }
                }
                public virtual void シーンを描画する()
                {
@@ -66,8 +73,12 @@ namespace FDK
                        // 以下は、実装例。
                        //------------------
 
+#warning " 最終的に削除すること。"
                        if( null == this.testTexture )
-                               this.testTexture = new メディア.テクスチャ();
+                       {
+                               this.testTexture = new メディア.テクスチャ( "テスト用テクスチャ画像.jpg" );
+                               this.testTexture.活性化する( this.デバイスリソース );
+                       }
 
                        var d3dContext = this.デバイスリソース.D3DDevice.ImmediateContext;
 
@@ -83,78 +94,9 @@ namespace FDK
                                stencil: 0 );
                        //----------------
                        #endregion
-                       #region " 定数バッファを更新する。"
-                       //----------------
-                       {
-                               // ワールド変換行列
-                               var matScale = SharpDX.Matrix.Scaling( 320f, 240f, 1.0f );
-                               var matY = SharpDX.Matrix.RotationY( (float) ( Math.PI * ( timeGetTime() % 3000 ) ) / 1500.0f );
-                               var matX = SharpDX.Matrix.RotationX( (float) ( Math.PI * ( timeGetTime() % 1500 ) ) / 750.0f );
-                               var mat = matScale * matY * matX;
-                               mat.Transpose();    // 転置
-                               this.デバイスリソース.定数バッファの転送元データ.World = mat;
-
-                               // ビュー変換行列
-                               this.デバイスリソース.定数バッファの転送元データ.View = this.デバイスリソース.ビュー変換行列;
-
-                               // 射影変換行列
-                               this.デバイスリソース.定数バッファの転送元データ.Projection = this.デバイスリソース.射影変換行列;
-
-                               // 描画元矩形
-                               this.デバイスリソース.定数バッファの転送元データ.TexLeft = 0f;
-                               this.デバイスリソース.定数バッファの転送元データ.TexTop = 0f;
-                               this.デバイスリソース.定数バッファの転送元データ.TexRight = 0.5f;
-                               this.デバイスリソース.定数バッファの転送元データ.TexBottom = 0.5f;
-
-                               // アルファ
-                               this.デバイスリソース.定数バッファの転送元データ.TexAlpha = this.デバイスリソース.不透明度;
-                               this.デバイスリソース.定数バッファの転送元データ.dummy1 = 0f;
-                               this.デバイスリソース.定数バッファの転送元データ.dummy2 = 0f;
-                               this.デバイスリソース.定数バッファの転送元データ.dummy3 = 0f;
-
-                               // 定数バッファへの書き込み
-                               var dataBox = d3dContext.MapSubresource(
-                                       resourceRef: this.デバイスリソース.ConstantBuffer,
-                                       subresource: 0,
-                                       mapType: SharpDX.Direct3D11.MapMode.WriteDiscard,
-                                       mapFlags: SharpDX.Direct3D11.MapFlags.None );
-                               SharpDX.Utilities.Write( dataBox.DataPointer, ref this.デバイスリソース.定数バッファの転送元データ );
-                               d3dContext.UnmapSubresource( this.デバイスリソース.ConstantBuffer, 0 );
-                       }
-                       //----------------
-                       #endregion
-                       #region " 3Dパイプラインを設定する。"
-                       //----------------
-                       // 入力アセンブラ
-                       d3dContext.InputAssembler.InputLayout = null;
-                       d3dContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip;
-
-                       // 頂点シェーダ
-                       d3dContext.VertexShader.Set( this.デバイスリソース.VertexShader );
-                       d3dContext.VertexShader.SetConstantBuffers( 0, this.デバイスリソース.ConstantBuffer );
-
-                       // ジオメトリシェーダ
-                       d3dContext.GeometryShader.Set( null );
-
-                       // ラスタライザ
-                       d3dContext.Rasterizer.SetViewports( this.デバイスリソース.ViewPort );
-                       d3dContext.Rasterizer.State = this.デバイスリソース.RasterizerState;
-
-                       // ピクセルシェーダ
-                       d3dContext.PixelShader.Set( this.デバイスリソース.PixelShader );
-                       d3dContext.PixelShader.SetConstantBuffers( 0, this.デバイスリソース.ConstantBuffer );
-                       d3dContext.PixelShader.SetShaderResources( 0, 1, this.デバイスリソース.ShaderResourceView );
-                       d3dContext.PixelShader.SetSamplers( 0, 1, this.デバイスリソース.SamplerState );
-
-                       // 出力マージャ
-                       d3dContext.OutputMerger.SetTargets( this.デバイスリソース.DepthStencilView, this.デバイスリソース.RenderTargetView );
-                       d3dContext.OutputMerger.SetBlendState( this.デバイスリソース.BlendState, new SharpDX.Mathematics.Interop.RawColor4( 0f, 0f, 0f, 0f ), -1 );
-                       d3dContext.OutputMerger.SetDepthStencilState( this.デバイスリソース.DepthStencilState, 0 );
-                       //----------------
-                       #endregion
 
-                       // 頂点バッファとインデックスバッファを使わずに 4 つの頂点を描画する。
-                       d3dContext.Draw( vertexCount: 4, startVertexLocation: 0 );
+#warning " 最終的に削除すること。"
+                       this.testTexture?.進行描画する( this.デバイスリソース );
                }
 
                protected bool アプリを終了せよ = false;
@@ -186,12 +128,7 @@ namespace FDK
                        this.デバイスリソース.サイズに依存するリソースを作成する();
                }
 
-#warning "これ以降は、最終的に削除すること。"
-
+#warning " 最終的に削除すること。"
                private FDK.メディア.テクスチャ testTexture = null;
-               [System.Runtime.InteropServices.DllImport( "winmm.dll" )]
-               private static extern uint timeGetTime();
-               private const int WM_SIZE = 0x0005;
-               private const int SIZE_MINIMIZED = 1;
        }
 }
index b7c9092..e4aa9c4 100644 (file)
@@ -13,5 +13,95 @@ namespace FDK.メディア
                public static void 共有リソースを解放する()
                {
                }
+
+               public テクスチャ( string 画像ファイルパス )
+               {
+                       this.画像ファイルパス = 画像ファイルパス;
+               }
+               protected override void On進行描画( デバイスリソース dr )
+               {
+                       var d3dContext = dr.D3DDevice.ImmediateContext;
+                       
+                       #region " 定数バッファを更新する。"
+                       //----------------
+                       {
+                               // ワールド変換行列
+                               var matScale = SharpDX.Matrix.Scaling( 320f, 240f, 1.0f );
+                               var matY = SharpDX.Matrix.RotationY( (float) ( Math.PI * ( timeGetTime() % 3000 ) ) / 1500.0f );
+                               var matX = SharpDX.Matrix.RotationX( (float) ( Math.PI * ( timeGetTime() % 1500 ) ) / 750.0f );
+                               var mat = matScale * matY * matX;
+                               mat.Transpose();    // 転置
+                               dr.定数バッファの転送元データ.World = mat;
+
+                               // ビュー変換行列
+                               dr.定数バッファの転送元データ.View = dr.ビュー変換行列;
+
+                               // 射影変換行列
+                               dr.定数バッファの転送元データ.Projection = dr.射影変換行列;
+
+                               // 描画元矩形
+                               dr.定数バッファの転送元データ.TexLeft = 0f;
+                               dr.定数バッファの転送元データ.TexTop = 0f;
+                               dr.定数バッファの転送元データ.TexRight = 0.5f;
+                               dr.定数バッファの転送元データ.TexBottom = 0.5f;
+
+                               // アルファ
+                               dr.定数バッファの転送元データ.TexAlpha = dr.不透明度;
+                               dr.定数バッファの転送元データ.dummy1 = 0f;
+                               dr.定数バッファの転送元データ.dummy2 = 0f;
+                               dr.定数バッファの転送元データ.dummy3 = 0f;
+
+                               // 定数バッファへの書き込み
+                               var dataBox = d3dContext.MapSubresource(
+                                       resourceRef: dr.ConstantBuffer,
+                                       subresource: 0,
+                                       mapType: SharpDX.Direct3D11.MapMode.WriteDiscard,
+                                       mapFlags: SharpDX.Direct3D11.MapFlags.None );
+                               SharpDX.Utilities.Write( dataBox.DataPointer, ref dr.定数バッファの転送元データ );
+                               d3dContext.UnmapSubresource( dr.ConstantBuffer, 0 );
+                       }
+                       //----------------
+                       #endregion
+                       #region " 3Dパイプラインを設定する。"
+                       //----------------
+                       // 入力アセンブラ
+                       d3dContext.InputAssembler.InputLayout = null;
+                       d3dContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip;
+
+                       // 頂点シェーダ
+                       d3dContext.VertexShader.Set( dr.VertexShader );
+                       d3dContext.VertexShader.SetConstantBuffers( 0, dr.ConstantBuffer );
+
+                       // ジオメトリシェーダ
+                       d3dContext.GeometryShader.Set( null );
+
+                       // ラスタライザ
+                       d3dContext.Rasterizer.SetViewports( dr.ViewPort );
+                       d3dContext.Rasterizer.State = dr.RasterizerState;
+
+                       // ピクセルシェーダ
+                       d3dContext.PixelShader.Set( dr.PixelShader );
+                       d3dContext.PixelShader.SetConstantBuffers( 0, dr.ConstantBuffer );
+                       d3dContext.PixelShader.SetShaderResources( 0, 1, dr.ShaderResourceView );
+                       d3dContext.PixelShader.SetSamplers( 0, 1, dr.SamplerState );
+
+                       // 出力マージャ
+                       d3dContext.OutputMerger.SetTargets( dr.DepthStencilView, dr.RenderTargetView );
+                       d3dContext.OutputMerger.SetBlendState( dr.BlendState, new SharpDX.Mathematics.Interop.RawColor4( 0f, 0f, 0f, 0f ), -1 );
+                       d3dContext.OutputMerger.SetDepthStencilState( dr.DepthStencilState, 0 );
+                       //----------------
+                       #endregion
+
+                       // 頂点バッファとインデックスバッファを使わずに 4 つの頂点を描画する。
+                       d3dContext.Draw( vertexCount: 4, startVertexLocation: 0 );
+               }
+
+               protected string 画像ファイルパス = null;
+
+#warning " 最終的に削除すること。"
+               [System.Runtime.InteropServices.DllImport( "winmm.dll" )]
+               private static extern uint timeGetTime();
+               private const int WM_SIZE = 0x0005;
+               private const int SIZE_MINIMIZED = 1;
        }
 }