Minor code cleanup.

pull/3/head
Chris Laurel 2001-03-05 22:48:16 +00:00
parent 8de9195fa9
commit 6215d145c8
4 changed files with 47 additions and 11 deletions

View File

@ -10,6 +10,8 @@
#include "celestia.h"
#include "texmanager.h"
using namespace std;
TextureManager::~TextureManager()
{
@ -17,25 +19,25 @@ TextureManager::~TextureManager()
}
bool TextureManager::find(string name, CTexture** tex)
bool TextureManager::find(const string& name, CTexture** tex)
{
return findResource(name, (void**) tex);
}
CTexture* TextureManager::load(string name)
CTexture* TextureManager::load(const string& name)
{
DPRINTF("Loading texture: %s\n", name.c_str());
CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name);
if (tex != NULL)
tex->bindName();
tex->bindName(true);
addResource(name, (void*) tex);
return tex;
}
CTexture* TextureManager::loadBumpMap(string name)
CTexture* TextureManager::loadBumpMap(const string& name)
{
DPRINTF("Loading bump map: %s\n", name.c_str());
CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name);

View File

@ -20,13 +20,13 @@ class TextureManager : public ResourceManager
{
public:
TextureManager() : ResourceManager() {};
TextureManager(string _baseDir) : ResourceManager(_baseDir) {};
TextureManager(std::string _baseDir) : ResourceManager(_baseDir) {};
TextureManager(char* _baseDir) : ResourceManager(_baseDir) {};
~TextureManager();
bool find(string name, CTexture**);
CTexture* load(std::string name);
CTexture* loadBumpMap(std::string name);
bool find(const std::string& name, CTexture**);
CTexture* load(const std::string& name);
CTexture* loadBumpMap(const std::string& name);
};
#endif // _TEXMANAGER_H_

View File

@ -230,7 +230,7 @@ CTexture* CreateProceduralTexture(int width, int height,
}
CTexture* LoadTextureFromFile(string filename)
CTexture* LoadTextureFromFile(const string& filename)
{
int extPos = filename.length() - 3;
if (extPos < 0)
@ -555,6 +555,41 @@ static Vec3f cubeVector(int face, float s, float t)
break;
}
#if 0
// Silly test here . . . this produces a normal map with (0, 0, 1) on
// on the half of the cube on the positive size of the z=0 plane and
// (0, 0, -1) on the other half.
//
// TODO: Experiment with other normal maps as a way to approximate various
// illumination functions that may be more accurate for planetary rendering
// than the standard Lambertian model.
v = Vec3f(0, 0, 1);
switch (face)
{
case 0:
if (s > 0)
v = -v;
break;
case 1:
if (s < 0)
v = -v;
break;
case 2:
if (t < 0)
v = -v;
break;
case 3:
if (t > 0)
v = -v;
break;
case 4:
break;
case 5:
v = -v;
break;
}
#endif
v.normalize();
return v;

View File

@ -12,7 +12,6 @@
#include <string>
using namespace std;
typedef void (*ProceduralTexEval)(float, float, float, unsigned char*);
@ -54,7 +53,7 @@ extern CTexture* CreateJPEGTexture(const char* filename,
int channels = CTexture::ColorChannel);
extern CTexture* CreateBMPTexture(const char* filename);
extern CTexture* LoadTextureFromFile(string filename);
extern CTexture* LoadTextureFromFile(const std::string& filename);
extern CTexture* CreateNormalizationCubeMap(int size);