-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile_texture_manager.h
More file actions
66 lines (54 loc) · 2.14 KB
/
tile_texture_manager.h
File metadata and controls
66 lines (54 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// tile_texture_manager.h
#ifndef TILE_TEXTURE_MANAGER_H
#define TILE_TEXTURE_MANAGER_H
#include <QOpenGLFunctions>
#include <QOpenGLTexture>
#include <QMatrix4x4>
#include <QCache>
#include <QString>
struct TileCoords {
int ring;
int segment;
bool operator==(const TileCoords& other) const {
return ring == other.ring && segment == other.segment;
}
};
// For QCache
inline uint qHash(const TileCoords& key) {
return qHash(QString("%1_%2").arg(key.ring).arg(key.segment));
}
class Tile {
public:
Tile() : texture(nullptr), isLoaded(false) {}
~Tile() { }
std::unique_ptr<QOpenGLTexture> texture;
QRectF uvCoords; // UV-координаты тайла в текстуре
QRectF sphereCoords; // Сферические координаты тайла (phi1, theta1, phi2, theta2)
bool isLoaded;
};
class TileTextureManager : protected QOpenGLFunctions {
public:
TileTextureManager(const QString& imagePath, int rings, int segments);
~TileTextureManager();
void initialize();
bool bindTileTexture(int ring, int segment);
const QRectF& getTileUVCoords(int ring, int segment);
void updateVisibleTiles(const QMatrix4x4& viewProjection);
private:
void loadTile(const TileCoords& coords);
void calculateTileCoordinates(const TileCoords& coords, QRectF& uvCoords, QRectF& sphereCoords) const;
bool isTileVisible(const QRectF& sphereCoords, const QMatrix4x4& viewProjection) const;
void cleanupUnusedTiles();
QString imagePath;
QImage sourceImage;
int numRings;
int numSegments;
QOpenGLTexture* textureAtlas;
QVector<QRectF> tileUVCoords; // Кэшируем UV-координаты для каждого тайла
QSize atlasSize; // Размер атласа текстур
int tilesPerRow; // Количество тайлов в строке атласа
// Используем QCache для автоматического управления памятью
QCache<TileCoords, Tile> tileCache;
static constexpr int MAX_CACHE_SIZE = 512; // В мегабайтах
};
#endif // TILE_TEXTURE_MANAGER_H