llprimtexturelist.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /**
  2. * @file llprimtexturelist.cpp
  3. * @brief LLPrimTextureList (virtual) base class
  4. *
  5. * $LicenseInfo:firstyear=2008&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "llprimtexturelist.h"
  34. #include "llmaterialid.h"
  35. #include "lltextureentry.h"
  36. // static
  37. //int (TMyClass::*pt2Member)(float, char, char) = NULL; // C++
  38. LLTextureEntry* (*LLPrimTextureList::sNewTextureEntryCallback)() = &(LLTextureEntry::newTextureEntry);
  39. // static
  40. void LLPrimTextureList::setNewTextureEntryCallback( LLTextureEntry* (*callback)() )
  41. {
  42. if (callback)
  43. {
  44. LLPrimTextureList::sNewTextureEntryCallback = callback;
  45. }
  46. else
  47. {
  48. LLPrimTextureList::sNewTextureEntryCallback = &(LLTextureEntry::newTextureEntry);
  49. }
  50. }
  51. // static
  52. // call this to get a new texture entry
  53. LLTextureEntry* LLPrimTextureList::newTextureEntry()
  54. {
  55. return (*sNewTextureEntryCallback)();
  56. }
  57. LLPrimTextureList::LLPrimTextureList()
  58. {
  59. }
  60. // virtual
  61. LLPrimTextureList::~LLPrimTextureList()
  62. {
  63. clear();
  64. }
  65. void LLPrimTextureList::clear()
  66. {
  67. texture_list_t::iterator itr = mEntryList.begin();
  68. while (itr != mEntryList.end())
  69. {
  70. delete *itr;
  71. *itr++ = NULL;
  72. }
  73. mEntryList.clear();
  74. }
  75. // Clears current entries, copies contents of other_list; this is somewhat
  76. // expensive, so it must be called explicitly
  77. void LLPrimTextureList::copy(const LLPrimTextureList& other_list)
  78. {
  79. // Compare the sizes
  80. S32 this_size = mEntryList.size();
  81. S32 other_size = other_list.mEntryList.size();
  82. if (this_size > other_size)
  83. {
  84. // Remove the extra entries
  85. for (S32 index = this_size; index > other_size; --index)
  86. {
  87. delete mEntryList[index-1];
  88. }
  89. mEntryList.resize(other_size);
  90. this_size = other_size;
  91. }
  92. S32 index = 0;
  93. // Copy for the entries that already exist
  94. for ( ; index < this_size; ++index)
  95. {
  96. delete mEntryList[index];
  97. mEntryList[index] = other_list.getTexture(index)->newCopy();
  98. }
  99. // Add new entires if needed
  100. for ( ; index < other_size; ++index)
  101. {
  102. mEntryList.emplace_back(other_list.getTexture(index)->newCopy());
  103. }
  104. }
  105. // Clears current copies, takes contents of other_list, clears other_list
  106. void LLPrimTextureList::take(LLPrimTextureList& other_list)
  107. {
  108. clear();
  109. mEntryList = other_list.mEntryList;
  110. other_list.mEntryList.clear();
  111. }
  112. // Copies LLTextureEntry 'te' and returns TEM_CHANGE_TEXTURE if successful,
  113. // otherwise TEM_CHANGE_NONE.
  114. //virtual
  115. S32 LLPrimTextureList::copyTexture(U8 index, const LLTextureEntry* te)
  116. {
  117. if (index == 255)
  118. {
  119. llwarns << "ignore copy of invalid index (255)" << llendl;
  120. return TEM_CHANGE_NONE;
  121. }
  122. if (S32(index) >= mEntryList.size())
  123. {
  124. S32 current_size = mEntryList.size();
  125. llwarns << "ignore copy of index = " << S32(index)
  126. << " into texture entry list of size = " << current_size
  127. << llendl;
  128. return TEM_CHANGE_NONE;
  129. }
  130. // we're changing an existing entry
  131. llassert(mEntryList[index]);
  132. delete (mEntryList[index]);
  133. if (te)
  134. {
  135. mEntryList[index] = te->newCopy();
  136. }
  137. else
  138. {
  139. mEntryList[index] = LLPrimTextureList::newTextureEntry();
  140. }
  141. return TEM_CHANGE_TEXTURE;
  142. }
  143. // Takes ownership of LLTextureEntry* 'te' and returns TEM_CHANGE_TEXTURE if
  144. // successful, otherwise TEM_CHANGE_NONE. IMPORTANT: if you use this function
  145. // you must check the return value.
  146. //virtual
  147. S32 LLPrimTextureList::takeTexture(U8 index, LLTextureEntry* te)
  148. {
  149. if (index == 255 || S32(index) >= mEntryList.size())
  150. {
  151. return TEM_CHANGE_NONE;
  152. }
  153. // We are changing an existing entry
  154. llassert(mEntryList[index]);
  155. delete mEntryList[index];
  156. mEntryList[index] = te;
  157. return TEM_CHANGE_TEXTURE;
  158. }
  159. // returns pointer to texture at 'index' slot
  160. LLTextureEntry* LLPrimTextureList::getTexture(U8 index) const
  161. {
  162. if (index != 255 && index < mEntryList.size())
  163. {
  164. return mEntryList[index];
  165. }
  166. return NULL;
  167. }
  168. S32 LLPrimTextureList::setID(U8 index, const LLUUID& id)
  169. {
  170. if (index != 255 && index < mEntryList.size())
  171. {
  172. return mEntryList[index]->setID(id);
  173. }
  174. return TEM_CHANGE_NONE;
  175. }
  176. S32 LLPrimTextureList::setColor(U8 index, const LLColor3& color)
  177. {
  178. if (index != 255 && index < mEntryList.size())
  179. {
  180. return mEntryList[index]->setColor(color);
  181. }
  182. return TEM_CHANGE_NONE;
  183. }
  184. S32 LLPrimTextureList::setColor(U8 index, const LLColor4& color)
  185. {
  186. if (index != 255 && index < mEntryList.size())
  187. {
  188. return mEntryList[index]->setColor(color);
  189. }
  190. return TEM_CHANGE_NONE;
  191. }
  192. S32 LLPrimTextureList::setAlpha(U8 index, F32 alpha)
  193. {
  194. if (index != 255 && index < mEntryList.size())
  195. {
  196. return mEntryList[index]->setAlpha(alpha);
  197. }
  198. return TEM_CHANGE_NONE;
  199. }
  200. S32 LLPrimTextureList::setScale(U8 index, F32 s, F32 t)
  201. {
  202. if (index != 255 && index < mEntryList.size())
  203. {
  204. return mEntryList[index]->setScale(s, t);
  205. }
  206. return TEM_CHANGE_NONE;
  207. }
  208. S32 LLPrimTextureList::setScaleS(U8 index, F32 s)
  209. {
  210. if (index != 255 && index < mEntryList.size())
  211. {
  212. return mEntryList[index]->setScaleS(s);
  213. }
  214. return TEM_CHANGE_NONE;
  215. }
  216. S32 LLPrimTextureList::setScaleT(U8 index, F32 t)
  217. {
  218. if (index != 255 && index < mEntryList.size())
  219. {
  220. return mEntryList[index]->setScaleT(t);
  221. }
  222. return TEM_CHANGE_NONE;
  223. }
  224. S32 LLPrimTextureList::setOffset(U8 index, F32 s, F32 t)
  225. {
  226. if (index != 255 && index < mEntryList.size())
  227. {
  228. return mEntryList[index]->setOffset(s, t);
  229. }
  230. return TEM_CHANGE_NONE;
  231. }
  232. S32 LLPrimTextureList::setOffsetS(U8 index, F32 s)
  233. {
  234. if (index != 255 && index < mEntryList.size())
  235. {
  236. return mEntryList[index]->setOffsetS(s);
  237. }
  238. return TEM_CHANGE_NONE;
  239. }
  240. S32 LLPrimTextureList::setOffsetT(U8 index, F32 t)
  241. {
  242. if (index != 255 && index < mEntryList.size())
  243. {
  244. return mEntryList[index]->setOffsetT(t);
  245. }
  246. return TEM_CHANGE_NONE;
  247. }
  248. S32 LLPrimTextureList::setRotation(U8 index, F32 r)
  249. {
  250. if (index != 255 && index < mEntryList.size())
  251. {
  252. return mEntryList[index]->setRotation(r);
  253. }
  254. return TEM_CHANGE_NONE;
  255. }
  256. S32 LLPrimTextureList::setBumpShinyFullbright(U8 index, U8 bump)
  257. {
  258. if (index != 255 && index < mEntryList.size())
  259. {
  260. return mEntryList[index]->setBumpShinyFullbright(bump);
  261. }
  262. return TEM_CHANGE_NONE;
  263. }
  264. S32 LLPrimTextureList::setMediaTexGen(U8 index, U8 media)
  265. {
  266. if (index != 255 && index < mEntryList.size())
  267. {
  268. return mEntryList[index]->setMediaTexGen(media);
  269. }
  270. return TEM_CHANGE_NONE;
  271. }
  272. S32 LLPrimTextureList::setBumpMap(U8 index, U8 bump)
  273. {
  274. if (index != 255 && index < mEntryList.size())
  275. {
  276. return mEntryList[index]->setBumpmap(bump);
  277. }
  278. return TEM_CHANGE_NONE;
  279. }
  280. S32 LLPrimTextureList::setBumpShiny(U8 index, U8 bump_shiny)
  281. {
  282. if (index != 255 && index < mEntryList.size())
  283. {
  284. return mEntryList[index]->setBumpShiny(bump_shiny);
  285. }
  286. return TEM_CHANGE_NONE;
  287. }
  288. S32 LLPrimTextureList::setTexGen(U8 index, U8 texgen)
  289. {
  290. if (index != 255 && index < mEntryList.size())
  291. {
  292. return mEntryList[index]->setTexGen(texgen);
  293. }
  294. return TEM_CHANGE_NONE;
  295. }
  296. S32 LLPrimTextureList::setShiny(U8 index, U8 shiny)
  297. {
  298. if (index != 255 && index < mEntryList.size())
  299. {
  300. return mEntryList[index]->setShiny(shiny);
  301. }
  302. return TEM_CHANGE_NONE;
  303. }
  304. S32 LLPrimTextureList::setFullbright(U8 index, U8 fullbright)
  305. {
  306. if (index != 255 && index < mEntryList.size())
  307. {
  308. return mEntryList[index]->setFullbright(fullbright);
  309. }
  310. return TEM_CHANGE_NONE;
  311. }
  312. S32 LLPrimTextureList::setMediaFlags(U8 index, U8 media_flags)
  313. {
  314. if (index != 255 && index < mEntryList.size())
  315. {
  316. return mEntryList[index]->setMediaFlags(media_flags);
  317. }
  318. return TEM_CHANGE_NONE;
  319. }
  320. S32 LLPrimTextureList::setGlow(U8 index, F32 glow)
  321. {
  322. if (index != 255 && index < mEntryList.size())
  323. {
  324. return mEntryList[index]->setGlow(glow);
  325. }
  326. return TEM_CHANGE_NONE;
  327. }
  328. S32 LLPrimTextureList::setMaterialID(U8 index, const LLMaterialID& matidp)
  329. {
  330. if (index != 255 && index < mEntryList.size())
  331. {
  332. return mEntryList[index]->setMaterialID(matidp);
  333. }
  334. return TEM_CHANGE_NONE;
  335. }
  336. S32 LLPrimTextureList::setMaterialParams(U8 index, const LLMaterialPtr paramsp)
  337. {
  338. if (index != 255 && index < mEntryList.size())
  339. {
  340. return mEntryList[index]->setMaterialParams(paramsp);
  341. }
  342. return TEM_CHANGE_NONE;
  343. }
  344. LLMaterialPtr LLPrimTextureList::getMaterialParams(U8 index)
  345. {
  346. if (index < mEntryList.size())
  347. {
  348. return mEntryList[index]->getMaterialParams();
  349. }
  350. return LLMaterialPtr();
  351. }
  352. S32 LLPrimTextureList::size() const
  353. {
  354. return mEntryList.size();
  355. }
  356. // Sets the size of the mEntryList container
  357. void LLPrimTextureList::setSize(S32 new_size)
  358. {
  359. if (new_size < 0)
  360. {
  361. new_size = 0;
  362. }
  363. S32 current_size = mEntryList.size();
  364. if (new_size > current_size)
  365. {
  366. mEntryList.resize(new_size);
  367. for (S32 index = current_size; index < new_size; ++index)
  368. {
  369. if (current_size > 0 && mEntryList[current_size - 1])
  370. {
  371. // Copy the last valid entry for the new one
  372. mEntryList[index] = mEntryList[current_size - 1]->newCopy();
  373. }
  374. else
  375. {
  376. // No valid enries to copy, so we new one up
  377. LLTextureEntry* new_entry =
  378. LLPrimTextureList::newTextureEntry();
  379. mEntryList[index] = new_entry;
  380. }
  381. }
  382. }
  383. else if (new_size < current_size)
  384. {
  385. for (S32 index = current_size - 1; index >= new_size; --index)
  386. {
  387. delete mEntryList[index];
  388. }
  389. mEntryList.resize(new_size);
  390. }
  391. }
  392. void LLPrimTextureList::setAllIDs(const LLUUID& id)
  393. {
  394. texture_list_t::iterator itr = mEntryList.begin();
  395. while (itr != mEntryList.end())
  396. {
  397. (*itr++)->setID(id);
  398. }
  399. }