Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Texture Class Reference

#include <aux_texture.h>

Inheritance diagram for Texture:
AnimatedTexture PipelinedTexture StreamTexture Animation

Public Member Functions

void FileNotFound (const std::string &)
 
GFXBOOL checkold (const std::string &s, bool shared, std::string &hashname)
 Returns if this texture is actually already loaded. More...
 
void modold (const std::string &s, bool shared, std::string &hashname)
 
void setold ()
 Loads the old texture. More...
 
bool checkbad (const string &s)
 
void setbad (const string &s)
 
void InitTexture ()
 Inits the class with default values. More...
 
int Bind (Texture *other, int maxdimension=65536, GFXBOOL detailtexture=GFXFALSE)
 Binds this texture to the same name as the given texture - for multipart textures. More...
 
 Texture (int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE)
 Creates an unbounded texture. Set data and dimensions before binding. Or explicitly load a file. More...
 
 Texture (const char *, const char *, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, float alpha=1, int zeroval=0, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 Creates a texture with a single bitmap as color data and another grayscale .bmp as alpha data. More...
 
 Texture (const char *FileName, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 Creates a texture with only color data as a single bitmap. More...
 
 Texture (VSFileSystem::VSFile *f, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 
void Load (const char *, const char *, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, float alpha=1, int zeroval=0, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 
void Load (const char *FileName, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 
virtual const TextureOriginal () const
 
virtual TextureOriginal ()
 
virtual TextureClone ()
 
virtual ~Texture ()
 Texture copy constructor that increases appropriate refcounts. More...
 
virtual unsigned int numFrames () const
 
virtual double curTime () const
 
virtual void setTime (double tim)
 
virtual float framesPerSecond () const
 
virtual unsigned int numLayers () const
 
virtual unsigned int numPasses () const
 
virtual bool canMultiPass () const
 
virtual bool constFrameRate () const
 
int getStage () const
 
int getFilter () const
 
int getTarget () const
 
int getImageTarget () const
 
bool operator< (const Texture &b) const
 A way to sort the texture by the original address (to make sure like textures stick togehter. More...
 
bool operator== (const Texture &b) const
 A way to test if the texture is equal to another based on original values. More...
 
void setReference (Texture *other)
 Make this instance a reference of "other". More...
 
virtual void MakeActive ()
 Binds the texture in the GFX library. More...
 
virtual void MakeActive (int stage)
 
virtual void MakeActive (int stage, int pass)
 
virtual bool SetupPass (int pass, const enum BLENDFUNC src, const enum BLENDFUNC dst)
 
virtual bool SetupPass (int pass, int stage, const enum BLENDFUNC src, const enum BLENDFUNC dst)
 
virtual bool LoadSuccess ()
 If the texture has loaded properly returns true. More...
 
virtual void Prioritize (float)
 Changes priority of texture. More...
 

Static Public Member Functions

static TextureExists (std::string s)
 Whether or not the string exists as a texture. More...
 
static TextureExists (std::string s, std::string a)
 Whether or not the color and alpha data already exist. More...
 

Public Attributes

StringPool::Reference texfilename
 The file name used to load this texture. More...
 
enum FILTER ismipmapped
 the filter mode of this texture More...
 
unsigned char * data
 The data of this texture (used in between functions, deleted) More...
 
int name
 The GFXname of this texture. More...
 
int stage
 The multitexture stage of this texture. More...
 
Vector mintcoord
 The minimum/maximum texturing coordinates for this texture (have in mind that it is not always enforce, ie. for meshes) (i=s, j=t, k=u) More...
 
Vector maxtcoord
 
Textureoriginal
 The original data that would represent this texture. More...
 
bool bound
 For re-biding. More...
 
uint boundSizeX
 
uint boundSizeY
 
VSImageMode boundMode
 
int refcount
 The number of references on the original data. More...
 
enum TEXTURE_TARGET texture_target
 The target this will go to (cubemap or otherwise) More...
 
enum TEXTURE_IMAGE_TARGET image_target
 
enum ADDRESSMODE address_mode
 The address mode being used with this texture. More...
 

Protected Member Functions

int Bind (int maxdimension, GFXBOOL detailtexture)
 Binds this texture to GFX library. More...
 
void UnBind ()
 UnBinds from GFX library. More...
 
void Transfer (int maxdimension, GFXBOOL detailtexture)
 Transfers this texture to GFX library. More...
 

Detailed Description

The texture class defines a method of loading bitmap textures It also defines a hash table in which textures are kept and looked up to prevent the loading of duplicate textures

Definition at line 38 of file aux_texture.h.

Constructor & Destructor Documentation

Texture::Texture ( int  stage = 0,
enum FILTER  mipmap = MIPMAP,
enum TEXTURE_TARGET  target = TEXTURE2D,
enum TEXTURE_IMAGE_TARGET  imagetarget = TEXTURE_2D,
enum ADDRESSMODE  address_mode = DEFAULT_ADDRESS_MODE 
)

Creates an unbounded texture. Set data and dimensions before binding. Or explicitly load a file.

Definition at line 208 of file aux_texture.cpp.

Referenced by AnimatedTexture::LoadAni().

213 {
214  InitTexture();
215  data = NULL;
216  ismipmapped = mipmap;
217  palette = NULL;
218  texture_target = target;
219  image_target = imagetarget;
220  this->stage = stage;
221 }
Texture::Texture ( const char *  FileNameRGB,
const char *  FileNameA,
int  stage = 0,
enum FILTER  mipmap = MIPMAP,
enum TEXTURE_TARGET  target = TEXTURE2D,
enum TEXTURE_IMAGE_TARGET  imagetarget = TEXTURE_2D,
float  alpha = 1,
int  zeroval = 0,
GFXBOOL  force = GFXFALSE,
int  max_dimension_size = 65536,
GFXBOOL  detail_texture = GFXFALSE,
GFXBOOL  nocache = false,
enum ADDRESSMODE  address_mode = DEFAULT_ADDRESS_MODE,
Texture main = 0 
)

Creates a texture with a single bitmap as color data and another grayscale .bmp as alpha data.

Definition at line 388 of file aux_texture.cpp.

402 {
403  InitTexture();
404  Load( FileNameRGB,
405  FileNameA,
406  stage,
407  mipmap,
408  target,
409  imagetarget,
410  alpha,
411  zeroval,
412  force_load,
413  maxdimension,
414  detailtexture,
415  nocache,
416  address_mode,
417  main );
418 }
Texture::Texture ( const char *  FileName,
int  stage = 0,
enum FILTER  mipmap = MIPMAP,
enum TEXTURE_TARGET  target = TEXTURE2D,
enum TEXTURE_IMAGE_TARGET  imagetarget = TEXTURE_2D,
GFXBOOL  force = GFXFALSE,
int  max_dimension_size = 65536,
GFXBOOL  detail_texture = GFXFALSE,
GFXBOOL  nocache = false,
enum ADDRESSMODE  address_mode = DEFAULT_ADDRESS_MODE,
Texture main = 0 
)

Creates a texture with only color data as a single bitmap.

Definition at line 262 of file aux_texture.cpp.

273 {
274  InitTexture();
275  Load( FileName, stage, mipmap, target, imagetarget, force_load, maxdimension, detailtexture, nocache, address_mode, main );
276 }
Texture::Texture ( VSFileSystem::VSFile f,
int  stage = 0,
enum FILTER  mipmap = MIPMAP,
enum TEXTURE_TARGET  target = TEXTURE2D,
enum TEXTURE_IMAGE_TARGET  imagetarget = TEXTURE_2D,
GFXBOOL  force = GFXFALSE,
int  max_dimension_size = 65536,
GFXBOOL  detail_texture = GFXFALSE,
GFXBOOL  nocache = false,
enum ADDRESSMODE  address_mode = DEFAULT_ADDRESS_MODE,
Texture main = 0 
)

Definition at line 223 of file aux_texture.cpp.

References VSFileSystem::FileNotFound, and NEAREST.

234 {
235  data = NULL;
236  ismipmapped = mipmap;
237  InitTexture();
238  palette = NULL;
239  texture_target = target;
240  image_target = imagetarget;
241  this->stage = stage;
242  data = this->ReadImage( f, NULL, true, NULL );
243  if (data) {
244  if (mode >= _DXT1 && mode <= _DXT5) {
245  if ( (int) data[0] == 0 ) {
246  detailtexture = NEAREST;
248  }
249  }
250  if (main)
251  Bind( main, maxdimension, detailtexture );
252  else
253  Bind( maxdimension, detailtexture );
254  free( data );
255  data = NULL;
256  if (!nocache) setold();
257  } else {
259  }
260 }
Texture::~Texture ( )
virtual

Texture copy constructor that increases appropriate refcounts.

Destructor for texture

DEPRECATED if(data != NULL) { delete [] data;

data = NULL; }

Definition at line 519 of file aux_texture.cpp.

520 {
521  if (original == NULL) {
530  UnBind();
531  if (palette != NULL) {
532  free( palette );
533  palette = NULL;
534  }
535  } else {
536  original->refcount--;
537  if (original->refcount == 0)
538  delete original;
539  }
540 }

Member Function Documentation

int Texture::Bind ( int  maxdimension,
GFXBOOL  detailtexture 
)
protected

Binds this texture to GFX library.

Definition at line 598 of file aux_texture.cpp.

References DXT1, DXT1RGBA, DXT3, DXT5, GFXCreateTexture(), PALETTE8, RGB24, and RGBA32.

Referenced by AnimatedTexture::LoadVideoSource().

599 {
600  if ( !bound || (boundSizeX != sizeX) || (boundSizeY != sizeY) || (boundMode != mode) ) {
601  UnBind();
602  switch (mode)
603  {
604  case _DXT1:
606  break;
607  case _DXT1RGBA:
609  break;
610 
611  case _DXT3:
613  break;
614  case _DXT5:
616  break;
617 
618  case _24BITRGBA:
619  //GFXCreateTexture(sizeX, sizeY, RGBA32, &name, NULL, stage);
621  break;
622  case _24BIT:
623  //not supported by most cards, so i use rgba32
624  //GFXCreateTexture(sizeX, sizeY, RGB24, &name);
626  break;
627  case _8BIT:
628  GFXCreateTexture( sizeX, sizeY, PALETTE8, &name, (char*) palette, stage, ismipmapped, texture_target, address_mode );
629  break;
630  }
631  }
632  boundSizeX = sizeX;
633  boundSizeY = sizeY;
634  boundMode = mode;
635  bound = true;
636  Transfer( maxdimension, detailtexture );
637  return name;
638 }
int Texture::Bind ( Texture other,
int  maxdimension = 65536,
GFXBOOL  detailtexture = GFXFALSE 
)

Binds this texture to the same name as the given texture - for multipart textures.

Definition at line 640 of file aux_texture.cpp.

References bound, boundMode, boundSizeX, boundSizeY, and name.

641 {
642  UnBind();
643 
644  boundSizeX = other->boundSizeX;
645  boundSizeY = other->boundSizeY;
646  boundMode = other->boundMode;
647  bound = other->bound;
648  name = other->name;
649  Transfer( maxdimension, detailtexture );
650  return name;
651 }
virtual bool Texture::canMultiPass ( ) const
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 218 of file aux_texture.h.

219  {
220  return true;
221  } //True, if full functionality can be achieved after multipass rendering. If false, fallback rendering must be possible by multipass (or singlepass) rendering. True, also, if texturing units are sufficient for singlepass rendering.
bool Texture::checkbad ( const string &  s)

Definition at line 185 of file aux_texture.cpp.

References badtexHashTable, VSFileSystem::GetHashName(), and VSFileSystem::GetSharedTextureHashName().

186 {
187  string hashname = VSFileSystem::GetSharedTextureHashName( s );
188  bool *found = NULL;
189  found = badtexHashTable.Get( hashname );
190  if (found != NULL)
191  return true;
192  hashname = VSFileSystem::GetHashName( s );
193  found = badtexHashTable.Get( hashname );
194  if (found != NULL)
195  return true;
196  return false;
197 }
GFXBOOL Texture::checkold ( const std::string &  s,
bool  shared,
std::string &  hashname 
)

Returns if this texture is actually already loaded.

Definition at line 86 of file aux_texture.cpp.

References VSFileSystem::GetHashName(), VSFileSystem::GetSharedTextureHashName(), GFXFALSE, GFXTRUE, and texHashTable.

87 {
88  hashname = shared ? VSFileSystem::GetSharedTextureHashName( s ) : VSFileSystem::GetHashName( s );
89  Texture *oldtex = texHashTable.Get( hashname );
90  if (oldtex != NULL) {
91  //*this = *oldtex;//will be obsoleted--unpredictable results with string()
92  setReference( oldtex );
93  //cerr<<"Found cached texture : "<<s<<" with hashname="<<hashname<<endl;
94  return GFXTRUE;
95  } else {
96  return GFXFALSE;
97  }
98 }
Texture * Texture::Clone ( )
virtual

Reimplemented in AnimatedTexture, PipelinedTexture, and StreamTexture.

Definition at line 152 of file aux_texture.cpp.

References name, original, refcount, and BaseUtil::Texture().

Referenced by Background::Cache(), AnimatedTexture::Clone(), Flightgroup::operator=(), SpriteStarVlist::SpriteStarVlist(), and VSSprite::VSSprite().

153 {
154  Texture *retval = new Texture();
155  Texture *target = Original();
156  *retval = *target;
157  //memcpy (this, target, sizeof (Texture));
158  if (retval->name != -1) {
159  retval->original = target;
160  retval->original->refcount++;
161  } else {
162  retval->original = NULL;
163  }
164  retval->refcount = 0;
165  return retval;
166  //assert (!original->original);
167 }
virtual bool Texture::constFrameRate ( ) const
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 223 of file aux_texture.h.

224  {
225  return true;
226  } //If frames advance at a regular rate - keyframe based animations would return false.
virtual double Texture::curTime ( ) const
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 196 of file aux_texture.h.

197  {
198  return 0;
199  } //Current time of an animated texture
static Texture* Texture::Exists ( std::string  s)
static

Whether or not the string exists as a texture.

Referenced by DecalQueue::AddTexture().

static Texture* Texture::Exists ( std::string  s,
std::string  a 
)
static

Whether or not the color and alpha data already exist.

void Texture::FileNotFound ( const std::string &  )

Definition at line 169 of file aux_texture.cpp.

References texHashTable.

170 {
171  //We may need to remove from texHashTable if we found the file but it is a bad one
172  texHashTable.Delete( texfilename );
173 
174  setbad( texfilename );
175  name = -1;
176  data = NULL;
177  if (original != NULL) {
178  original->name = -1;
179  delete original;
180  original = NULL;
181  }
182  palette = NULL;
183 }
virtual float Texture::framesPerSecond ( ) const
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 203 of file aux_texture.h.

204  {
205  return 0;
206  } //Frames per second, if applicable.
int Texture::getFilter ( ) const
inline

Definition at line 233 of file aux_texture.h.

References ismipmapped.

234  {
235  return ismipmapped;
236  }
int Texture::getImageTarget ( ) const
inline

Definition at line 243 of file aux_texture.h.

References image_target.

244  {
245  return image_target;
246  }
int Texture::getStage ( ) const
inline

Definition at line 228 of file aux_texture.h.

References stage.

229  {
230  return stage;
231  }
int Texture::getTarget ( ) const
inline

Definition at line 238 of file aux_texture.h.

References texture_target.

239  {
240  return texture_target;
241  }
void Texture::InitTexture ( )

Inits the class with default values.

Definition at line 114 of file aux_texture.cpp.

References DEFAULT_ADDRESS_MODE, f, Mesh::refcount, and Vector.

115 {
116  bound = false;
117  original = 0;
118  refcount = 0;
119  name = -1;
120  palette = NULL;
121  data = NULL;
122  mintcoord = Vector( 0.0f, 0.0f, 0.0f );
123  maxtcoord = Vector( 1.0f, 1.0f, 1.0f );
125 }
void Texture::Load ( const char *  FileNameRGB,
const char *  FileNameA,
int  stage = 0,
enum FILTER  mipmap = MIPMAP,
enum TEXTURE_TARGET  target = TEXTURE2D,
enum TEXTURE_IMAGE_TARGET  imagetarget = TEXTURE_2D,
float  alpha = 1,
int  zeroval = 0,
GFXBOOL  force = GFXFALSE,
int  max_dimension_size = 65536,
GFXBOOL  detail_texture = GFXFALSE,
GFXBOOL  nocache = false,
enum ADDRESSMODE  address_mode = DEFAULT_ADDRESS_MODE,
Texture main = 0 
)

Definition at line 420 of file aux_texture.cpp.

References VSFileSystem::VSFile::Close(), f, VSFileSystem::FileNotFound, g_game, VegaConfig::getVariable(), NEAREST, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), XMLSupport::parse_bool(), VSFileSystem::Shared, VSFileSystem::TextureFile, VSFileSystem::Unspecified, game_data_t::use_textures, and vs_config.

434 {
435  if (data) free( data );
436  if (palette) free( palette );
437  data = NULL;
438  palette = NULL;
439  ismipmapped = mipmap;
440 
441  this->stage = stage;
442  this->address_mode = address_mode;
443  texture_target = target;
444  image_target = imagetarget;
445  string texfn = string( FileNameRGB )+string( "|" )+string( FileNameA );
446  if (!nocache) {
447  string tempstr;
448  if ( checkold( texfn, false, tempstr )
449  || checkold( texfn, true, tempstr ) ) {
450  texfilename = tempstr;
451  return;
452  }
453  }
454  //VSFileSystem::vs_fprintf (stderr,"2.Loading bmp file %s alp %s ",FileNameRGB,FileNameA);
455  //this->texfilename = texfilename;
456  //strcpy (filename,texfilename.c_str());
457  VSFile f;
458  VSError err = Unspecified;
459  err = f.OpenReadOnly( FileNameRGB, TextureFile );
460  if (!nocache) {
461  bool shared = (err == Shared);
462  string tempstr;
463  modold( texfn, shared, tempstr );
464  texfilename = tempstr;
465  }
466  if (err <= Ok && g_game.use_textures == 0 && !force_load) {
467  f.Close();
468  err = Unspecified;
469  }
470  if (err > Ok) {
472  return;
473  }
474  VSFile f1;
475  VSError err1 = Unspecified;
476  bool shared1;
477  if (FileNameA) {
478  static bool use_alphamap =
479  parse_bool( vs_config->getVariable( "graphics",
480  "bitmap_alphamap",
481  "true" ) );
482  if (use_alphamap) {
483  std::string tmp;
484  f1.OpenReadOnly( FileNameA, TextureFile );
485 
486  shared1 = (err1 == Shared);
487  if (err1 > Ok) {
488  data = NULL;
489  FileNameA = NULL;
490  }
491  } else {FileNameA = 0; }}
492  if (err1 > Ok)
493  data = this->ReadImage( &f, NULL, true, NULL );
494  else
495  data = this->ReadImage( &f, NULL, true, &f1 );
496  if (data) {
497  if (mode >= _DXT1 && mode <= _DXT5) {
498  if ( (int) data[0] == 0 ) {
499  detailtexture = NEAREST;
501  }
502  }
503  if (main)
504  Bind( main, maxdimension, detailtexture );
505  else
506  Bind( maxdimension, detailtexture );
507  free( data );
508  data = NULL;
509  if (!nocache) setold();
510  } else {
512  }
513  f.Close();
514  if (err1 <= Ok)
515  f1.Close();
516  //VSFileSystem::vs_fprintf (stderr,"Load Success\n");
517 }
void Texture::Load ( const char *  FileName,
int  stage = 0,
enum FILTER  mipmap = MIPMAP,
enum TEXTURE_TARGET  target = TEXTURE2D,
enum TEXTURE_IMAGE_TARGET  imagetarget = TEXTURE_2D,
GFXBOOL  force = GFXFALSE,
int  max_dimension_size = 65536,
GFXBOOL  detail_texture = GFXFALSE,
GFXBOOL  nocache = false,
enum ADDRESSMODE  address_mode = DEFAULT_ADDRESS_MODE,
Texture main = 0 
)

Definition at line 278 of file aux_texture.cpp.

References bootstrap_draw(), VSFileSystem::VSFile::Close(), f, VSFileSystem::FileNotFound, g_game, VegaConfig::getVariable(), NEAREST, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), XMLSupport::parse_bool(), VSFileSystem::Shared, VSFileSystem::TextureFile, VSFileSystem::Unspecified, game_data_t::use_textures, VSFileSystem::VSFile::Valid(), and vs_config.

289 {
290  if (data) free( data );
291  if (palette) free( palette );
292  data = NULL;
293  palette = NULL;
294  ismipmapped = mipmap;
295  texture_target = target;
296  image_target = imagetarget;
297  this->stage = stage;
298  this->address_mode = address_mode;
299  string texfn = string( FileName );
300  if ( checkbad( texfn ) )
301  return;
302  if (!nocache) {
303  string tempstr;
304  if ( checkold( texfn, false, tempstr )
305  || checkold( texfn, true, tempstr ) ) {
306  texfilename = tempstr;
307  return;
308  }
309  }
310  //VSFileSystem::vs_fprintf (stderr,"1.Loading bmp file %s ",FileName);
311  char *t = strdup( FileName );
312  int tmp = strlen( FileName );
313  if (tmp > 3) {
314  t[tmp-3] = 'a';
315  t[tmp-2] = 'l';
316  t[tmp-1] = 'p';
317  }
318  VSFile f2;
320  if (t) {
321  if (t[0] != '\0') {
322  static bool use_alphamap = parse_bool( vs_config->getVariable( "graphics",
323  "bitmap_alphamap",
324  "true" ) );
325  if (use_alphamap)
326  err2 = f2.OpenReadOnly( t, TextureFile );
327  }
328  }
329  if (err2 <= Ok) {
330  //texfilename += string(t);
331  }
332  //this->texfilename = texfilename;
333  //strcpy (filename,texfilename.c_str());
334  VSFile f;
335  VSError err; //FIXME err not always initialized before use
336  err = Ok; //FIXME this line added temporarily by chuck_starchaser
337  if (FileName)
338  if (FileName[0])
339  err = f.OpenReadOnly( FileName, TextureFile );
340  bool shared = (err == Shared);
341  free( t );
342  if (err <= Ok && g_game.use_textures == 0 && !force_load) {
343  f.Close();
344  err = Unspecified;
345  }
346  if (err > Ok) { //FIXME err not guaranteed to have been initialized!
347  FileNotFound( texfn );
348 //VSFileSystem::vs_fprintf (stderr, "\n%s, not found\n",FileName);
349  if (err2 <= Ok)
350  f2.Close();
351  return;
352  }
353  if (!nocache) {
354  string tempstr;
355  modold( texfn, shared, tempstr );
356  texfilename = tempstr;
357  }
358  if (texfn.find( "white" ) == string::npos)
359  bootstrap_draw( "Loading "+string( FileName ) );
360  //strcpy(filename, FileName);
361  if (err2 > Ok)
362  data = this->ReadImage( &f, NULL, true, NULL );
363  else
364  data = this->ReadImage( &f, NULL, true, &f2 );
365  if (data) {
366  if (mode >= _DXT1 && mode <= _DXT5) {
367  if ( (int) data[0] == 0 ) {
368  detailtexture = NEAREST;
370  }
371  }
372  if (main)
373  Bind( main, maxdimension, detailtexture );
374  else
375  Bind( maxdimension, detailtexture );
376  free( data );
377  data = NULL;
378  if (!nocache) setold();
379  } else {
381  }
382  f.Close();
383  if ( f2.Valid() )
384  f2.Close();
385  //VSFileSystem::vs_fprintf (stderr," Load Success\n");
386 }
virtual bool Texture::LoadSuccess ( )
inlinevirtual

If the texture has loaded properly returns true.

Reimplemented in AnimatedTexture.

Definition at line 287 of file aux_texture.h.

References name.

Referenced by ActivateWhite(), DecalQueue::AddTexture(), Background::Background(), VSSprite::LoadSuccess(), GuiTexture::read(), and VSSprite::VSSprite().

288  {
289  return name >= 0;
290  }
virtual void Texture::MakeActive ( int  stage)
inlinevirtual

Reimplemented in AnimatedTexture, and StreamTexture.

Definition at line 269 of file aux_texture.h.

References MakeActive().

270  {
271  MakeActive( stage, 0 );
272  } //Assumes pass=0
void Texture::MakeActive ( int  stage,
int  pass 
)
virtual

Reimplemented in AnimatedTexture.

Definition at line 665 of file aux_texture.cpp.

References ActivateWhite(), CLAMP, CUBEMAP, DEFAULT_ADDRESS_MODE, GFXActiveTexture(), GFXSelectTexture(), GFXTextureAddressMode(), TEXTURE1D, TEXTURE2D, TEXTURE3D, TEXTURERECT, and WRAP.

666 {
667  static bool missing = false;
668  if ( (name == -1) || (pass != 0) ) {
669  ActivateWhite( stag );
670  } else {
671  // Lazy-init default address mode
672  // So that texture_target is properly initiated
673  // by the time we do
675  switch (texture_target)
676  {
677  case TEXTURE1D:
678  case TEXTURE2D:
679  #ifdef GL_EXT_texture3D
680  case TEXTURE3D:
681  #endif
682  default:
683  address_mode = WRAP;
684  break;
685  case TEXTURERECT:
686  case CUBEMAP:
688  break;
689  }
690  }
691 
692  GFXActiveTexture( stag );
693  GFXSelectTexture( name, stag );
694  GFXTextureAddressMode( address_mode, texture_target ); //In case it changed - it's possible
695  }
696 }
void Texture::modold ( const std::string &  s,
bool  shared,
std::string &  hashname 
)

Definition at line 100 of file aux_texture.cpp.

References data, VSFileSystem::GetHashName(), VSFileSystem::GetSharedTextureHashName(), name, original, refcount, texHashTable, and BaseUtil::Texture().

101 {
102  hashname = shared ? VSFileSystem::GetSharedTextureHashName( s ) : VSFileSystem::GetHashName( s );
103  Texture *oldtex = new Texture;
104  //oldtex->InitTexture();new calls this
105  oldtex->name = -1;
106  oldtex->refcount = 1;
107  oldtex->original = NULL;
108  oldtex->palette = NULL;
109  oldtex->data = NULL;
110  texHashTable.Put( hashname, oldtex );
111  original = oldtex;
112 }
virtual unsigned int Texture::numFrames ( ) const
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 191 of file aux_texture.h.

192  {
193  return 1;
194  } //Number of frames in an animated texture (or, rather, keyframes)
virtual unsigned int Texture::numLayers ( ) const
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 208 of file aux_texture.h.

Referenced by Background::Draw(), and VSSprite::Draw().

209  {
210  return 1;
211  } //Number of layers in the texture. If more than 1, makeActive() sets up multitexturing units, and other use of multitexture units, other than [stage..stage+numLayers), should be avoided. If not enough multitexturing units are available, special fall-back mechanisms should be implmemented by MakeActive() so that it still renders as correctly as possible. In that case, canMultiPass(), numPasses() and MakeActive(stage,pass) could be used to process in multipass mode (one stage at a time, or a stage group at a time, depending on fallback implementation), if possible.
virtual unsigned int Texture::numPasses ( ) const
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 213 of file aux_texture.h.

Referenced by Background::Draw(), and VSSprite::Draw().

214  {
215  return 1;
216  } //Number of passes when on multipass rendering.
bool Texture::operator< ( const Texture b) const

A way to sort the texture by the original address (to make sure like textures stick togehter.

Definition at line 59 of file aux_texture.cpp.

References Original().

60 {
61  return Original() < b.Original();
62 }
bool Texture::operator== ( const Texture b) const

A way to test if the texture is equal to another based on original values.

Definition at line 64 of file aux_texture.cpp.

References Original().

65 {
66  return Original() == b.Original();
67 }
const Texture * Texture::Original ( ) const
virtual

Reimplemented in AnimatedTexture.

Definition at line 136 of file aux_texture.cpp.

References Original().

Referenced by operator<(), operator==(), PipelinedTexture::Original(), AnimatedTexture::Original(), and Original().

137 {
138  if (original)
139  return original->Original();
140  else
141  return this;
142 }
Texture * Texture::Original ( )
virtual

Reimplemented in AnimatedTexture, and PipelinedTexture.

Definition at line 144 of file aux_texture.cpp.

References Original().

145 {
146  if (original)
147  return original->Original();
148  else
149  return this;
150 }
void Texture::Prioritize ( float  priority)
virtual

Changes priority of texture.

Definition at line 653 of file aux_texture.cpp.

References GFXPrioritizeTexture().

654 {
655  GFXPrioritizeTexture( name, priority );
656 }
void Texture::setbad ( const string &  s)

Definition at line 199 of file aux_texture.cpp.

References b, badtexHashTable, bool, VSFileSystem::current_path, VSFileSystem::GetHashName(), and VSFileSystem::GetSharedTextureHashName().

200 {
201  //Put both current path+texfile and shared texfile since they both have been looked for
202  bool *b = new bool(true);
203  if (VSFileSystem::current_path.back() != "")
206 }
void Texture::setold ( )

Loads the old texture.

Definition at line 127 of file aux_texture.cpp.

128 {
129  //*original = *this;//will be obsoleted in new C++ standard unpredictable results when using string() (and its strangeass copy constructor)
130  *original = *this;
131  //memcpy (original, this, sizeof (Texture));
132  original->original = NULL;
133  original->refcount++;
134 }
void Texture::setReference ( Texture other)

Make this instance a reference of "other".

Definition at line 69 of file aux_texture.cpp.

References bound, boundMode, boundSizeX, boundSizeY, data, image_target, name, refcount, texfilename, and texture_target.

70 {
71  original = other;
72  original->refcount++;
73 
74  //Copy shared attributes
75  texfilename = other->texfilename;
76  data = other->data;
77  name = other->name;
78  bound = other->bound;
79  boundSizeX = other->boundSizeX;
80  boundSizeY = other->boundSizeY;
81  boundMode = other->boundMode;
83  image_target = other->image_target;
84 }
virtual void Texture::setTime ( double  tim)
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 201 of file aux_texture.h.

Referenced by VSSprite::SetTime().

201 {}
virtual bool Texture::SetupPass ( int  pass,
const enum BLENDFUNC  src,
const enum BLENDFUNC  dst 
)
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 276 of file aux_texture.h.

References stage.

Referenced by Background::Draw(), and VSSprite::Draw().

277  {
278  return SetupPass( pass, stage, src, dst );
279  } //If one is going to perform multipass rendering of this texture, the Texture() must handle blending - SetupPass() sets up blending. If it returns false, then blending is not compatible with the requested blend mode emulation. One may assume that if numPasses()==1, no SetupPass() is needed. pass==-1 means restore setup. You should call it after multipass rendering.
virtual bool Texture::SetupPass ( int  pass,
int  stage,
const enum BLENDFUNC  src,
const enum BLENDFUNC  dst 
)
inlinevirtual

Reimplemented in AnimatedTexture.

Definition at line 281 of file aux_texture.h.

282  {
283  return true;
284  } //If one is going to perform multipass rendering of this texture, the Texture() must handle blending - SetupPass() sets up blending. If it returns false, then blending is not compatible with the requested blend mode emulation. One may assume that if numPasses()==1, no SetupPass() is needed. pass==-1 means restore setup. You should call it after multipass rendering.
void Texture::Transfer ( int  maxdimension,
GFXBOOL  detailtexture 
)
protected

Transfers this texture to GFX library.

Definition at line 552 of file aux_texture.cpp.

References CUBEMAP_NEGATIVE_X, CUBEMAP_NEGATIVE_Y, CUBEMAP_NEGATIVE_Z, CUBEMAP_POSITIVE_X, CUBEMAP_POSITIVE_Y, CUBEMAP_POSITIVE_Z, DXT1, DXT1RGBA, DXT3, DXT5, GFXTransferTexture(), PALETTE8, RGB24, and RGBA32.

Referenced by AnimatedTexture::MakeActive().

553 {
554  //Implement this in D3D
555  //if(mode == _8BIT)
556  //glColorTable(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB8, 256, GL_RGB, GL_UNSIGNED_BYTE, palette);
557 
558  TEXTUREFORMAT internformat;
559  switch (mode)
560  {
561  //send DXT1,DXT3,DXT5 ...need to have the function call other glcompressedTexImage2D function
562  case _DXT1:
563  internformat = DXT1;
564  break;
565  case _DXT1RGBA:
566  internformat = DXT1RGBA;
567  break;
568  case _DXT3:
569  internformat = DXT3;
570  break;
571  case _DXT5:
572  internformat = DXT5;
573  break;
574  case _24BITRGBA:
575  internformat = RGBA32;
576  break;
577  case _24BIT:
578  internformat = RGB24;
579  break;
580  case _8BIT:
581  internformat = PALETTE8;
582  break;
583  default:
584  return;
585  }
586  if (img_sides == SIDE_SINGLE) {
587  GFXTransferTexture( data, name, sizeX, sizeY, internformat, image_target, maxdimension, detailtexture );
588  } else {
589  GFXTransferTexture( data, name, sizeX, sizeY, internformat, CUBEMAP_POSITIVE_X, maxdimension, detailtexture, 0 );
590  GFXTransferTexture( data, name, sizeX, sizeY, internformat, CUBEMAP_NEGATIVE_X, maxdimension, detailtexture, 1 );
591  GFXTransferTexture( data, name, sizeX, sizeY, internformat, CUBEMAP_POSITIVE_Y, maxdimension, detailtexture, 2 );
592  GFXTransferTexture( data, name, sizeX, sizeY, internformat, CUBEMAP_NEGATIVE_Y, maxdimension, detailtexture, 3 );
593  GFXTransferTexture( data, name, sizeX, sizeY, internformat, CUBEMAP_POSITIVE_Z, maxdimension, detailtexture, 4 );
594  GFXTransferTexture( data, name, sizeX, sizeY, internformat, CUBEMAP_NEGATIVE_Z, maxdimension, detailtexture, 5 );
595  }
596 }
void Texture::UnBind ( )
protected

UnBinds from GFX library.

Definition at line 542 of file aux_texture.cpp.

References GFXDeleteTexture(), and texHashTable.

543 {
544  if (name != -1) {
545  texHashTable.Delete( texfilename );
547  name = -1;
548  }
549  //glDeleteTextures(1, &name);
550 }

Member Data Documentation

enum ADDRESSMODE Texture::address_mode

The address mode being used with this texture.

Definition at line 78 of file aux_texture.h.

bool Texture::bound

For re-biding.

Definition at line 66 of file aux_texture.h.

Referenced by Bind(), AnimatedTexture::Clone(), and setReference().

VSImageMode Texture::boundMode

Definition at line 68 of file aux_texture.h.

Referenced by Bind(), and setReference().

uint Texture::boundSizeX

Definition at line 67 of file aux_texture.h.

Referenced by Bind(), Background::Draw(), and setReference().

uint Texture::boundSizeY

Definition at line 67 of file aux_texture.h.

Referenced by Bind(), Background::Draw(), and setReference().

unsigned char* Texture::data
enum FILTER Texture::ismipmapped

the filter mode of this texture

Definition at line 48 of file aux_texture.h.

Referenced by getFilter(), PipelinedTexture::PipelinedTexture(), and StreamTexture::StreamTexture().

Vector Texture::mintcoord

The minimum/maximum texturing coordinates for this texture (have in mind that it is not always enforce, ie. for meshes) (i=s, j=t, k=u)

Definition at line 60 of file aux_texture.h.

Referenced by Background::Draw(), VSSprite::Draw(), Animation::DrawAsVSSprite(), Animation::DrawNoTransform(), Animation::DrawNow(), AnimatedTexture::LoadAni(), AnimatedTexture::LoadVideoSource(), and AnimatedTexture::MakeActive().

Texture* Texture::original
int Texture::refcount

The number of references on the original data.

Definition at line 71 of file aux_texture.h.

Referenced by Clone(), modold(), PipelinedTexture::PipelinedTexture(), setReference(), and StreamTexture::StreamTexture().

StringPool::Reference Texture::texfilename

The file name used to load this texture.

Definition at line 45 of file aux_texture.h.

Referenced by buildShipDescription(), and setReference().

enum TEXTURE_TARGET Texture::texture_target

The target this will go to (cubemap or otherwise)

Definition at line 74 of file aux_texture.h.

Referenced by VSSprite::Draw(), getTarget(), AnimatedTexture::LoadVideoSource(), PipelinedTexture::PipelinedTexture(), setReference(), and StreamTexture::StreamTexture().


The documentation for this class was generated from the following files: