Fix Ambient Occlusion Calculator to accept functors, functions and lambdas
By changing the 'pass by value' to be a 'pass by const reference' (and adding some const qualifiers) the calculator can take any of the three types. Performance could be improved further using C++11 perfect forwarding to pass the function on without changing a thing. I added a comment to remind us of this. Also added a test for passing a function and a (commented out) test for passing a lambda.
This commit is contained in:
@ -33,12 +33,17 @@ using namespace PolyVox;
|
||||
class IsVoxelTransparent
|
||||
{
|
||||
public:
|
||||
bool operator()(uint8_t voxel)
|
||||
bool operator()(uint8_t voxel) const
|
||||
{
|
||||
return voxel == 0;
|
||||
}
|
||||
};
|
||||
|
||||
bool isVoxelTransparentFunction(uint8_t voxel)
|
||||
{
|
||||
return voxel == 0;
|
||||
}
|
||||
|
||||
void TestAmbientOcclusionGenerator::testExecute()
|
||||
{
|
||||
const int32_t g_uVolumeSideLength = 64;
|
||||
@ -78,6 +83,12 @@ void TestAmbientOcclusionGenerator::testExecute()
|
||||
QCOMPARE(static_cast<int>(ambientOcclusionResult[16][16][16]), 103);
|
||||
QCOMPARE(static_cast<int>(ambientOcclusionResult[16][24][16]), 123);
|
||||
QCOMPARE(static_cast<int>(ambientOcclusionResult[16][31][16]), 173);
|
||||
|
||||
//Just run a quick test to make sure that it compiles when taking a function pointer
|
||||
calculateAmbientOcclusion(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 8, &isVoxelTransparentFunction);
|
||||
|
||||
//Also test it using a lambda
|
||||
//calculateAmbientOcclusion(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 8, [](uint8_t voxel){return voxel == 0;});
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestAmbientOcclusionGenerator)
|
||||
|
Reference in New Issue
Block a user