尝试下图片
尝试下代码,好像要装插件才行,用了这个CodeFormatterPlugin2.0.0.1
//-------------------------------------------------------------------------------------- // This callback function is called by OnFrameRender // It performs HW Instancing //-------------------------------------------------------------------------------------- void OnRenderHWInstancing( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime ) { HRESULT hr; UINT iPass, cPasses; V( pd3dDevice->SetVertexDeclaration( g_pVertexDeclHardware ) ); // Stream zero is our model, and its frequency is how we communicate the number of instances required, // which in this case is the total number of boxes V( pd3dDevice->SetStreamSource( 0, g_pVBBox, 0, sizeof( BOX_VERTEX ) ) ); V( pd3dDevice->SetStreamSourceFreq( 0, D3DSTREAMSOURCE_INDEXEDDATA | g_NumBoxes ) ); // Stream one is the Instancing buffer, so this advances to the next value // after each box instance has been drawn, so the divider is 1. V( pd3dDevice->SetStreamSource( 1, g_pVBInstanceData, 0, sizeof( BOX_INSTANCEDATA_POS ) ) ); V( pd3dDevice->SetStreamSourceFreq( 1, D3DSTREAMSOURCE_INSTANCEDATA | 1ul ) ); V( pd3dDevice->SetIndices( g_pIBBox ) ); // Render the scene with this technique // as defined in the .fx file V( g_pEffect->SetTechnique( g_HandleTechnique ) ); V( g_pEffect->Begin( &cPasses, 0 ) ); for( iPass = 0; iPass < cPasses; iPass++ ) { V( g_pEffect->BeginPass( iPass ) ); // Render the boxes with the applied technique V( g_pEffect->SetTexture( g_HandleTexture, g_pBoxTexture ) ); // The effect interface queues up the changes and performs them // with the CommitChanges call. You do not need to call CommitChanges if // you are not setting any parameters between the BeginPass and EndPass. V( g_pEffect->CommitChanges() ); V( pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 4 * 6, 0, 6 * 2 ) ); V( g_pEffect->EndPass() ); } V( g_pEffect->End() ); V( pd3dDevice->SetStreamSourceFreq( 0, 1 ) ); V( pd3dDevice->SetStreamSourceFreq( 1, 1 ) ); }