Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CubeMap Class Reference

#include <texture.h>

Inheritance diagram for CubeMap:

Inheritance graph
Collaboration diagram for CubeMap:

Collaboration graph
List of all members.

Public Member Functions

virtual void bind ()
 CubeMap (Image *faces[])
virtual const TextureTile getTile (int lod, int u, int v)
virtual void setBorderColor (Color)
 ~CubeMap ()

Private Attributes

unsigned int glName

Constructor & Destructor Documentation

CubeMap::CubeMap Image faces[]  ) 
 

Definition at line 711 of file texture.cpp.

References CalcMipLevelCount(), Image::getFormat(), Texture::getHeight(), getInternalFormat(), Image::getPixels(), Texture::getWidth(), GL_CLAMP_TO_EDGE, GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, glName, LoadMiplessTexture(), and LoadMipmapSet().

00711                                :
00712     Texture(faces[0]->getWidth(), faces[0]->getHeight()),
00713     glName(0)
00714 {
00715     // Verify that all the faces are square and have the same size
00716     int width = faces[0]->getWidth();
00717     int format = faces[0]->getFormat();
00718     int i = 0;
00719     for (i = 0; i < 6; i++)
00720     {
00721         if (faces[i]->getWidth() != width ||
00722             faces[i]->getHeight() != width ||
00723             faces[i]->getFormat() != format)
00724             return;
00725     }
00726 
00727     // For now, always enable mipmaps; in the future, it should be possible to
00728     // override this.
00729     bool mipmap = true;
00730     bool precomputedMipMaps = false;
00731 
00732     // Require a complete set of mipmaps
00733     int mipLevelCount = faces[0]->getMipLevelCount();
00734     if (mipmap && mipLevelCount == CalcMipLevelCount(width, width))
00735         precomputedMipMaps = true;
00736 
00737     // We can't automatically generate mipmaps for compressed textures.
00738     // If a precomputed mipmap set isn't provided, turn of mipmapping entirely.
00739     if (!precomputedMipMaps && faces[0]->isCompressed())
00740         mipmap = false;
00741 
00742     glGenTextures(1, (GLuint*)&glName);
00743     glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, glName);
00744 
00745     glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00746     glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00747     glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00748     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
00749                     mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
00750 
00751     int internalFormat = getInternalFormat(format);
00752 
00753     for (i = 0; i < 6; i++)
00754     {
00755         GLenum targetFace = (GLenum) ((int) GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i);
00756         Image* face = faces[i];
00757 
00758         if (mipmap)
00759         {
00760             if (precomputedMipMaps)
00761             {
00762                 LoadMipmapSet(*face, targetFace);
00763             }
00764             else
00765             {
00766                 gluBuild2DMipmaps(targetFace,
00767                                   internalFormat,
00768                                   getWidth(), getHeight(),
00769                                   (GLenum) face->getFormat(),
00770                                   GL_UNSIGNED_BYTE,
00771                                   face->getPixels());
00772             }
00773         }
00774         else
00775         {
00776             LoadMiplessTexture(*face, targetFace);
00777         }
00778     }
00779 }

CubeMap::~CubeMap  ) 
 

Definition at line 782 of file texture.cpp.

References glName.

00783 {
00784     if (glName != 0)
00785         glDeleteTextures(1, (const GLuint*) &glName);
00786 }


Member Function Documentation

void CubeMap::bind  )  [virtual]
 

Implements Texture.

Definition at line 789 of file texture.cpp.

References GL_TEXTURE_CUBE_MAP_EXT, and glName.

Referenced by setBorderColor().

00790 {
00791     glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, glName);
00792 }

const TextureTile CubeMap::getTile int  lod,
int  u,
int  v
[virtual]
 

Implements Texture.

Definition at line 795 of file texture.cpp.

References glName.

00796 {
00797     if (lod != 0 || u != 0 || v != 0)
00798         return TextureTile(0);
00799     else
00800         return TextureTile(glName);
00801 }

void CubeMap::setBorderColor Color   )  [virtual]
 

Reimplemented from Texture.

Definition at line 804 of file texture.cpp.

References bind(), GL_TEXTURE_CUBE_MAP_EXT, and SetBorderColor().

00805 {
00806     bind();
00807     SetBorderColor(borderColor, GL_TEXTURE_CUBE_MAP_EXT);
00808 }


Member Data Documentation

unsigned int CubeMap::glName [private]
 

Definition at line 147 of file texture.h.

Referenced by bind(), CubeMap(), getTile(), and ~CubeMap().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:16 2006 for Celestia by  doxygen 1.4.1