void CpuClipmapRenderer::createBlockIndices( GeometryClipmapLevel& level, const Rectangle2i& blockRect, int levelSampleCount, IndexList& indices ) { // todo: this needs rework.. if( blockRect.isEmpty() ) { return; } assert( blockRect._x0 >= 0 ); assert( blockRect._y0 >= 0 ); assert( blockRect._x1 > blockRect._x0 ); assert( blockRect._y1 > blockRect._y0 ); assert( blockRect._x0 < levelSampleCount ); assert( blockRect._y0 < levelSampleCount ); assert( blockRect._x1 < levelSampleCount ); assert( blockRect._y1 < levelSampleCount ); for( int y = blockRect._y0; y < blockRect._y1; ++y ) { assert( y + 1 < levelSampleCount ); const int row0 = ( level.blockOrigin[ 1 ] + y ) % levelSampleCount; const int row1 = ( level.blockOrigin[ 1 ] + y + 1 ) % levelSampleCount; for( int x = blockRect._x0; x < blockRect._x1; ++x ) { assert( x + 1 < levelSampleCount ); const int col0 = ( level.blockOrigin[ 0 ] + x ) % levelSampleCount; const int col1 = ( level.blockOrigin[ 0 ] + x + 1 ) % levelSampleCount; const int idx0 = row0 * levelSampleCount + col0; const int idx1 = row0 * levelSampleCount + col1; const int idx2 = row1 * levelSampleCount + col0; const int idx3 = row1 * levelSampleCount + col1; assert( idx0 < 65536 ); assert( idx1 < 65536 ); assert( idx2 < 65536 ); assert( idx3 < 65536 ); indices.push_back( idx0 ); indices.push_back( idx2 ); indices.push_back( idx1 ); indices.push_back( idx1 ); indices.push_back( idx2 ); indices.push_back( idx3 ); } } }
int GeometryClipmaps::updateBigLevelBlock( GeometryClipmapLevel& level, const GeometryClipmapLevel* parentLevel, const Rectangle2i& targetRect ) { if( targetRect.isEmpty() ) { return 0; } const int levelSampleCount = level.heightmap.size; // split the rect into up to 4 subrects and update them individually: Rectangle2i subRects[ 4 ]; int subRectCount = 0; #if 0 int midY = 0; int maxY = 0; int midX = 0; int maxX = 0; #endif subRects[ 0 ] = targetRect; subRectCount++; if( targetRect._x1 < targetRect._x0 ) { // split in X: subRects[ 0 ]._x1 = levelSampleCount; subRects[ 1 ] = targetRect; subRects[ 1 ]._x0 = 0; subRectCount++; } else if( targetRect._x1 > levelSampleCount ) { // split in X: subRects[ 0 ]._x1 = levelSampleCount; subRects[ 1 ] = targetRect; subRects[ 1 ]._x0 = 0; subRects[ 1 ]._x1 -= levelSampleCount; subRectCount++; } // ok.. we have 1 or 2 subRects already: split them on the Y axis: if( targetRect._y1 < targetRect._y0 ) { // patch the existing ones: for( int i = 0; i < subRectCount; ++i ) { subRects[ subRectCount + i ] = subRects[ i ]; subRects[ subRectCount + i ]._y0 = 0; subRects[ i ]._y1 = levelSampleCount; } subRectCount += subRectCount; } else if( targetRect._y1 > levelSampleCount ) { // patch the existing ones: for( int i = 0; i < subRectCount; ++i ) { subRects[ subRectCount + i ] = subRects[ i ]; subRects[ subRectCount + i ]._y0 = 0; subRects[ subRectCount + i ]._y1 -= levelSampleCount; subRects[ i ]._y1 = levelSampleCount; } subRectCount += subRectCount; } int sampleUpdateCount = 0; for( int i = 0; i < subRectCount; ++i ) { sampleUpdateCount += updateLevelBlock( level, parentLevel, subRects[ i ] ); } return sampleUpdateCount; }