rISurfaceTexture Class Reference

abstract texture class working with SDL surfaces More...

#include <rTexture.h>

Inheritance diagram for rISurfaceTexture:

Inheritance graph
[legend]
Collaboration diagram for rISurfaceTexture:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 rISurfaceTexture (int group, bool repx=0, bool repy=0, bool storeAlpha=false)
 constructor setting flags
virtual ~rISurfaceTexture ()
 destructor
bool Loaded ()
 returns whether the texture is currently loaded

Static Public Attributes

static bool storageHack_ = false
 when set, this flag inhibits storage of the alpha channel (for compatibility with some cards)

Protected Member Functions

virtual void ProcessImage (SDL_Surface *)
 process the surface before uploading it to GL
void Upload (rSurface &surface)
 Uploads the passed surface to OpenGL (for use in OnSelect).
virtual void OnSelect (bool enforce)
 Selects the texture for rendering.
virtual void OnSelect ()=0
 Selects the texture for rendering (core part).
virtual void OnUnload ()
 Unloads the texture from OpenGL and memory.
void StoreAlpha ()
 sets the alpha store flag

Static Protected Attributes

static bool s_reportErrors_ = false
 flag indicating whether errors should be reported

Private Attributes

int group_
 the texture group (determines rendering options)
int textureModeLast_
 the last texture storage mode this texture was used with
rGLuintObjectTexture tint_
 the OpenGL id of this texture
bool repx_
bool repy_
 flags indicating whether the texture repeats in x and y direction
bool storeAlpha_
 flag indicating whether the alpha value should be stored


Detailed Description

abstract texture class working with SDL surfaces

Definition at line 124 of file rTexture.h.


Constructor & Destructor Documentation

rISurfaceTexture::rISurfaceTexture ( int  group,
bool  repx = 0,
bool  repy = 0,
bool  storeAlpha = false 
)

constructor setting flags

Parameters:
group texture group ( floor/wall)
repx flag indicating the x repeat mode
repy flag indicating the y repeat mode
storeAlpha flag indicating whether the alpha channel should be stored

Definition at line 438 of file rTexture.cpp.

00439         : group_( group ), textureModeLast_( -1), repx_( repx ), repy_( repy ), storeAlpha_( storeAlpha )
00440 {
00441 }

rISurfaceTexture::~rISurfaceTexture ( void   )  [virtual]

destructor

Definition at line 452 of file rTexture.cpp.

References rDisplayList::ClearAll(), and tint_.

00453 {
00454     if (tint_.IsValid() )
00455     {
00456         rDisplayList::ClearAll();
00457     }
00458 }

Here is the call graph for this function:


Member Function Documentation

bool rISurfaceTexture::Loaded (  )  [inline]

returns whether the texture is currently loaded

Definition at line 131 of file rTexture.h.

References textureModeLast_.

Referenced by gLogo::Display(), and rFont::OnSelect().

Here is the caller graph for this function:

void rISurfaceTexture::ProcessImage ( SDL_Surface *  surface  )  [protected, virtual]

process the surface before uploading it to GL

Parameters:
surface the surface to process

Reimplemented in rFont, and gTextureCycle.

Definition at line 470 of file rTexture.cpp.

Referenced by Upload().

00471 {
00472 }

Here is the caller graph for this function:

void rISurfaceTexture::Upload ( rSurface surface  )  [protected]

Uploads the passed surface to OpenGL (for use in OnSelect).

Parameters:
surface 

Definition at line 484 of file rTexture.cpp.

References rSurface::GetFormat(), rSurface::GetSurface(), GL_CLAMP_TO_EDGE, ProcessImage(), repx_, repy_, sr_LockSDL(), sr_texturesTruecolor, sr_UnlockSDL(), storageHack_, storeAlpha_, and tASSERT.

Referenced by rSurfaceTexture::OnSelect(), and rFileTexture::OnSelect().

00485 {
00486 #ifndef DEDICATED
00487     sr_LockSDL();
00488     GLenum texformat = surface.GetFormat();
00489     SDL_Surface * tex = surface.GetSurface();
00490     tASSERT( tex );
00491 
00492     bool texalpha=tex->format->Amask;
00493 
00494     ProcessImage(tex);
00495 
00496     if(repx_)
00497         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
00498     else
00499         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
00500     if(repy_)
00501         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
00502     else
00503         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
00504 
00505     int format;
00506     if (sr_texturesTruecolor)
00507         if (storageHack_ || ( storeAlpha_ && texalpha ) )
00508             format=GL_RGBA8;
00509         else
00510             format=GL_RGB8;
00511     else
00512         if (storageHack_ || ( storeAlpha_ && texalpha ) )
00513             format=GL_RGBA4;
00514         else
00515             format=GL_RGB5;
00516 
00517     gluBuild2DMipmaps(GL_TEXTURE_2D,format,tex->w,tex->h,
00518                       texformat,GL_UNSIGNED_BYTE,tex->pixels);
00519 
00520     sr_UnlockSDL();
00521  #endif
00522 }

Here is the call graph for this function:

Here is the caller graph for this function:

void rISurfaceTexture::OnSelect ( bool  enforce  )  [protected, virtual]

Selects the texture for rendering.

Parameters:
enforce enforce when set to true, the texture should be loaded even if the configuration says it should not

Implements rITexture.

Reimplemented in rFont, and gTextureCycle.

Definition at line 534 of file rTexture.cpp.

References rDisplayList::Cancel(), group_, rITexture::OnSelect(), OnSelect(), RenderEnd(), sr_glOut, rTextureGroups::TextureMode, textureModeLast_, tint_, and rITexture::Unload().

00535 {
00536 #ifndef DEDICATED
00537     if(sr_glOut)
00538     {
00539         RenderEnd(true);
00540 
00541         int texmod=rTextureGroups::TextureMode[group_];
00542         if (enforce && texmod<0) texmod=GL_NEAREST_MIPMAP_NEAREST;
00543 
00544         if(textureModeLast_!=texmod)
00545         {
00546             // unload texture if the mode changed
00547             Unload();
00548             // std::cerr << "loading texture " << fileName << ':' << tint << "\n";
00549 
00550             if (texmod>0){
00551                 // don't generate textures inside display lists
00552                 rDisplayList::Cancel();
00553 
00554                 glBindTexture(GL_TEXTURE_2D,tint_);
00555 
00556                 if (textureModeLast_<0)
00557                 {
00558                     // delegate core loading work to derived class
00559                     OnSelect();
00560                 }
00561 
00562                 //glEnable(GL_TEXTURE);
00563                 glEnable(GL_TEXTURE_2D);
00564 
00565                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
00566                                 texmod);
00567 
00568                 switch(texmod)
00569                 {
00570                 case GL_NEAREST:
00571                 case GL_NEAREST_MIPMAP_NEAREST:
00572                     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,
00573                                     GL_NEAREST);
00574                     break;
00575                 default:
00576                     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,
00577                                     GL_LINEAR);
00578                     break;
00579                 }
00580 
00581             }
00582             else
00583             {
00584                 glDisable(GL_TEXTURE_2D);
00585             }
00586         }
00587         else
00588         {
00589             glBindTexture(GL_TEXTURE_2D,tint_);
00590             if (texmod>0)
00591             {
00592                 glEnable(GL_TEXTURE_2D);
00593             }
00594             else
00595             {
00596                 glDisable(GL_TEXTURE_2D);
00597             }
00598         }
00599         textureModeLast_=texmod;
00600     }
00601     rITexture::OnSelect(enforce);
00602 #endif
00603 }

Here is the call graph for this function:

void rISurfaceTexture::OnSelect (  )  [protected, pure virtual]

Selects the texture for rendering (core part).

In derived classes, this routine is supposed to do the work of loading the texture into memory and using the Upload() function to upload it to OpenGL.

Implemented in rFileTexture, and rSurfaceTexture.

Definition at line 616 of file rTexture.cpp.

Referenced by gTextureCycle::OnSelect(), rSurfaceTexture::OnSelect(), rFileTexture::OnSelect(), OnSelect(), and rFont::OnSelect().

00617 {
00618 }

Here is the caller graph for this function:

void rISurfaceTexture::OnUnload ( void   )  [protected, virtual]

Unloads the texture from OpenGL and memory.

Implements rITexture.

Definition at line 629 of file rTexture.cpp.

References rDisplayList::ClearAll(), rITexture::OnUnload(), textureModeLast_, and tint_.

00630 {
00631 #ifndef DEDICATED
00632     if ( tint_.IsValid() )
00633     {
00634         rDisplayList::ClearAll();
00635     }
00636 
00637     tint_.Delete();
00638     textureModeLast_=-100;
00639     rITexture::OnUnload();
00640 #endif
00641 }

Here is the call graph for this function:

void rISurfaceTexture::StoreAlpha ( void   )  [protected]

sets the alpha store flag

Definition at line 652 of file rTexture.cpp.

References storeAlpha_.

Referenced by rFont::rFont().

00653 {
00654     storeAlpha_ = true;
00655 }

Here is the caller graph for this function:


Member Data Documentation

bool rISurfaceTexture::storageHack_ = false [static]

when set, this flag inhibits storage of the alpha channel (for compatibility with some cards)

Definition at line 134 of file rTexture.h.

Referenced by lowlevel_sr_InitDisplay(), and Upload().

bool rISurfaceTexture::s_reportErrors_ = false [static, protected]

flag indicating whether errors should be reported

Definition at line 146 of file rTexture.h.

Referenced by rFileTexture::OnSelect().

int rISurfaceTexture::group_ [private]

the texture group (determines rendering options)

Definition at line 149 of file rTexture.h.

Referenced by OnSelect().

int rISurfaceTexture::textureModeLast_ [private]

the last texture storage mode this texture was used with

Definition at line 151 of file rTexture.h.

Referenced by Loaded(), OnSelect(), and OnUnload().

rGLuintObjectTexture rISurfaceTexture::tint_ [private]

the OpenGL id of this texture

Definition at line 153 of file rTexture.h.

Referenced by OnSelect(), OnUnload(), and ~rISurfaceTexture().

bool rISurfaceTexture::repx_ [private]

Definition at line 154 of file rTexture.h.

Referenced by Upload().

bool rISurfaceTexture::repy_ [private]

flags indicating whether the texture repeats in x and y direction

Definition at line 154 of file rTexture.h.

Referenced by Upload().

bool rISurfaceTexture::storeAlpha_ [private]

flag indicating whether the alpha value should be stored

Definition at line 155 of file rTexture.h.

Referenced by StoreAlpha(), and Upload().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:52:49 2008 for Armagetron Advanced by  doxygen 1.5.4