void TerrainPageSurfaceLayer::populate(const TerrainPageGeometry& geometry) { const SegmentVector validSegments = geometry.getValidSegments(); for (SegmentVector::const_iterator I = validSegments.begin(); I != validSegments.end(); ++I) { #if 0 //the current Mercator code works such that whenever an Area is added to Terrain, _all_ surfaces for the affected segments are invalidated, thus requiering a total repopulation of the segment //If however that code was changed to only invalidate the affected surface the code below would be very much handy Mercator::Surface* surface(getSurfaceForSegment(I->segment)); if (surface) { surface->populate(); } #else Mercator::Segment* segment(I->segment); if (!segment->isValid()) { segment->populate(); } Mercator::Segment::Surfacestore::iterator I2(segment->getSurfaces().find(mSurfaceIndex)); if (I2 == segment->getSurfaces().end()) { //the segment doesn't contain this surface yet, lets add it if (mShader.checkIntersect(*segment)) { S_LOG_VERBOSE("Adding new surface with id " << mSurfaceIndex << " to segment at x: " << segment->getXRef() << " y: " << segment->getYRef()); Mercator::Segment::Surfacestore & sss = segment->getSurfaces(); sss[mSurfaceIndex] = mShader.newSurface(*segment); } } //NOTE: we have to repopulate all surfaces mainly to get the foliage to work. segment->populateSurfaces(); #endif } }
void TerrainPageSurfaceLayer::fillImage(const TerrainPageGeometry& geometry, Image& image, unsigned int channel) const { SegmentVector validSegments = geometry.getValidSegments(); for (SegmentVector::const_iterator I = validSegments.begin(); I != validSegments.end(); ++I) { Mercator::Segment* segment = I->segment; if (mShader.checkIntersect(*segment)) { Mercator::Surface* surface = getSurfaceForSegment(segment); if (surface && surface->isValid()) { Image::ImageBuffer* textureBitmap = new Image::ImageBuffer(segment->getResolution(), 1); auto srcPtr = surface->getData(); auto dataPtr = textureBitmap->getData(); auto segmentSize = segment->getSize(); for (int i = 0; i < segment->getResolution(); ++i) { for (int j = 0; j < segment->getResolution(); ++j) { //interpolate four samples to get the fragment coverage *dataPtr = (unsigned char)((srcPtr[(i * segmentSize) + j] + srcPtr[(i * segmentSize) + j + 1] + srcPtr[((i + 1) * segmentSize) + j] + srcPtr[((i + 1) * segmentSize) + j + 1]) / 4); dataPtr++; } } WFImage sourceImage(textureBitmap); image.blit(sourceImage, channel, ((int)I->index.x() * segment->getResolution()), ((mTerrainPageSurface.getNumberOfSegmentsPerAxis() - (int)I->index.y() - 1) * segment->getResolution())); } } } }
bool TerrainPageSurfaceLayer::intersects(const TerrainPageGeometry& geometry) const { const SegmentVector validSegments = geometry.getValidSegments(); //check if at least one surface intersects for (SegmentVector::const_iterator I = validSegments.begin(); I != validSegments.end(); ++I) { if (mShader.checkIntersect(*I->segment)) { return true; } } return false; }
void TerrainPageSurfaceLayer::fillImage(const TerrainPageGeometry& geometry, Image& image, unsigned int channel) const { SegmentVector validSegments = geometry.getValidSegments(); for (SegmentVector::const_iterator I = validSegments.begin(); I != validSegments.end(); ++I) { if (mShader.checkIntersect(*I->segment)) { Mercator::Surface* surface = getSurfaceForSegment(I->segment); if (surface && surface->isValid()) { WFImage sourceImage(new Image::ImageBuffer(65, 1, surface->getData())); //We need to adjust the position of the x index by one because there's a one pixel offset when converting between the Mercator Segments and the Ogre page. image.blit(sourceImage, channel, ((int)I->index.x() * 64) + 1, ((mTerrainPageSurface.getNumberOfSegmentsPerAxis() - (int)I->index.y() - 1) * 64)); } } } }