00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "multitexture.h"
00011 #include "texmanager.h"
00012 #include <celutil/debug.h>
00013
00014 using namespace std;
00015
00016
00017 MultiResTexture::MultiResTexture()
00018 {
00019 tex[lores] = InvalidResource;
00020 tex[medres] = InvalidResource;
00021 tex[hires] = InvalidResource;
00022 }
00023
00024
00025 MultiResTexture::MultiResTexture(ResourceHandle loTex,
00026 ResourceHandle medTex,
00027 ResourceHandle hiTex)
00028 {
00029 tex[lores] = loTex;
00030 tex[medres] = medTex;
00031 tex[hires] = hiTex;
00032 }
00033
00034
00035 MultiResTexture::MultiResTexture(const string& source,
00036 const string& path)
00037 {
00038 setTexture(source, path);
00039 }
00040
00041
00042 void MultiResTexture::setTexture(const string& source, const string& path,
00043 unsigned int flags)
00044 {
00045 TextureManager* texMan = GetTextureManager();
00046 tex[lores] = texMan->getHandle(TextureInfo(source, path, flags, lores));
00047 tex[medres] = texMan->getHandle(TextureInfo(source, path, flags, medres));
00048 tex[hires] = texMan->getHandle(TextureInfo(source, path, flags, hires));
00049 }
00050
00051
00052 void MultiResTexture::setTexture(const string& source, const string& path,
00053 float bumpHeight, unsigned int flags)
00054 {
00055 TextureManager* texMan = GetTextureManager();
00056 tex[lores] = texMan->getHandle(TextureInfo(source, path, bumpHeight, flags, lores));
00057 tex[medres] = texMan->getHandle(TextureInfo(source, path, bumpHeight, flags, medres));
00058 tex[hires] = texMan->getHandle(TextureInfo(source, path, bumpHeight, flags, hires));
00059 }
00060
00061
00062 Texture* MultiResTexture::find(unsigned int resolution)
00063 {
00064 TextureManager* texMan = GetTextureManager();
00065 Texture* res = texMan->find(tex[resolution]);
00066 if (res != NULL)
00067 return res;
00068 if(resolution == lores)
00069 tex[resolution] = tex[resolution +1];
00070 else
00071 tex[resolution] = tex[resolution -1];
00072 res = texMan->find(tex[resolution]);
00073 if(res != NULL)
00074 return res;
00075 if(resolution == hires)
00076 return texMan->find(tex[lores]);
00077 else
00078 return texMan->find(tex[hires]);
00079 }