void WaitingForYou::fillIB() { int w = _mapWidth - 1; if (_lod >= 1) { w -= (int)(_mapWidth * getSeriesSum(0.5, _lod)); } _triangleNumber2GPU = w * w * 2; int offset = Euler::Basic::power(2, _lod); if (++_lod >= 8) { _lod = 0; } void* data = _ib->lock(0, 0, Euclid::eLock_Null); u16* dataIndex = (u16*)data; for (int i = 0; i < _mapWidth - 1;i += offset) { for (int j = 0; j < _mapWidth - 1; j += offset) { u16 baseIndex = j + i * _mapWidth; u16 indices[] = { baseIndex, baseIndex + _mapWidth * offset, baseIndex + offset, baseIndex + _mapWidth * offset, baseIndex + offset + _mapWidth * offset, baseIndex + offset }; memcpy(dataIndex, indices, sizeof(u16) * 6); dataIndex += 6; } } _ib->unLock(); }
void WaitingForYou::toggleLOD() { // if (_ib) { _ib->destroy(); //delete _ib; //_ib = NULL; } { static int lod = 0; int w = _mapWidth - 1; if (lod >= 1) { w -= (int)(_mapWidth * getSeriesSum(0.5, lod)); } int offset = Euler::Basic::power(2, lod); _triangleNumber2GPU = w * w * 2; if (_ib) { _ib->create(_triangleNumber2GPU * 3 * sizeof(u16), Euclid::eUsage_WriteOnly, Euclid::eFormat_Index16,Euclid::ePool_Default); } else { _ib = _modules->getRenderEngine()->getBufferManager()->createIndexBuffer(_triangleNumber2GPU * 3 * sizeof(u16), Euclid::eUsage_WriteOnly, Euclid::eFormat_Index16,Euclid::ePool_Default); } void* data = _ib->lock(0, 0, Euclid::eLock_Null); u16* dataIndex = (u16*)data; for (int i = 0; i < _mapWidth - 1;i += offset) { for (int j = 0; j < _mapWidth - 1; j += offset) { u16 baseIndex = j + i * _mapWidth; u16 indices[] = { baseIndex, baseIndex + _mapWidth * offset, baseIndex + offset, baseIndex + _mapWidth * offset, baseIndex + offset + _mapWidth * offset, baseIndex + offset }; memcpy(dataIndex, indices, sizeof(u16) * 6); dataIndex += 6; } } _ib->unLock(); ++lod; if (lod >= 8) { lod = 0; } } }
// a + a*a + a*a*a + ... float getSeriesSum(float a, int b) { if(b <= 1) return a; return Euler::Basic::power(a, b) + getSeriesSum(a, b - 1); }