| 1359 | } |
| 1360 | |
| 1361 | void ProcessedShaderMaterial::setBuffers( GFXVertexBufferHandleBase *vertBuffer, GFXPrimitiveBufferHandle *primBuffer ) |
| 1362 | { |
| 1363 | PROFILE_SCOPE(ProcessedShaderMaterial_setBuffers); |
| 1364 | |
| 1365 | // If we're not instanced then just call the parent. |
| 1366 | if ( !mInstancingState ) |
| 1367 | { |
| 1368 | Parent::setBuffers( vertBuffer, primBuffer ); |
| 1369 | return; |
| 1370 | } |
| 1371 | |
| 1372 | PROFILE_SCOPE(ProcessedShaderMaterial_setBuffers_instancing); |
| 1373 | |
| 1374 | const S32 instCount = mInstancingState->getCount(); |
| 1375 | AssertFatal( instCount > 0, |
| 1376 | "ProcessedShaderMaterial::setBuffers - No instances rendered!" ); |
| 1377 | |
| 1378 | // Nothing special here. |
| 1379 | GFX->setPrimitiveBuffer( *primBuffer ); |
| 1380 | |
| 1381 | // Set the first stream the the normal VB and set the |
| 1382 | // correct frequency for the number of instances to render. |
| 1383 | GFX->setVertexBuffer( *vertBuffer, 0, instCount ); |
| 1384 | |
| 1385 | // Get a volatile VB and fill it with the vertex data. |
| 1386 | const GFXVertexFormat *instFormat = mInstancingState->getFormat(); |
| 1387 | GFXVertexBufferDataHandle instVB; |
| 1388 | instVB.set( GFX, instFormat->getSizeInBytes(), instFormat, instCount, GFXBufferTypeVolatile ); |
| 1389 | U8 *dest = instVB.lock(); |
| 1390 | if(!dest) return; |
| 1391 | dMemcpy( dest, mInstancingState->getBuffer(), instFormat->getSizeInBytes() * instCount ); |
| 1392 | instVB.unlock(); |
| 1393 | |
| 1394 | // Set the instance vb for streaming. |
| 1395 | GFX->setVertexBuffer( instVB, 1, 1 ); |
| 1396 | |
| 1397 | // Finally set the vertex format which defines |
| 1398 | // both of the streams. |
| 1399 | GFX->setVertexFormat( mInstancingState->getDeclFormat() ); |
| 1400 | |
| 1401 | // Done... reset the count. |
| 1402 | mInstancingState->resetStep(); |
| 1403 | } |
| 1404 | |
| 1405 | bool ProcessedShaderMaterial::stepInstance() |
| 1406 | { |
no test coverage detected