TORCS  1.3.9
The Open Racing Car Simulator
grtexture.h
Go to the documentation of this file.
1 /***************************************************************************
2 
3  file : grtexture.h
4  created : Wed Jun 1 14:56:31 CET 2005
5  copyright : (C) 2005 by Bernhard Wymann
6  version : $Id$
7 
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 /*
20  This classes/methods are used to handle texture compression and
21  textures which are shared among multiple objects. In the long term
22  they should obsolete parts of grutil.cpp.
23 */
24 
25 #ifndef _GRTEXTURE_H_
26 #define _GRTEXTURE_H_
27 
28 #include <stdio.h>
29 #include <plib/ssg.h>
30 #include <glfeatures.h>
31 #include "grloadsgi.h"
32 
33 bool doMipMap(const char *tfname, int mipmap);
34 void grRemoveState(char* img);
35 
36 
37 // This state does currently not manage anything!
38 // TODO: manage shared textures, obsolete grutil.cpp parts.
39 class grManagedState : public ssgSimpleState {
40  public:
41 
42  /*static int ms;
43 
44  grManagedState() {
45  GfError("Created state: %0xd, #: %d\n", this, ++ms);
46  }
47 */
48  virtual ~grManagedState() {
49  //GfError("delete this: %0xd, #: %d\n", this, --ms);
50  if (this->getTexture() != NULL) {
51  grRemoveState(this->getTexture()->getFilename());
52  }
53  }
54 
55  virtual void setTexture(ssgTexture *tex) {
56  //printf("tex: %s\n", tex->getFilename());
57  ssgSimpleState::setTexture(tex);
58  }
59 
60  virtual void setTexture(const char *fname, int _wrapu = TRUE, int _wrapv = TRUE, int _mipmap = TRUE) {
61  //printf("texw: %s\n", fname);
62  _mipmap = doMipMap(fname, _mipmap);
63  ssgSimpleState::setTexture(fname, _wrapu, _wrapv, _mipmap);
64  }
65 
66  virtual void setTexture(GLuint tex) {
67  printf("Obsolete call: setTexture(GLuint tex)\n");
68  ssgSimpleState::setTexture(tex);
69  }
70 };
71 
72 // Managed state factory.
73 inline grManagedState* grStateFactory(void) { return new grManagedState(); }
74 
75 // Prototype for mipmap generation.
76 bool grMakeMipMaps(GLubyte *image, int xsize, int ysize, int zsize, bool mipmap);
77 
78 // Prototype for SGI texture loading function.
79 bool grLoadSGI(const char *fname, ssgTextureInfo* info);
80 
81 // Register customized loader in plib.
82 void grRegisterCustomSGILoader(void);
83 
84 // SGI loader class to call customized ssgMakeMipMaps. This is necessary because
85 // of plib architecture which does not allow to customize the mipmap
86 // generation.
87 class grSGIHeader : public ssgSGIHeader {
88  public:
89  grSGIHeader(const char *fname, ssgTextureInfo* info);
90 };
91 
92 
93 
94 #endif // _GRTEXTURE_H_
grSGIHeader(const char *fname, ssgTextureInfo *info)
Definition: grtexture.cpp:118
void grRemoveState(char *img)
Definition: grutil.cpp:156
virtual ~grManagedState()
Definition: grtexture.h:48
bool grMakeMipMaps(GLubyte *image, int xsize, int ysize, int zsize, bool mipmap)
Definition: grtexture.cpp:213
grManagedState * grStateFactory(void)
Definition: grtexture.h:73
virtual void setTexture(const char *fname, int _wrapu=TRUE, int _wrapv=TRUE, int _mipmap=TRUE)
Definition: grtexture.h:60
void grRegisterCustomSGILoader(void)
Definition: grtexture.cpp:108
virtual void setTexture(GLuint tex)
Definition: grtexture.h:66
bool grLoadSGI(const char *fname, ssgTextureInfo *info)
Definition: grtexture.cpp:98
bool doMipMap(const char *tfname, int mipmap)
Definition: grtexture.cpp:29
virtual void setTexture(ssgTexture *tex)
Definition: grtexture.h:55