1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
21 #include "nel/3d/hls_texture_manager.h"
22 #include "nel/misc/common.h"
23 #include "nel/misc/algo.h"
26 using namespace NLMISC
;
35 // ***************************************************************************
36 CHLSTextureManager::CHLSTextureManager()
40 // ***************************************************************************
41 CHLSTextureManager::~CHLSTextureManager()
46 // ***************************************************************************
47 void CHLSTextureManager::reset()
50 contReset(_Instances
);
53 for(uint i
=0;i
<_Banks
.size();i
++)
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
78 if(_Instances
.empty())
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()) )
98 // ***************************************************************************
99 bool CHLSTextureManager::buildTexture(sint textId
, NLMISC::CBitmap
&out
) const
101 if(textId
<0 || textId
>=(sint
)_Instances
.size())
105 // Ok. build the bitmap
106 CHLSTextureBank::CTextureInstance
&textInst
= *_Instances
[textId
].Texture
;
107 textInst
.buildColorVersion(out
);
113 // ***************************************************************************
114 const char *CHLSTextureManager::getTextureName(uint i
) const
116 nlassert(i
<_Instances
.size());
117 return _Instances
[i
].Texture
->getName();