#include <rTexture.h>
Public Member Functions | |
rSurface (char const *fileName, tPath const *path=&tDirectories::Data()) | |
constructor creating the surface from a file | |
~rSurface () | |
destructor | |
rSurface (rSurface const &other) | |
copy constructor | |
rSurface & | operator= (rSurface const &other) |
copy operator | |
SDL_Surface * | GetSurface (void) const |
Gets the surface itself. | |
rSurface const & | GetSurface (SDL_Surface *&surface) const |
Gets the surface itself. | |
GLenum const & | GetFormat (void) const |
Gets openGL texture format to use. | |
rSurface const & | GetFormat (GLenum &format) const |
Gets openGL texture format to use. | |
Protected Member Functions | |
rSurface () | |
default constructor, not creating a real surface | |
void | Init () |
initialize data members | |
void | Clear () |
destroys data members | |
void | Create (char const *fileName, tPath const *path=&tDirectories::Data()) |
create surface from file | |
void | Create (SDL_Surface *surface) |
take ownership of surface | |
rSurface & | SetSurface (SDL_Surface *surface) |
Sets the surface itself. | |
rSurface & | SetFormat (GLenum const &format) |
Sets openGL texture format to use. | |
Private Member Functions | |
void | CopyFrom (rSurface const &other) |
copy function | |
Private Attributes | |
SDL_Surface * | surface_ |
the surface itself | |
GLenum | format_ |
OpenGL texture format to use. |
Definition at line 60 of file rTexture.h.
rSurface::rSurface | ( | char const * | fileName, | |
tPath const * | path = &tDirectories::Data() | |||
) | [explicit] |
rSurface::~rSurface | ( | void | ) |
destructor
Definition at line 116 of file rTexture.cpp.
References Clear().
00117 { 00118 Clear(); 00119 }
rSurface::rSurface | ( | rSurface const & | other | ) |
copy constructor
other | source to copy from |
Definition at line 145 of file rTexture.cpp.
References CopyFrom(), and Init().
rSurface::rSurface | ( | void | ) | [protected] |
default constructor, not creating a real surface
Definition at line 130 of file rTexture.cpp.
References Init().
00131 { 00132 Init(); 00133 }
copy operator
other |
Definition at line 162 of file rTexture.cpp.
References Clear(), and CopyFrom().
00163 { 00164 if ( &other != this ) 00165 { 00166 Clear(); 00167 CopyFrom( other ); 00168 } 00169 00170 return *this; 00171 }
void rSurface::Init | ( | void | ) | [protected] |
initialize data members
Definition at line 182 of file rTexture.cpp.
References format_, and surface_.
Referenced by rSurface().
void rSurface::Clear | ( | void | ) | [protected] |
destroys data members
Definition at line 197 of file rTexture.cpp.
References surface_.
Referenced by Create(), operator=(), and ~rSurface().
00198 { 00199 #ifndef DEDICATED 00200 // delete surface 00201 if ( surface_ ) 00202 SDL_FreeSurface( surface_ ); 00203 00204 #endif 00205 surface_ = 0; 00206 }
void rSurface::Create | ( | char const * | fileName, | |
tPath const * | path = &tDirectories::Data() | |||
) | [protected] |
create surface from file
fileName | name of the image file to load |
Definition at line 218 of file rTexture.cpp.
References tPath::GetReadPath(), sr_LockSDL(), and sr_UnlockSDL().
Referenced by rSurface().
00219 { 00220 #ifndef DEDICATED 00221 sr_LockSDL(); 00222 00223 IMG_InvertAlpha(true); 00224 00225 // find path of image and load it 00226 SDL_Surface *surface; 00227 if(path) { 00228 tString s = path->GetReadPath( fileName ); 00229 surface = IMG_Load(s); 00230 } else { 00231 surface = IMG_Load(fileName); 00232 } 00233 Create(surface); 00234 00235 //if ( surface_ ) 00236 // std::cerr << "loaded surface " << fileName << "\n"; 00237 00238 sr_UnlockSDL(); 00239 #endif 00240 }
void rSurface::Create | ( | SDL_Surface * | surface | ) | [protected] |
take ownership of surface
surface |
Definition at line 252 of file rTexture.cpp.
References Clear(), format_, and surface_.
00253 { 00254 #ifndef DEDICATED 00255 // clear previous surface 00256 Clear(); 00257 00258 // take ownership 00259 surface_ = surface; 00260 00261 // determine texture format 00262 if ( surface_ ) 00263 { 00264 switch (surface_->format->BytesPerPixel){ 00265 case 1: 00266 format_ = GL_LUMINANCE; 00267 break; 00268 00269 case 2: 00270 format_ = GL_LUMINANCE8_ALPHA8; 00271 break; 00272 00273 case 3: 00274 format_ = GL_RGB; 00275 break; 00276 00277 case 4: 00278 format_ = GL_RGBA; 00279 break; 00280 00281 default: 00282 { 00283 // fallback: convert the texture into a known format. 00284 00285 SDL_Surface *dummy = 00286 SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 00287 32, 00288 0x0000FF, 0x00FF00, 00289 0xFF0000 ,0xFF000000); 00290 00291 SDL_Surface *convtex = 00292 SDL_ConvertSurface(surface_, dummy->format, SDL_SWSURFACE); 00293 00294 SDL_FreeSurface(surface_); 00295 surface_ = convtex; 00296 SDL_FreeSurface(dummy); 00297 00298 format_ = GL_RGBA; 00299 } 00300 break; 00301 } 00302 } 00303 #endif 00304 }
void rSurface::CopyFrom | ( | rSurface const & | other | ) | [private] |
copy function
other |
Definition at line 316 of file rTexture.cpp.
References format_, surface_, and tASSERT.
Referenced by operator=(), and rSurface().
00317 { 00318 #ifndef DEDICATED 00319 tASSERT( 0 == surface_ ); 00320 tASSERT( other.surface_ ); 00321 00322 // copy surface 00323 surface_ = SDL_ConvertSurface(other.surface_, other.surface_->format, SDL_SWSURFACE); 00324 00325 // copy flags 00326 format_ = other.format_; 00327 #endif 00328 }
SDL_Surface * rSurface::GetSurface | ( | void | ) | const [inline] |
Gets the surface itself.
Definition at line 260 of file rTexture.h.
References surface_.
Referenced by rSurfaceTexture::OnSelect(), rFileTexture::OnSelect(), sg_SetIcon(), and rISurfaceTexture::Upload().
00261 { 00262 return this->surface_; 00263 }
rSurface const & rSurface::GetSurface | ( | SDL_Surface *& | surface | ) | const [inline] |
Gets the surface itself.
surface | the surface itself to fill |
Definition at line 276 of file rTexture.h.
References surface_.
00277 { 00278 surface = this->surface_; 00279 return *this; 00280 }
GLenum const & rSurface::GetFormat | ( | void | ) | const [inline] |
Gets openGL texture format to use.
Definition at line 309 of file rTexture.h.
References format_.
Referenced by rISurfaceTexture::Upload().
00310 { 00311 return this->format_; 00312 }
rSurface const & rSurface::GetFormat | ( | GLenum & | format | ) | const [inline] |
Gets openGL texture format to use.
format | OpenGL texture format to use to fill |
Definition at line 325 of file rTexture.h.
References format_.
00326 { 00327 format = this->format_; 00328 return *this; 00329 }
rSurface & rSurface::SetSurface | ( | SDL_Surface * | surface | ) | [inline, protected] |
Sets the surface itself.
surface | the surface itself to set |
Definition at line 293 of file rTexture.h.
References surface_.
00294 { 00295 this->surface_ = surface; 00296 return *this; 00297 }
rSurface & rSurface::SetFormat | ( | GLenum const & | format | ) | [inline, protected] |
Sets openGL texture format to use.
format | OpenGL texture format to use to set |
Definition at line 342 of file rTexture.h.
References format_.
00343 { 00344 this->format_ = format; 00345 return *this; 00346 }
SDL_Surface* rSurface::surface_ [private] |
the surface itself
Definition at line 76 of file rTexture.h.
Referenced by Clear(), CopyFrom(), Create(), GetSurface(), Init(), and SetSurface().
GLenum rSurface::format_ [private] |
OpenGL texture format to use.
Definition at line 77 of file rTexture.h.
Referenced by CopyFrom(), Create(), GetFormat(), Init(), and SetFormat().