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/>.
19 #include "nel/3d/texture_multi_file.h"
20 #include "nel/3d/texture_file.h"
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())
61 sint usedTexture
= index
>= _FileNames
.size() ? 0 : index
;
62 if (_FileNames
[usedTexture
].empty())
64 return (usedTexture
!= 0 && !_FileNames
[0].empty()) ? 0 : -1;
70 ///===========================================================
71 void CTextureMultiFile::doGenerate(bool async
)
73 sint usedTexture
= getTexIndex(_CurrSelectedTexture
);
74 if (usedTexture
== -1)
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.
92 f
.serialCont(_FileNames
);
93 f
.serial(_CurrSelectedTexture
);
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
;
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