Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / 3d / hls_texture_manager.cpp
blob59020646af798f38eb8e39824e783b9dc7df577f
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "std3d.h"
21 #include "nel/3d/hls_texture_manager.h"
22 #include "nel/misc/common.h"
23 #include "nel/misc/algo.h"
25 using namespace std;
26 using namespace NLMISC;
28 #ifdef DEBUG_NEW
29 #define new DEBUG_NEW
30 #endif
32 namespace NL3D {
35 // ***************************************************************************
36 CHLSTextureManager::CHLSTextureManager()
40 // ***************************************************************************
41 CHLSTextureManager::~CHLSTextureManager()
43 reset();
46 // ***************************************************************************
47 void CHLSTextureManager::reset()
49 // delete instances.
50 contReset(_Instances);
52 // delete banks.
53 for(uint i=0;i<_Banks.size();i++)
55 delete _Banks[i];
57 contReset(_Banks);
60 // ***************************************************************************
61 void CHLSTextureManager::addBank(CHLSTextureBank *bank)
63 // add the bank to the list
64 _Banks.push_back(bank);
66 // Add the bank instance list to the main.
67 bank->fillHandleArray(_Instances);
69 // then re-sort this array.
70 sort(_Instances.begin(), _Instances.end());
74 // ***************************************************************************
75 sint CHLSTextureManager::findTexture(const std::string &name) const
77 // empty?
78 if(_Instances.empty())
79 return -1;
81 // Build a valid key.
82 string nameLwr= toLowerAscii(name);
83 CHLSTextureBank::CTextureInstance textKey;
84 CHLSTextureBank::CTextureInstanceHandle textKeyHandle;
85 textKey.buildAsKey(nameLwr.c_str());
86 textKeyHandle.Texture= &textKey;
88 // logN search it in the array
89 uint id= searchLowerBound(_Instances, textKeyHandle);
90 // verify if really same name (index must exist since 0 if error, and not empty here)
91 CHLSTextureBank::CTextureInstance &textInst= *_Instances[id].Texture;
92 if( textInst.sameName(nameLwr.c_str()) )
93 return id;
94 else
95 return -1;
98 // ***************************************************************************
99 bool CHLSTextureManager::buildTexture(sint textId, NLMISC::CBitmap &out) const
101 if(textId<0 || textId>=(sint)_Instances.size())
102 return false;
103 else
105 // Ok. build the bitmap
106 CHLSTextureBank::CTextureInstance &textInst= *_Instances[textId].Texture;
107 textInst.buildColorVersion(out);
108 return true;
113 // ***************************************************************************
114 const char *CHLSTextureManager::getTextureName(uint i) const
116 nlassert(i<_Instances.size());
117 return _Instances[i].Texture->getName();
121 } // NL3D