Skip to content

Commit

Permalink
implement texture update for stretch icons
Browse files Browse the repository at this point in the history
  • Loading branch information
stmitt committed Jan 9, 2025
1 parent 25a1470 commit a9936aa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ void Tiled2dMapVectorSymbolGroup::update(const double zoomIdentifier, const doub
scaleFactor, rotation, now, viewPortSize, spriteTexture, spriteData);
}
object->updateStretchIconProperties(stretchedIconPositions, stretchedIconScales, stretchedIconRotations,
stretchedIconAlphas, stretchedIconStretchInfos, stretchedIconOffset, zoomIdentifier,
stretchedIconAlphas, stretchedIconStretchInfos, stretchedIconTextureCoordinates, stretchedIconOffset, zoomIdentifier,
scaleFactor, rotation, now, viewPortSize);
auto font = object->getFont();
if (font) {
Expand Down Expand Up @@ -746,6 +746,11 @@ void Tiled2dMapVectorSymbolGroup::update(const double zoomIdentifier, const doub
stretchedIconStretchInfos.resetModificationFlag();
}

if (stretchedIconTextureCoordinates.wasModified()) {
stretchedInstancedObject->setStretchInfos(SharedBytes((int64_t) stretchedIconTextureCoordinates.data(), iconCount,
4 * (int32_t) sizeof(float)));
stretchedIconTextureCoordinates.resetModificationFlag();
}
}

for (size_t i = 0; i < textDescriptors.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ void Tiled2dMapVectorSymbolObject::setupStretchIconProperties(VectorModification

const auto spriteIt = spriteData->sprites.find(iconImage);
if (spriteIt == spriteData->sprites.end()) {
LogError << "Unable to find sprite " << iconImage;
LogError << "Unable to find sprite " <<= iconImage;
writePosition(0, 0, countOffset, positions);
countOffset += instanceCounts.stretchedIcons;
return;
Expand All @@ -647,6 +647,7 @@ void Tiled2dMapVectorSymbolObject::setupStretchIconProperties(VectorModification
textureCoordinates[4 * countOffset + 2] = ((double) spriteIt->second.width) / textureWidth;
textureCoordinates[4 * countOffset + 3] = ((double) spriteIt->second.height) / textureHeight;

lastIconImage = iconImage;
}

writePosition(renderCoordinate.x, renderCoordinate.y, countOffset, positions);
Expand All @@ -656,7 +657,7 @@ void Tiled2dMapVectorSymbolObject::setupStretchIconProperties(VectorModification
lastStretchIconUpdateScaleFactor = -1;
}

void Tiled2dMapVectorSymbolObject::updateStretchIconProperties(VectorModificationWrapper<float> &positions, VectorModificationWrapper<float> &scales, VectorModificationWrapper<float> &rotations, VectorModificationWrapper<float> &alphas, VectorModificationWrapper<float> &stretchInfos, int &countOffset, const double zoomIdentifier, const double scaleFactor, const double rotation, long long now, const Vec2I viewPortSize) {
void Tiled2dMapVectorSymbolObject::updateStretchIconProperties(VectorModificationWrapper<float> &positions, VectorModificationWrapper<float> &scales, VectorModificationWrapper<float> &rotations, VectorModificationWrapper<float> &alphas, VectorModificationWrapper<float> &stretchInfos, VectorModificationWrapper<float> &textureCoordinates, int &countOffset, const double zoomIdentifier, const double scaleFactor, const double rotation, long long now, const Vec2I viewPortSize) {

if (instanceCounts.stretchedIcons == 0) {
return;
Expand Down Expand Up @@ -686,6 +687,35 @@ void Tiled2dMapVectorSymbolObject::updateStretchIconProperties(VectorModificatio

evaluateStyleProperties(zoomIdentifier);

if (iconImage != lastIconImage && !(iconImage.empty() || !spriteTexture)) {
const auto textureWidth = (double) spriteTexture->getImageWidth();
const auto textureHeight = (double) spriteTexture->getImageHeight();

renderCoordinate = getRenderCoordinates(iconAnchor, 0.0, textureWidth, textureHeight);

const auto spriteIt = spriteData->sprites.find(iconImage);
if (spriteIt == spriteData->sprites.end()) {
LogError << "Unable to find sprite " <<= iconImage;
writePosition(0, 0, countOffset, positions);
countOffset += instanceCounts.stretchedIcons;
return;
}

const double densityOffset = (camera->getScreenDensityPpi() / 160.0) / spriteIt->second.pixelRatio;

stretchSpriteSize.x = spriteIt->second.width * densityOffset;
stretchSpriteSize.y = spriteIt->second.height * densityOffset;

stretchSpriteInfo = spriteIt->second;

textureCoordinates[4 * countOffset + 0] = ((double) spriteIt->second.x) / textureWidth;
textureCoordinates[4 * countOffset + 1] = ((double) spriteIt->second.y) / textureHeight;
textureCoordinates[4 * countOffset + 2] = ((double) spriteIt->second.width) / textureWidth;
textureCoordinates[4 * countOffset + 3] = ((double) spriteIt->second.height) / textureHeight;

lastIconImage = iconImage;
}

if (!isCoordinateOwner) {
alphas[countOffset] = 0.0;
} else if (animationCoordinator->isColliding() || !(description->minZoom <= zoomIdentifier && description->maxZoom >= zoomIdentifier) || !stretchSpriteInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Tiled2dMapVectorSymbolObject {
void updateTextProperties(VectorModificationWrapper<float> &positions, VectorModificationWrapper<float> &referencePositions, VectorModificationWrapper<float> &scales, VectorModificationWrapper<float> &rotations, VectorModificationWrapper<float> &styles, int &countOffset, uint16_t &styleOffset, const double zoomIdentifier, const double scaleFactor, const double rotation, long long now, const Vec2I viewPortSize, const std::vector<float>& vpMatrix, const Vec3D& origin);

void setupStretchIconProperties(VectorModificationWrapper<float> &positions, VectorModificationWrapper<float> &textureCoordinates, int &countOffset, const double zoomIdentifier, const std::shared_ptr<TextureHolderInterface> spriteTexture, const std::shared_ptr<SpriteData> spriteData);
void updateStretchIconProperties(VectorModificationWrapper<float> &positions, VectorModificationWrapper<float> &scales, VectorModificationWrapper<float> &rotations, VectorModificationWrapper<float> &alphas, VectorModificationWrapper<float> &stretchInfos, int &countOffset, const double zoomIdentifier, const double scaleFactor, const double rotation, long long now, const Vec2I viewPortSize);
void updateStretchIconProperties(VectorModificationWrapper<float> &positions, VectorModificationWrapper<float> &scales, VectorModificationWrapper<float> &rotations, VectorModificationWrapper<float> &alphas, VectorModificationWrapper<float> &stretchInfos, VectorModificationWrapper<float> &textureCoordinates, int &countOffset, const double zoomIdentifier, const double scaleFactor, const double rotation, long long now, const Vec2I viewPortSize);

std::shared_ptr<FontLoaderResult> getFont() {
if (labelObject) {
Expand Down

0 comments on commit a9936aa

Please sign in to comment.