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
aux_texture.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2001-2002 Daniel Horn
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 #ifndef _TEXTURE_H_
22 #define _TEXTURE_H_
23 #include "vsimage.h"
24 #include "gfxlib.h"
25 #include "gfxlib_struct.h"
26 #include "../SharedPool.h"
27 
28 #include <string>
29 //#include "vsimage.h"
30 //#include "vsfilesystem.h" this is included by gfxlib.h
31 
37 ;
38 class Texture : public::VSImage
39 {
40  typedef unsigned int uint;
41 public:
42  void FileNotFound( const std::string& ); //undoes what it did to hash table when file is not located
43 
46 
49 
51  unsigned char *data;
52 
54  int name;
55 
57  int stage;
58 
61 
64 
66  bool bound;
68  VSImageMode boundMode;
69 
71  int refcount;
72 
76 
79 
81  GFXBOOL checkold( const std::string &s, bool shared, std::string &hashname );
82  void modold( const std::string &s, bool shared, std::string &hashname );
83 
85  void setold();
86  bool checkbad( const string &s );
87  void setbad( const string &s );
88 
90  void InitTexture();
91 
92 protected:
93 
95  int Bind( int maxdimension, GFXBOOL detailtexture );
96 
98  void UnBind();
99 
101  void Transfer( int maxdimension, GFXBOOL detailtexture );
102 
103 public:
104 
106  int Bind( Texture *other, int maxdimension = 65536, GFXBOOL detailtexture = GFXFALSE );
107 
108 public:
109 
111  Texture( int stage = 0,
112  enum FILTER mipmap = MIPMAP,
113  enum TEXTURE_TARGET target = TEXTURE2D,
114  enum TEXTURE_IMAGE_TARGET imagetarget = TEXTURE_2D,
116 
118  Texture( const char*,
119  const char*,
120  int stage = 0,
121  enum FILTER mipmap = MIPMAP,
122  enum TEXTURE_TARGET target = TEXTURE2D,
123  enum TEXTURE_IMAGE_TARGET imagetarget = TEXTURE_2D,
124  float alpha = 1,
125  int zeroval = 0,
126  GFXBOOL force = GFXFALSE,
127  int max_dimension_size = 65536,
128  GFXBOOL detail_texture = GFXFALSE,
129  GFXBOOL nocache = false,
131  Texture *main = 0 );
132 
134  Texture( const char *FileName,
135  int stage = 0,
136  enum FILTER mipmap = MIPMAP,
137  enum TEXTURE_TARGET target = TEXTURE2D,
138  enum TEXTURE_IMAGE_TARGET imagetarget = TEXTURE_2D,
139  GFXBOOL force = GFXFALSE,
140  int max_dimension_size = 65536,
141  GFXBOOL detail_texture = GFXFALSE,
142  GFXBOOL nocache = false,
144  Texture *main = 0 );
146  int stage = 0,
147  enum FILTER mipmap = MIPMAP,
148  enum TEXTURE_TARGET target = TEXTURE2D,
149  enum TEXTURE_IMAGE_TARGET imagetarget = TEXTURE_2D,
150  GFXBOOL force = GFXFALSE,
151  int max_dimension_size = 65536,
152  GFXBOOL detail_texture = GFXFALSE,
153  GFXBOOL nocache = false,
155  Texture *main = 0 );
156  void Load( const char*,
157  const char*,
158  int stage = 0,
159  enum FILTER mipmap = MIPMAP,
160  enum TEXTURE_TARGET target = TEXTURE2D,
161  enum TEXTURE_IMAGE_TARGET imagetarget = TEXTURE_2D,
162  float alpha = 1,
163  int zeroval = 0,
164  GFXBOOL force = GFXFALSE,
165  int max_dimension_size = 65536,
166  GFXBOOL detail_texture = GFXFALSE,
167  GFXBOOL nocache = false,
169  Texture *main = 0 );
170  void Load( const char *FileName,
171  int stage = 0,
172  enum FILTER mipmap = MIPMAP,
173  enum TEXTURE_TARGET target = TEXTURE2D,
174  enum TEXTURE_IMAGE_TARGET imagetarget = TEXTURE_2D,
175  GFXBOOL force = GFXFALSE,
176  int max_dimension_size = 65536,
177  GFXBOOL detail_texture = GFXFALSE,
178  GFXBOOL nocache = false,
180  Texture *main = 0 );
181  virtual const Texture * Original() const;
182  virtual Texture * Original();
183  virtual Texture * Clone();
184 
186  //Texture (Texture *t);
187 
189  virtual ~Texture();
190 
191  virtual unsigned int numFrames() const
192  {
193  return 1;
194  } //Number of frames in an animated texture (or, rather, keyframes)
195 
196  virtual double curTime() const
197  {
198  return 0;
199  } //Current time of an animated texture
200 
201  virtual void setTime( double tim ) {}
202 
203  virtual float framesPerSecond() const
204  {
205  return 0;
206  } //Frames per second, if applicable.
207 
208  virtual unsigned int numLayers() const
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.
212 
213  virtual unsigned int numPasses() const
214  {
215  return 1;
216  } //Number of passes when on multipass rendering.
217 
218  virtual bool canMultiPass() const
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.
222 
223  virtual bool constFrameRate() const
224  {
225  return true;
226  } //If frames advance at a regular rate - keyframe based animations would return false.
227 
228  int getStage() const
229  {
230  return stage;
231  }
232 
233  int getFilter() const
234  {
235  return ismipmapped;
236  }
237 
238  int getTarget() const
239  {
240  return texture_target;
241  }
242 
243  int getImageTarget() const
244  {
245  return image_target;
246  }
247 
249  static Texture * Exists( std::string s );
250 
252  static Texture * Exists( std::string s, std::string a );
253 
255  bool operator<( const Texture &b ) const;
256 
258  bool operator==( const Texture &b ) const;
259 
261  void setReference( Texture *other );
262 
264  virtual void MakeActive()
265  {
266  MakeActive( this->stage, 0 );
267  } //Assumes stage=this->stage, pass=0
268 
269  virtual void MakeActive( int stage )
270  {
271  MakeActive( stage, 0 );
272  } //Assumes pass=0
273 
274  virtual void MakeActive( int stage, int pass );
275 
276  virtual bool SetupPass( int pass, const enum BLENDFUNC src, const enum BLENDFUNC dst )
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.
280 
281  virtual bool SetupPass( int pass, int stage, const enum BLENDFUNC src, const enum BLENDFUNC dst )
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.
285 
287  virtual bool LoadSuccess()
288  {
289  return name >= 0;
290  }
291 
293  virtual void Prioritize( float );
294 };
295 
296 #endif
297