eggTexture.I 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. // Filename: eggTexture.I
  2. // Created by: drose (18Jan99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: EggTexture::set_format
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE void EggTexture::
  24. set_format(Format format) {
  25. _format = format;
  26. }
  27. ////////////////////////////////////////////////////////////////////
  28. // Function: EggTexture::get_format
  29. // Access: Public
  30. // Description:
  31. ////////////////////////////////////////////////////////////////////
  32. INLINE EggTexture::Format EggTexture::
  33. get_format() const {
  34. return _format;
  35. }
  36. ////////////////////////////////////////////////////////////////////
  37. // Function: EggTexture::set_wrap_mode
  38. // Access: Public
  39. // Description:
  40. ////////////////////////////////////////////////////////////////////
  41. INLINE void EggTexture::
  42. set_wrap_mode(WrapMode mode) {
  43. _wrap_mode = mode;
  44. }
  45. ////////////////////////////////////////////////////////////////////
  46. // Function: EggTexture::get_wrap_mode
  47. // Access: Public
  48. // Description:
  49. ////////////////////////////////////////////////////////////////////
  50. INLINE EggTexture::WrapMode EggTexture::
  51. get_wrap_mode() const {
  52. return _wrap_mode;
  53. }
  54. ////////////////////////////////////////////////////////////////////
  55. // Function: EggTexture::set_wrap_u
  56. // Access: Public
  57. // Description:
  58. ////////////////////////////////////////////////////////////////////
  59. INLINE void EggTexture::
  60. set_wrap_u(WrapMode mode) {
  61. _wrap_u = mode;
  62. }
  63. ////////////////////////////////////////////////////////////////////
  64. // Function: EggTexture::get_wrap_u
  65. // Access: Public
  66. // Description: Returns the amount specified for U wrap. This may be
  67. // unspecified, even if there is an overall wrap value.
  68. ////////////////////////////////////////////////////////////////////
  69. INLINE EggTexture::WrapMode EggTexture::
  70. get_wrap_u() const {
  71. return _wrap_u;
  72. }
  73. ////////////////////////////////////////////////////////////////////
  74. // Function: EggTexture::determine_wrap_u
  75. // Access: Public
  76. // Description: Determines the appropriate wrap in the U direction.
  77. // This is different from get_wrap_u() in that if the U
  78. // wrap is unspecified, it returns the overall wrap
  79. // value.
  80. ////////////////////////////////////////////////////////////////////
  81. INLINE EggTexture::WrapMode EggTexture::
  82. determine_wrap_u() const {
  83. return (_wrap_u == WM_unspecified) ? get_wrap_mode() : get_wrap_u();
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Function: EggTexture::set_wrap_v
  87. // Access: Public
  88. // Description:
  89. ////////////////////////////////////////////////////////////////////
  90. INLINE void EggTexture::
  91. set_wrap_v(WrapMode mode) {
  92. _wrap_v = mode;
  93. }
  94. ////////////////////////////////////////////////////////////////////
  95. // Function: EggTexture::get_wrap_v
  96. // Access: Public
  97. // Description: Returns the amount specified for V wrap. This may be
  98. // unspecified, even if there is an overall wrap value.
  99. ////////////////////////////////////////////////////////////////////
  100. INLINE EggTexture::WrapMode EggTexture::
  101. get_wrap_v() const {
  102. return _wrap_v;
  103. }
  104. ////////////////////////////////////////////////////////////////////
  105. // Function: EggTexture::determine_wrap_v
  106. // Access: Public
  107. // Description: Determines the appropriate wrap in the V direction.
  108. // This is different from get_wrap_v() in that if the U
  109. // wrap is unspecified, it returns the overall wrap
  110. // value.
  111. ////////////////////////////////////////////////////////////////////
  112. INLINE EggTexture::WrapMode EggTexture::
  113. determine_wrap_v() const {
  114. return (_wrap_v == WM_unspecified) ? get_wrap_mode() : get_wrap_v();
  115. }
  116. ////////////////////////////////////////////////////////////////////
  117. // Function: EggTexture::set_minfilter
  118. // Access: Public
  119. // Description:
  120. ////////////////////////////////////////////////////////////////////
  121. INLINE void EggTexture::
  122. set_minfilter(FilterType type) {
  123. _minfilter = type;
  124. }
  125. ////////////////////////////////////////////////////////////////////
  126. // Function: EggTexture::get_minfilter
  127. // Access: Public
  128. // Description:
  129. ////////////////////////////////////////////////////////////////////
  130. INLINE EggTexture::FilterType EggTexture::
  131. get_minfilter() const {
  132. return _minfilter;
  133. }
  134. ////////////////////////////////////////////////////////////////////
  135. // Function: EggTexture::set_magfilter
  136. // Access: Public
  137. // Description:
  138. ////////////////////////////////////////////////////////////////////
  139. INLINE void EggTexture::
  140. set_magfilter(FilterType type) {
  141. _magfilter = type;
  142. }
  143. ////////////////////////////////////////////////////////////////////
  144. // Function: EggTexture::get_magfilter
  145. // Access: Public
  146. // Description:
  147. ////////////////////////////////////////////////////////////////////
  148. INLINE EggTexture::FilterType EggTexture::
  149. get_magfilter() const {
  150. return _magfilter;
  151. }
  152. ////////////////////////////////////////////////////////////////////
  153. // Function: EggTexture::set_magfilteralpha
  154. // Access: Public
  155. // Description:
  156. ////////////////////////////////////////////////////////////////////
  157. INLINE void EggTexture::
  158. set_magfilteralpha(FilterType type) {
  159. _magfilteralpha = type;
  160. }
  161. ////////////////////////////////////////////////////////////////////
  162. // Function: EggTexture::get_magfilteralpha
  163. // Access: Public
  164. // Description:
  165. ////////////////////////////////////////////////////////////////////
  166. INLINE EggTexture::FilterType EggTexture::
  167. get_magfilteralpha() const {
  168. return _magfilteralpha;
  169. }
  170. ////////////////////////////////////////////////////////////////////
  171. // Function: EggTexture::set_magfiltercolor
  172. // Access: Public
  173. // Description:
  174. ////////////////////////////////////////////////////////////////////
  175. INLINE void EggTexture::
  176. set_magfiltercolor(FilterType type) {
  177. _magfiltercolor = type;
  178. }
  179. ////////////////////////////////////////////////////////////////////
  180. // Function: EggTexture::get_magfiltercolor
  181. // Access: Public
  182. // Description:
  183. ////////////////////////////////////////////////////////////////////
  184. INLINE EggTexture::FilterType EggTexture::
  185. get_magfiltercolor() const {
  186. return _magfiltercolor;
  187. }
  188. ////////////////////////////////////////////////////////////////////
  189. // Function: EggTexture::set_anisotropic_degree
  190. // Access: Public
  191. // Description: Sets the degree of anisotropic filtering for this
  192. // texture. 1 is off; higher levels indicate filtering
  193. // in effect.
  194. ////////////////////////////////////////////////////////////////////
  195. INLINE void EggTexture::
  196. set_anisotropic_degree(int anisotropic_degree) {
  197. _anisotropic_degree = anisotropic_degree;
  198. _flags |= F_has_anisotropic_degree;
  199. }
  200. ////////////////////////////////////////////////////////////////////
  201. // Function: EggTexture::clear_anisotropic_degree
  202. // Access: Public
  203. // Description: Removes the specification of anisotropic filtering
  204. // from the texture.
  205. ////////////////////////////////////////////////////////////////////
  206. INLINE void EggTexture::
  207. clear_anisotropic_degree() {
  208. _anisotropic_degree = 0;
  209. _flags &= ~F_has_anisotropic_degree;
  210. }
  211. ////////////////////////////////////////////////////////////////////
  212. // Function: EggTexture::has_anisotropic_degree
  213. // Access: Public
  214. // Description: Returns true if a value for the anisotropic filtering
  215. // degree has been specified for this texture, false
  216. // otherwise.
  217. ////////////////////////////////////////////////////////////////////
  218. INLINE bool EggTexture::
  219. has_anisotropic_degree() const {
  220. return (_flags & F_has_anisotropic_degree) != 0;
  221. }
  222. ////////////////////////////////////////////////////////////////////
  223. // Function: EggTexture::get_anisotropic_degree
  224. // Access: Public
  225. // Description: Returns the anisotropic filtering degree that has
  226. // been specified for this texture. It is an error to
  227. // call this unless has_anisotropic_degree() returns
  228. // true.
  229. ////////////////////////////////////////////////////////////////////
  230. INLINE int EggTexture::
  231. get_anisotropic_degree() const {
  232. nassertr(has_anisotropic_degree(), 1);
  233. return _anisotropic_degree;
  234. }
  235. ////////////////////////////////////////////////////////////////////
  236. // Function: EggTexture::set_env_type
  237. // Access: Public
  238. // Description:
  239. ////////////////////////////////////////////////////////////////////
  240. INLINE void EggTexture::
  241. set_env_type(EnvType type) {
  242. _env_type = type;
  243. }
  244. ////////////////////////////////////////////////////////////////////
  245. // Function: EggTexture::get_env_type
  246. // Access: Public
  247. // Description:
  248. ////////////////////////////////////////////////////////////////////
  249. INLINE EggTexture::EnvType EggTexture::
  250. get_env_type() const {
  251. return _env_type;
  252. }
  253. ////////////////////////////////////////////////////////////////////
  254. // Function: EggTexture::set_transform
  255. // Access: Public
  256. // Description:
  257. ////////////////////////////////////////////////////////////////////
  258. INLINE void EggTexture::
  259. set_transform(const LMatrix3d &transform) {
  260. _transform = transform;
  261. _flags |= F_has_transform;
  262. }
  263. ////////////////////////////////////////////////////////////////////
  264. // Function: EggTexture::clear_transform
  265. // Access: Public
  266. // Description:
  267. ////////////////////////////////////////////////////////////////////
  268. INLINE void EggTexture::
  269. clear_transform() {
  270. _transform = LMatrix3d::ident_mat();
  271. _flags &= ~F_has_transform;
  272. }
  273. ////////////////////////////////////////////////////////////////////
  274. // Function: EggTexture::has_transform
  275. // Access: Public
  276. // Description: Returns true if a texture matrix transform has been
  277. // specified for the texture (even if the transform is
  278. // identity).
  279. ////////////////////////////////////////////////////////////////////
  280. INLINE bool EggTexture::
  281. has_transform() const {
  282. return (_flags & F_has_transform) != 0;
  283. }
  284. ////////////////////////////////////////////////////////////////////
  285. // Function: EggTexture::get_transform
  286. // Access: Public
  287. // Description:
  288. ////////////////////////////////////////////////////////////////////
  289. INLINE LMatrix3d EggTexture::
  290. get_transform() const {
  291. nassertr(has_transform(), LMatrix3d::ident_mat());
  292. return _transform;
  293. }
  294. ////////////////////////////////////////////////////////////////////
  295. // Function: EggTexture::transform_is_identity()
  296. // Access: Public
  297. // Description: Returns true if no texture matrix transform has been
  298. // specified, or if the one specified is the identity
  299. // transform. Returns false only if a nonidentity
  300. // transform has been applied.
  301. ////////////////////////////////////////////////////////////////////
  302. INLINE bool EggTexture::
  303. transform_is_identity() const {
  304. return (!has_transform() ||
  305. _transform.almost_equal(LMatrix3d::ident_mat(), 0.0001));
  306. }
  307. ////////////////////////////////////////////////////////////////////
  308. // Function: EggTexture::set_alpha_file
  309. // Access: Public
  310. // Description: Specifies a separate file that will be loaded in with
  311. // the 1- or 3-component texture and applied as the
  312. // alpha channel. This is useful when loading textures
  313. // from file formats that do not support alpha, for
  314. // instance jpg.
  315. ////////////////////////////////////////////////////////////////////
  316. INLINE void EggTexture::
  317. set_alpha_file(const Filename &alpha_file) {
  318. _alpha_file = alpha_file;
  319. _flags |= F_has_alpha_file;
  320. }
  321. ////////////////////////////////////////////////////////////////////
  322. // Function: EggTexture::clear_alpha_file
  323. // Access: Public
  324. // Description:
  325. ////////////////////////////////////////////////////////////////////
  326. INLINE void EggTexture::
  327. clear_alpha_file() {
  328. _alpha_file = Filename();
  329. _flags &= ~F_has_alpha_file;
  330. }
  331. ////////////////////////////////////////////////////////////////////
  332. // Function: EggTexture::has_alpha_file
  333. // Access: Public
  334. // Description: Returns true if a separate file for the alpha
  335. // component has been applied, false otherwise. See
  336. // set_alpha_file().
  337. ////////////////////////////////////////////////////////////////////
  338. INLINE bool EggTexture::
  339. has_alpha_file() const {
  340. return (_flags & F_has_alpha_file) != 0;
  341. }
  342. ////////////////////////////////////////////////////////////////////
  343. // Function: EggTexture::get_alpha_file
  344. // Access: Public
  345. // Description: Returns the separate file assigned for the alpha
  346. // channel. It is an error to call this unless
  347. // has_alpha_file() returns true. See set_alpha_file().
  348. ////////////////////////////////////////////////////////////////////
  349. INLINE const Filename &EggTexture::
  350. get_alpha_file() const {
  351. nassertr(has_alpha_file(), _alpha_file);
  352. return _alpha_file;
  353. }
  354. ////////////////////////////////////////////////////////////////////
  355. // Function: EggTexture::update_alpha_file
  356. // Access: Public
  357. // Description: Returns a modifiable reference to the separate file
  358. // assigned for the alpha channel. If an alpha file has
  359. // not yet been added, this adds an empty one.
  360. ////////////////////////////////////////////////////////////////////
  361. INLINE Filename &EggTexture::
  362. update_alpha_file() {
  363. if (!has_alpha_file()) {
  364. set_alpha_file(Filename());
  365. }
  366. return _alpha_file;
  367. }
  368. ////////////////////////////////////////////////////////////////////
  369. // Function: UniqueEggTextures::Constructor
  370. // Access: Public
  371. // Description:
  372. ////////////////////////////////////////////////////////////////////
  373. INLINE UniqueEggTextures::
  374. UniqueEggTextures(int eq) : _eq(eq) {
  375. }
  376. ////////////////////////////////////////////////////////////////////
  377. // Function: UniqueEggTextures::Function operator
  378. // Access: Public
  379. // Description:
  380. ////////////////////////////////////////////////////////////////////
  381. INLINE bool UniqueEggTextures::
  382. operator ()(const EggTexture *t1, const EggTexture *t2) const {
  383. return t1->sorts_less_than(*t2, _eq);
  384. }