OSDN Git Service

rev154(Direct3D9Ex対応)の続き。
[dtxmania/dtxmania.git] / FDK17プロジェクト / コード / 04.グラフィック / CTexture.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Drawing;\r
5 using System.Drawing.Imaging;\r
6 using System.IO;\r
7 using SlimDX;\r
8 using SlimDX.Direct3D9;\r
9 \r
10 namespace FDK\r
11 {\r
12         public class CTexture : IDisposable\r
13         {\r
14                 // プロパティ\r
15 \r
16                 public bool b加算合成\r
17                 {\r
18                         get;\r
19                         set; \r
20                 }\r
21                 public float fZ軸中心回転\r
22                 {\r
23                         get;\r
24                         set;\r
25                 }\r
26                 public int n透明度\r
27                 {\r
28                         get\r
29                         {\r
30                                 return this._透明度;\r
31                         }\r
32                         set\r
33                         {\r
34                                 if( value < 0 )\r
35                                 {\r
36                                         this._透明度 = 0;\r
37                                 }\r
38                                 else if( value > 0xff )\r
39                                 {\r
40                                         this._透明度 = 0xff;\r
41                                 }\r
42                                 else\r
43                                 {\r
44                                         this._透明度 = value;\r
45                                 }\r
46                         }\r
47                 }\r
48                 public Size szテクスチャサイズ\r
49                 {\r
50                         get; \r
51                         private set;\r
52                 }\r
53                 public Size sz画像サイズ\r
54                 {\r
55                         get;\r
56                         private set;\r
57                 }\r
58                 public Texture texture\r
59                 {\r
60                         get;\r
61                         private set;\r
62                 }\r
63                 public Vector3 vc拡大縮小倍率;\r
64 \r
65 \r
66                 // コンストラクタ\r
67 \r
68                 public CTexture()\r
69                 {\r
70                         this.sz画像サイズ = new Size( 0, 0 );\r
71                         this.szテクスチャサイズ = new Size( 0, 0 );\r
72                         this._透明度 = 0xff;\r
73                         this.texture = null;\r
74                         this.vbPositionColoredVertexBuffer = null;\r
75                         this.cvPositionColoredVertexies = null;\r
76                         this.b加算合成 = false;\r
77                         this.fZ軸中心回転 = 0f;\r
78                         this.vc拡大縮小倍率 = new Vector3( 1f, 1f, 1f );\r
79                 }\r
80                 \r
81                 /// <summary>\r
82                 /// <para>指定されたビットマップオブジェクトから Managed テクスチャを作成する。</para>\r
83                 /// <para>テクスチャのサイズは、BITMAP画像のサイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
84                 /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
85                 /// <para>その他、ミップマップ数は 1、Usage は None、Pool は Managed、イメージフィルタは Point、ミップマップフィルタは\r
86                 /// None、カラーキーは 0xFFFFFFFF(完全なる黒を透過)になる。</para>\r
87                 /// </summary>\r
88                 /// <param name="device">Direct3D9 デバイス。</param>\r
89                 /// <param name="bitmap">作成元のビットマップ。</param>\r
90                 /// <param name="format">テクスチャのフォーマット。</param>\r
91                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
92                 public CTexture( Device device, Bitmap bitmap, Format format )\r
93                         : this()\r
94                 {\r
95                         try\r
96                         {\r
97                                 this.sz画像サイズ = new Size( bitmap.Width, bitmap.Height );\r
98                                 this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
99                                 using( MemoryStream stream = new MemoryStream() )\r
100                                 {\r
101                                         bitmap.Save( stream, ImageFormat.Bmp );\r
102                                         stream.Seek( 0L, SeekOrigin.Begin );\r
103                                         unchecked\r
104                                         {\r
105                                                 int colorKey = (int) 0xFF000000;        // -16777216;\r
106                                                 this.texture = Texture.FromStream( device, stream, this.szテクスチャサイズ.Width, this.szテクスチャサイズ.Height, 1, Usage.None, format, poolvar, Filter.Point, Filter.None, colorKey );\r
107                                         }\r
108                                 }\r
109                                 this.t頂点バッファの作成( device );\r
110                         }\r
111                         catch\r
112                         {\r
113                                 this.Dispose();\r
114                                 throw new CTextureCreateFailedException( "ビットマップからのテクスチャの生成に失敗しました。" );\r
115                         }\r
116                 }\r
117         \r
118                 /// <summary>\r
119                 /// <para>空の Managed テクスチャを作成する。</para>\r
120                 /// <para>テクスチャのサイズは、指定された希望サイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
121                 /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
122                 /// <para>テクスチャのテクセルデータは未初期化。(おそらくゴミデータが入ったまま。)</para>\r
123                 /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None、\r
124                 /// カラーキーは 0x00000000(透過しない)になる。</para>\r
125                 /// </summary>\r
126                 /// <param name="device">Direct3D9 デバイス。</param>\r
127                 /// <param name="n幅">テクスチャの幅(希望値)。</param>\r
128                 /// <param name="n高さ">テクスチャの高さ(希望値)。</param>\r
129                 /// <param name="format">テクスチャのフォーマット。</param>\r
130                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
131                 public CTexture( Device device, int n幅, int n高さ, Format format )\r
132                         : this( device, n幅, n高さ, format, Pool.Managed )\r
133                 {\r
134                 }\r
135                 \r
136                 /// <summary>\r
137                 /// <para>指定された画像ファイルから Managed テクスチャを作成する。</para>\r
138                 /// <para>利用可能な画像形式は、BMP, JPG, PNG, TGA, DDS, PPM, DIB, HDR, PFM のいずれか。</para>\r
139                 /// </summary>\r
140                 /// <param name="device">Direct3D9 デバイス。</param>\r
141                 /// <param name="strファイル名">画像ファイル名。</param>\r
142                 /// <param name="format">テクスチャのフォーマット。</param>\r
143                 /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>\r
144                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
145                 public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する )\r
146                         : this( device, strファイル名, format, b黒を透過する, Pool.Managed )\r
147                 {\r
148                 }\r
149                 \r
150                 /// <summary>\r
151                 /// <para>空のテクスチャを作成する。</para>\r
152                 /// <para>テクスチャのサイズは、指定された希望サイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
153                 /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
154                 /// <para>テクスチャのテクセルデータは未初期化。(おそらくゴミデータが入ったまま。)</para>\r
155                 /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None、\r
156                 /// カラーキーは 0x00000000(透過しない)になる。</para>\r
157                 /// </summary>\r
158                 /// <param name="device">Direct3D9 デバイス。</param>\r
159                 /// <param name="n幅">テクスチャの幅(希望値)。</param>\r
160                 /// <param name="n高さ">テクスチャの高さ(希望値)。</param>\r
161                 /// <param name="format">テクスチャのフォーマット。</param>\r
162                 /// <param name="pool">テクスチャの管理方法。</param>\r
163                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
164                 public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool )\r
165                         : this( device, n幅, n高さ, format, pool, Usage.None )\r
166                 {\r
167                 }\r
168                 public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool, Usage usage )\r
169                         : this()\r
170                 {\r
171                         try\r
172                         {\r
173                                 this.sz画像サイズ = new Size( n幅, n高さ );\r
174                                 this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
175                                 using ( Bitmap bitmap = new Bitmap( 1, 1 ) )\r
176                                 {\r
177                                         using ( Graphics graphics = Graphics.FromImage( bitmap ) )\r
178                                         {\r
179                                                 graphics.FillRectangle( Brushes.Black, 0, 0, 1, 1 );\r
180                                         }\r
181                                         using ( MemoryStream stream = new MemoryStream() )\r
182                                         {\r
183                                                 bitmap.Save( stream, ImageFormat.Bmp );\r
184                                                 stream.Seek( 0L, SeekOrigin.Begin );\r
185 #if TEST_Direct3D9Ex\r
186                                                 pool = poolvar;\r
187 #endif\r
188                                                 // 中で更にメモリ読み込みし直していて無駄なので、Streamを使うのは止めたいところ\r
189                                                 this.texture = Texture.FromStream( device, stream, n幅, n高さ, 1, usage, format, pool, Filter.Point, Filter.None, 0 );\r
190                                         }\r
191                                 }\r
192                                 this.t頂点バッファの作成( device );\r
193                         }\r
194                         catch\r
195                         {\r
196                                 this.Dispose();\r
197                                 throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n({0}x{1}, {2})", n幅, n高さ, format ) );\r
198                         }\r
199                 }\r
200                 \r
201                 /// <summary>\r
202                 /// <para>画像ファイルからテクスチャを生成する。</para>\r
203                 /// <para>利用可能な画像形式は、BMP, JPG, PNG, TGA, DDS, PPM, DIB, HDR, PFM のいずれか。</para>\r
204                 /// <para>テクスチャのサイズは、画像のサイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
205                 /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
206                 /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None になる。</para>\r
207                 /// </summary>\r
208                 /// <param name="device">Direct3D9 デバイス。</param>\r
209                 /// <param name="strファイル名">画像ファイル名。</param>\r
210                 /// <param name="format">テクスチャのフォーマット。</param>\r
211                 /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>\r
212                 /// <param name="pool">テクスチャの管理方法。</param>\r
213                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
214                 public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool )\r
215                         : this()\r
216                 {\r
217                         try\r
218                         {\r
219                                 ImageInformation information = ImageInformation.FromFile( strファイル名 );\r
220                                 this.sz画像サイズ = new Size( information.Width, information.Height );\r
221                                 this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
222 #if TEST_Direct3D9Ex\r
223                                 pool = poolvar;\r
224 #endif\r
225                                 this.texture = Texture.FromFile( device, strファイル名, this.sz画像サイズ.Width, this.sz画像サイズ.Height, 1, Usage.None, format, pool, Filter.Point, Filter.None, b黒を透過する ? -16777216 : 0 );\r
226                                 this.t頂点バッファの作成( device );\r
227                         }\r
228                         catch\r
229                         {\r
230                                 this.Dispose();\r
231                                 throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n{0}", strファイル名 ) );\r
232                         }\r
233                 }\r
234 \r
235 \r
236                 // メソッド\r
237 \r
238                 /// <summary>\r
239                 /// テクスチャを 2D 画像と見なして描画する。\r
240                 /// </summary>\r
241                 /// <param name="device">Direct3D9 デバイス。</param>\r
242                 /// <param name="x">描画位置(テクスチャの左上位置の X 座標[dot])。</param>\r
243                 /// <param name="y">描画位置(テクスチャの左上位置の Y 座標[dot])。</param>\r
244                 public void t2D描画( Device device, int x, int y )\r
245                 {\r
246                         this.t2D描画( device, x, y, new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height ) );\r
247                 }\r
248                 public void t2D描画( Device device, int x, int y, Rectangle rc画像内の描画領域 )\r
249                 {\r
250                         this.t2D描画( device, x, y, 1f, rc画像内の描画領域 );\r
251                 }\r
252                 public void t2D描画( Device device, int x, int y, float depth, Rectangle rc画像内の描画領域 )\r
253                 {\r
254                         if( this.texture != null )\r
255                         {\r
256                                 this.tレンダリングステートの設定( device );\r
257                                 if( this.fZ軸中心回転 == 0f )\r
258                                 {\r
259                                         float num = -0.5f;\r
260                                         float num2 = -0.5f;\r
261                                         float width = rc画像内の描画領域.Width;\r
262                                         float height = rc画像内の描画領域.Height;\r
263                                         float num5 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
264                                         float num6 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
265                                         float num7 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
266                                         float num8 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
267                                         int color4 = new Color4( ( (float) this._透明度 ) / 255f, 1f, 1f, 1f ).ToArgb();\r
268                                         if( this.cvTransformedColoredVertexies == null )\r
269                                         {\r
270                                                 this.cvTransformedColoredVertexies = new TransformedColoredTexturedVertex[ 4 ];\r
271                                         }\r
272                                         this.cvTransformedColoredVertexies[ 0 ].Position = new Vector4( x + num, y + num2, depth, 1f );\r
273                                         this.cvTransformedColoredVertexies[ 0 ].Color = color4;\r
274                                         this.cvTransformedColoredVertexies[ 0 ].TextureCoordinates = new Vector2( num5, num7 );\r
275                                         this.cvTransformedColoredVertexies[ 1 ].Position = new Vector4( ( x + ( width * this.vc拡大縮小倍率.X ) ) + num, y + num2, depth, 1f );\r
276                                         this.cvTransformedColoredVertexies[ 1 ].Color = color4;\r
277                                         this.cvTransformedColoredVertexies[ 1 ].TextureCoordinates = new Vector2( num6, num7 );\r
278                                         this.cvTransformedColoredVertexies[ 2 ].Position = new Vector4( x + num, ( y + ( height * this.vc拡大縮小倍率.Y ) ) + num2, depth, 1f );\r
279                                         this.cvTransformedColoredVertexies[ 2 ].Color = color4;\r
280                                         this.cvTransformedColoredVertexies[ 2 ].TextureCoordinates = new Vector2( num5, num8 );\r
281                                         this.cvTransformedColoredVertexies[ 3 ].Position = new Vector4( ( x + ( width * this.vc拡大縮小倍率.X ) ) + num, ( y + ( height * this.vc拡大縮小倍率.Y ) ) + num2, depth, 1f );\r
282                                         this.cvTransformedColoredVertexies[ 3 ].Color = color4;\r
283                                         this.cvTransformedColoredVertexies[ 3 ].TextureCoordinates = new Vector2( num6, num8 );\r
284                                         device.SetTexture( 0, this.texture );\r
285                                         device.VertexFormat = TransformedColoredTexturedVertex.Format;\r
286                                         device.DrawUserPrimitives<TransformedColoredTexturedVertex>( PrimitiveType.TriangleStrip, 0, 2, this.cvTransformedColoredVertexies );\r
287                                 }\r
288                                 else\r
289                                 {\r
290                                         float num10 = ( ( rc画像内の描画領域.Width % 2 ) == 0 ) ? -0.5f : 0f;\r
291                                         float num11 = ( ( rc画像内の描画領域.Height % 2 ) == 0 ) ? -0.5f : 0f;\r
292                                         float num12 = ( (float) rc画像内の描画領域.Width ) / 2f;\r
293                                         float num13 = ( (float) rc画像内の描画領域.Height ) / 2f;\r
294                                         int num1 = rc画像内の描画領域.Width;\r
295                                         int num21 = rc画像内の描画領域.Height;\r
296                                         float num14 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
297                                         float num15 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
298                                         float num16 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
299                                         float num17 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
300                                         int color4 = new Color4( ( (float) this._透明度 ) / 255f, 1f, 1f, 1f ).ToArgb();\r
301                                         if( this.cvPositionColoredVertexies == null )\r
302                                         {\r
303                                                 this.cvPositionColoredVertexies = new PositionColoredTexturedVertex[ 4 ];\r
304                                         }\r
305                                         this.cvPositionColoredVertexies[ 0 ].Position = new Vector3( -num12 + num10, num13 + num11, depth );\r
306                                         this.cvPositionColoredVertexies[ 0 ].Color = color4;\r
307                                         this.cvPositionColoredVertexies[ 0 ].TextureCoordinates = new Vector2( num14, num16 );\r
308                                         this.cvPositionColoredVertexies[ 1 ].Position = new Vector3( num12 + num10, num13 + num11, depth );\r
309                                         this.cvPositionColoredVertexies[ 1 ].Color = color4;\r
310                                         this.cvPositionColoredVertexies[ 1 ].TextureCoordinates = new Vector2( num15, num16 );\r
311                                         this.cvPositionColoredVertexies[ 2 ].Position = new Vector3( -num12 + num10, -num13 + num11, depth );\r
312                                         this.cvPositionColoredVertexies[ 2 ].Color = color4;\r
313                                         this.cvPositionColoredVertexies[ 2 ].TextureCoordinates = new Vector2( num14, num17 );\r
314                                         this.cvPositionColoredVertexies[ 3 ].Position = new Vector3( num12 + num10, -num13 + num11, depth );\r
315                                         this.cvPositionColoredVertexies[ 3 ].Color = color4;\r
316                                         this.cvPositionColoredVertexies[ 3 ].TextureCoordinates = new Vector2( num15, num17 );\r
317                                         using( DataStream stream = this.vbPositionColoredVertexBuffer.Lock( 0, 0, LockFlags.NoOverwrite ) )     // LockFlags.None\r
318                                         {\r
319                                                 stream.WriteRange<PositionColoredTexturedVertex>( this.cvPositionColoredVertexies );\r
320                                                 this.vbPositionColoredVertexBuffer.Unlock();\r
321                                         }\r
322                                         int num19 = x + ( rc画像内の描画領域.Width / 2 );\r
323                                         int num20 = y + ( rc画像内の描画領域.Height / 2 );\r
324                                         Vector3 amount = new Vector3( num19 - ( ( (float) device.Viewport.Width ) / 2f ), -( num20 - ( ( (float) device.Viewport.Height ) / 2f ) ), 0f );\r
325                                         Matrix matrix = Matrix.Identity * Matrix.Scaling( this.vc拡大縮小倍率 );\r
326                                         matrix *= Matrix.RotationZ( this.fZ軸中心回転 );\r
327                                         matrix *= Matrix.Translation( amount );\r
328                                         device.SetTransform( TransformState.World, matrix );\r
329                                         device.SetTexture( 0, this.texture );\r
330                                         device.SetStreamSource( 0, this.vbPositionColoredVertexBuffer, 0, PositionColoredTexturedVertex.SizeInBytes );\r
331                                         device.VertexFormat = PositionColoredTexturedVertex.Format;\r
332                                         device.DrawPrimitives( PrimitiveType.TriangleStrip, 0, 2 );\r
333                                 }\r
334                         }\r
335                 }\r
336 \r
337                 /// <summary>\r
338                 /// テクスチャを 3D 画像と見なして描画する。\r
339                 /// </summary>\r
340                 public void t3D描画( Device device, Matrix mat )\r
341                 {\r
342                         this.t3D描画( device, mat, new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height ) );\r
343                 }\r
344                 public void t3D描画( Device device, Matrix mat, Rectangle rc画像内の描画領域 )\r
345                 {\r
346                         if( this.texture != null )\r
347                         {\r
348                                 float x = ( (float) rc画像内の描画領域.Width ) / 2f;\r
349                                 float y = ( (float) rc画像内の描画領域.Height ) / 2f;\r
350                                 int width = rc画像内の描画領域.Width;\r
351                                 int height = rc画像内の描画領域.Height;\r
352                                 float num3 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
353                                 float num4 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
354                                 float num5 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
355                                 float num6 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
356                                 int color4 = new Color4( ( (float) this._透明度 ) / 255f, 1f, 1f, 1f ).ToArgb();\r
357                                 if( this.cvPositionColoredVertexies == null )\r
358                                 {\r
359                                         this.cvPositionColoredVertexies = new PositionColoredTexturedVertex[ 4 ];\r
360                                 }\r
361                                 float z = 0f;\r
362                                 this.cvPositionColoredVertexies[ 0 ].Position = new Vector3( -x, y, z );\r
363                                 this.cvPositionColoredVertexies[ 0 ].Color = color4;\r
364                                 this.cvPositionColoredVertexies[ 0 ].TextureCoordinates = new Vector2( num3, num5 );\r
365                                 this.cvPositionColoredVertexies[ 1 ].Position = new Vector3( x, y, z );\r
366                                 this.cvPositionColoredVertexies[ 1 ].Color = color4;\r
367                                 this.cvPositionColoredVertexies[ 1 ].TextureCoordinates = new Vector2( num4, num5 );\r
368                                 this.cvPositionColoredVertexies[ 2 ].Position = new Vector3( -x, -y, z );\r
369                                 this.cvPositionColoredVertexies[ 2 ].Color = color4;\r
370                                 this.cvPositionColoredVertexies[ 2 ].TextureCoordinates = new Vector2( num3, num6 );\r
371                                 this.cvPositionColoredVertexies[ 3 ].Position = new Vector3( x, -y, z );\r
372                                 this.cvPositionColoredVertexies[ 3 ].Color = color4;\r
373                                 this.cvPositionColoredVertexies[ 3 ].TextureCoordinates = new Vector2( num4, num6 );\r
374                                 using( DataStream stream = this.vbPositionColoredVertexBuffer.Lock( 0, 0, LockFlags.NoOverwrite ) )             // LockFlags.None\r
375                                 {\r
376                                         stream.WriteRange<PositionColoredTexturedVertex>( this.cvPositionColoredVertexies );\r
377                                         this.vbPositionColoredVertexBuffer.Unlock();\r
378                                 }\r
379                                 this.tレンダリングステートの設定( device );\r
380                                 device.SetTransform( TransformState.World, mat );\r
381                                 device.SetTexture( 0, this.texture );\r
382                                 device.SetStreamSource( 0, this.vbPositionColoredVertexBuffer, 0, PositionColoredTexturedVertex.SizeInBytes );\r
383                                 device.VertexFormat = PositionColoredTexturedVertex.Format;\r
384                                 device.DrawPrimitives( PrimitiveType.TriangleStrip, 0, 2 );\r
385                         }\r
386                 }\r
387 \r
388                 #region [ IDosposable 実装 ]\r
389                 //-----------------\r
390                 public void Dispose()\r
391                 {\r
392                         if( !this.bDispose完了済み )\r
393                         {\r
394                                 // テクスチャの破棄\r
395                                 if( this.texture != null )\r
396                                 {\r
397                                         this.texture.Dispose();\r
398                                         this.texture = null;\r
399                                 }\r
400 \r
401                                 // 頂点バッファの破棄\r
402                                 if( this.vbPositionColoredVertexBuffer != null )\r
403                                 {\r
404                                         this.vbPositionColoredVertexBuffer.Dispose();\r
405                                         this.vbPositionColoredVertexBuffer = null;\r
406                                 }\r
407                                 this.bDispose完了済み = true;\r
408                         }\r
409                 }\r
410                 //-----------------\r
411                 #endregion\r
412 \r
413 \r
414                 // その他\r
415 \r
416                 #region [ private ]\r
417                 //-----------------\r
418                 private int _透明度;\r
419                 private bool bDispose完了済み;\r
420                 private PositionColoredTexturedVertex[] cvPositionColoredVertexies;\r
421                 private TransformedColoredTexturedVertex[] cvTransformedColoredVertexies;\r
422                 private VertexBuffer vbPositionColoredVertexBuffer;\r
423                 private const Pool poolvar =                                                                                            // 2011.4.25 yyagi\r
424 #if TEST_Direct3D9Ex\r
425                         Pool.Default;\r
426 #else\r
427                         Pool.Managed;\r
428 #endif\r
429 \r
430 \r
431                 private void tレンダリングステートの設定( Device device )\r
432                 {\r
433                         if( this.b加算合成 )\r
434                         {\r
435                                 device.SetRenderState( RenderState.AlphaBlendEnable, true );\r
436                                 device.SetRenderState( RenderState.SourceBlend, SlimDX.Direct3D9.Blend.SourceAlpha );                           // 5\r
437                                 device.SetRenderState( RenderState.DestinationBlend, SlimDX.Direct3D9.Blend.One );                                      // 2\r
438                         }\r
439                         else\r
440                         {\r
441                                 device.SetRenderState( RenderState.AlphaBlendEnable, true );\r
442                                 device.SetRenderState( RenderState.SourceBlend, SlimDX.Direct3D9.Blend.SourceAlpha );                           // 5\r
443                                 device.SetRenderState( RenderState.DestinationBlend, SlimDX.Direct3D9.Blend.InverseSourceAlpha );       // 6\r
444                         }\r
445                 }\r
446                 private Size t指定されたサイズを超えない最適なテクスチャサイズを返す( Device device, Size sz指定サイズ )\r
447                 {\r
448                         bool flag = ( device.Capabilities.TextureCaps & TextureCaps.NonPow2Conditional ) != 0;\r
449                         bool flag2 = ( device.Capabilities.TextureCaps & TextureCaps.Pow2 ) != 0;\r
450                         bool flag3 = ( device.Capabilities.TextureCaps & TextureCaps.SquareOnly ) != 0;\r
451                         int maxTextureWidth = device.Capabilities.MaxTextureWidth;\r
452                         int maxTextureHeight = device.Capabilities.MaxTextureHeight;\r
453                         Size size = new Size( sz指定サイズ.Width, sz指定サイズ.Height );\r
454                         if( flag2 && !flag )\r
455                         {\r
456                                 int num3 = 1;\r
457                                 do\r
458                                 {\r
459                                         num3 *= 2;\r
460                                 }\r
461                                 while( num3 <= sz指定サイズ.Width );\r
462                                 sz指定サイズ.Width = num3;\r
463                                 num3 = 1;\r
464                                 do\r
465                                 {\r
466                                         num3 *= 2;\r
467                                 }\r
468                                 while( num3 <= sz指定サイズ.Height );\r
469                                 sz指定サイズ.Height = num3;\r
470                         }\r
471                         if( sz指定サイズ.Width > maxTextureWidth )\r
472                         {\r
473                                 sz指定サイズ.Width = maxTextureWidth;\r
474                         }\r
475                         if( sz指定サイズ.Height > maxTextureHeight )\r
476                         {\r
477                                 sz指定サイズ.Height = maxTextureHeight;\r
478                         }\r
479                         if( flag3 )\r
480                         {\r
481                                 if( size.Width > size.Height )\r
482                                 {\r
483                                         size.Height = size.Width;\r
484                                         return size;\r
485                                 }\r
486                                 if( size.Width < size.Height )\r
487                                 {\r
488                                         size.Width = size.Height;\r
489                                 }\r
490                         }\r
491                         return size;\r
492                 }\r
493                 private void t頂点バッファの作成( Device device )\r
494                 {\r
495                         this.vbPositionColoredVertexBuffer = new VertexBuffer( device, 4 * PositionColoredTexturedVertex.SizeInBytes, Usage.WriteOnly, VertexFormat.None, poolvar );\r
496                 }\r
497                 //-----------------\r
498                 #endregion\r
499         }\r
500 }\r