SizeReferenceTileProvider renders referred distance next to its text

This commit is contained in:
Erik Broberg
2016-08-31 14:38:05 -04:00
parent b064c5606f
commit c201957001
4 changed files with 48 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -90,6 +90,7 @@ return {
Type = "SizeReference",
Name = "Size Reference",
Radii = marsEllipsoid,
BackgroundImagePath = "../debugglobe/textures/arrows.png",
},
},
HeightMaps = {

View File

@@ -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<Texture>(
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

View File

@@ -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