eggTexture.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // Filename: eggTexture.h
  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. #ifndef EGGTEXTURE_H
  19. #define EGGTEXTURE_H
  20. #include <pandabase.h>
  21. #include "eggRenderMode.h"
  22. #include "eggFilenameNode.h"
  23. #include <luse.h>
  24. ////////////////////////////////////////////////////////////////////
  25. // Class : EggTexture
  26. // Description : Defines a texture map that may be applied to
  27. // geometry.
  28. ////////////////////////////////////////////////////////////////////
  29. class EXPCL_PANDAEGG EggTexture : public EggFilenameNode, public EggRenderMode {
  30. public:
  31. EggTexture(const string &tref_name, const string &filename);
  32. EggTexture(const EggTexture &copy);
  33. EggTexture &operator = (const EggTexture &copy);
  34. virtual void write(ostream &out, int indent_level) const;
  35. enum Equivalence {
  36. E_basename = 0x001,
  37. E_extension = 0x002,
  38. E_dirname = 0x004,
  39. E_complete_filename = 0x007,
  40. E_transform = 0x008,
  41. E_attributes = 0x010,
  42. E_tref_name = 0x020,
  43. };
  44. bool is_equivalent_to(const EggTexture &other, int eq) const;
  45. bool sorts_less_than(const EggTexture &other, int eq) const;
  46. bool has_alpha_channel(int num_components) const;
  47. enum Format {
  48. F_unspecified,
  49. F_rgba, F_rgbm, F_rgba12, F_rgba8, F_rgba4, F_rgba5,
  50. F_rgb, F_rgb12, F_rgb8, F_rgb5, F_rgb332,
  51. F_red, F_green, F_blue, F_alpha, F_luminance,
  52. F_luminance_alpha, F_luminance_alphamask
  53. };
  54. enum WrapMode {
  55. WM_unspecified, WM_repeat, WM_clamp
  56. };
  57. enum FilterType {
  58. // Note that these type values match up, name-for-name, with a
  59. // similar enumerated type in Panda's Texture object. However,
  60. // they do *not* match up numerically. You must convert between
  61. // them using a switch statement.
  62. FT_unspecified,
  63. // Mag Filter and Min Filter
  64. FT_nearest,
  65. FT_linear,
  66. // Min Filter Only
  67. FT_nearest_mipmap_nearest, // "mipmap point"
  68. FT_linear_mipmap_nearest, // "mipmap linear"
  69. FT_nearest_mipmap_linear, // "mipmap bilinear"
  70. FT_linear_mipmap_linear, // "mipmap trilinear"
  71. };
  72. enum EnvType {
  73. ET_unspecified, ET_modulate, ET_decal
  74. };
  75. INLINE void set_format(Format format);
  76. INLINE Format get_format() const;
  77. INLINE void set_wrap_mode(WrapMode mode);
  78. INLINE WrapMode get_wrap_mode() const;
  79. INLINE void set_wrap_u(WrapMode mode);
  80. INLINE WrapMode get_wrap_u() const;
  81. INLINE WrapMode determine_wrap_u() const;
  82. INLINE void set_wrap_v(WrapMode mode);
  83. INLINE WrapMode get_wrap_v() const;
  84. INLINE WrapMode determine_wrap_v() const;
  85. INLINE void set_minfilter(FilterType type);
  86. INLINE FilterType get_minfilter() const;
  87. INLINE void set_magfilter(FilterType type);
  88. INLINE FilterType get_magfilter() const;
  89. INLINE void set_anisotropic_degree(int anisotropic_degree);
  90. INLINE void clear_anisotropic_degree();
  91. INLINE bool has_anisotropic_degree() const;
  92. INLINE int get_anisotropic_degree() const;
  93. INLINE void set_env_type(EnvType type);
  94. INLINE EnvType get_env_type() const;
  95. INLINE void set_transform(const LMatrix3d &transform);
  96. INLINE void clear_transform();
  97. INLINE bool has_transform() const;
  98. INLINE LMatrix3d get_transform() const;
  99. INLINE bool transform_is_identity() const;
  100. INLINE void set_alpha_file(const Filename &filename);
  101. INLINE void clear_alpha_file();
  102. INLINE bool has_alpha_file() const;
  103. INLINE const Filename &get_alpha_file() const;
  104. INLINE Filename &update_alpha_file();
  105. static Format string_format(const string &string);
  106. static WrapMode string_wrap_mode(const string &string);
  107. static FilterType string_filter_type(const string &string);
  108. static EnvType string_env_type(const string &string);
  109. protected:
  110. virtual bool egg_start_parse_body();
  111. private:
  112. enum Flags {
  113. F_has_transform = 0x0001,
  114. F_has_alpha_file = 0x0002,
  115. F_has_anisotropic_degree = 0x0004,
  116. };
  117. Format _format;
  118. WrapMode _wrap_mode, _wrap_u, _wrap_v;
  119. FilterType _minfilter, _magfilter;
  120. int _anisotropic_degree;
  121. EnvType _env_type;
  122. int _flags;
  123. LMatrix3d _transform;
  124. Filename _alpha_file;
  125. public:
  126. static TypeHandle get_class_type() {
  127. return _type_handle;
  128. }
  129. static void init_type() {
  130. EggFilenameNode::init_type();
  131. EggRenderMode::init_type();
  132. register_type(_type_handle, "EggTexture",
  133. EggFilenameNode::get_class_type(),
  134. EggRenderMode::get_class_type());
  135. }
  136. virtual TypeHandle get_type() const {
  137. return get_class_type();
  138. }
  139. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  140. private:
  141. static TypeHandle _type_handle;
  142. };
  143. ///////////////////////////////////////////////////////////////////
  144. // Class : UniqueEggTextures
  145. // Description : An STL function object for sorting textures into
  146. // order by properties. Returns true if the two
  147. // referenced EggTexture pointers are in sorted order,
  148. // false otherwise.
  149. ////////////////////////////////////////////////////////////////////
  150. class EXPCL_PANDAEGG UniqueEggTextures {
  151. public:
  152. INLINE UniqueEggTextures(int eq = ~0);
  153. INLINE bool operator ()(const EggTexture *t1, const EggTexture *t2) const;
  154. int _eq;
  155. };
  156. INLINE ostream &operator << (ostream &out, const EggTexture &n) {
  157. return out << n.get_filename();
  158. }
  159. ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::Format format);
  160. ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::WrapMode mode);
  161. ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::FilterType type);
  162. ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::EnvType type);
  163. #include "eggTexture.I"
  164. #endif