OSDN Git Service

1f5176dcf8bce1170f67b7d194b77057728d36ca
[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                                         int colorKey = 0;\r
104                                         colorKey = -16777216;\r
105                                         this.texture = Texture.FromStream( device, stream, this.szテクスチャサイズ.Width, this.szテクスチャサイズ.Height, 1, Usage.None, format, Pool.Managed, Filter.Point, Filter.None, colorKey );\r
106                                 }\r
107                                 this.t頂点バッファの作成( device );\r
108                         }\r
109                         catch\r
110                         {\r
111                                 this.Dispose();\r
112                                 throw new CTextureCreateFailedException( "ビットマップからのテクスチャの生成に失敗しました。" );\r
113                         }\r
114                 }\r
115         \r
116                 /// <summary>\r
117                 /// <para>空の Managed テクスチャを作成する。</para>\r
118                 /// <para>テクスチャのサイズは、指定された希望サイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
119                 /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
120                 /// <para>テクスチャのテクセルデータは未初期化。(おそらくゴミデータが入ったまま。)</para>\r
121                 /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None、\r
122                 /// カラーキーは 0x00000000(透過しない)になる。</para>\r
123                 /// </summary>\r
124                 /// <param name="device">Direct3D9 デバイス。</param>\r
125                 /// <param name="n幅">テクスチャの幅(希望値)。</param>\r
126                 /// <param name="n高さ">テクスチャの高さ(希望値)。</param>\r
127                 /// <param name="format">テクスチャのフォーマット。</param>\r
128                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
129                 public CTexture( Device device, int n幅, int n高さ, Format format )\r
130                         : this( device, n幅, n高さ, format, Pool.Managed )\r
131                 {\r
132                 }\r
133                 \r
134                 /// <summary>\r
135                 /// <para>指定された画像ファイルから Managed テクスチャを作成する。</para>\r
136                 /// <para>利用可能な画像形式は、BMP, JPG, PNG, TGA, DDS, PPM, DIB, HDR, PFM のいずれか。</para>\r
137                 /// </summary>\r
138                 /// <param name="device">Direct3D9 デバイス。</param>\r
139                 /// <param name="strファイル名">画像ファイル名。</param>\r
140                 /// <param name="format">テクスチャのフォーマット。</param>\r
141                 /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>\r
142                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
143                 public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する )\r
144                         : this( device, strファイル名, format, b黒を透過する, Pool.Managed )\r
145                 {\r
146                 }\r
147                 \r
148                 /// <summary>\r
149                 /// <para>空のテクスチャを作成する。</para>\r
150                 /// <para>テクスチャのサイズは、指定された希望サイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
151                 /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
152                 /// <para>テクスチャのテクセルデータは未初期化。(おそらくゴミデータが入ったまま。)</para>\r
153                 /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None、\r
154                 /// カラーキーは 0x00000000(透過しない)になる。</para>\r
155                 /// </summary>\r
156                 /// <param name="device">Direct3D9 デバイス。</param>\r
157                 /// <param name="n幅">テクスチャの幅(希望値)。</param>\r
158                 /// <param name="n高さ">テクスチャの高さ(希望値)。</param>\r
159                 /// <param name="format">テクスチャのフォーマット。</param>\r
160                 /// <param name="pool">テクスチャの管理方法。</param>\r
161                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
162                 public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool )\r
163                         : this()\r
164                 {\r
165                         try\r
166                         {\r
167                                 this.sz画像サイズ = new Size( n幅, n高さ );\r
168                                 this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
169                                 using( Bitmap bitmap = new Bitmap( 1, 1 ) )\r
170                                 {\r
171                                         using( Graphics graphics = Graphics.FromImage( bitmap ) )\r
172                                         {\r
173                                                 graphics.FillRectangle( Brushes.Black, 0, 0, 1, 1 );\r
174                                         }\r
175                                         using( MemoryStream stream = new MemoryStream() )\r
176                                         {\r
177                                                 bitmap.Save( stream, ImageFormat.Bmp );\r
178                                                 stream.Seek( 0L, SeekOrigin.Begin );\r
179                                                 this.texture = Texture.FromStream( device, stream, n幅, n高さ, 1, Usage.None, format, pool, Filter.Point, Filter.None, 0 );\r
180                                         }\r
181                                 }\r
182                                 this.t頂点バッファの作成( device );\r
183                         }\r
184                         catch\r
185                         {\r
186                                 this.Dispose();\r
187                                 throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n({0}x{1}, {2})", n幅, n高さ, format ) );\r
188                         }\r
189                 }\r
190                 \r
191                 /// <summary>\r
192                 /// <para>画像ファイルからテクスチャを生成する。</para>\r
193                 /// <para>利用可能な画像形式は、BMP, JPG, PNG, TGA, DDS, PPM, DIB, HDR, PFM のいずれか。</para>\r
194                 /// <para>テクスチャのサイズは、画像のサイズ以上、かつ、D3D9デバイスで生成可能な最小のサイズに自動的に調節される。\r
195                 /// その際、テクスチャの調節後のサイズにあわせた画像の拡大縮小は行わない。</para>\r
196                 /// <para>その他、ミップマップ数は 1、Usage は None、イメージフィルタは Point、ミップマップフィルタは None になる。</para>\r
197                 /// </summary>\r
198                 /// <param name="device">Direct3D9 デバイス。</param>\r
199                 /// <param name="strファイル名">画像ファイル名。</param>\r
200                 /// <param name="format">テクスチャのフォーマット。</param>\r
201                 /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>\r
202                 /// <param name="pool">テクスチャの管理方法。</param>\r
203                 /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>\r
204                 public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool )\r
205                         : this()\r
206                 {\r
207                         try\r
208                         {\r
209                                 ImageInformation information = ImageInformation.FromFile( strファイル名 );\r
210                                 this.sz画像サイズ = new Size( information.Width, information.Height );\r
211                                 this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );\r
212                                 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
213                                 this.t頂点バッファの作成( device );\r
214                         }\r
215                         catch\r
216                         {\r
217                                 this.Dispose();\r
218                                 throw new CTextureCreateFailedException( string.Format( "テクスチャの生成に失敗しました。\n{0}", strファイル名 ) );\r
219                         }\r
220                 }\r
221 \r
222 \r
223                 // メソッド\r
224 \r
225                 /// <summary>\r
226                 /// テクスチャを 2D 画像と見なして描画する。\r
227                 /// </summary>\r
228                 /// <param name="device">Direct3D9 デバイス。</param>\r
229                 /// <param name="x">描画位置(テクスチャの左上位置の X 座標[dot])。</param>\r
230                 /// <param name="y">描画位置(テクスチャの左上位置の Y 座標[dot])。</param>\r
231                 public void t2D描画( Device device, int x, int y )\r
232                 {\r
233                         this.t2D描画( device, x, y, new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height ) );\r
234                 }\r
235                 public void t2D描画( Device device, int x, int y, Rectangle rc画像内の描画領域 )\r
236                 {\r
237                         this.t2D描画( device, x, y, 1f, rc画像内の描画領域 );\r
238                 }\r
239                 public void t2D描画( Device device, int x, int y, float depth, Rectangle rc画像内の描画領域 )\r
240                 {\r
241                         if( this.texture != null )\r
242                         {\r
243                                 this.tレンダリングステートの設定( device );\r
244                                 if( this.fZ軸中心回転 == 0f )\r
245                                 {\r
246                                         float num = -0.5f;\r
247                                         float num2 = -0.5f;\r
248                                         float width = rc画像内の描画領域.Width;\r
249                                         float height = rc画像内の描画領域.Height;\r
250                                         float num5 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
251                                         float num6 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
252                                         float num7 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
253                                         float num8 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
254                                         int num9 = new Color4( ( (float) this._透明度 ) / 255f, 1f, 1f, 1f ).ToArgb();\r
255                                         if( this.cvTransformedColoredVertexies == null )\r
256                                         {\r
257                                                 this.cvTransformedColoredVertexies = new TransformedColoredTexturedVertex[ 4 ];\r
258                                         }\r
259                                         this.cvTransformedColoredVertexies[ 0 ].Position = new Vector4( x + num, y + num2, depth, 1f );\r
260                                         this.cvTransformedColoredVertexies[ 0 ].Color = num9;\r
261                                         this.cvTransformedColoredVertexies[ 0 ].TextureCoordinates = new Vector2( num5, num7 );\r
262                                         this.cvTransformedColoredVertexies[ 1 ].Position = new Vector4( ( x + ( width * this.vc拡大縮小倍率.X ) ) + num, y + num2, depth, 1f );\r
263                                         this.cvTransformedColoredVertexies[ 1 ].Color = num9;\r
264                                         this.cvTransformedColoredVertexies[ 1 ].TextureCoordinates = new Vector2( num6, num7 );\r
265                                         this.cvTransformedColoredVertexies[ 2 ].Position = new Vector4( x + num, ( y + ( height * this.vc拡大縮小倍率.Y ) ) + num2, depth, 1f );\r
266                                         this.cvTransformedColoredVertexies[ 2 ].Color = num9;\r
267                                         this.cvTransformedColoredVertexies[ 2 ].TextureCoordinates = new Vector2( num5, num8 );\r
268                                         this.cvTransformedColoredVertexies[ 3 ].Position = new Vector4( ( x + ( width * this.vc拡大縮小倍率.X ) ) + num, ( y + ( height * this.vc拡大縮小倍率.Y ) ) + num2, depth, 1f );\r
269                                         this.cvTransformedColoredVertexies[ 3 ].Color = num9;\r
270                                         this.cvTransformedColoredVertexies[ 3 ].TextureCoordinates = new Vector2( num6, num8 );\r
271                                         device.SetTexture( 0, this.texture );\r
272                                         device.VertexFormat = TransformedColoredTexturedVertex.Format;\r
273                                         device.DrawUserPrimitives<TransformedColoredTexturedVertex>( PrimitiveType.TriangleStrip, 0, 2, this.cvTransformedColoredVertexies );\r
274                                 }\r
275                                 else\r
276                                 {\r
277                                         float num10 = ( ( rc画像内の描画領域.Width % 2 ) == 0 ) ? -0.5f : 0f;\r
278                                         float num11 = ( ( rc画像内の描画領域.Height % 2 ) == 0 ) ? -0.5f : 0f;\r
279                                         float num12 = ( (float) rc画像内の描画領域.Width ) / 2f;\r
280                                         float num13 = ( (float) rc画像内の描画領域.Height ) / 2f;\r
281                                         int num1 = rc画像内の描画領域.Width;\r
282                                         int num21 = rc画像内の描画領域.Height;\r
283                                         float num14 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
284                                         float num15 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
285                                         float num16 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
286                                         float num17 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
287                                         int num18 = new Color4( ( (float) this._透明度 ) / 255f, 1f, 1f, 1f ).ToArgb();\r
288                                         if( this.cvPositionColoredVertexies == null )\r
289                                         {\r
290                                                 this.cvPositionColoredVertexies = new PositionColoredTexturedVertex[ 4 ];\r
291                                         }\r
292                                         this.cvPositionColoredVertexies[ 0 ].Position = new Vector3( -num12 + num10, num13 + num11, depth );\r
293                                         this.cvPositionColoredVertexies[ 0 ].Color = num18;\r
294                                         this.cvPositionColoredVertexies[ 0 ].TextureCoordinates = new Vector2( num14, num16 );\r
295                                         this.cvPositionColoredVertexies[ 1 ].Position = new Vector3( num12 + num10, num13 + num11, depth );\r
296                                         this.cvPositionColoredVertexies[ 1 ].Color = num18;\r
297                                         this.cvPositionColoredVertexies[ 1 ].TextureCoordinates = new Vector2( num15, num16 );\r
298                                         this.cvPositionColoredVertexies[ 2 ].Position = new Vector3( -num12 + num10, -num13 + num11, depth );\r
299                                         this.cvPositionColoredVertexies[ 2 ].Color = num18;\r
300                                         this.cvPositionColoredVertexies[ 2 ].TextureCoordinates = new Vector2( num14, num17 );\r
301                                         this.cvPositionColoredVertexies[ 3 ].Position = new Vector3( num12 + num10, -num13 + num11, depth );\r
302                                         this.cvPositionColoredVertexies[ 3 ].Color = num18;\r
303                                         this.cvPositionColoredVertexies[ 3 ].TextureCoordinates = new Vector2( num15, num17 );\r
304                                         using( DataStream stream = this.vbPositionColoredVertexBuffer.Lock( 0, 0, LockFlags.None ) )\r
305                                         {\r
306                                                 stream.WriteRange<PositionColoredTexturedVertex>( this.cvPositionColoredVertexies );\r
307                                                 this.vbPositionColoredVertexBuffer.Unlock();\r
308                                         }\r
309                                         int num19 = x + ( rc画像内の描画領域.Width / 2 );\r
310                                         int num20 = y + ( rc画像内の描画領域.Height / 2 );\r
311                                         Vector3 amount = new Vector3( num19 - ( ( (float) device.Viewport.Width ) / 2f ), -( num20 - ( ( (float) device.Viewport.Height ) / 2f ) ), 0f );\r
312                                         Matrix matrix = Matrix.Identity * Matrix.Scaling( this.vc拡大縮小倍率 );\r
313                                         matrix *= Matrix.RotationZ( this.fZ軸中心回転 );\r
314                                         matrix *= Matrix.Translation( amount );\r
315                                         device.SetTransform( TransformState.World, matrix );\r
316                                         device.SetTexture( 0, this.texture );\r
317                                         device.SetStreamSource( 0, this.vbPositionColoredVertexBuffer, 0, PositionColoredTexturedVertex.SizeInBytes );\r
318                                         device.VertexFormat = PositionColoredTexturedVertex.Format;\r
319                                         device.DrawPrimitives( PrimitiveType.TriangleStrip, 0, 2 );\r
320                                 }\r
321                         }\r
322                 }\r
323 \r
324                 /// <summary>\r
325                 /// テクスチャを 3D 画像と見なして描画する。\r
326                 /// </summary>\r
327                 public void t3D描画( Device device, Matrix mat )\r
328                 {\r
329                         this.t3D描画( device, mat, new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height ) );\r
330                 }\r
331                 public void t3D描画( Device device, Matrix mat, Rectangle rc画像内の描画領域 )\r
332                 {\r
333                         if( this.texture != null )\r
334                         {\r
335                                 float x = ( (float) rc画像内の描画領域.Width ) / 2f;\r
336                                 float y = ( (float) rc画像内の描画領域.Height ) / 2f;\r
337                                 int width = rc画像内の描画領域.Width;\r
338                                 int height = rc画像内の描画領域.Height;\r
339                                 float num3 = ( (float) rc画像内の描画領域.Left ) / ( (float) this.szテクスチャサイズ.Width );\r
340                                 float num4 = ( (float) rc画像内の描画領域.Right ) / ( (float) this.szテクスチャサイズ.Width );\r
341                                 float num5 = ( (float) rc画像内の描画領域.Top ) / ( (float) this.szテクスチャサイズ.Height );\r
342                                 float num6 = ( (float) rc画像内の描画領域.Bottom ) / ( (float) this.szテクスチャサイズ.Height );\r
343                                 int num7 = new Color4( ( (float) this._透明度 ) / 255f, 1f, 1f, 1f ).ToArgb();\r
344                                 if( this.cvPositionColoredVertexies == null )\r
345                                 {\r
346                                         this.cvPositionColoredVertexies = new PositionColoredTexturedVertex[ 4 ];\r
347                                 }\r
348                                 float z = 0f;\r
349                                 this.cvPositionColoredVertexies[ 0 ].Position = new Vector3( -x, y, z );\r
350                                 this.cvPositionColoredVertexies[ 0 ].Color = num7;\r
351                                 this.cvPositionColoredVertexies[ 0 ].TextureCoordinates = new Vector2( num3, num5 );\r
352                                 this.cvPositionColoredVertexies[ 1 ].Position = new Vector3( x, y, z );\r
353                                 this.cvPositionColoredVertexies[ 1 ].Color = num7;\r
354                                 this.cvPositionColoredVertexies[ 1 ].TextureCoordinates = new Vector2( num4, num5 );\r
355                                 this.cvPositionColoredVertexies[ 2 ].Position = new Vector3( -x, -y, z );\r
356                                 this.cvPositionColoredVertexies[ 2 ].Color = num7;\r
357                                 this.cvPositionColoredVertexies[ 2 ].TextureCoordinates = new Vector2( num3, num6 );\r
358                                 this.cvPositionColoredVertexies[ 3 ].Position = new Vector3( x, -y, z );\r
359                                 this.cvPositionColoredVertexies[ 3 ].Color = num7;\r
360                                 this.cvPositionColoredVertexies[ 3 ].TextureCoordinates = new Vector2( num4, num6 );\r
361                                 using( DataStream stream = this.vbPositionColoredVertexBuffer.Lock( 0, 0, LockFlags.None ) )\r
362                                 {\r
363                                         stream.WriteRange<PositionColoredTexturedVertex>( this.cvPositionColoredVertexies );\r
364                                         this.vbPositionColoredVertexBuffer.Unlock();\r
365                                 }\r
366                                 this.tレンダリングステートの設定( device );\r
367                                 device.SetTransform( TransformState.World, mat );\r
368                                 device.SetTexture( 0, this.texture );\r
369                                 device.SetStreamSource( 0, this.vbPositionColoredVertexBuffer, 0, PositionColoredTexturedVertex.SizeInBytes );\r
370                                 device.VertexFormat = PositionColoredTexturedVertex.Format;\r
371                                 device.DrawPrimitives( PrimitiveType.TriangleStrip, 0, 2 );\r
372                         }\r
373                 }\r
374 \r
375                 #region [ IDosposable 実装 ]\r
376                 //-----------------\r
377                 public void Dispose()\r
378                 {\r
379                         if( !this.bDispose完了済み )\r
380                         {\r
381                                 // テクスチャの破棄\r
382                                 if( this.texture != null )\r
383                                 {\r
384                                         this.texture.Dispose();\r
385                                         this.texture = null;\r
386                                 }\r
387 \r
388                                 // 頂点バッファの破棄\r
389                                 if( this.vbPositionColoredVertexBuffer != null )\r
390                                 {\r
391                                         this.vbPositionColoredVertexBuffer.Dispose();\r
392                                         this.vbPositionColoredVertexBuffer = null;\r
393                                 }\r
394                                 this.bDispose完了済み = true;\r
395                         }\r
396                 }\r
397                 //-----------------\r
398                 #endregion\r
399 \r
400 \r
401                 // その他\r
402 \r
403                 #region [ private ]\r
404                 //-----------------\r
405                 private int _透明度;\r
406                 private bool bDispose完了済み;\r
407                 private PositionColoredTexturedVertex[] cvPositionColoredVertexies;\r
408                 private TransformedColoredTexturedVertex[] cvTransformedColoredVertexies;\r
409                 private VertexBuffer vbPositionColoredVertexBuffer;\r
410 \r
411                 private void tレンダリングステートの設定( Device device )\r
412                 {\r
413                         if( this.b加算合成 )\r
414                         {\r
415                                 device.SetRenderState( RenderState.AlphaBlendEnable, true );\r
416                                 device.SetRenderState( RenderState.SourceBlend, 5 );\r
417                                 device.SetRenderState( RenderState.DestinationBlend, 2 );\r
418                         }\r
419                         else\r
420                         {\r
421                                 device.SetRenderState( RenderState.AlphaBlendEnable, true );\r
422                                 device.SetRenderState( RenderState.SourceBlend, 5 );\r
423                                 device.SetRenderState( RenderState.DestinationBlend, 6 );\r
424                         }\r
425                 }\r
426                 private Size t指定されたサイズを超えない最適なテクスチャサイズを返す( Device device, Size sz指定サイズ )\r
427                 {\r
428                         bool flag = ( device.Capabilities.TextureCaps & TextureCaps.NonPow2Conditional ) != 0;\r
429                         bool flag2 = ( device.Capabilities.TextureCaps & TextureCaps.Pow2 ) != 0;\r
430                         bool flag3 = ( device.Capabilities.TextureCaps & TextureCaps.SquareOnly ) != 0;\r
431                         int maxTextureWidth = device.Capabilities.MaxTextureWidth;\r
432                         int maxTextureHeight = device.Capabilities.MaxTextureHeight;\r
433                         Size size = new Size( sz指定サイズ.Width, sz指定サイズ.Height );\r
434                         if( flag2 && !flag )\r
435                         {\r
436                                 int num3 = 1;\r
437                                 do\r
438                                 {\r
439                                         num3 *= 2;\r
440                                 }\r
441                                 while( num3 <= sz指定サイズ.Width );\r
442                                 sz指定サイズ.Width = num3;\r
443                                 num3 = 1;\r
444                                 do\r
445                                 {\r
446                                         num3 *= 2;\r
447                                 }\r
448                                 while( num3 <= sz指定サイズ.Height );\r
449                                 sz指定サイズ.Height = num3;\r
450                         }\r
451                         if( sz指定サイズ.Width > maxTextureWidth )\r
452                         {\r
453                                 sz指定サイズ.Width = maxTextureWidth;\r
454                         }\r
455                         if( sz指定サイズ.Height > maxTextureHeight )\r
456                         {\r
457                                 sz指定サイズ.Height = maxTextureHeight;\r
458                         }\r
459                         if( flag3 )\r
460                         {\r
461                                 if( size.Width > size.Height )\r
462                                 {\r
463                                         size.Height = size.Width;\r
464                                         return size;\r
465                                 }\r
466                                 if( size.Width < size.Height )\r
467                                 {\r
468                                         size.Width = size.Height;\r
469                                 }\r
470                         }\r
471                         return size;\r
472                 }\r
473                 private void t頂点バッファの作成( Device device )\r
474                 {\r
475                         this.vbPositionColoredVertexBuffer = new VertexBuffer( device, 4 * PositionColoredTexturedVertex.SizeInBytes, Usage.WriteOnly, VertexFormat.None, Pool.Managed );\r
476                 }\r
477                 //-----------------\r
478                 #endregion\r
479         }\r
480 }\r