+++ /dev/null
-using System;\r
-using System.Collections.Generic;\r
-using System.Text;\r
-using System.Drawing;\r
-using System.Drawing.Imaging;\r
-using System.IO;\r
-using System.Diagnostics;\r
-using SharpDX;\r
-using SharpDX.Direct3D9;\r
-\r
-using Rectangle = System.Drawing.Rectangle;\r
-\r
-namespace FDK\r
-{\r
- public class CTexture : IDisposable\r
- {\r
- #region [ プロパティ ]\r
-\r
- public bool b加算合成\r
- {\r
- get;\r
- set; \r
- }\r
- public bool bFlipY\r
- {\r
- get;\r
- set;\r
- }\r
- public float fZ軸中心回転\r
- {\r
- get;\r
- set;\r
- }\r
- public int n透明度\r
- {\r
- get\r
- {\r
- return this._透明度;\r
- }\r
- set\r
- {\r
- if( value < 0 )\r
- {\r
- this._透明度 = 0;\r
- }\r
- else if( value > 0xff )\r
- {\r
- this._透明度 = 0xff;\r
- }\r
- else\r
- {\r
- this._透明度 = value;\r
- }\r
- }\r
- }\r
- public Size szテクスチャサイズ\r
- {\r
- get; \r
- protected set;\r
- }\r
- public Size sz画像サイズ\r
- {\r
- get;\r
- protected set;\r
- }\r
- public Texture texture\r
- {\r
- get;\r
- private set;\r
- }\r
- public Format Format\r
- {\r
- get;\r
- protected set;\r
- }\r
- public Vector3 vc拡大縮小倍率;\r
- #endregion\r
-\r
- // コンストラクタ\r
-\r
- public CTexture()\r
- {\r
- this.sz画像サイズ = new Size( 0, 0 );\r
- this.szテクスチャサイズ = new Size( 0, 0 );\r
- this._透明度 = 0xff;\r
- this.texture = null;\r
- this.cvPositionColoredVertexies = null;\r
- this.b加算合成 = false;\r
- this.fZ軸中心回転 = 0f;\r
- this.vc拡大縮小倍率 = new Vector3( 1f, 1f, 1f );\r
- this.bFlipY = false;\r
-// this._txData = null;\r
- }\r
- \r
- /// <summary>\r
- /// <para>指定されたビットマップオブジェクトから Managed テクスチャを作成する。</para>\r
- /// <para>テクスチャのサイズは、BITMAP画像のサイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
- /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
- /// <para>その他、ミップマップ数は 1、Usage は None、Pool は Managed、イメージフィルタは Point、ミップマップフィルタは\r
- /// None、カラーキーは 0xFFFFFFFF(完全なる黒を透過)になる。</para>\r
- /// </summary>\r
- /// <param name="device">Direct3D9 デバイス。</param>\r
- /// <param name="bitmap">作成元のビットマップ。</param>\r
- /// <param name="format">テクスチャのフォーマット。</param>\r
- /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
- public CTexture( Device device, Bitmap bitmap, Format format )\r
- : this()\r
- {\r
- try\r
- {\r
- this.Format = format;\r
- this.sz画像サイズ = new Size( bitmap.Width, bitmap.Height );\r
- this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
- this.rc全画像 = new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height );\r
-\r
- using( var stream = new MemoryStream() )\r
- {\r
- bitmap.Save( stream, ImageFormat.Bmp );\r
- stream.Seek( 0L, SeekOrigin.Begin );\r
- int colorKey = unchecked( (int) 0xFF000000 );\r
- this.texture = Texture.FromStream( device, stream, this.szテクスチャサイズ.Width, this.szテクスチャサイズ.Height, 1, Usage.None, format, poolvar, Filter.Point, Filter.None, colorKey );\r
- }\r
- }\r
- catch ( Exception e )\r
- {\r
- this.Dispose();\r
- throw new CTextureCreateFailedException( "ビットマップからのテクスチャの生成に失敗しました。(" + e.Message + ")" );\r
- }\r
- }\r
- \r
- /// <summary>\r
- /// <para>空の Managed テクスチャを作成する。</para>\r
- /// <para>テクスチャのサイズは、指定された希望サイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
- /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
- /// <para>テクスチャのテクセルデータは未初期化。(おそらくゴミデータが入ったまま。)</para>\r
- /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None、\r
- /// カラーキーは 0x00000000(透過しない)になる。</para>\r
- /// </summary>\r
- /// <param name="device">Direct3D9 デバイス。</param>\r
- /// <param name="n幅">テクスチャの幅(希望値)。</param>\r
- /// <param name="n高さ">テクスチャの高さ(希望値)。</param>\r
- /// <param name="format">テクスチャのフォーマット。</param>\r
- /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
- public CTexture( Device device, int n幅, int n高さ, Format format )\r
- : this( device, n幅, n高さ, format, Pool.Managed )\r
- {\r
- }\r
- \r
- /// <summary>\r
- /// <para>指定された画像ファイルから Managed テクスチャを作成する。</para>\r
- /// <para>利用可能な画像形式は、BMP, JPG, PNG, TGA, DDS, PPM, DIB, HDR, PFM のいずれか。</para>\r
- /// </summary>\r
- /// <param name="device">Direct3D9 デバイス。</param>\r
- /// <param name="strファイル名">画像ファイル名。</param>\r
- /// <param name="format">テクスチャのフォーマット。</param>\r
- /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>\r
- /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
- public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する )\r
- : this( device, strファイル名, format, b黒を透過する, Pool.Managed )\r
- {\r
- }\r
- public CTexture( Device device, byte[] txData, Format format, bool b黒を透過する )\r
- : this( device, txData, format, b黒を透過する, Pool.Managed )\r
- {\r
- }\r
- public CTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する )\r
- : this( device, bitmap, format, b黒を透過する, Pool.Managed )\r
- {\r
- }\r
- \r
- /// <summary>\r
- /// <para>空のテクスチャを作成する。</para>\r
- /// <para>テクスチャのサイズは、指定された希望サイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
- /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
- /// <para>テクスチャのテクセルデータは未初期化。(おそらくゴミデータが入ったまま。)</para>\r
- /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None、\r
- /// カラーキーは 0x00000000(透過しない)になる。</para>\r
- /// </summary>\r
- /// <param name="device">Direct3D9 デバイス。</param>\r
- /// <param name="n幅">テクスチャの幅(希望値)。</param>\r
- /// <param name="n高さ">テクスチャの高さ(希望値)。</param>\r
- /// <param name="format">テクスチャのフォーマット。</param>\r
- /// <param name="pool">テクスチャの管理方法。</param>\r
- /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
- public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool )\r
- : this( device, n幅, n高さ, format, pool, Usage.None, false )\r
- {\r
- }\r
- \r
- public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool, Usage usage, bool b黒を透過する )\r
- : this()\r
- {\r
- try\r
- {\r
- this.Format = format;\r
- this.sz画像サイズ = new Size( n幅, n高さ );\r
- this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
- this.rc全画像 = new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height );\r
- int colorKey = ( b黒を透過する ) ? unchecked((int) 0xFF000000) : 0;\r
-\r
- using( var bitmap = new Bitmap( 1, 1 ) )\r
- {\r
- using ( var graphics = Graphics.FromImage( bitmap ) )\r
- {\r
- graphics.FillRectangle( Brushes.Black, 0, 0, 1, 1 );\r
- }\r
- using ( var stream = new MemoryStream() )\r
- {\r
- bitmap.Save( stream, ImageFormat.Bmp );\r
- stream.Seek( 0L, SeekOrigin.Begin );\r
-#if TEST_Direct3D9Ex\r
- pool = poolvar;\r
-#endif\r
- // 中で更にメモリ読み込みし直していて無駄なので、Streamを使うのは止めたいところ\r
- this.texture = Texture.FromStream( device, stream, n幅, n高さ, 1, usage, format, pool, Filter.Point, Filter.None, colorKey );\r
- }\r
- }\r
- }\r
- catch\r
- {\r
- this.Dispose();\r
- throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n({0}x{1}, {2})", n幅, n高さ, format ) );\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// <para>画像ファイルからテクスチャを生成する。</para>\r
- /// <para>利用可能な画像形式は、BMP, JPG, PNG, TGA, DDS, PPM, DIB, HDR, PFM のいずれか。</para>\r
- /// <para>テクスチャのサイズは、画像のサイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
- /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
- /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None になる。</para>\r
- /// </summary>\r
- /// <param name="device">Direct3D9 デバイス。</param>\r
- /// <param name="strファイル名">画像ファイル名。</param>\r
- /// <param name="format">テクスチャのフォーマット。</param>\r
- /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>\r
- /// <param name="pool">テクスチャの管理方法。</param>\r
- /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
- public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool )\r
- : this()\r
- {\r
- MakeTexture( device, strファイル名, format, b黒を透過する, pool );\r
- }\r
- public void MakeTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool )\r
- {\r
- if ( !File.Exists( strファイル名 ) ) // #27122 2012.1.13 from: ImageInformation では FileNotFound 例外は返ってこないので、ここで自分でチェックする。わかりやすいログのために。\r
- throw new FileNotFoundException( string.Format( "ファイルが存在しません。\n[{0}]", strファイル名 ) );\r
-\r
- Byte[] _txData = File.ReadAllBytes( strファイル名 );\r
- MakeTexture( device, _txData, format, b黒を透過する, pool );\r
- }\r
-\r
- public CTexture( Device device, byte[] txData, Format format, bool b黒を透過する, Pool pool )\r
- : this()\r
- {\r
- MakeTexture( device, txData, format, b黒を透過する, pool );\r
- }\r
- public void MakeTexture( Device device, byte[] txData, Format format, bool b黒を透過する, Pool pool )\r
- {\r
- try\r
- {\r
- var information = ImageInformation.FromMemory( txData );\r
- this.Format = format;\r
- this.sz画像サイズ = new Size( information.Width, information.Height );\r
- this.rc全画像 = new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height );\r
- int colorKey = ( b黒を透過する ) ? unchecked( (int) 0xFF000000 ) : 0;\r
- this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
- //if ( ( device.Capabilities.TextureFilterCaps & FilterCaps.MagPoint ) != 0 )\r
- //{\r
- // device.SetSamplerState( 0, SamplerState.MagFilter, TextureFilter.Point );\r
- //}\r
-#if TEST_Direct3D9Ex\r
- pool = poolvar;\r
-#endif\r
- // lock ( lockobj )\r
- // {\r
- //Trace.TraceInformation( "CTexture() start: " );\r
- this.texture = Texture.FromMemory( device, txData, this.sz画像サイズ.Width, this.sz画像サイズ.Height, 1, Usage.None, format, pool, Filter.Point, Filter.None, colorKey );\r
- //Trace.TraceInformation( "CTexture() end: " );\r
- // }\r
- }\r
- catch\r
- {\r
- this.Dispose();\r
- // throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n{0}", strファイル名 ) );\r
- throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n" ) );\r
- }\r
- }\r
-\r
- public CTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する, Pool pool )\r
- : this()\r
- {\r
- MakeTexture( device, bitmap, format, b黒を透過する, pool );\r
- }\r
- public void MakeTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する, Pool pool )\r
- {\r
- try\r
- {\r
- this.Format = format;\r
- this.sz画像サイズ = new Size( bitmap.Width, bitmap.Height );\r
- this.rc全画像 = new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height );\r
- int colorKey = ( b黒を透過する ) ? unchecked( (int) 0xFF000000 ) : 0;\r
- this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
- //if ( ( device.Capabilities.TextureFilterCaps & FilterCaps.MagPoint ) != 0 )\r
- //{\r
- // device.SetSamplerState( 0, SamplerState.MagFilter, TextureFilter.Point );\r
- //}\r
-#if TEST_Direct3D9Ex\r
- pool = poolvar;\r
-#endif\r
- //Trace.TraceInformation( "CTExture() start: " );\r
- unsafe // Bitmapの内部データ(a8r8g8b8)を自前でゴリゴリコピーする\r
- {\r
- int tw =\r
-#if TEST_Direct3D9Ex\r
- this.sz画像サイズ.Width;\r
- if ( tw % 32 != 0 ) // 32の倍数にする\r
- {\r
- //tw = tw & ( ~31 ) + 32;\r
- tw /= 32;\r
- tw++;\r
- tw *= 32;\r
- }\r
-#else\r
- this.sz画像サイズ.Width;\r
-#endif\r
-#if TEST_Direct3D9Ex\r
- this.texture = new Texture( device, tw, this.sz画像サイズ.Height, 1, Usage.Dynamic, format, Pool.Default );\r
-#else\r
- this.texture = new Texture( device, this.sz画像サイズ.Width, this.sz画像サイズ.Height, 1, Usage.None, format, pool );\r
-#endif\r
- BitmapData srcBufData = bitmap.LockBits( new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height ), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb );\r
- DataRectangle destDataRectangle = texture.LockRectangle( 0, LockFlags.Discard ); // None\r
-#if TEST_Direct3D9Ex\r
- byte[] filldata = null;\r
- if ( tw > this.sz画像サイズ.Width )\r
- {\r
- filldata = new byte[ (tw - this.sz画像サイズ.Width) * 4 ];\r
- }\r
- for ( int y = 0; y < this.sz画像サイズ.Height; y++ )\r
- {\r
- IntPtr src_scan0 = (IntPtr) ( (Int64) srcBufData.Scan0 + y * srcBufData.Stride );\r
- destDataRectangle.Data.WriteRange( src_scan0, this.sz画像サイズ.Width * 4 );\r
- if ( tw > this.sz画像サイズ.Width )\r
- {\r
- destDataRectangle.Data.WriteRange( filldata );\r
- }\r
- }\r
-#else\r
- IntPtr src_scan0 = (IntPtr) ( (Int64) srcBufData.Scan0 );\r
- //destDataRectangle.Data.WriteRange( src_scan0, this.sz画像サイズ.Width * 4 * this.sz画像サイズ.Height );\r
- CopyMemory( destDataRectangle.DataPointer.ToPointer(), src_scan0.ToPointer(), this.sz画像サイズ.Width * 4 * this.sz画像サイズ.Height );\r
-#endif\r
- texture.UnlockRectangle( 0 );\r
- bitmap.UnlockBits( srcBufData );\r
- }\r
- //Trace.TraceInformation( "CTExture() End: " );\r
- }\r
- catch\r
- {\r
- this.Dispose();\r
- // throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n{0}", strファイル名 ) );\r
- throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n" ) );\r
- }\r
- }\r
- // メソッド\r
-\r
- /// <summary>\r
- /// テクスチャを 2D 画像と見なして描画する。\r
- /// </summary>\r
- /// <param name="device">Direct3D9 デバイス。</param>\r
- /// <param name="x">描画位置(テクスチャの左上位置の X 座標[dot])。</param>\r
- /// <param name="y">描画位置(テクスチャの左上位置の Y 座標[dot])。</param>\r
- public void t2D描画( Device device, int x, int y )\r
- {\r
- this.t2D描画( device, x, y, 1f, this.rc全画像 );\r
- }\r
- public void t2D描画( Device device, int x, int y, Rectangle rc画像内の描画領域 )\r
- {\r
- this.t2D描画( device, x, y, 1f, rc画像内の描画領域 );\r
- }\r
- public void t2D描画( Device device, float x, float y )\r
- {\r
- this.t2D描画( device, (int)x, (int)y, 1f, this.rc全画像 );\r
- }\r
- public void t2D描画( Device device, float x, float y, Rectangle rc画像内の描画領域 )\r
- {\r
- this.t2D描画( device, (int)x, (int)y, 1f, rc画像内の描画領域 );\r
- }\r
- public void t2D描画( Device device, int x, int y, float depth, Rectangle rc画像内の描画領域 )\r
- {\r
- if( this.texture == null )\r
- return;\r
-\r
- this.tレンダリングステートの設定( device );\r
-\r
- if( this.fZ軸中心回転 == 0f )\r
- {\r
- #region [ (A) 回転なし ]\r
- //-----------------\r
- float f補正値X = -0.5f; // -0.5 は座標とピクセルの誤差を吸収するための座標補正値。(MSDN参照)\r
- float f補正値Y = -0.5f; //\r
- float w = rc画像内の描画領域.Width;\r
- float h = rc画像内の描画領域.Height;\r
- float f左U値 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
- float f右U値 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
- float f上V値 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
- float f下V値 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
- this.color4.Alpha = ( (float) this._透明度 ) / 255f;\r
- int color = this.color4.ToRgba();\r
-\r
- if( this.bFlipY )\r
- {\r
- float swap = f上V値;\r
- f上V値 = f下V値;\r
- f下V値 = swap;\r
- }\r
-\r
- if ( this.cvTransformedColoredVertexies == null )\r
- this.cvTransformedColoredVertexies = new TransformedColoredTexturedVertex[ 4 ];\r
-\r
- // #27122 2012.1.13 from: 以下、マネージドオブジェクト(=ガベージ)の量産を抑えるため、new は使わず、メンバに値を1つずつ直接上書きする。\r
-\r
- this.cvTransformedColoredVertexies[ 0 ].Position.X = x + f補正値X;\r
- this.cvTransformedColoredVertexies[ 0 ].Position.Y = y + f補正値Y;\r
- this.cvTransformedColoredVertexies[ 0 ].Position.Z = depth;\r
- this.cvTransformedColoredVertexies[ 0 ].Position.W = 1.0f;\r
- this.cvTransformedColoredVertexies[ 0 ].Color = color;\r
- this.cvTransformedColoredVertexies[ 0 ].TextureCoordinates.X = f左U値;\r
- this.cvTransformedColoredVertexies[ 0 ].TextureCoordinates.Y = f上V値;\r
-\r
- this.cvTransformedColoredVertexies[ 1 ].Position.X = ( x + ( w * this.vc拡大縮小倍率.X ) ) + f補正値X;\r
- this.cvTransformedColoredVertexies[ 1 ].Position.Y = y + f補正値Y;\r
- this.cvTransformedColoredVertexies[ 1 ].Position.Z = depth;\r
- this.cvTransformedColoredVertexies[ 1 ].Position.W = 1.0f;\r
- this.cvTransformedColoredVertexies[ 1 ].Color = color;\r
- this.cvTransformedColoredVertexies[ 1 ].TextureCoordinates.X = f右U値;\r
- this.cvTransformedColoredVertexies[ 1 ].TextureCoordinates.Y = f上V値;\r
-\r
- this.cvTransformedColoredVertexies[ 2 ].Position.X = x + f補正値X;\r
- this.cvTransformedColoredVertexies[ 2 ].Position.Y = ( y + ( h * this.vc拡大縮小倍率.Y ) ) + f補正値Y;\r
- this.cvTransformedColoredVertexies[ 2 ].Position.Z = depth;\r
- this.cvTransformedColoredVertexies[ 2 ].Position.W = 1.0f;\r
- this.cvTransformedColoredVertexies[ 2 ].Color = color;\r
- this.cvTransformedColoredVertexies[ 2 ].TextureCoordinates.X = f左U値;\r
- this.cvTransformedColoredVertexies[ 2 ].TextureCoordinates.Y = f下V値;\r
-\r
- this.cvTransformedColoredVertexies[ 3 ].Position.X = ( x + ( w * this.vc拡大縮小倍率.X ) ) + f補正値X;\r
- this.cvTransformedColoredVertexies[ 3 ].Position.Y = ( y + ( h * this.vc拡大縮小倍率.Y ) ) + f補正値Y;\r
- this.cvTransformedColoredVertexies[ 3 ].Position.Z = depth;\r
- this.cvTransformedColoredVertexies[ 3 ].Position.W = 1.0f;\r
- this.cvTransformedColoredVertexies[ 3 ].Color = color;\r
- this.cvTransformedColoredVertexies[ 3 ].TextureCoordinates.X = f右U値;\r
- this.cvTransformedColoredVertexies[ 3 ].TextureCoordinates.Y = f下V値;\r
-\r
- device.SetTexture( 0, this.texture );\r
- device.VertexFormat = TransformedColoredTexturedVertex.Format;\r
- device.DrawUserPrimitives( PrimitiveType.TriangleStrip, 0, 2, this.cvTransformedColoredVertexies );\r
- //-----------------\r
- #endregion\r
- }\r
- else\r
- {\r
- #region [ (B) 回転あり ]\r
- //-----------------\r
- float f補正値X = ( ( rc画像内の描画領域.Width % 2 ) == 0 ) ? -0.5f : 0f; // -0.5 は座標とピクセルの誤差を吸収するための座標補正値。(MSDN参照)\r
- float f補正値Y = ( ( rc画像内の描画領域.Height % 2 ) == 0 ) ? -0.5f : 0f; // 3D(回転する)なら補正はいらない。\r
- float f中央X = ( (float) rc画像内の描画領域.Width ) / 2f;\r
- float f中央Y = ( (float) rc画像内の描画領域.Height ) / 2f;\r
- float f左U値 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
- float f右U値 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
- float f上V値 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
- float f下V値 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
- this.color4.Alpha = ( (float) this._透明度 ) / 255f;\r
- int color = this.color4.ToRgba();\r
-\r
- if( this.cvPositionColoredVertexies == null )\r
- this.cvPositionColoredVertexies = new PositionColoredTexturedVertex[ 4 ];\r
-\r
- // #27122 2012.1.13 from: 以下、マネージドオブジェクト(=ガベージ)の量産を抑えるため、new は使わず、メンバに値を1つずつ直接上書きする。\r
-\r
- this.cvPositionColoredVertexies[ 0 ].Position.X = -f中央X + f補正値X;\r
- this.cvPositionColoredVertexies[ 0 ].Position.Y = f中央Y + f補正値Y;\r
- this.cvPositionColoredVertexies[ 0 ].Position.Z = depth;\r
- this.cvPositionColoredVertexies[ 0 ].Color = color;\r
- this.cvPositionColoredVertexies[ 0 ].TextureCoordinates.X = f左U値;\r
- this.cvPositionColoredVertexies[ 0 ].TextureCoordinates.Y = f上V値;\r
-\r
- this.cvPositionColoredVertexies[ 1 ].Position.X = f中央X + f補正値X;\r
- this.cvPositionColoredVertexies[ 1 ].Position.Y = f中央Y + f補正値Y;\r
- this.cvPositionColoredVertexies[ 1 ].Position.Z = depth;\r
- this.cvPositionColoredVertexies[ 1 ].Color = color;\r
- this.cvPositionColoredVertexies[ 1 ].TextureCoordinates.X = f右U値;\r
- this.cvPositionColoredVertexies[ 1 ].TextureCoordinates.Y = f上V値;\r
-\r
- this.cvPositionColoredVertexies[ 2 ].Position.X = -f中央X + f補正値X;\r
- this.cvPositionColoredVertexies[ 2 ].Position.Y = -f中央Y + f補正値Y;\r
- this.cvPositionColoredVertexies[ 2 ].Position.Z = depth;\r
- this.cvPositionColoredVertexies[ 2 ].Color = color;\r
- this.cvPositionColoredVertexies[ 2 ].TextureCoordinates.X = f左U値;\r
- this.cvPositionColoredVertexies[ 2 ].TextureCoordinates.Y = f下V値;\r
-\r
- this.cvPositionColoredVertexies[ 3 ].Position.X = f中央X + f補正値X;\r
- this.cvPositionColoredVertexies[ 3 ].Position.Y = -f中央Y + f補正値Y;\r
- this.cvPositionColoredVertexies[ 3 ].Position.Z = depth;\r
- this.cvPositionColoredVertexies[ 3 ].Color = color;\r
- this.cvPositionColoredVertexies[ 3 ].TextureCoordinates.X = f右U値;\r
- this.cvPositionColoredVertexies[ 3 ].TextureCoordinates.Y = f下V値;\r
-\r
- int n描画領域内X = (int)(x + this.vc拡大縮小倍率.X * ( rc画像内の描画領域.Width / 2 ));\r
- int n描画領域内Y = (int)(y + this.vc拡大縮小倍率.Y * ( rc画像内の描画領域.Height / 2 ));\r
- var vc3移動量 = new Vector3( n描画領域内X - ( ( (float) device.Viewport.Width ) / 2f ), -( n描画領域内Y - ( ( (float) device.Viewport.Height ) / 2f ) ), 0f );\r
- \r
- var matrix = Matrix.Identity * Matrix.Scaling( this.vc拡大縮小倍率 );\r
- matrix *= Matrix.RotationZ( this.fZ軸中心回転 );\r
- matrix *= Matrix.Translation( vc3移動量 );\r
- device.SetTransform( TransformState.World, matrix );\r
-\r
- device.SetTexture( 0, this.texture );\r
- device.VertexFormat = PositionColoredTexturedVertex.Format;\r
- device.DrawUserPrimitives( PrimitiveType.TriangleStrip, 2, this.cvPositionColoredVertexies );\r
- //-----------------\r
- #endregion\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// テクスチャを 3D 画像と見なして描画する。\r
- /// </summary>\r
- public void t3D描画( Device device, Matrix mat )\r
- {\r
- this.t3D描画( device, mat, this.rc全画像 );\r
- }\r
- public void t3D描画( Device device, Matrix mat, Rectangle rc画像内の描画領域 )\r
- {\r
- if( this.texture == null )\r
- return;\r
-\r
- float x = ( (float) rc画像内の描画領域.Width ) / 2f;\r
- float y = ( (float) rc画像内の描画領域.Height ) / 2f;\r
- float z = 0.0f;\r
- float f左U値 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
- float f右U値 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
- float f上V値 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
- float f下V値 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
- this.color4.Alpha = ( (float) this._透明度 ) / 255f;\r
- int color = this.color4.ToRgba();\r
- \r
- if( this.cvPositionColoredVertexies == null )\r
- this.cvPositionColoredVertexies = new PositionColoredTexturedVertex[ 4 ];\r
-\r
- // #27122 2012.1.13 from: 以下、マネージドオブジェクト(=ガベージ)の量産を抑えるため、new は使わず、メンバに値を1つずつ直接上書きする。\r
-\r
- this.cvPositionColoredVertexies[ 0 ].Position.X = -x;\r
- this.cvPositionColoredVertexies[ 0 ].Position.Y = y;\r
- this.cvPositionColoredVertexies[ 0 ].Position.Z = z;\r
- this.cvPositionColoredVertexies[ 0 ].Color = color;\r
- this.cvPositionColoredVertexies[ 0 ].TextureCoordinates.X = f左U値;\r
- this.cvPositionColoredVertexies[ 0 ].TextureCoordinates.Y = f上V値;\r
-\r
- this.cvPositionColoredVertexies[ 1 ].Position.X = x;\r
- this.cvPositionColoredVertexies[ 1 ].Position.Y = y;\r
- this.cvPositionColoredVertexies[ 1 ].Position.Z = z;\r
- this.cvPositionColoredVertexies[ 1 ].Color = color;\r
- this.cvPositionColoredVertexies[ 1 ].TextureCoordinates.X = f右U値;\r
- this.cvPositionColoredVertexies[ 1 ].TextureCoordinates.Y = f上V値;\r
-\r
- this.cvPositionColoredVertexies[ 2 ].Position.X = -x;\r
- this.cvPositionColoredVertexies[ 2 ].Position.Y = -y;\r
- this.cvPositionColoredVertexies[ 2 ].Position.Z = z;\r
- this.cvPositionColoredVertexies[ 2 ].Color = color;\r
- this.cvPositionColoredVertexies[ 2 ].TextureCoordinates.X = f左U値;\r
- this.cvPositionColoredVertexies[ 2 ].TextureCoordinates.Y = f下V値;\r
-\r
- this.cvPositionColoredVertexies[ 3 ].Position.X = x;\r
- this.cvPositionColoredVertexies[ 3 ].Position.Y = -y;\r
- this.cvPositionColoredVertexies[ 3 ].Position.Z = z;\r
- this.cvPositionColoredVertexies[ 3 ].Color = color;\r
- this.cvPositionColoredVertexies[ 3 ].TextureCoordinates.X = f右U値;\r
- this.cvPositionColoredVertexies[ 3 ].TextureCoordinates.Y = f下V値;\r
-\r
- this.tレンダリングステートの設定( device );\r
-\r
- device.SetTransform( TransformState.World, mat );\r
- device.SetTexture( 0, this.texture );\r
- device.VertexFormat = PositionColoredTexturedVertex.Format;\r
- device.DrawUserPrimitives( PrimitiveType.TriangleStrip, 2, this.cvPositionColoredVertexies );\r
- }\r
-\r
- #region [ IDisposable 実装 ]\r
- //-----------------\r
- public void Dispose()\r
- {\r
- if( !this.bDispose完了済み )\r
- {\r
- // テクスチャの破棄\r
- if( this.texture != null )\r
- {\r
- this.texture.Dispose();\r
- this.texture = null;\r
- }\r
-\r
- this.bDispose完了済み = true;\r
- }\r
- }\r
- //-----------------\r
- #endregion\r
-\r
-\r
- // その他\r
-\r
- #region [ private ]\r
- //-----------------\r
- protected int _透明度;\r
- private bool bDispose完了済み;\r
- protected PositionColoredTexturedVertex[] cvPositionColoredVertexies;\r
- protected TransformedColoredTexturedVertex[] cvTransformedColoredVertexies;\r
- protected const Pool poolvar = // 2011.4.25 yyagi\r
-#if TEST_Direct3D9Ex\r
- Pool.Default;\r
-#else\r
- Pool.Managed;\r
-#endif\r
-// byte[] _txData;\r
- static object lockobj = new object();\r
-\r
- protected void tレンダリングステートの設定( Device device )\r
- {\r
- if( this.b加算合成 )\r
- {\r
- device.SetRenderState( RenderState.AlphaBlendEnable, true );\r
- device.SetRenderState( RenderState.SourceBlend, Blend.SourceAlpha );\r
- device.SetRenderState( RenderState.DestinationBlend, Blend.One );\r
- }\r
- else\r
- {\r
- device.SetRenderState( RenderState.AlphaBlendEnable, true );\r
- device.SetRenderState( RenderState.SourceBlend, Blend.SourceAlpha );\r
- device.SetRenderState( RenderState.DestinationBlend, Blend.InverseSourceAlpha );\r
- }\r
- }\r
- protected Size t指定されたサイズを超えない最適なテクスチャサイズを返す( Device device, Size sz指定サイズ )\r
- {\r
- bool b条件付きでサイズは2の累乗でなくてもOK = ( device.Capabilities.TextureCaps & TextureCaps.NonPow2Conditional ) != 0;\r
- bool bサイズは2の累乗でなければならない = ( device.Capabilities.TextureCaps & TextureCaps.Pow2 ) != 0;\r
- bool b正方形でなければならない = ( device.Capabilities.TextureCaps & TextureCaps.SquareOnly ) != 0;\r
- int n最大幅 = device.Capabilities.MaxTextureWidth;\r
- int n最大高 = device.Capabilities.MaxTextureHeight;\r
- var szサイズ = new Size( sz指定サイズ.Width, sz指定サイズ.Height );\r
- \r
- if( bサイズは2の累乗でなければならない && !b条件付きでサイズは2の累乗でなくてもOK )\r
- {\r
- // 幅を2の累乗にする\r
- int n = 1;\r
- do\r
- {\r
- n *= 2;\r
- }\r
- while( n <= sz指定サイズ.Width );\r
- sz指定サイズ.Width = n;\r
-\r
- // 高さを2の累乗にする\r
- n = 1;\r
- do\r
- {\r
- n *= 2;\r
- }\r
- while( n <= sz指定サイズ.Height );\r
- sz指定サイズ.Height = n;\r
- }\r
-\r
- if( sz指定サイズ.Width > n最大幅 )\r
- sz指定サイズ.Width = n最大幅;\r
-\r
- if( sz指定サイズ.Height > n最大高 )\r
- sz指定サイズ.Height = n最大高;\r
-\r
- if( b正方形でなければならない )\r
- {\r
- if( szサイズ.Width > szサイズ.Height )\r
- {\r
- szサイズ.Height = szサイズ.Width;\r
- }\r
- else if( szサイズ.Width < szサイズ.Height )\r
- {\r
- szサイズ.Width = szサイズ.Height;\r
- }\r
- }\r
-\r
- return szサイズ;\r
- }\r
-\r
- \r
- // 2012.3.21 さらなる new の省略作戦\r
-\r
- protected Rectangle rc全画像; // テクスチャ作ったらあとは不変\r
- protected Color4 color4 = new Color4( 1f, 1f, 1f, 1f ); // アルファ以外は不変\r
- //-----------------\r
- #endregion\r
-\r
- #region " Win32 API "\r
- //-----------------\r
- [System.Runtime.InteropServices.DllImport( "kernel32.dll", SetLastError = true )]\r
- private static extern unsafe void CopyMemory( void* dst, void* src, int size );\r
- //-----------------\r
- #endregion\r
- }\r
-}\r