1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "nel/3d/hls_texture_manager.h"
19 #include "nel/misc/common.h"
20 #include "nel/misc/algo.h"
23 using namespace NLMISC
;
32 // ***************************************************************************
33 CHLSTextureManager::CHLSTextureManager()
37 // ***************************************************************************
38 CHLSTextureManager::~CHLSTextureManager()
43 // ***************************************************************************
44 void CHLSTextureManager::reset()
47 contReset(_Instances
);
50 for(uint i
=0;i
<_Banks
.size();i
++)
57 // ***************************************************************************
58 void CHLSTextureManager::addBank(CHLSTextureBank
*bank
)
60 // add the bank to the list
61 _Banks
.push_back(bank
);
63 // Add the bank instance list to the main.
64 bank
->fillHandleArray(_Instances
);
66 // then re-sort this array.
67 sort(_Instances
.begin(), _Instances
.end());
71 // ***************************************************************************
72 sint
CHLSTextureManager::findTexture(const std::string
&name
) const
75 if(_Instances
.empty())
79 string nameLwr
= toLowerAscii(name
);
80 CHLSTextureBank::CTextureInstance textKey
;
81 CHLSTextureBank::CTextureInstanceHandle textKeyHandle
;
82 textKey
.buildAsKey(nameLwr
.c_str());
83 textKeyHandle
.Texture
= &textKey
;
85 // logN search it in the array
86 uint id
= searchLowerBound(_Instances
, textKeyHandle
);
87 // verify if really same name (index must exist since 0 if error, and not empty here)
88 CHLSTextureBank::CTextureInstance
&textInst
= *_Instances
[id
].Texture
;
89 if( textInst
.sameName(nameLwr
.c_str()) )
95 // ***************************************************************************
96 bool CHLSTextureManager::buildTexture(sint textId
, NLMISC::CBitmap
&out
) const
98 if(textId
<0 || textId
>=(sint
)_Instances
.size())
102 // Ok. build the bitmap
103 CHLSTextureBank::CTextureInstance
&textInst
= *_Instances
[textId
].Texture
;
104 textInst
.buildColorVersion(out
);
110 // ***************************************************************************
111 const char *CHLSTextureManager::getTextureName(uint i
) const
113 nlassert(i
<_Instances
.size());
114 return _Instances
[i
].Texture
->getName();