Solve texture wrapping problem for clipmap rendering.

This commit is contained in:
Kalle Bladin
2016-05-04 19:46:05 -04:00
parent 04a363bab1
commit cc4c035f6b
7 changed files with 48 additions and 10 deletions
@@ -80,7 +80,7 @@ namespace openspace {
std::shared_ptr<UninitializedTextureTile> getUninitializedTextureTile(
GDALDataset * dataSet,
const GeodeticTileIndex & tileIndex,
GeodeticTileIndex tileIndex,
int minNumPixelsRequired);
UninitializedTextureTile::TextureFormat getTextureFormatFromRasterCount(
@@ -44,7 +44,7 @@ namespace openspace {
template<class T>
std::shared_ptr<UninitializedTextureTile> GdalDataConverter<T>::getUninitializedTextureTile(
GDALDataset* dataSet,
const GeodeticTileIndex& tileIndex,
GeodeticTileIndex tileIndex,
int minNumPixelsRequired) {
int nRasters = dataSet->GetRasterCount();
@@ -65,7 +65,6 @@ namespace openspace {
glm::uvec2 pixelEnd0 = geodeticToPixel(dataSet, patch.southEastCorner());
glm::uvec2 numberOfPixels0 = pixelEnd0 - pixelStart0;
int minNumPixels0 = glm::min(numberOfPixels0.x, numberOfPixels0.y);
int ov = log2(minNumPixels0) - log2(minNumPixelsRequired + 1);
@@ -49,7 +49,7 @@ namespace openspace {
}
GeodeticTileIndex PatchCoverageProvider::getTileIndex(const GeodeticPatch& patch) {
// Calculate the level of the index depanding on the size of the incoming patch.
// Calculate the level of the index depending on the size of the incoming patch.
// The level is as big as possible (as far down as possible) but it can't be
// too big since at maximum four tiles should be used to cover a patch
int level = log2(static_cast<int>(glm::max(
@@ -60,13 +60,14 @@ namespace openspace {
level = glm::min(level, _depth);
// Calculate the index in x y where the tile should be positioned
Geodetic2 tileSize = _sizeLevel0 / pow(2, level);
int nIndices = pow(2, level);
Geodetic2 tileSize = _sizeLevel0 / nIndices;
Geodetic2 nw = patch.northWestCorner();
glm::ivec2 tileIndexXY =
(nw.toLonLatVec2() - _offsetLevel0.toLonLatVec2()) / tileSize.toLonLatVec2();
glm::floor((nw.toLonLatVec2() - _offsetLevel0.toLonLatVec2()) / tileSize.toLonLatVec2());
// Flip y since indices increase from top to bottom
tileIndexXY.y = pow(2, level) - 1 - tileIndexXY.y;
tileIndexXY.y = nIndices - 1 - tileIndexXY.y;
// Create the tileindex
GeodeticTileIndex tileIndex = { tileIndexXY.x, tileIndexXY.y, level };
@@ -125,6 +126,9 @@ namespace openspace {
tileIndex.x += x;
tileIndex.y += y;
int xMax = static_cast<int>(glm::pow(2, tileIndex.level));
int yMax = static_cast<int>(glm::pow(2, tileIndex.level));
int numLevelsToLoop = tileIndex.level;
// Start at the highest level and go down if the texture don't exist
for (int j = numLevelsToLoop; j >= 0; j--)
@@ -151,7 +155,7 @@ namespace openspace {
patchCoverageToReturn.textureTransformPairs[linearIdx].first =
tileProvider->getTemporaryTexture();
patchCoverageToReturn.textureTransformPairs[linearIdx].second =
glm::mat3(1);
getUvTransformationPatchToTile(patch, tileIndex);
}
}
}
+7 -1
View File
@@ -65,6 +65,7 @@ namespace openspace {
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
//_testTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_tempTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_tempTexture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
}
@@ -102,7 +103,12 @@ namespace openspace {
}
}
std::shared_ptr<Texture> TileProvider::getTile(const GeodeticTileIndex& tileIndex) {
std::shared_ptr<Texture> TileProvider::getTile(GeodeticTileIndex tileIndex) {
// If the tile index is negative or too big it needs to wrap around
int nIndices = pow(2, tileIndex.level);
tileIndex.x += (tileIndex.x < 0) ? nIndices : ((tileIndex.x > nIndices - 1) ? -nIndices : 0);
tileIndex.y += (tileIndex.y < 0) ? nIndices : ((tileIndex.y > nIndices - 1) ? -nIndices : 0);
HashKey hashkey = tileIndex.hashKey();
if (_tileCache.exist(hashkey)) {
+1 -1
View File
@@ -59,7 +59,7 @@ namespace openspace {
int minimumPixelsize);
~TileProvider();
std::shared_ptr<Texture> getTile(const GeodeticTileIndex& tileIndex);
std::shared_ptr<Texture> getTile(GeodeticTileIndex tileIndex);
std::shared_ptr<Texture> getTemporaryTexture();
void prerender();