/*********************/ /*** Texture Cache ***/ /*********************/ #include "stdafx.h" #include #include #include #include #include #include "TexCache.h" #include "utils.h" /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /* int CTexCache::GetTexIdx(const char *Filename,int Flags) { sTex Tex; Tex.Filename=Filename; Tex.Flags=Flags; return(TexList.Find(Tex)); } */ /*****************************************************************************/ // Checks loaded files for dups, assumes all passed RGB is unique int CTexCache::ProcessTexture(const char *Filename,int Flags,sRGBData *RGBData) { int ListSize=TexList.size(); sTex NewTex; sRGBData ThisRGB; GFName FName=Filename; NewTex.Name=FName.File(); NewTex.Filename=Filename; NewTex.Flags=Flags; if (!RGBData) // Need to load file { int Idx=GetTexIdx(NewTex); // Is already loaded? if (Idx!=-1) return(Idx); // TRACE1("Loading Texture %s\n",NewTex.Filename); if (!LoadBMP(NewTex.Filename,ThisRGB)) { exit(-1); return(ListSize); } RGBData=&ThisRGB; LoadTex(NewTex,RGBData); FreeBMP(ThisRGB); NewTex.Loaded=TRUE; } else { LoadTex(NewTex,RGBData); NewTex.Loaded=FALSE; } TexList.push_back(NewTex); return(ListSize); } /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ const int TexAlignTable[]={1,2,4,8,16,32,64,128,256}; const int TexAlignTableSize=sizeof(TexAlignTable)/sizeof(int); int CTexCache::AlignSize(int Size) { for (int i=0;iTexAlignTable[i] && SizeWidth; int TexHeight=TexData->Height; int GLWidth=AlignSize(TexWidth); int GLHeight=AlignSize(TexHeight); u8 *Src,*Dst; // create RGB & alpha texture & ensuse texture is correct size for GL Buffer=(u8*)malloc(GLWidth*GLHeight*4); Src=TexData->RGB; Dst=&Buffer[0]; for (int Y=0; Y