mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 20:50:59 -05:00
Add the ability to provide a random background image to TileIndexTileProviders
This commit is contained in:
@@ -336,6 +336,7 @@ std::vector<documentation::Documentation> GlobeBrowsingModule::documentations()
|
||||
globebrowsing::SingleImageProvider::Documentation(),
|
||||
globebrowsing::SizeReferenceTileProvider::Documentation(),
|
||||
globebrowsing::TemporalTileProvider::Documentation(),
|
||||
globebrowsing::TileIndexTileProvider::Documentation(),
|
||||
globebrowsing::TileProviderByIndex::Documentation(),
|
||||
globebrowsing::TileProviderByLevel::Documentation(),
|
||||
globebrowsing::GeoJsonManager::Documentation(),
|
||||
|
||||
@@ -109,7 +109,7 @@ void main() {
|
||||
levelWeights = getLevelWeights(distToVertexOnEllipsoid);
|
||||
|
||||
// Get the height value and apply skirts
|
||||
float height = getTileHeight(in_uv, levelWeights) - getTileVertexSkirtLength();
|
||||
float height = getTileHeight(in_uv, levelWeights) - getTileVertexSkirtLength();
|
||||
|
||||
#if USE_ACCURATE_NORMALS
|
||||
// Calculate tangents
|
||||
|
||||
@@ -60,7 +60,8 @@ void TextTileProvider::internalDeinitialize() {
|
||||
}
|
||||
|
||||
Tile TextTileProvider::renderTile(const TileIndex& tileIndex, const std::string& text,
|
||||
const glm::vec2& position, const glm::vec4& color)
|
||||
const glm::vec2& position, const glm::vec4& color,
|
||||
const glm::vec4& backgroundColor)
|
||||
{
|
||||
ZoneScoped;
|
||||
TracyGpuZone("tile");
|
||||
@@ -88,7 +89,12 @@ Tile TextTileProvider::renderTile(const TileIndex& tileIndex, const std::string&
|
||||
GLsizei h = static_cast<GLsizei>(texture->height());
|
||||
global::renderEngine->openglStateCache().loadCurrentGLState();
|
||||
glViewport(0, 0, w, h);
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClearColor(
|
||||
backgroundColor.r,
|
||||
backgroundColor.g,
|
||||
backgroundColor.b,
|
||||
backgroundColor.a
|
||||
);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
fontRenderer->render(*font, position, text, color);
|
||||
|
||||
@@ -38,7 +38,8 @@ public:
|
||||
|
||||
protected:
|
||||
Tile renderTile(const TileIndex& tileIndex, const std::string& text,
|
||||
const glm::vec2& position, const glm::vec4& color);
|
||||
const glm::vec2& position, const glm::vec4& color,
|
||||
const glm::vec4& backgroundColor = glm::vec4(0.0));
|
||||
|
||||
const TileTextureInitData initData;
|
||||
|
||||
|
||||
@@ -24,24 +24,82 @@
|
||||
|
||||
#include <modules/globebrowsing/src/tileprovider/tileindextileprovider.h>
|
||||
|
||||
namespace openspace::globebrowsing {
|
||||
#include <openspace/documentation/documentation.h>
|
||||
|
||||
TileIndexTileProvider::TileIndexTileProvider(const ghoul::Dictionary&)
|
||||
namespace {
|
||||
constexpr openspace::properties::Property::PropertyInfo UniqueBackgroundColors = {
|
||||
"UniqueBackgroundColor",
|
||||
"Unique Background Color",
|
||||
"If 'true' each index tile will have a unique background color assigned to it",
|
||||
openspace::properties::Property::Visibility::Developer
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(TileIndexTileProvider)]] Parameters {
|
||||
// [[codegen::verbatim(UniqueBackgroundColors.description)]]
|
||||
std::optional<bool> uniqueBackgroundColors;
|
||||
};
|
||||
#include "tileindextileprovider_codegen.cpp"
|
||||
} // namespace
|
||||
|
||||
namespace openspace::globebrowsing {
|
||||
|
||||
documentation::Documentation TileIndexTileProvider::Documentation() {
|
||||
return codegen::doc<Parameters>("globebrowsing_tileindextileprovider");
|
||||
}
|
||||
|
||||
TileIndexTileProvider::TileIndexTileProvider(const ghoul::Dictionary& dictionary)
|
||||
: TextTileProvider(tileTextureInitData(layers::Group::ID::ColorLayers, false))
|
||||
{}
|
||||
, _uniqueBackgroundColors(UniqueBackgroundColors, false)
|
||||
{
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
_uniqueBackgroundColors = p.uniqueBackgroundColors.value_or(_uniqueBackgroundColors);
|
||||
addProperty(_uniqueBackgroundColors);
|
||||
}
|
||||
|
||||
Tile TileIndexTileProvider::tile(const TileIndex& tileIndex) {
|
||||
ZoneScoped;
|
||||
std::string text = fmt::format(
|
||||
"level: {}\nx: {}\ny: {}", tileIndex.level, tileIndex.x, tileIndex.y
|
||||
);
|
||||
glm::vec2 textPosition = glm::vec2(
|
||||
glm::vec2 position = glm::vec2(
|
||||
initData.dimensions.x / 4 -
|
||||
(initData.dimensions.x / 32) * log10(1 << tileIndex.level),
|
||||
initData.dimensions.y / 2 + fontSize
|
||||
);
|
||||
|
||||
return TextTileProvider::renderTile(tileIndex, text, textPosition, glm::vec4(1.f));
|
||||
if (_uniqueBackgroundColors) {
|
||||
TileIndex::TileHashKey key = tileIndex.hashKey();
|
||||
size_t hash = std::hash<TileIndex::TileHashKey>{}(key);
|
||||
|
||||
// This is pretty ugly, but it's just for debugging and it is reproducable... We
|
||||
// take the first three bytes of the hash, treat them as an 8-bit unsigned integer
|
||||
// which makes them [0, 255] and also pseudorandom while being always the same for
|
||||
// each tile. If we divide the resulting number by 255 we get a value [0, 1] that
|
||||
// we can use for the color channel
|
||||
|
||||
uint8_t red = reinterpret_cast<uint8_t*>(&hash)[0];
|
||||
uint8_t green = reinterpret_cast<uint8_t*>(&hash)[1];
|
||||
uint8_t blue = reinterpret_cast<uint8_t*>(&hash)[2];
|
||||
|
||||
glm::vec4 backgroundColor = glm::vec4(
|
||||
static_cast<float>(red) / 255.f,
|
||||
static_cast<float>(green) / 255.f,
|
||||
static_cast<float>(blue) / 255.f,
|
||||
0.75f
|
||||
);
|
||||
|
||||
return TextTileProvider::renderTile(
|
||||
tileIndex,
|
||||
text,
|
||||
position,
|
||||
glm::vec4(1.f),
|
||||
backgroundColor
|
||||
);
|
||||
}
|
||||
else {
|
||||
return TextTileProvider::renderTile(tileIndex, text, position, glm::vec4(1.f));
|
||||
}
|
||||
}
|
||||
|
||||
Tile::Status TileIndexTileProvider::tileStatus(const TileIndex&) {
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <modules/globebrowsing/src/tileprovider/texttileprovider.h>
|
||||
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
|
||||
namespace openspace::globebrowsing {
|
||||
|
||||
class TileIndexTileProvider : public TextTileProvider {
|
||||
@@ -40,6 +42,11 @@ public:
|
||||
int minLevel() override final;
|
||||
int maxLevel() override final;
|
||||
float noDataValueAsFloat() override final;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
properties::BoolProperty _uniqueBackgroundColors;
|
||||
};
|
||||
|
||||
} // namespace openspace::globebrowsing
|
||||
|
||||
Reference in New Issue
Block a user