Make tiles get correct part of texture for ffmpegtileprovider

This commit is contained in:
Ylva Selling
2023-01-18 18:08:18 -05:00
parent cf95a9f35f
commit e3c7d782bd
2 changed files with 25 additions and 3 deletions

View File

@@ -616,6 +616,26 @@ void FfmpegTileProvider::handleMpvProperties(mpv_event* event) {
}
}
ChunkTile FfmpegTileProvider::chunkTile(TileIndex tileIndex, int parents, int maxParents) {
ZoneScoped
ghoul_assert(_isInitialized, "FfmpegTileProvider was not initialized");
lambda ascendToParent = [](TileIndex& ti, TileUvTransform& uv) {
ti.level--;
};
glm::vec2 noOfTiles = { pow(2, tileIndex.level), pow(2, tileIndex.level - 1) };
glm::vec2 ratios = { 1.f / noOfTiles.x, 1.f / noOfTiles.y };
float offsetX = ratios.x * static_cast<float>(tileIndex.x);
// The tiles on the y-axis should be traversed backwards
float offsetY = ratios.y * (noOfTiles.y - static_cast<float>(tileIndex.y - 1));
TileUvTransform uvTransform = { glm::vec2(offsetX, offsetY), ratios };
return traverseTree(tileIndex, parents, maxParents, ascendToParent, uvTransform);
}
void FfmpegTileProvider::handleMpvEvents() {
while (_mpvHandle) {
mpv_event* event = mpv_wait_event(_mpvHandle, 0);
@@ -702,9 +722,9 @@ int FfmpegTileProvider::minLevel() {
}
int FfmpegTileProvider::maxLevel() {
// Every tile needs to be 512 by 512, how far can we subdivide this video
// TODO: Check if it should be floor or ceil
return std::floor(std::log2(_resolution.x) - std::log2(1024)) + 1;
// This is the level where above the tile is marked as unavailable and is no longer
// displayed. Since we want to display the tiles at all times we set the max level
return 1337;
}
void FfmpegTileProvider::reset() {

View File

@@ -55,6 +55,8 @@ public:
int maxLevel() override final;
float noDataValueAsFloat() override final;
ChunkTile chunkTile(TileIndex tileIndex, int parents, int maxParents = 1337) override;
static documentation::Documentation Documentation();
private: