Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

virtualtex.cpp File Reference

#include <string>
#include <iostream>
#include <fstream>
#include <cmath>
#include <cassert>
#include <cstdio>
#include "celutil/debug.h"
#include "celutil/directory.h"
#include "virtualtex.h"
#include "gl.h"
#include "parser.h"

Include dependency graph for virtualtex.cpp:

Go to the source code of this file.

Functions

static VirtualTextureCreateVirtualTexture (Hash *texParams, const string &path)
static bool isPow2 (int x)
VirtualTextureLoadVirtualTexture (const string &filename)
static VirtualTextureLoadVirtualTexture (istream &in, const string &path)

Variables

static const int MaxResolutionLevels = 11


Function Documentation

static VirtualTexture* CreateVirtualTexture Hash texParams,
const string path
[static]
 

Definition at line 323 of file virtualtex.cpp.

References DPRINTF, and isPow2().

Referenced by LoadVirtualTexture().

00325 {
00326     string imageDirectory;
00327     if (!texParams->getString("ImageDirectory", imageDirectory))
00328     {
00329         DPRINTF(0, "ImageDirectory missing in virtual texture.\n");
00330         return NULL;
00331     }
00332 
00333     double baseSplit = 0.0;
00334     if (!texParams->getNumber("BaseSplit", baseSplit) ||
00335         baseSplit < 0.0 || baseSplit != floor(baseSplit))
00336     {
00337         DPRINTF(0, "BaseSplit in virtual texture missing or has bad value\n");
00338         return NULL;
00339     }
00340 
00341     double tileSize = 0.0;
00342     if (!texParams->getNumber("TileSize", tileSize))
00343     {
00344         DPRINTF(0, "TileSize is missing from virtual texture\n");
00345         return NULL;
00346     }
00347 
00348     if (tileSize != floor(tileSize) ||
00349         tileSize < 64.0 ||
00350         !isPow2((int) tileSize))
00351     {
00352         DPRINTF(0, "Virtual texture tile size must be a power of two >= 64\n");
00353         return NULL;
00354     }
00355 
00356     string tileType = "dds";
00357     texParams->getString("TileType", tileType);
00358 
00359     string tilePrefix = "tx_";
00360     texParams->getString("TilePrefix", tilePrefix);
00361 
00362     return new VirtualTexture(path + "/" + imageDirectory + "/",
00363                               (unsigned int) baseSplit,
00364                               (unsigned int) tileSize,
00365                               tilePrefix,
00366                               tileType);
00367 
00368     return NULL;
00369 }

static bool isPow2 int  x  )  [static]
 

Definition at line 38 of file virtualtex.cpp.

00039 {
00040     return ((x & (x - 1)) == 0);
00041 }

VirtualTexture* LoadVirtualTexture const string filename  ) 
 

Definition at line 397 of file virtualtex.cpp.

References LoadVirtualTexture().

00398 {
00399     ifstream in(filename.c_str(), ios::in);
00400 
00401     if (!in.good())
00402     {
00403         //DPRINTF(0, "Error opening virtual texture file: %s\n", filename.c_str());
00404         return NULL;
00405     }
00406 
00407     // Strip off every character including and after the final slash to get
00408     // the pathname.
00409     string path = ".";
00410     string::size_type pos = filename.rfind('/');
00411     if (pos != string::npos)
00412         path = string(filename, 0, pos);
00413 
00414     return LoadVirtualTexture(in, path);
00415 }

static VirtualTexture* LoadVirtualTexture istream &  in,
const string path
[static]
 

Definition at line 372 of file virtualtex.cpp.

References CreateVirtualTexture(), DPRINTF, Value::getHash(), Tokenizer::getNameValue(), Value::getType(), Tokenizer::nextToken(), and Parser::readValue().

Referenced by LoadTextureFromFile(), and LoadVirtualTexture().

00373 {
00374     Tokenizer tokenizer(&in);
00375     Parser parser(&tokenizer);
00376 
00377     if (tokenizer.nextToken() != Tokenizer::TokenName)
00378         return NULL;
00379 
00380     string virtTexString = tokenizer.getNameValue();
00381     if (virtTexString != "VirtualTexture")
00382         return NULL;
00383 
00384     Value* texParamsValue = parser.readValue();
00385     if (texParamsValue == NULL || texParamsValue->getType() != Value::HashType)
00386     {
00387         DPRINTF(0, "Error parsing virtual texture\n");
00388         return NULL;
00389     }
00390 
00391     Hash* texParams = texParamsValue->getHash();
00392     
00393     return CreateVirtualTexture(texParams, path);
00394 }


Variable Documentation

const int MaxResolutionLevels = 11 [static]
 

Definition at line 24 of file virtualtex.cpp.

Referenced by VirtualTexture::loadTileTexture(), and VirtualTexture::populateTileTree().


Generated on Sat Jan 14 22:31:31 2006 for Celestia by  doxygen 1.4.1