gfx::Texture Class Reference

OpenGL 2D texture. More...

#include <gfx_opengl_texture2.hh>

Inheritance diagram for gfx::Texture:

gfx::TextureBase gfx::TextureModes gfx::TexelDefs gfx::TextureMethods

List of all members.

Public Types

enum  eForceAlpha { eForceAlpha_FALSE, eForceAlpha_TRUE }
enum  { MAX_TEXTURE_WIDTH_BITS = 12 }
enum  { MAX_TEXTURE_WIDTH = 1 << (MAX_TEXTURE_WIDTH_BITS-1) }
enum  { MAX_TEXTURE_BYTES = MAX_TEXTURE_WIDTH * MAX_TEXTURE_WIDTH * 4 }

Public Member Functions

 Texture (void)
 Texture (const uint width, const uint height, const eTexelType externalTexelType, const eTexelType internalTexelType)
 Texture (const Targa &targa, const eMipmap mipmap=eMipmap_OFF, const eForceAlpha forceAlpha=eForceAlpha_FALSE)
 ~Texture ()
void Bind (void) const
CLASS_METHOD void Map (const TexCoord2 &tc)
CLASS_METHOD void Map (fp tx, fp ty)
bool IfValid (void) const
uint GetWidth (void) const
uint GetHeight (void) const
uint DimCnt (void) const
uint GetTexelCnt (void) const
uint GetExternalByteCnt (void) const
CLASS_METHOD uint GetTotalMemoryUsed (void)
void SetTextureImage (const Array< Texel32 > &texels, const eMipmap mipmap=eMipmap_OFF)
void SetTextureImage (const Texel32 *texels, const uint texelCnt, const eMipmap mipmap=eMipmap_OFF)
void SetTextureImage (const uint8 *texels, const uint externalByteCnt, const eMipmap mipmap=eMipmap_OFF)
void SetMinFilter (eMinFilter filter)
void SetMagFilter (eMagFilter filter)
void SetFastestFilters (void)
void SetWrap (eWrap wrap, uint dim)
void SetWrap (eWrap wrap)
void SetFunc (eFunc func)

Private Member Functions

void Init (const uint width, const uint height, const eTexelType externalTexelType, const eTexelType internalTexelType)
uint TexelCntToExternalByteCnt (const uint texelCnt) const
uint TexelCntToInternalByteCnt (const uint texelCnt) const
uint GetInternalTexelCnt (void) const
uint GetInternalByteCnt (void) const
uint GetByteCnt_ (const bool hasAlpha) const
uint GetTexelCnt_ (const bool hasAlpha) const
uint TexelCntToByteCnt_ (const uint texelCnt, const uint texelLen) const
uint EstimateInternalByteCnt (const eMipmap mipmap) const

Private Attributes

Bits mBits
eTexelType mExternalTexelType
 GL_GBRA8, GL_RGBA8, etc.
eTexelType mInternalTexelType
 not BGR/BGRA
GLuint mId
 OpenGL texture object ID.
eFunc mTexFunc
 passed to glTexEnv() by Texture::Begin()
CLASS_VAR int msTotalMemoryUsed
 total memory used by all textures

Friends

bool operator< (Texture &a, Texture &b)

Classes

struct  Bits


Detailed Description

OpenGL 2D texture.

///
/// Texture is a mixin class for 2D textures.
///
/// - Clients are the source of texture images.
///   Clients can procedurally-generate or load texture images from files
///   and pass them to Texture::SetTextureImage().
/// - Interface for setting texture modes (filters, blend functions, etc).
/// - Abstracts texel types (BGRA8, RGBA8).
/// - Tracks texture memory usage.
///
/// Invalid textures are useful:
/// ----------------------------
/// The default Texture ctor creates an inexpensive-but-invalid Texture.
/// Invalid Textures are a substitute for NULL pointers.
/// Any client that does construct invalid Textures is responsible
/// for checking Texture::IfValid() before calling a Texture method
/// (else results are UNDEFINED).
///
/// Example of procedural textures:
/// -------------------------------
/// // Creates a Texture object.  It has no image yet.
/// shptr<Texture> tex = new Texture( TEXEL_BGRA8, width, height );
///
/// // Generate texture image.
/// // Client allocates and fills the texture image.
/// // Texel32 is a typedef that abstracts BGRA8 or RGBA8 format.
/// const uint texelCnt = tex->GetTexelCnt();
/// Array<Texture::Texel32> texels( texelCnt );
/// for ( uint i = 0; i < texelCnt; i += Texture::TEXEL32_LEN )
/// {
///     // Whether Texel32 is in RGBA8 or BGRA8 order
///     // is abstracted by these #defines.
///     ASSERT( i < texelCnt );
///     Texture::Texel32 texel = (b << Texture::TEXEL32_BB_BIT_SHIFT)
///                            | (g << Texture::TEXEL32_GG_BIT_SHIFT)
///                            | (r << Texture::TEXEL32_RR_BIT_SHIFT)
///                            | (a << Texture::TEXEL32_AA_BIT_SHIFT);
///     texels[i] = texel;
/// }
/// tex->SetTextureImage( texels );
///
/// 

Member Enumeration Documentation

enum gfx::Texture::eForceAlpha

Enumerator:
eForceAlpha_FALSE 
eForceAlpha_TRUE 

anonymous enum

Enumerator:
MAX_TEXTURE_WIDTH_BITS 

anonymous enum

Enumerator:
MAX_TEXTURE_WIDTH 

anonymous enum

Enumerator:
MAX_TEXTURE_BYTES 


Constructor & Destructor Documentation

gfx::Texture::Texture ( void   ) 

Construct an invalid Texture (substitutes for NULL pointer).

gfx::Texture::Texture ( const uint  width,
const uint  height,
const eTexelType  externalTexelType,
const eTexelType  internalTexelType 
)

gfx::Texture::Texture ( const Targa targa,
const eMipmap  mipmap = eMipmap_OFF,
const eForceAlpha  forceAlpha = eForceAlpha_FALSE 
)

Construct Texture object from a Targa graphics file.

Parameters:
targa 
mimap 
forceAlpha Treat the Targa object has having an Alpha channel even if, according to the Targa file's format (header), it doesn't. Forcing is possible since the old Targa C code converts to full RGBA.

gfx::Texture::~Texture (  ) 


Member Function Documentation

void gfx::Texture::Bind ( void   )  const [inline]

Bind texture.

Precondition:
Texture is valid.

Caller has enabled texturing using GFX::EnableTexture2(true). BTW, to disable texturing, call GFX::EnableTexture2(false).

CLASS_METHOD void gfx::Texture::Map ( const TexCoord2 tc  )  [inline]

Send 2D texture coordinates to map texture to a polygon. Map are class methods since, being unassociated with a texture object, simplifies code that switches between texture objects.

CLASS_METHOD void gfx::Texture::Map ( fp  tx,
fp  ty 
) [inline]

bool gfx::Texture::IfValid ( void   )  const [inline]

Texture info.

uint gfx::Texture::GetWidth ( void   )  const [inline]

uint gfx::Texture::GetHeight ( void   )  const [inline]

uint gfx::Texture::DimCnt ( void   )  const [inline]

uint gfx::Texture::GetTexelCnt ( void   )  const

Returns:
Amount of texels in texture image. Whether loaded or not, or internal or external. Ignoring mipmaps.

uint gfx::Texture::GetExternalByteCnt ( void   )  const

Returns:
Amount of bytes a texture image has or will have (whether loaded or not). Excluding mipmaps (if mipmapped, only returns the size of the largest mipmap).

CLASS_METHOD uint gfx::Texture::GetTotalMemoryUsed ( void   )  [inline]

void gfx::Texture::SetTextureImage ( const Array< Texel32 > &  texels,
const eMipmap  mipmap = eMipmap_OFF 
)

Texture image. GetTextureImage() omitted.

void gfx::Texture::SetTextureImage ( const Texel32 *  texels,
const uint  texelCnt,
const eMipmap  mipmap = eMipmap_OFF 
)

void gfx::Texture::SetTextureImage ( const uint8 *  texels,
const uint  externalByteCnt,
const eMipmap  mipmap = eMipmap_OFF 
)

Load texture image into OpenGL (from raw byte array).

Parameters:
texels This class checks that caller used the right count.
externalByteCnt Count of BYTES in source texture image (external from gfxsys).
mipmap 

void gfx::Texture::SetMinFilter ( eMinFilter  filter  ) 

Texture mode.

Texture modes.

Some OpenGL texture functions affect all texture objects, some affect only the bound one. Thus, since glTexEnv() doesn't affect the bound texture object, Texture::Bind() must call it every time.

http://www.opengl.org/resources/faq/technical/texture.htm The following functions affect the state of a texture object: glTexImage*(), glTexSubImage*(), glCopyTexImage*(), glCopyTexSubImage*(), glTexParameter*(), and glPrioritizeTextures(). Since the GLU routines for building mipmap pyramids ultimately call glTexImage*(), they also affect texture objects. Absent from this list are: glTexEnv*() and glTexGen*() which don't affect a particular texture object.

void gfx::Texture::SetMagFilter ( eMagFilter  filter  ) 

void gfx::Texture::SetFastestFilters ( void   ) 

void gfx::Texture::SetWrap ( eWrap  wrap,
uint  dim 
)

void gfx::Texture::SetWrap ( eWrap  wrap  ) 

void gfx::Texture::SetFunc ( eFunc  func  ) 

void gfx::Texture::Init ( const uint  width,
const uint  height,
const eTexelType  externalTexelType,
const eTexelType  internalTexelType 
) [private]

Misc private methods.

uint gfx::Texture::TexelCntToExternalByteCnt ( const uint  texelCnt  )  const [private]

Returns:
Convert texel count to byte count.

uint gfx::Texture::TexelCntToInternalByteCnt ( const uint  texelCnt  )  const [private]

uint gfx::Texture::GetInternalTexelCnt ( void   )  const [private]

uint gfx::Texture::GetInternalByteCnt ( void   )  const [private]

uint gfx::Texture::GetByteCnt_ ( const bool  hasAlpha  )  const [private]

uint gfx::Texture::GetTexelCnt_ ( const bool  hasAlpha  )  const [private]

uint gfx::Texture::TexelCntToByteCnt_ ( const uint  texelCnt,
const uint  texelLen 
) const [private]

uint gfx::Texture::EstimateInternalByteCnt ( const eMipmap  mipmap  )  const [private]

Estimate the amount of memory a texture is ACTIVELY consuming, including mipmaps.


Friends And Related Function Documentation

bool operator< ( Texture a,
Texture b 
) [friend]

For STL containers.


Member Data Documentation

Bits gfx::Texture::mBits [private]

eTexelType gfx::Texture::mExternalTexelType [private]

GL_GBRA8, GL_RGBA8, etc.

eTexelType gfx::Texture::mInternalTexelType [private]

not BGR/BGRA

GLuint gfx::Texture::mId [private]

OpenGL texture object ID.

eFunc gfx::Texture::mTexFunc [private]

passed to glTexEnv() by Texture::Begin()

int gfx::Texture::msTotalMemoryUsed [private]

total memory used by all textures


The documentation for this class was generated from the following files: Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:28 2007