#include <virtualtex.h>
Inheritance diagram for VirtualTexture:


Public Member Functions | |
| virtual void | beginUsage () |
| virtual void | bind () |
| virtual void | endUsage () |
| virtual int | getLODCount () const |
| virtual const TextureTile | getTile (int lod, int u, int v) |
| virtual int | getUTileCount (int lod) const |
| virtual int | getVTileCount (int lod) const |
| VirtualTexture (const std::string &_tilePath, unsigned int _baseSplit, unsigned int _tileSize, const std::string &tilePrefix, const std::string &tileType) | |
| ~VirtualTexture () | |
Private Types | |
| enum | { TileNotLoaded = -1, TileLoadFailed = -2 } |
Private Member Functions | |
| void | addTileToTree (Tile *tile, uint lod, uint v, uint u) |
| Tile * | findTile (unsigned int lod, unsigned int u, unsigned int v) |
| ImageTexture * | loadTileTexture (uint lod, uint u, uint v) |
| void | makeResident (Tile *tile, uint lod, uint v, uint u) |
| void | populateTileTree () |
Private Attributes | |
| unsigned int | baseSplit |
| unsigned int | nResolutionLevels |
| unsigned int | ticks |
| std::string | tileExt |
| std::string | tilePath |
| std::string | tilePrefix |
| Tile * | tiles |
| unsigned int | tileSize |
| unsigned int | tilesRequested |
| TileQuadtreeNode * | tileTree [2] |
Classes | |
| struct | Tile |
| struct | TileQuadtreeNode |
|
|
Definition at line 78 of file virtualtex.h. 00078 {
00079 TileNotLoaded = -1,
00080 TileLoadFailed = -2,
00081 };
|
|
||||||||||||||||||||||||
|
Definition at line 54 of file virtualtex.cpp. References isPow2(), populateTileTree(), tileExt, tileSize, and tileTree. 00058 : 00059 Texture(_tileSize << (_baseSplit + 1), _tileSize << _baseSplit), 00060 tilePath(_tilePath), 00061 baseSplit(_baseSplit), 00062 tilePrefix(_tilePrefix), 00063 tileSize(_tileSize), 00064 ticks(0), 00065 nResolutionLevels(0) 00066 { 00067 assert(tileSize != 0 && isPow2(tileSize)); 00068 tileTree[0] = new TileQuadtreeNode(); 00069 tileTree[1] = new TileQuadtreeNode(); 00070 tileExt = string(".") + _tileType; 00071 populateTileTree(); 00072 }
|
|
|
Definition at line 75 of file virtualtex.cpp. 00076 {
00077 }
|
|
||||||||||||||||||||
|
Definition at line 301 of file virtualtex.cpp. References VirtualTexture::TileQuadtreeNode::children, VirtualTexture::TileQuadtreeNode::tile, and tileTree. Referenced by populateTileTree(). 00302 {
00303 TileQuadtreeNode* node = tileTree[u >> lod];
00304
00305 for (uint i = 0; i < lod; i++)
00306 {
00307 uint mask = 1 << (lod - i - 1);
00308 uint child = (((v & mask) << 1) | (u & mask)) >> (lod - i - 1);
00309 if (node->children[child] == NULL)
00310 node->children[child] = new TileQuadtreeNode();
00311 node = node->children[child];
00312 }
00313 #if 0
00314 clog << "addTileToTree: " << node << ", " << lod << ", " << u << ", " << v << '\n';
00315 #endif
00316
00317 // Verify that the tile doesn't already exist
00318 if (node->tile == NULL)
00319 node->tile = tile;
00320 }
|
|
|
Reimplemented from Texture. Definition at line 191 of file virtualtex.cpp. References ticks, and tilesRequested. 00192 {
00193 ticks++;
00194 tilesRequested = 0;
00195 }
|
|
|
Implements Texture. Definition at line 166 of file virtualtex.cpp. 00167 {
00168 // Treating a virtual texture like an ordinary one will not work; this is a
00169 // weakness in the class hierarchy.
00170 }
|
|
|
Reimplemented from Texture. Definition at line 198 of file virtualtex.cpp. 00199 {
00200 }
|
|
||||||||||||||||
|
|
|
|
Reimplemented from Texture. Definition at line 173 of file virtualtex.cpp. References baseSplit, and nResolutionLevels. 00174 {
00175 return nResolutionLevels - baseSplit;
00176 }
|
|
||||||||||||||||
|
Implements Texture. Definition at line 80 of file virtualtex.cpp. References baseSplit, VirtualTexture::TileQuadtreeNode::children, ImageTexture::getName(), makeResident(), nResolutionLevels, VirtualTexture::Tile::tex, VirtualTexture::TileQuadtreeNode::tile, tilesRequested, and tileTree. 00081 {
00082 tilesRequested++;
00083 #if 0
00084 cout << "getTile(" << lod << ", " << u << ", " << v << ")\n";
00085 #endif
00086
00087 lod += baseSplit;
00088
00089 if (lod < 0 || (uint) lod >= nResolutionLevels ||
00090 u < 0 || u >= (2 << lod) ||
00091 v < 0 || v >= (1 << lod))
00092 {
00093 return TextureTile(0);
00094 }
00095 else
00096 {
00097 TileQuadtreeNode* node = tileTree[u >> lod];
00098 Tile* tile = node->tile;
00099 uint tileLOD = 0;
00100
00101 for (int n = 0; n < lod; n++)
00102 {
00103 uint mask = 1 << (lod - n - 1);
00104 uint child = (((v & mask) << 1) | (u & mask)) >> (lod - n - 1);
00105 //int child = (((v << 1) | u) >> (lod - n - 1)) & 3;
00106 if (node->children[child] == NULL)
00107 {
00108 break;
00109 }
00110 else
00111 {
00112 node = node->children[child];
00113 if (node->tile != NULL)
00114 {
00115 tile = node->tile;
00116 tileLOD = n + 1;
00117 }
00118 }
00119 }
00120
00121 // No tile was found at all--not even the base texture was found
00122 if (tile == NULL)
00123 {
00124 return TextureTile(0);
00125 }
00126
00127 // Make the tile resident.
00128 uint tileU = u >> (lod - tileLOD);
00129 uint tileV = v >> (lod - tileLOD);
00130 makeResident(tile, tileLOD, tileU, tileV);
00131
00132 // It's possible that we failed to make the tile resident, either
00133 // because the texture file was bad, or there was an unresolvable
00134 // out of memory situation. In that case there is nothing else to
00135 // do but return a texture tile with a null texture name.
00136 if (tile->tex == NULL)
00137 {
00138 return TextureTile(0);
00139 }
00140 else
00141 {
00142 // Set up the texture subrect to be the entire texture
00143 float texU = 0.0f;
00144 float texV = 0.0f;
00145 float texDU = 1.0f;
00146 float texDV = 1.0f;
00147
00148 // If the tile came from a lower LOD than the requested one,
00149 // we'll only use a subsection of it.
00150 uint lodDiff = lod - tileLOD;
00151 texDU = texDV = 1.0f / (float) (1 << lodDiff);
00152 texU = (u & ((1 << lodDiff) - 1)) * texDU;
00153 texV = (v & ((1 << lodDiff) - 1)) * texDV;
00154
00155 #if 0
00156 cout << "Tile: " << tile->tex->getName() << ", " <<
00157 texU << ", " << texV << ", " << texDU << ", " << texDV << '\n';
00158 #endif
00159 return TextureTile(tile->tex->getName(),
00160 texU, texV, texDU, texDV);
00161 }
00162 }
00163 }
|
|
|
Reimplemented from Texture. Definition at line 179 of file virtualtex.cpp. References baseSplit. 00180 {
00181 return 2 << (lod + baseSplit);
00182 }
|
|
|
Reimplemented from Texture. Definition at line 185 of file virtualtex.cpp. References baseSplit. 00186 {
00187 return 1 << (lod + baseSplit);
00188 }
|
|
||||||||||||||||
|
Definition at line 213 of file virtualtex.cpp. References baseSplit, Image::getHeight(), Image::getWidth(), isPow2(), LoadImageFromFile(), MaxResolutionLevels, tileExt, tilePath, and tilePrefix. Referenced by makeResident(). 00214 {
00215 lod >>= baseSplit;
00216
00217 assert(lod < (unsigned)MaxResolutionLevels);
00218
00219 char filename[64];
00220 sprintf(filename, "level%d/%s%d_%d", lod, tilePrefix.c_str(), u, v);
00221
00222 string pathname = tilePath + filename + tileExt;
00223 Image* img = LoadImageFromFile(pathname);
00224 if (img == NULL)
00225 return NULL;
00226
00227 ImageTexture* tex = NULL;
00228
00229 // Only use mip maps for the LOD 0; for higher LODs, the function of mip
00230 // mapping is built into the texture.
00231 MipMapMode mipMapMode = lod == 0 ? DefaultMipMaps : NoMipMaps;
00232
00233 if (isPow2(img->getWidth()) && isPow2(img->getHeight()))
00234 tex = new ImageTexture(*img, EdgeClamp, mipMapMode);
00235 delete img;
00236
00237 return tex;
00238 }
|
|
||||||||||||||||||||
|
Definition at line 241 of file virtualtex.cpp. References loadTileTexture(). Referenced by getTile(). 00242 {
00243 if (tile->tex == NULL && !tile->loadFailed)
00244 {
00245 // Potentially evict other tiles in order to make this one fit
00246 tile->tex = loadTileTexture(lod, u, v);
00247 if (tile->tex == NULL)
00248 {
00249 // cout << "Texture load failed!\n";
00250 tile->loadFailed = true;
00251 }
00252 }
00253 }
|
|
|
Definition at line 256 of file virtualtex.cpp. References addTileToTree(), baseSplit, IsDirectory(), MaxResolutionLevels, Directory::nextFile(), nResolutionLevels, OpenDirectory(), tilePath, and tilePrefix. Referenced by VirtualTexture(). 00257 {
00258 // Count the number of resolution levels present
00259 uint maxLevel = 0;
00260
00261 // Crash potential if the tile prefix contains a %, so disallow it
00262 string pattern;
00263 if (tilePrefix.find('%') == string::npos)
00264 pattern = tilePrefix + "%d_%d.";
00265
00266 for (int i = 0; i < MaxResolutionLevels; i++)
00267 {
00268 char filename[32];
00269 sprintf(filename, "level%d", i);
00270 if (IsDirectory(tilePath + filename))
00271 {
00272 Directory* dir = OpenDirectory(tilePath + filename);
00273 if (dir != NULL)
00274 {
00275 maxLevel = i + baseSplit;
00276 int uLimit = 2 << maxLevel;
00277 int vLimit = 1 << maxLevel;
00278
00279 string filename;
00280 while (dir->nextFile(filename))
00281 {
00282 int u = -1, v = -1;
00283 if (sscanf(filename.c_str(), pattern.c_str(), &u, &v) == 2)
00284 {
00285 if (u >= 0 && v >= 0 && u < uLimit && v < vLimit)
00286 {
00287 // Found a tile, so add it to the quadtree
00288 Tile* tile = new Tile();
00289 addTileToTree(tile, maxLevel, (uint) u, (uint) v);
00290 }
00291 }
00292 }
00293 }
00294 }
00295 }
00296
00297 nResolutionLevels = maxLevel + 1;
00298 }
|
|
|
Definition at line 72 of file virtualtex.h. Referenced by getLODCount(), getTile(), getUTileCount(), getVTileCount(), loadTileTexture(), and populateTileTree(). |
|
|
Definition at line 76 of file virtualtex.h. Referenced by getLODCount(), getTile(), and populateTileTree(). |
|
|
Definition at line 74 of file virtualtex.h. Referenced by beginUsage(). |
|
|
Definition at line 70 of file virtualtex.h. Referenced by loadTileTexture(), and VirtualTexture(). |
|
|
Definition at line 69 of file virtualtex.h. Referenced by loadTileTexture(), and populateTileTree(). |
|
|
Definition at line 71 of file virtualtex.h. Referenced by loadTileTexture(), and populateTileTree(). |
|
|
Definition at line 64 of file virtualtex.h. |
|
|
Definition at line 73 of file virtualtex.h. Referenced by VirtualTexture(). |
|
|
Definition at line 75 of file virtualtex.h. Referenced by beginUsage(), and getTile(). |
|
|
Definition at line 83 of file virtualtex.h. Referenced by addTileToTree(), getTile(), and VirtualTexture(). |
1.4.1