Skip to content

Commit

Permalink
use "power of two" tile size
Browse files Browse the repository at this point in the history
older/mobile OpenGL (without GL_ARB_texture_non_power_of_two) requires textures with size of power of two
we should provide tiles with required size to avoid scaling in QOpenGLTextureCache::bindTexture
  • Loading branch information
Karry committed Nov 11, 2024
1 parent 1c10957 commit d721e81
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions libosmscout-client-qt/src/osmscoutclientqt/TiledMapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,17 @@ void TiledMapRenderer::onLoadJobFinished(QMap<QString,QMap<osmscout::TileKey,osm
(double)loadXFrom + (double)width/2.0,
(double)loadYFrom + (double)height/2.0);

/** tiles are up-scaled almost two times, when zoom level is near its next integer value (for example 16.99)
* to avoid blured result, we render tiles two times bigger than its minimum visual size.
* Another possible upscale (screenPixelRatio) is for HiDPI screens - when there is ratio 2.0, 100px on Qt canvas
* is displayed as 200px on the screen. To provide best results on HiDPI screen, we upscale tiles by this pixel ratio.
*/
double finalDpi = mapDpi * 2 * this->screenPixelRatio;
// For HiDPI screens (screenPixelRatio > 1) tiles as up-scaled before displaying. When there is ratio 2.0, 100px on Qt canvas
// is displayed as 200px on the screen. To provide best results on HiDPI screen, we upscale tiles by this pixel ratio.
double finalDpi = mapDpi * this->screenPixelRatio;

uint32_t tileDimension = double(OSMTile::osmTileOriginalWidth()) * (finalDpi / OSMTile::tileDPI()); // pixels

// older/mobile OpenGL (without GL_ARB_texture_non_power_of_two) requires textures with size of power of two
// we should provide tiles with required size to avoid scaling in QOpenGLTextureCache::bindTexture
tileDimension = qNextPowerOfTwo(tileDimension - 1);
finalDpi = (double(tileDimension) / double(OSMTile::osmTileOriginalWidth())) * OSMTile::tileDPI();

QImage canvas(width * tileDimension,
height * tileDimension,
QImage::Format_RGBA8888_Premultiplied);
Expand Down

0 comments on commit d721e81

Please sign in to comment.