diff --git a/data/scene/debugglobe/textures/arrows.png b/data/scene/debugglobe/textures/arrows.png new file mode 100644 index 0000000000..d10df6684c Binary files /dev/null and b/data/scene/debugglobe/textures/arrows.png differ diff --git a/data/scene/lodmars/lodmars.mod b/data/scene/lodmars/lodmars.mod index 15127ad591..c540ee38c3 100644 --- a/data/scene/lodmars/lodmars.mod +++ b/data/scene/lodmars/lodmars.mod @@ -90,6 +90,7 @@ return { Type = "SizeReference", Name = "Size Reference", Radii = marsEllipsoid, + BackgroundImagePath = "../debugglobe/textures/arrows.png", }, }, HeightMaps = { diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp index dc516383eb..66e8a0d9cf 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp @@ -100,8 +100,7 @@ namespace openspace { } Tile TextTileProvider::createChunkIndexTile(const ChunkIndex& chunkIndex) { - glm::uvec4 color = { 0, 0, 0, 0 }; - Tile tile = Tile::createPlainTile(_textureSize, color); + Tile tile = backgroundTile(chunkIndex); // Keep track of defaultFBO and viewport to be able to reset state when done GLint defaultFBO; @@ -142,6 +141,11 @@ namespace openspace { return 1337; // unlimited } + Tile TextTileProvider::backgroundTile(const ChunkIndex& chunkIndex) const { + glm::uvec4 color = { 0, 0, 0, 0 }; + return Tile::createPlainTile(_textureSize, color); + } + ////////////////////////////////////////////////////////////////////////////////////// // Chunk Index Tile Provider // @@ -165,16 +169,30 @@ namespace openspace { namespace { const std::string KeyRadii = "Radii"; + const std::string KeyBackgroundImagePath = "BackgroundImagePath"; } SizeReferenceTileProvider::SizeReferenceTileProvider(const ghoul::Dictionary& dictionary) { _fontSize = 64; _font = OsEng.fontManager().font("Mono", _fontSize); + glm::dvec3 radii(1,1,1); if (!dictionary.getValue(KeyRadii, radii)) { throw std::runtime_error("Must define key '" + KeyRadii + "'"); } _ellipsoid = Ellipsoid(radii); + + _backgroundTile.status = Tile::Status::Unavailable; + std::string backgroundImagePath; + if (dictionary.getValue(KeyBackgroundImagePath, backgroundImagePath)) { + using namespace ghoul::io; + std::string imgAbsPath = absPath(backgroundImagePath); + _backgroundTile.texture = TextureReader::ref().loadTexture(imgAbsPath); + _backgroundTile.texture->uploadTexture(); + _backgroundTile.texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + _backgroundTile.status = Tile::Status::OK; + } + } void SizeReferenceTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const { @@ -206,5 +224,26 @@ namespace openspace { ); } + Tile SizeReferenceTileProvider::backgroundTile(const ChunkIndex& chunkIndex) const { + if (_backgroundTile.status == Tile::Status::OK) { + Tile tile; + auto t = _backgroundTile.texture; + void* pixelData = new char[t->expectedPixelDataSize()]; + memcpy(pixelData, t->pixelData(), t->expectedPixelDataSize()); + tile.texture = std::make_shared( + pixelData, t->dimensions(), t->format(), t->internalFormat(), t->dataType(), t->filter(), t->wrapping()); + tile.texture->uploadTexture(); + tile.texture->setDataOwnership(Texture::TakeOwnership::Yes); + tile.status = Tile::Status::OK; + return tile; + } + else { + // use default background + return TextTileProvider::backgroundTile(chunkIndex); + } + } + + + } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.h b/modules/globebrowsing/tile/tileprovider/texttileprovider.h index bb40eeaf06..79e9f6523a 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.h @@ -73,6 +73,9 @@ namespace openspace { virtual void reset(); virtual int maxLevel(); + // Returns the tile which will be used to draw text onto. + // Default implementation returns a tile with a plain transparent texture. + virtual Tile backgroundTile(const ChunkIndex& chunkIndex) const; // This method is pure and should be implemented by subclasses virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const = 0; @@ -102,10 +105,13 @@ namespace openspace { class SizeReferenceTileProvider : public TextTileProvider { public: SizeReferenceTileProvider(const ghoul::Dictionary& dictionary); + virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const; + virtual Tile backgroundTile(const ChunkIndex& chunkIndex) const; private: Ellipsoid _ellipsoid; + Tile _backgroundTile; }; } // namespace openspace