NL3D::CHLSTextureBank Class Reference

#include <hls_texture_bank.h>


Detailed Description

A bank of HLS colorisable textures
Author:
Lionel Berenguier

Nevrax France

Date:
2002

Definition at line 50 of file hls_texture_bank.h.

Public Member Functions

 CHLSTextureBank ()
 Constructor.

Build
uint32 addColorTexture (const CHLSColorTexture &tex)
 Add a colorisable texture to the bank.

void addTextureInstance (const std::string &name, uint32 colorTextureId, const std::vector< CHLSColorDelta > &cols)
void compile ()
 compile the bank.

void reset ()
 clear the bank

void serial (NLMISC::IStream &f)
 serial. if loading, ptrs are correclty setuped => no compile() needed

Usage
void fillHandleArray (std::vector< CTextureInstanceHandle > &array)
 Append handle into the array (build of the manager).


Private Member Functions

void compilePtrs ()

Private Attributes

std::vector< CHLSColorTexture_ColorTextures
 Array of colorisable texture.

std::vector< uint8_TextureInstanceData
 Raw Array of Name+HLS color delta.

std::vector< CTextureInstance_TextureInstances
 Array of textureInstances.


Constructor & Destructor Documentation

NL3D::CHLSTextureBank::CHLSTextureBank  ) 
 

Constructor.

Definition at line 45 of file hls_texture_bank.cpp.

00046 {
00047 }


Member Function Documentation

uint32 NL3D::CHLSTextureBank::addColorTexture const CHLSColorTexture tex  ) 
 

Add a colorisable texture to the bank.

Definition at line 56 of file hls_texture_bank.cpp.

References _ColorTextures, and uint32.

00057 {
00058         _ColorTextures.push_back(tex);
00059         return _ColorTextures.size()-1;
00060 }

void NL3D::CHLSTextureBank::addTextureInstance const std::string &  name,
uint32  colorTextureId,
const std::vector< CHLSColorDelta > &  cols
 

Add an instance texture (ie colorised) to the bank

Parameters:
name name of the colored texture. NB: it is lowered in this method
colorTextureId index returned by addColorTexture()
cols must be same size of number of mask of the colorTextureId pointed (nlassert)

Definition at line 62 of file hls_texture_bank.cpp.

References NL3D::CHLSTextureBank::CTextureInstance::_ColorTextureId, NL3D::CHLSTextureBank::CTextureInstance::_ColorTexturePtr, _ColorTextures, NL3D::CHLSTextureBank::CTextureInstance::_DataIndex, NL3D::CHLSTextureBank::CTextureInstance::_DataPtr, _TextureInstanceData, _TextureInstances, NL3D::CHLSColorTexture::getNumMasks(), nlassert, NLMISC::strlwr(), and uint32.

00063 {
00064         string  nameLwr= strlwr(name);
00065 
00066         // checks
00067         nlassert(colorTextureId<_ColorTextures.size());
00068         CHLSColorTexture        &colText= _ColorTextures[colorTextureId];
00069         nlassert(cols.size()==colText.getNumMasks());
00070 
00071         // new instance
00072         CTextureInstance        textInst;
00073         textInst._ColorTextureId= colorTextureId;
00074         textInst._DataIndex= _TextureInstanceData.size();
00075         // leave ptrs undefined
00076         textInst._DataPtr= NULL;
00077         textInst._ColorTexturePtr= NULL;
00078 
00079         // allocate/fill data
00080         uint32  nameSize= (nameLwr.size()+1);
00081         uint32  colSize= cols.size()*sizeof(CHLSColorDelta);
00082         _TextureInstanceData.resize(_TextureInstanceData.size() + nameSize + colSize);
00083         // copy name
00084         memcpy(&_TextureInstanceData[textInst._DataIndex], nameLwr.c_str(), nameSize);
00085         // copy cols
00086         memcpy(&_TextureInstanceData[textInst._DataIndex+nameSize], &cols[0], colSize);
00087 
00088         // add the instance.
00089         _TextureInstances.push_back(textInst);
00090 }

void NL3D::CHLSTextureBank::compile  ) 
 

compile the bank.

Definition at line 107 of file hls_texture_bank.cpp.

References compilePtrs().

00108 {
00109         // compile the ptrs.
00110         compilePtrs();
00111 
00112         // No other ops for now.
00113 }

void NL3D::CHLSTextureBank::compilePtrs  )  [private]
 

Definition at line 92 of file hls_texture_bank.cpp.

References NL3D::CHLSTextureBank::CTextureInstance::_ColorTextureId, NL3D::CHLSTextureBank::CTextureInstance::_ColorTexturePtr, _ColorTextures, NL3D::CHLSTextureBank::CTextureInstance::_DataIndex, NL3D::CHLSTextureBank::CTextureInstance::_DataPtr, _TextureInstanceData, _TextureInstances, data, uint, and uint8.

Referenced by compile(), and serial().

00093 {
00094         uint8   *data= &_TextureInstanceData[0];
00095 
00096         // For all texture instances, compute ptr.
00097         for(uint i=0;i<_TextureInstances.size();i++)
00098         {
00099                 CTextureInstance        &text= _TextureInstances[i];
00100                 text._DataPtr= data + text._DataIndex;
00101                 text._ColorTexturePtr= &_ColorTextures[text._ColorTextureId];
00102         }
00103 }

void NL3D::CHLSTextureBank::fillHandleArray std::vector< CTextureInstanceHandle > &  array  ) 
 

Append handle into the array (build of the manager).

Definition at line 135 of file hls_texture_bank.cpp.

References _TextureInstances, NL3D::CHLSTextureBank::CTextureInstanceHandle::Texture, and uint.

Referenced by NL3D::CHLSTextureManager::addBank().

00136 {
00137         for(uint i=0;i<_TextureInstances.size();i++)
00138         {
00139                 CTextureInstanceHandle  h;
00140                 h.Texture= &_TextureInstances[i];
00141                 array.push_back(h);
00142         }
00143 }

void NL3D::CHLSTextureBank::reset  ) 
 

clear the bank

Definition at line 49 of file hls_texture_bank.cpp.

References _ColorTextures, _TextureInstanceData, and _TextureInstances.

00050 {
00051         contReset(_ColorTextures);
00052         contReset(_TextureInstanceData);
00053         contReset(_TextureInstances);
00054 }

void NL3D::CHLSTextureBank::serial NLMISC::IStream f  ) 
 

serial. if loading, ptrs are correclty setuped => no compile() needed

Definition at line 117 of file hls_texture_bank.cpp.

References _ColorTextures, _TextureInstanceData, _TextureInstances, compilePtrs(), NLMISC::IStream::isReading(), NLMISC::IStream::serialCont(), NLMISC::IStream::serialVersion(), and sint.

00118 {
00119         sint    ver= f.serialVersion(0);
00120 
00121         f.serialCont(_ColorTextures);
00122         f.serialCont(_TextureInstanceData);
00123         f.serialCont(_TextureInstances);
00124 
00125         // Must compile ptrs.
00126         if(f.isReading())
00127         {
00128                 // compile the ptrs only.
00129                 compilePtrs();
00130         }
00131 }


Field Documentation

std::vector<CHLSColorTexture> NL3D::CHLSTextureBank::_ColorTextures [private]
 

Array of colorisable texture.

Definition at line 147 of file hls_texture_bank.h.

Referenced by addColorTexture(), addTextureInstance(), compilePtrs(), reset(), and serial().

std::vector<uint8> NL3D::CHLSTextureBank::_TextureInstanceData [private]
 

Raw Array of Name+HLS color delta.

Definition at line 150 of file hls_texture_bank.h.

Referenced by addTextureInstance(), compilePtrs(), reset(), and serial().

std::vector<CTextureInstance> NL3D::CHLSTextureBank::_TextureInstances [private]
 

Array of textureInstances.

Definition at line 153 of file hls_texture_bank.h.

Referenced by addTextureInstance(), compilePtrs(), fillHandleArray(), reset(), and serial().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:47:08 2004 for NeL by doxygen 1.3.6