ページ「ファイル:NSTokenField.png」と「MonoGame/クラスライブラリ/IndexBufferクラス」の間の差分
(ページ間の差分)
ナビゲーションに移動
検索に移動
imported>Administrator (Administrator 「ファイル:NSTokenField.png」の新しい版をアップロードしました) |
imported>Administrator (→使用例) |
||
1行目: | 1行目: | ||
− | [[ | + | IndexBufferクラスは、[[ポリゴン]]を表示するのに使う[[頂点バッファ]]の無駄を省く[[インデックスバッファ]]を効率的に管理するクラスである。 |
+ | [[MonoGame/クラスライブラリ/VertexBufferクラス|VertexBufferクラス]]と同様に[[グラフィックボード]]上の[[VRAM]]に事前に展開しておくなどの機能を持つ。 | ||
+ | |||
+ | == 継承 == | ||
+ | * System.Object | ||
+ | ** [[MonoGame/クラスライブラリ/GraphicsResourceクラス|Microsoft.Xna.Framework.Graphics.GraphicsResource]] | ||
+ | *** [[MonoGame/クラスライブラリ/IndexBufferクラス|Microsoft.Xna.Framework.Graphics.IndexBuffer]] | ||
+ | **** [[MonoGame/クラスライブラリ/DynamicIndexBufferクラス|Microsoft.Xna.Framework.Graphics.DynamicIndexBuffer]] | ||
+ | |||
+ | == 名前空間 == | ||
+ | * [[MonoGame/クラスライブラリ/Microsoft.Xna.Framework.Graphics名前空間|Microsoft.Xna.Framework.Graphics名前空間]] | ||
+ | |||
+ | == 構文 == | ||
+ | public class IndexBuffer : GraphicsResource | ||
+ | |||
+ | == コンストラクタ == | ||
+ | {| class="wikitable" | ||
+ | |+ | ||
+ | ! | ||
+ | ! 名称 | ||
+ | ! 概要 | ||
+ | |- | ||
+ | | protected | ||
+ | ! style="white-space:nowrap;text-align:left" | IndexBuffer(GraphicsDevice, Type, int, BufferUsage, bool) | ||
+ | | | ||
+ | |- | ||
+ | | protected | ||
+ | ! style="white-space:nowrap;text-align:left" | IndexBuffer(GraphicsDevice, IndexElementSize, int, BufferUsage, bool) | ||
+ | | | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | IndexBuffer(GraphicsDevice, IndexElementSize, int, BufferUsage) | ||
+ | | | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | IndexBuffer(GraphicsDevice, Type, int, BufferUsage) | ||
+ | | | ||
+ | |} | ||
+ | |||
+ | == プロパティ == | ||
+ | {| class="wikitable" | ||
+ | |+ | ||
+ | ! | ||
+ | ! 名称 | ||
+ | ! 概要 | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | BufferUsage | ||
+ | | | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | GraphicsDevice | ||
+ | | (GameResourceクラスから継承) | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | IndexCount | ||
+ | | | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | IndexElementSize | ||
+ | | | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | IsDisposed | ||
+ | | (GameResourceクラスから継承) | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | Name | ||
+ | | (GameResourceクラスから継承) | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | Tag | ||
+ | | (GameResourceクラスから継承) | ||
+ | |} | ||
+ | |||
+ | == メソッド == | ||
+ | {| class="wikitable" | ||
+ | |+ | ||
+ | ! | ||
+ | ! 名称 | ||
+ | ! 概要 | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | Dispose() | ||
+ | | (GameResourceクラスから継承) | ||
+ | |- | ||
+ | | protected | ||
+ | ! style="white-space:nowrap;text-align:left" | Dispose(bool) | ||
+ | | 派生クラスを作る場合は自前管理のリソースの破棄を実装する必要がある。 | ||
+ | |- | ||
+ | | protected | ||
+ | ! style="white-space:nowrap;text-align:left" | Finalize | ||
+ | | (GameResourceクラスから継承) | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | GetData<T>(int, T[], int, int) | ||
+ | | このインデックスバッファからインデックスを取得する。 | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | GetData<T>(T[], int, int) | ||
+ | | | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | GetData<T>(T[]) | ||
+ | | | ||
+ | |- | ||
+ | | protected internal | ||
+ | ! style="white-space:nowrap;text-align:left" | GraphicsDeviceResetting | ||
+ | | GraphicsDeviceがリセットされGPU上のリソースを再作成する必要があるときに呼ばれる。 | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | SetData<T>(T[], int, int) | ||
+ | | この頂点バッファに頂点データを設定する。大雑把に言えば頂点データの配列をメインメモリからVRAMにコピーする。 | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | SetData<T>(T[]) | ||
+ | | | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | SetData<T>(int, T[], int, int) | ||
+ | | | ||
+ | |- | ||
+ | | protected | ||
+ | ! style="white-space:nowrap;text-align:left" | SetDataInternal<T> | ||
+ | | | ||
+ | |- | ||
+ | | public | ||
+ | ! style="white-space:nowrap;text-align:left" | ToString | ||
+ | | (GameResourceクラスから継承) | ||
+ | |} | ||
+ | |||
+ | == イベント == | ||
+ | {| class="wikitable" | ||
+ | |+ | ||
+ | ! | ||
+ | ! 名称 | ||
+ | ! 概要 | ||
+ | |- | ||
+ | | public | ||
+ | | Disposing | ||
+ | | (GameResourceクラスから継承) | ||
+ | |} | ||
+ | |||
+ | == 使用例 == | ||
+ | まず[[MonoGame/クラスライブラリ/VertexBufferクラス|VertexBuffer]]を作ってSetDataする。 | ||
+ | 次にIndexBufferを作ってSetDataする。 | ||
+ | IndexBufferは配列型と[[MonoGame/クラスライブラリ/IndexElementSize列挙体|IndexElementSize列挙体]]が食い違わないように注意すること。また[[配列]]の[[オーバーフロー]]にも注意。 | ||
+ | <source lang="csharp"> | ||
+ | // 頂点データを作成する | ||
+ | var vertices = new VertexPositionColor[4]; | ||
+ | vertices[0] = new VertexPositionColor(new Vector3(-10, -10, 0), Color.Red); | ||
+ | vertices[1] = new VertexPositionColor(new Vector3(-10, +10, 0), Color.Green); | ||
+ | vertices[2] = new VertexPositionColor(new Vector3(+10, +10, 0), Color.White); | ||
+ | vertices[3] = new VertexPositionColor(new Vector3(+10, -10, 0), Color.Blue); | ||
+ | |||
+ | // 頂点データをGPUに送り込む | ||
+ | _vertexBuffer = new VertexBuffer(_graphics.GraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.None); | ||
+ | _vertexBuffer.SetData(vertices); | ||
+ | |||
+ | // 16ビット配列のインデックスバッファを作成する | ||
+ | var indeces = new short[6]; | ||
+ | indeces[0] = 0; indeces[1] = 1; indeces[2] = 2; | ||
+ | indeces[3] = 0; indeces[4] = 2; indeces[5] = 3; | ||
+ | |||
+ | // インデックスデータをGPUに送り込む | ||
+ | _indexBuffer = new IndexBuffer(_graphics.GraphicsDevice, IndexElementSize.SixteenBits, indeces.Length, BufferUsage.None); | ||
+ | _indexBuffer.SetData(indeces); | ||
+ | </source> | ||
+ | |||
+ | 描画するときは、GraphicsDeviceクラスのSetVertexBufferメソッドでVertexBufferを読み出し、続いてGraphicsDevice.Indicesプロパティに[[インデックスバッファ]]を設定し、DrawIndexedPrimitivesメソッドで描画する。 | ||
+ | <source lang="csharp"> | ||
+ | // 描画 | ||
+ | |||
+ | _graphics.GraphicsDevice.SetVertexBuffer(_vertexBuffer); | ||
+ | _graphics.GraphicsDevice.Indices = _indexBuffer; | ||
+ | |||
+ | foreach (var pass in _effect.CurrentTechnique.Passes) | ||
+ | { | ||
+ | pass.Apply(); | ||
+ | _graphics.GraphicsDevice.DrawIndexedPrimitives( | ||
+ | PrimitiveType.TriangleList, // 三角形の秘密はね… | ||
+ | baseVertex: 0, // vertex側のはじまり | ||
+ | startIndex: 0, // index側のはじまり | ||
+ | primitiveCount: _indexBuffer.IndexCount / 3 // 全部三角形なので単純に3で割る | ||
+ | ); | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | == 関連項目 == | ||
+ | * [[インデックスバッファ]] | ||
+ | * [[MonoGame/クラスライブラリ/GraphicsResourceクラス]] | ||
+ | ** [[MonoGame/クラスライブラリ/VertexBufferクラス]] | ||
+ | ** [[MonoGame/クラスライブラリ/IndexBufferクラス]] | ||
+ | * [[MonoGame/クラスライブラリ/IVertexTypeインターフェイス]] | ||
+ | ** [[MonoGame/クラスライブラリ/VertexPositionColor構造体]] | ||
+ | ** [[MonoGame/クラスライブラリ/VertexPositionTexture構造体]] | ||
+ | ** [[MonoGame/クラスライブラリ/VertexPositionColorTexture構造体]] | ||
+ | ** [[MonoGame/クラスライブラリ/VertexPositionNormalTexture構造体]] | ||
+ | |||
+ | [[category: MonoGame]] |
2017年11月7日 (火) 04:00時点における版
IndexBufferクラスは、ポリゴンを表示するのに使う頂点バッファの無駄を省くインデックスバッファを効率的に管理するクラスである。 VertexBufferクラスと同様にグラフィックボード上のVRAMに事前に展開しておくなどの機能を持つ。
継承
- System.Object
名前空間
構文
public class IndexBuffer : GraphicsResource
コンストラクタ
名称 | 概要 | |
---|---|---|
protected | IndexBuffer(GraphicsDevice, Type, int, BufferUsage, bool) | |
protected | IndexBuffer(GraphicsDevice, IndexElementSize, int, BufferUsage, bool) | |
public | IndexBuffer(GraphicsDevice, IndexElementSize, int, BufferUsage) | |
public | IndexBuffer(GraphicsDevice, Type, int, BufferUsage) |
プロパティ
名称 | 概要 | |
---|---|---|
public | BufferUsage | |
public | GraphicsDevice | (GameResourceクラスから継承) |
public | IndexCount | |
public | IndexElementSize | |
public | IsDisposed | (GameResourceクラスから継承) |
public | Name | (GameResourceクラスから継承) |
public | Tag | (GameResourceクラスから継承) |
メソッド
名称 | 概要 | |
---|---|---|
public | Dispose() | (GameResourceクラスから継承) |
protected | Dispose(bool) | 派生クラスを作る場合は自前管理のリソースの破棄を実装する必要がある。 |
protected | Finalize | (GameResourceクラスから継承) |
public | GetData<T>(int, T[], int, int) | このインデックスバッファからインデックスを取得する。 |
public | GetData<T>(T[], int, int) | |
public | GetData<T>(T[]) | |
protected internal | GraphicsDeviceResetting | GraphicsDeviceがリセットされGPU上のリソースを再作成する必要があるときに呼ばれる。 |
public | SetData<T>(T[], int, int) | この頂点バッファに頂点データを設定する。大雑把に言えば頂点データの配列をメインメモリからVRAMにコピーする。 |
public | SetData<T>(T[]) | |
public | SetData<T>(int, T[], int, int) | |
protected | SetDataInternal<T> | |
public | ToString | (GameResourceクラスから継承) |
イベント
名称 | 概要 | |
---|---|---|
public | Disposing | (GameResourceクラスから継承) |
使用例
まずVertexBufferを作ってSetDataする。 次にIndexBufferを作ってSetDataする。 IndexBufferは配列型とIndexElementSize列挙体が食い違わないように注意すること。また配列のオーバーフローにも注意。
// 頂点データを作成する
var vertices = new VertexPositionColor[4];
vertices[0] = new VertexPositionColor(new Vector3(-10, -10, 0), Color.Red);
vertices[1] = new VertexPositionColor(new Vector3(-10, +10, 0), Color.Green);
vertices[2] = new VertexPositionColor(new Vector3(+10, +10, 0), Color.White);
vertices[3] = new VertexPositionColor(new Vector3(+10, -10, 0), Color.Blue);
// 頂点データをGPUに送り込む
_vertexBuffer = new VertexBuffer(_graphics.GraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.None);
_vertexBuffer.SetData(vertices);
// 16ビット配列のインデックスバッファを作成する
var indeces = new short[6];
indeces[0] = 0; indeces[1] = 1; indeces[2] = 2;
indeces[3] = 0; indeces[4] = 2; indeces[5] = 3;
// インデックスデータをGPUに送り込む
_indexBuffer = new IndexBuffer(_graphics.GraphicsDevice, IndexElementSize.SixteenBits, indeces.Length, BufferUsage.None);
_indexBuffer.SetData(indeces);
描画するときは、GraphicsDeviceクラスのSetVertexBufferメソッドでVertexBufferを読み出し、続いてGraphicsDevice.Indicesプロパティにインデックスバッファを設定し、DrawIndexedPrimitivesメソッドで描画する。
// 描画
_graphics.GraphicsDevice.SetVertexBuffer(_vertexBuffer);
_graphics.GraphicsDevice.Indices = _indexBuffer;
foreach (var pass in _effect.CurrentTechnique.Passes)
{
pass.Apply();
_graphics.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList, // 三角形の秘密はね…
baseVertex: 0, // vertex側のはじまり
startIndex: 0, // index側のはじまり
primitiveCount: _indexBuffer.IndexCount / 3 // 全部三角形なので単純に3で割る
);
}
関連項目
ファイルの履歴
過去の版のファイルを表示するには、その版の日時をクリックしてください。
日付と時刻 | サムネイル | 寸法 | 利用者 | コメント | |
---|---|---|---|---|---|
現在の版 | 2018年6月19日 (火) 06:24 | 510 × 187 (20キロバイト) | Maintenance script (トーク) |
- このファイルは上書きできません。
ファイルの使用状況
以下のページがこのファイルを使用しています: