PageRenderTime 184ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/llprimitive/llprimtexturelist.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 418 lines | 314 code | 48 blank | 56 comment | 41 complexity | 8e5e09025a0045c5f604da69fa98e78e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltexturelist.cpp
  3. * @brief LLPrimTextureList (virtual) base class
  4. *
  5. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "llprimtexturelist.h"
  28. #include "lltextureentry.h"
  29. #include "llmemtype.h"
  30. // static
  31. //int (TMyClass::*pt2Member)(float, char, char) = NULL; // C++
  32. LLTextureEntry* (*LLPrimTextureList::sNewTextureEntryCallback)() = &(LLTextureEntry::newTextureEntry);
  33. // static
  34. void LLPrimTextureList::setNewTextureEntryCallback( LLTextureEntry* (*callback)() )
  35. {
  36. if (callback)
  37. {
  38. LLPrimTextureList::sNewTextureEntryCallback = callback;
  39. }
  40. else
  41. {
  42. LLPrimTextureList::sNewTextureEntryCallback = &(LLTextureEntry::newTextureEntry);
  43. }
  44. }
  45. // static
  46. // call this to get a new texture entry
  47. LLTextureEntry* LLPrimTextureList::newTextureEntry()
  48. {
  49. return (*sNewTextureEntryCallback)();
  50. }
  51. LLPrimTextureList::LLPrimTextureList()
  52. {
  53. }
  54. // virtual
  55. LLPrimTextureList::~LLPrimTextureList()
  56. {
  57. clear();
  58. }
  59. void LLPrimTextureList::clear()
  60. {
  61. texture_list_t::iterator itr = mEntryList.begin();
  62. while (itr != mEntryList.end())
  63. {
  64. delete (*itr);
  65. (*itr) = NULL;
  66. ++itr;
  67. }
  68. mEntryList.clear();
  69. }
  70. // clears current entries
  71. // copies contents of other_list
  72. // this is somewhat expensive, so it must be called explicitly
  73. void LLPrimTextureList::copy(const LLPrimTextureList& other_list)
  74. {
  75. // compare the sizes
  76. S32 this_size = mEntryList.size();
  77. S32 other_size = other_list.mEntryList.size();
  78. if (this_size > other_size)
  79. {
  80. // remove the extra entries
  81. for (S32 index = this_size; index > other_size; --index)
  82. {
  83. delete mEntryList[index-1];
  84. }
  85. mEntryList.resize(other_size);
  86. this_size = other_size;
  87. }
  88. S32 index = 0;
  89. // copy for the entries that already exist
  90. for ( ; index < this_size; ++index)
  91. {
  92. delete mEntryList[index];
  93. mEntryList[index] = other_list.getTexture(index)->newCopy();
  94. }
  95. // add new entires if needed
  96. for ( ; index < other_size; ++index)
  97. {
  98. mEntryList.push_back( other_list.getTexture(index)->newCopy() );
  99. }
  100. }
  101. // clears current copies
  102. // takes contents of other_list
  103. // clears other_list
  104. void LLPrimTextureList::take(LLPrimTextureList& other_list)
  105. {
  106. clear();
  107. mEntryList = other_list.mEntryList;
  108. other_list.mEntryList.clear();
  109. }
  110. // virtual
  111. // copies LLTextureEntry 'te'
  112. // returns TEM_CHANGE_TEXTURE if successful, otherwise TEM_CHANGE_NONE
  113. S32 LLPrimTextureList::copyTexture(const U8 index, const LLTextureEntry& te)
  114. {
  115. if (S32(index) >= mEntryList.size())
  116. {
  117. S32 current_size = mEntryList.size();
  118. llwarns << "ignore copy of index = " << S32(index) << " into texture entry list of size = " << current_size << llendl;
  119. return TEM_CHANGE_NONE;
  120. }
  121. // we're changing an existing entry
  122. llassert(mEntryList[index]);
  123. delete (mEntryList[index]);
  124. if (&te)
  125. {
  126. mEntryList[index] = te.newCopy();
  127. }
  128. else
  129. {
  130. mEntryList[index] = LLPrimTextureList::newTextureEntry();
  131. }
  132. return TEM_CHANGE_TEXTURE;
  133. }
  134. // virtual
  135. // takes ownership of LLTextureEntry* 'te'
  136. // returns TEM_CHANGE_TEXTURE if successful, otherwise TEM_CHANGE_NONE
  137. // IMPORTANT! -- if you use this function you must check the return value
  138. S32 LLPrimTextureList::takeTexture(const U8 index, LLTextureEntry* te)
  139. {
  140. if (S32(index) >= mEntryList.size())
  141. {
  142. return TEM_CHANGE_NONE;
  143. }
  144. // we're changing an existing entry
  145. llassert(mEntryList[index]);
  146. delete (mEntryList[index]);
  147. mEntryList[index] = te;
  148. return TEM_CHANGE_TEXTURE;
  149. }
  150. // returns pointer to texture at 'index' slot
  151. LLTextureEntry* LLPrimTextureList::getTexture(const U8 index) const
  152. {
  153. if (index < mEntryList.size())
  154. {
  155. return mEntryList[index];
  156. }
  157. return NULL;
  158. }
  159. //virtual
  160. //S32 setTE(const U8 index, const LLTextureEntry& te) = 0;
  161. S32 LLPrimTextureList::setID(const U8 index, const LLUUID& id)
  162. {
  163. if (index < mEntryList.size())
  164. {
  165. return mEntryList[index]->setID(id);
  166. }
  167. return TEM_CHANGE_NONE;
  168. }
  169. S32 LLPrimTextureList::setColor(const U8 index, const LLColor3& color)
  170. {
  171. if (index < mEntryList.size())
  172. {
  173. return mEntryList[index]->setColor(color);
  174. }
  175. return TEM_CHANGE_NONE;
  176. }
  177. S32 LLPrimTextureList::setColor(const U8 index, const LLColor4& color)
  178. {
  179. if (index < mEntryList.size())
  180. {
  181. return mEntryList[index]->setColor(color);
  182. }
  183. return TEM_CHANGE_NONE;
  184. }
  185. S32 LLPrimTextureList::setAlpha(const U8 index, const F32 alpha)
  186. {
  187. if (index < mEntryList.size())
  188. {
  189. return mEntryList[index]->setAlpha(alpha);
  190. }
  191. return TEM_CHANGE_NONE;
  192. }
  193. S32 LLPrimTextureList::setScale(const U8 index, const F32 s, const F32 t)
  194. {
  195. if (index < mEntryList.size())
  196. {
  197. return mEntryList[index]->setScale(s, t);
  198. }
  199. return TEM_CHANGE_NONE;
  200. }
  201. S32 LLPrimTextureList::setScaleS(const U8 index, const F32 s)
  202. {
  203. if (index < mEntryList.size())
  204. {
  205. return mEntryList[index]->setScaleS(s);
  206. }
  207. return TEM_CHANGE_NONE;
  208. }
  209. S32 LLPrimTextureList::setScaleT(const U8 index, const F32 t)
  210. {
  211. if (index < mEntryList.size())
  212. {
  213. return mEntryList[index]->setScaleT(t);
  214. }
  215. return TEM_CHANGE_NONE;
  216. }
  217. S32 LLPrimTextureList::setOffset(const U8 index, const F32 s, const F32 t)
  218. {
  219. if (index < mEntryList.size())
  220. {
  221. return mEntryList[index]->setOffset(s, t);
  222. }
  223. return TEM_CHANGE_NONE;
  224. }
  225. S32 LLPrimTextureList::setOffsetS(const U8 index, const F32 s)
  226. {
  227. if (index < mEntryList.size())
  228. {
  229. return mEntryList[index]->setOffsetS(s);
  230. }
  231. return TEM_CHANGE_NONE;
  232. }
  233. S32 LLPrimTextureList::setOffsetT(const U8 index, const F32 t)
  234. {
  235. if (index < mEntryList.size())
  236. {
  237. return mEntryList[index]->setOffsetT(t);
  238. }
  239. return TEM_CHANGE_NONE;
  240. }
  241. S32 LLPrimTextureList::setRotation(const U8 index, const F32 r)
  242. {
  243. if (index < mEntryList.size())
  244. {
  245. return mEntryList[index]->setRotation(r);
  246. }
  247. return TEM_CHANGE_NONE;
  248. }
  249. S32 LLPrimTextureList::setBumpShinyFullbright(const U8 index, const U8 bump)
  250. {
  251. if (index < mEntryList.size())
  252. {
  253. return mEntryList[index]->setBumpShinyFullbright(bump);
  254. }
  255. return TEM_CHANGE_NONE;
  256. }
  257. S32 LLPrimTextureList::setMediaTexGen(const U8 index, const U8 media)
  258. {
  259. if (index < mEntryList.size())
  260. {
  261. return mEntryList[index]->setMediaTexGen(media);
  262. }
  263. return TEM_CHANGE_NONE;
  264. }
  265. S32 LLPrimTextureList::setBumpMap(const U8 index, const U8 bump)
  266. {
  267. if (index < mEntryList.size())
  268. {
  269. return mEntryList[index]->setBumpmap(bump);
  270. }
  271. return TEM_CHANGE_NONE;
  272. }
  273. S32 LLPrimTextureList::setBumpShiny(const U8 index, const U8 bump_shiny)
  274. {
  275. if (index < mEntryList.size())
  276. {
  277. return mEntryList[index]->setBumpShiny(bump_shiny);
  278. }
  279. return TEM_CHANGE_NONE;
  280. }
  281. S32 LLPrimTextureList::setTexGen(const U8 index, const U8 texgen)
  282. {
  283. if (index < mEntryList.size())
  284. {
  285. return mEntryList[index]->setTexGen(texgen);
  286. }
  287. return TEM_CHANGE_NONE;
  288. }
  289. S32 LLPrimTextureList::setShiny(const U8 index, const U8 shiny)
  290. {
  291. if (index < mEntryList.size())
  292. {
  293. return mEntryList[index]->setShiny(shiny);
  294. }
  295. return TEM_CHANGE_NONE;
  296. }
  297. S32 LLPrimTextureList::setFullbright(const U8 index, const U8 fullbright)
  298. {
  299. if (index < mEntryList.size())
  300. {
  301. return mEntryList[index]->setFullbright(fullbright);
  302. }
  303. return TEM_CHANGE_NONE;
  304. }
  305. S32 LLPrimTextureList::setMediaFlags(const U8 index, const U8 media_flags)
  306. {
  307. if (index < mEntryList.size())
  308. {
  309. return mEntryList[index]->setMediaFlags(media_flags);
  310. }
  311. return TEM_CHANGE_NONE;
  312. }
  313. S32 LLPrimTextureList::setGlow(const U8 index, const F32 glow)
  314. {
  315. if (index < mEntryList.size())
  316. {
  317. return mEntryList[index]->setGlow(glow);
  318. }
  319. return TEM_CHANGE_NONE;
  320. }
  321. S32 LLPrimTextureList::size() const
  322. {
  323. return mEntryList.size();
  324. }
  325. // sets the size of the mEntryList container
  326. void LLPrimTextureList::setSize(S32 new_size)
  327. {
  328. LLMemType m1(LLMemType::MTYPE_PRIMITIVE);
  329. if (new_size < 0)
  330. {
  331. new_size = 0;
  332. }
  333. S32 current_size = mEntryList.size();
  334. if (new_size > current_size)
  335. {
  336. mEntryList.resize(new_size);
  337. for (S32 index = current_size; index < new_size; ++index)
  338. {
  339. if (current_size > 0
  340. && mEntryList[current_size - 1])
  341. {
  342. // copy the last valid entry for the new one
  343. mEntryList[index] = mEntryList[current_size - 1]->newCopy();
  344. }
  345. else
  346. {
  347. // no valid enries to copy, so we new one up
  348. LLTextureEntry* new_entry = LLPrimTextureList::newTextureEntry();
  349. mEntryList[index] = new_entry;
  350. }
  351. }
  352. }
  353. else if (new_size < current_size)
  354. {
  355. for (S32 index = current_size-1; index >= new_size; --index)
  356. {
  357. delete mEntryList[index];
  358. }
  359. mEntryList.resize(new_size);
  360. }
  361. }
  362. void LLPrimTextureList::setAllIDs(const LLUUID& id)
  363. {
  364. texture_list_t::iterator itr = mEntryList.begin();
  365. while (itr != mEntryList.end())
  366. {
  367. (*itr)->setID(id);
  368. ++itr;
  369. }
  370. }