Microsoft DirectX 8.0 (C++) |
動的な頂点およびインデックス バッファには、サイズと使用方法に基づいてパフォーマンスに違いがある。次の使用方法を参考に、Lock メソッドの Flags パラメータに D3DLOCK_DISCARD を使用するか、または D3DLOCK_NOOVERWRITE を使用するかを判断する。
使用方法 1 :
for loop() { pBuffer->Lock(...D3DLOCK_DISCARD...); // 新しいポインタを返して、 // ハードウェアが機能停止しないことを // 保証する。 Fill data (optimally 1000s of vertices/indices, no fewer) in pBuffer. pBuffer->Unlock() Change state(s). DrawPrimitive() or DrawIndexedPrimitive() }
使用方法 2 :
for loop() { pVB->Lock(...D3DLOCK_DISCARD...);//新しいポインタが返ることによって //ハードウェアがストールしない //ようにする。 Fill data (optimally 1000s of vertices/indices, no fewer) in pBuffer. pBuffer->Unlock for loop( 100s of times ) { Change State DrawPrimitive() or DrawIndexPrimitives() //Tens of primitives } }
使用方法 3 :
for loop() { If there is space in the Buffer { // 頂点やインデックスを追加する。 pBuffer->Lock(D3DLOCK_NOOVERWRITE); } Else { // 先頭に戻る。 pBuffer->Lock(D3DLOCK_DISCARD); } Fill few 10s of vertices/indices in pBuffer pBuffer->Unlock Change State DrawPrimitive() or DrawIndexedPrimitive() // 数個のプリミティブ。
}
使用方法 1 は、使用方法 2 または 3 より処理は速いが、一般的には実用に向かない。アプリケーションで各 Lock に対して平均 2、3000 個の頂点やインデックスを追加する場合、使用方法 2 の方が使用方法 3 より処理が速い。平均より少ない場合には、使用方法 3 の方が速い。どの Lock メソッドが高速であるかに関しては確かな答えはなく、いろいろな方法を試すことで最善の方法を見つける。