Merge branch 'ryzom/ark-features' into main/gingo-test
[ryzomcore.git] / nel / src / 3d / texture_multi_file.cpp
blobcd05beb558aa9926a6ac9554ea6863891c6ec76b
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
17 #include "std3d.h"
19 #include "nel/3d/texture_multi_file.h"
20 #include "nel/3d/texture_file.h"
22 #ifdef DEBUG_NEW
23 #define new DEBUG_NEW
24 #endif
26 namespace NL3D
29 static std::string DummyTexName("CTextureMultiFile:Dummy");
31 ///===========================================================
32 CTextureMultiFile::CTextureMultiFile(uint numTexs /* = 0 */) : _CurrSelectedTexture(0), _FileNames(numTexs)
37 ///===========================================================
38 void CTextureMultiFile::setNumTextures(uint numTexs)
40 _FileNames.resize(numTexs);
41 _CurrSelectedTexture = (uint) std::min((sint) _CurrSelectedTexture, std::min((sint) 0, (sint) (numTexs - 1)));
45 ///===========================================================
46 void CTextureMultiFile::setFileName(uint index, const char *fileName)
48 _FileNames[index] = fileName;
49 if (index == _CurrSelectedTexture) touch();
54 ///===========================================================
55 sint CTextureMultiFile::getTexIndex(uint index) const
57 if (_FileNames.empty())
59 return -1;
61 sint usedTexture = index >= _FileNames.size() ? 0 : index;
62 if (_FileNames[usedTexture].empty())
64 return (usedTexture != 0 && !_FileNames[0].empty()) ? 0 : -1;
66 return usedTexture;
70 ///===========================================================
71 void CTextureMultiFile::doGenerate(bool async)
73 sint usedTexture = getTexIndex(_CurrSelectedTexture);
74 if (usedTexture == -1)
76 makeDummy();
78 else
80 CTextureFile::buildBitmapFromFile(*this, _FileNames[usedTexture], async);
84 ///===========================================================
85 void CTextureMultiFile::serial(NLMISC::IStream &f)
87 (void)f.serialVersion(0);
89 // serial the base part of ITexture.
90 ITexture::serial(f);
92 f.serialCont(_FileNames);
93 f.serial(_CurrSelectedTexture);
95 if(f.isReading())
96 touch();
100 ///===========================================================
101 const std::string &CTextureMultiFile::getTexNameByIndex(uint index) const
103 sint usedTexture = getTexIndex(index);
104 return usedTexture == -1 ? DummyTexName : _FileNames[usedTexture];
108 ///===========================================================
109 std::string CTextureMultiFile::getShareName() const
111 return getTexNameByIndex(_CurrSelectedTexture);
114 ///===========================================================
115 void CTextureMultiFile::selectTexture(uint index)
117 if (index != _CurrSelectedTexture)
119 _CurrSelectedTexture = index;
120 touch();
125 ///===========================================================
126 ITexture *CTextureMultiFile::buildNonSelectableVersion(uint index)
128 CTextureFile *tf = new CTextureFile(getTexNameByIndex(index));
129 // copy tex parameters
130 (ITexture &) *tf = (ITexture &) *this; // invoke ITexture = op for basics parameters
132 return tf;
136 } // NL3D