eggTexture.I 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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_anisotropic_degree
  154. // Access: Public
  155. // Description: Sets the degree of anisotropic filtering for this
  156. // texture. 1 is off; higher levels indicate filtering
  157. // in effect.
  158. ////////////////////////////////////////////////////////////////////
  159. INLINE void EggTexture::
  160. set_anisotropic_degree(int anisotropic_degree) {
  161. _anisotropic_degree = anisotropic_degree;
  162. _flags |= F_has_anisotropic_degree;
  163. }
  164. ////////////////////////////////////////////////////////////////////
  165. // Function: EggTexture::clear_anisotropic_degree
  166. // Access: Public
  167. // Description: Removes the specification of anisotropic filtering
  168. // from the texture.
  169. ////////////////////////////////////////////////////////////////////
  170. INLINE void EggTexture::
  171. clear_anisotropic_degree() {
  172. _anisotropic_degree = 0;
  173. _flags &= ~F_has_anisotropic_degree;
  174. }
  175. ////////////////////////////////////////////////////////////////////
  176. // Function: EggTexture::has_anisotropic_degree
  177. // Access: Public
  178. // Description: Returns true if a value for the anisotropic filtering
  179. // degree has been specified for this texture, false
  180. // otherwise.
  181. ////////////////////////////////////////////////////////////////////
  182. INLINE bool EggTexture::
  183. has_anisotropic_degree() const {
  184. return (_flags & F_has_anisotropic_degree) != 0;
  185. }
  186. ////////////////////////////////////////////////////////////////////
  187. // Function: EggTexture::get_anisotropic_degree
  188. // Access: Public
  189. // Description: Returns the anisotropic filtering degree that has
  190. // been specified for this texture. It is an error to
  191. // call this unless has_anisotropic_degree() returns
  192. // true.
  193. ////////////////////////////////////////////////////////////////////
  194. INLINE int EggTexture::
  195. get_anisotropic_degree() const {
  196. // nassertr(has_anisotropic_degree(), 1);
  197. // note: _anisotropic_degree's of 0 and 1 are equivalent (no anisotropic filtering to be done by gsg)
  198. return _anisotropic_degree;
  199. }
  200. ////////////////////////////////////////////////////////////////////
  201. // Function: EggTexture::set_env_type
  202. // Access: Public
  203. // Description:
  204. ////////////////////////////////////////////////////////////////////
  205. INLINE void EggTexture::
  206. set_env_type(EnvType type) {
  207. _env_type = type;
  208. }
  209. ////////////////////////////////////////////////////////////////////
  210. // Function: EggTexture::get_env_type
  211. // Access: Public
  212. // Description:
  213. ////////////////////////////////////////////////////////////////////
  214. INLINE EggTexture::EnvType EggTexture::
  215. get_env_type() const {
  216. return _env_type;
  217. }
  218. ////////////////////////////////////////////////////////////////////
  219. // Function: EggTexture::set_transform
  220. // Access: Public
  221. // Description:
  222. ////////////////////////////////////////////////////////////////////
  223. INLINE void EggTexture::
  224. set_transform(const LMatrix3d &transform) {
  225. _transform = transform;
  226. _flags |= F_has_transform;
  227. }
  228. ////////////////////////////////////////////////////////////////////
  229. // Function: EggTexture::clear_transform
  230. // Access: Public
  231. // Description:
  232. ////////////////////////////////////////////////////////////////////
  233. INLINE void EggTexture::
  234. clear_transform() {
  235. _transform = LMatrix3d::ident_mat();
  236. _flags &= ~F_has_transform;
  237. }
  238. ////////////////////////////////////////////////////////////////////
  239. // Function: EggTexture::has_transform
  240. // Access: Public
  241. // Description: Returns true if a texture matrix transform has been
  242. // specified for the texture (even if the transform is
  243. // identity).
  244. ////////////////////////////////////////////////////////////////////
  245. INLINE bool EggTexture::
  246. has_transform() const {
  247. return (_flags & F_has_transform) != 0;
  248. }
  249. ////////////////////////////////////////////////////////////////////
  250. // Function: EggTexture::get_transform
  251. // Access: Public
  252. // Description:
  253. ////////////////////////////////////////////////////////////////////
  254. INLINE LMatrix3d EggTexture::
  255. get_transform() const {
  256. nassertr(has_transform(), LMatrix3d::ident_mat());
  257. return _transform;
  258. }
  259. ////////////////////////////////////////////////////////////////////
  260. // Function: EggTexture::transform_is_identity()
  261. // Access: Public
  262. // Description: Returns true if no texture matrix transform has been
  263. // specified, or if the one specified is the identity
  264. // transform. Returns false only if a nonidentity
  265. // transform has been applied.
  266. ////////////////////////////////////////////////////////////////////
  267. INLINE bool EggTexture::
  268. transform_is_identity() const {
  269. return (!has_transform() ||
  270. _transform.almost_equal(LMatrix3d::ident_mat(), 0.0001));
  271. }
  272. ////////////////////////////////////////////////////////////////////
  273. // Function: EggTexture::set_alpha_file
  274. // Access: Public
  275. // Description: Specifies a separate file that will be loaded in with
  276. // the 1- or 3-component texture and applied as the
  277. // alpha channel. This is useful when loading textures
  278. // from file formats that do not support alpha, for
  279. // instance jpg.
  280. ////////////////////////////////////////////////////////////////////
  281. INLINE void EggTexture::
  282. set_alpha_file(const Filename &alpha_file) {
  283. _alpha_file = alpha_file;
  284. _flags |= F_has_alpha_file;
  285. }
  286. ////////////////////////////////////////////////////////////////////
  287. // Function: EggTexture::clear_alpha_file
  288. // Access: Public
  289. // Description:
  290. ////////////////////////////////////////////////////////////////////
  291. INLINE void EggTexture::
  292. clear_alpha_file() {
  293. _alpha_file = Filename();
  294. _flags &= ~F_has_alpha_file;
  295. }
  296. ////////////////////////////////////////////////////////////////////
  297. // Function: EggTexture::has_alpha_file
  298. // Access: Public
  299. // Description: Returns true if a separate file for the alpha
  300. // component has been applied, false otherwise. See
  301. // set_alpha_file().
  302. ////////////////////////////////////////////////////////////////////
  303. INLINE bool EggTexture::
  304. has_alpha_file() const {
  305. return (_flags & F_has_alpha_file) != 0;
  306. }
  307. ////////////////////////////////////////////////////////////////////
  308. // Function: EggTexture::get_alpha_file
  309. // Access: Public
  310. // Description: Returns the separate file assigned for the alpha
  311. // channel. It is an error to call this unless
  312. // has_alpha_file() returns true. See set_alpha_file().
  313. ////////////////////////////////////////////////////////////////////
  314. INLINE const Filename &EggTexture::
  315. get_alpha_file() const {
  316. nassertr(has_alpha_file(), _alpha_file);
  317. return _alpha_file;
  318. }
  319. ////////////////////////////////////////////////////////////////////
  320. // Function: EggTexture::update_alpha_file
  321. // Access: Public
  322. // Description: Returns a modifiable reference to the separate file
  323. // assigned for the alpha channel. If an alpha file has
  324. // not yet been added, this adds an empty one.
  325. ////////////////////////////////////////////////////////////////////
  326. INLINE Filename &EggTexture::
  327. update_alpha_file() {
  328. if (!has_alpha_file()) {
  329. set_alpha_file(Filename());
  330. }
  331. return _alpha_file;
  332. }
  333. ////////////////////////////////////////////////////////////////////
  334. // Function: UniqueEggTextures::Constructor
  335. // Access: Public
  336. // Description:
  337. ////////////////////////////////////////////////////////////////////
  338. INLINE UniqueEggTextures::
  339. UniqueEggTextures(int eq) : _eq(eq) {
  340. }
  341. ////////////////////////////////////////////////////////////////////
  342. // Function: UniqueEggTextures::Function operator
  343. // Access: Public
  344. // Description:
  345. ////////////////////////////////////////////////////////////////////
  346. INLINE bool UniqueEggTextures::
  347. operator ()(const EggTexture *t1, const EggTexture *t2) const {
  348. return t1->sorts_less_than(*t2, _eq);
  349. }