textureStage.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // Filename: textureStage.h
  2. // Created by: drose (14Jul04)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef TEXTURESTAGE_H
  15. #define TEXTURESTAGE_H
  16. #include "pandabase.h"
  17. #include "internalName.h"
  18. #include "pointerTo.h"
  19. #include "typedWritableReferenceCount.h"
  20. #include "updateSeq.h"
  21. #include "luse.h"
  22. class FactoryParams;
  23. ////////////////////////////////////////////////////////////////////
  24. // Class : TextureStage
  25. // Description : Defines the properties of a named stage of the
  26. // multitexture pipeline. The TextureAttrib will
  27. // associated a number of these stages with Texture
  28. // objects, and the GSG will render geometry by sorting
  29. // all of the currently active TextureStages in order
  30. // and then issuing the appropriate rendering calls to
  31. // activate them.
  32. ////////////////////////////////////////////////////////////////////
  33. class EXPCL_PANDA_GOBJ TextureStage : public TypedWritableReferenceCount {
  34. PUBLISHED:
  35. explicit TextureStage(const string &name);
  36. INLINE TextureStage(TextureStage &copy);
  37. void operator = (const TextureStage &copy);
  38. virtual ~TextureStage();
  39. enum Mode {
  40. // Modes that pertain to the fixed-function pipeline.
  41. M_modulate,
  42. M_decal,
  43. M_blend,
  44. M_replace,
  45. M_add,
  46. M_combine,
  47. M_blend_color_scale,
  48. M_modulate_glow, // When fixed-function, equivalent to modulate.
  49. M_modulate_gloss, // When fixed-function, equivalent to modulate.
  50. // Modes that are only relevant to shader-based rendering.
  51. M_normal,
  52. M_normal_height,
  53. M_glow, // Rarely used: modulate_glow is more efficient.
  54. M_gloss, // Rarely used: modulate_gloss is more efficient.
  55. M_height, // Rarely used: normal_height is more efficient.
  56. M_selector,
  57. M_normal_gloss,
  58. };
  59. enum CombineMode {
  60. CM_undefined,
  61. CM_replace,
  62. CM_modulate,
  63. CM_add,
  64. CM_add_signed,
  65. CM_interpolate,
  66. CM_subtract,
  67. // The following are valid only for combine_rgb, not
  68. // combine_alpha.
  69. CM_dot3_rgb,
  70. CM_dot3_rgba,
  71. };
  72. enum CombineSource {
  73. CS_undefined,
  74. CS_texture,
  75. CS_constant,
  76. CS_primary_color,
  77. CS_previous,
  78. CS_constant_color_scale,
  79. CS_last_saved_result,
  80. };
  81. enum CombineOperand {
  82. CO_undefined,
  83. CO_src_color,
  84. CO_one_minus_src_color,
  85. CO_src_alpha,
  86. CO_one_minus_src_alpha,
  87. };
  88. INLINE void set_name(const string &name);
  89. INLINE const string &get_name() const;
  90. INLINE void set_sort(int sort);
  91. INLINE int get_sort() const;
  92. INLINE void set_priority(int priority);
  93. INLINE int get_priority() const;
  94. INLINE void set_texcoord_name(InternalName *name);
  95. INLINE void set_texcoord_name(const string &texcoord_name);
  96. INLINE InternalName *get_texcoord_name() const;
  97. INLINE InternalName *get_tangent_name() const;
  98. INLINE InternalName *get_binormal_name() const;
  99. INLINE void set_mode(Mode mode);
  100. INLINE Mode get_mode() const;
  101. INLINE bool is_fixed_function() const;
  102. INLINE void set_color(const LColor &color);
  103. INLINE LColor get_color() const;
  104. INLINE void set_rgb_scale(int rgb_scale);
  105. INLINE int get_rgb_scale() const;
  106. INLINE void set_alpha_scale(int alpha_scale);
  107. INLINE int get_alpha_scale() const;
  108. INLINE void set_saved_result(bool saved_result);
  109. INLINE bool get_saved_result() const;
  110. INLINE void set_tex_view_offset(int tex_view_offset);
  111. INLINE int get_tex_view_offset() const;
  112. INLINE void set_combine_rgb(CombineMode mode,
  113. CombineSource source0, CombineOperand operand0);
  114. INLINE void set_combine_rgb(CombineMode mode,
  115. CombineSource source0, CombineOperand operand0,
  116. CombineSource source1, CombineOperand operand1);
  117. INLINE void set_combine_rgb(CombineMode mode,
  118. CombineSource source0, CombineOperand operand0,
  119. CombineSource source1, CombineOperand operand1,
  120. CombineSource source2, CombineOperand operand2);
  121. INLINE CombineMode get_combine_rgb_mode() const;
  122. INLINE int get_num_combine_rgb_operands() const;
  123. INLINE CombineSource get_combine_rgb_source0() const;
  124. INLINE CombineOperand get_combine_rgb_operand0() const;
  125. INLINE CombineSource get_combine_rgb_source1() const;
  126. INLINE CombineOperand get_combine_rgb_operand1() const;
  127. INLINE CombineSource get_combine_rgb_source2() const;
  128. INLINE CombineOperand get_combine_rgb_operand2() const;
  129. INLINE void set_combine_alpha(CombineMode mode,
  130. CombineSource source0, CombineOperand operand0);
  131. INLINE void set_combine_alpha(CombineMode mode,
  132. CombineSource source0, CombineOperand operand0,
  133. CombineSource source1, CombineOperand operand1);
  134. INLINE void set_combine_alpha(CombineMode mode,
  135. CombineSource source0, CombineOperand operand0,
  136. CombineSource source1, CombineOperand operand1,
  137. CombineSource source2, CombineOperand operand2);
  138. INLINE CombineMode get_combine_alpha_mode() const;
  139. INLINE int get_num_combine_alpha_operands() const;
  140. INLINE CombineSource get_combine_alpha_source0() const;
  141. INLINE CombineOperand get_combine_alpha_operand0() const;
  142. INLINE CombineSource get_combine_alpha_source1() const;
  143. INLINE CombineOperand get_combine_alpha_operand1() const;
  144. INLINE CombineSource get_combine_alpha_source2() const;
  145. INLINE CombineOperand get_combine_alpha_operand2() const;
  146. INLINE bool involves_color_scale() const;
  147. INLINE bool uses_color() const;
  148. INLINE bool uses_primary_color() const;
  149. INLINE bool uses_last_saved_result() const;
  150. INLINE bool operator == (const TextureStage &other) const;
  151. INLINE bool operator != (const TextureStage &other) const;
  152. INLINE bool operator < (const TextureStage &other) const;
  153. int compare_to(const TextureStage &other) const;
  154. void write(ostream &out) const;
  155. void output(ostream &out) const;
  156. INLINE static TextureStage *get_default();
  157. public:
  158. INLINE static UpdateSeq get_sort_seq();
  159. private:
  160. INLINE void update_color_flags();
  161. static int get_expected_num_combine_operands(CombineMode cm);
  162. static bool operand_valid_for_rgb(CombineOperand co);
  163. static bool operand_valid_for_alpha(CombineOperand co);
  164. string _name;
  165. int _sort;
  166. int _priority;
  167. PT(InternalName) _texcoord_name;
  168. Mode _mode;
  169. LColor _color;
  170. int _rgb_scale;
  171. int _alpha_scale;
  172. bool _saved_result;
  173. int _tex_view_offset;
  174. bool _involves_color_scale;
  175. bool _uses_color;
  176. bool _uses_primary_color;
  177. bool _uses_last_saved_result;
  178. CombineMode _combine_rgb_mode;
  179. int _num_combine_rgb_operands;
  180. CombineSource _combine_rgb_source0;
  181. CombineOperand _combine_rgb_operand0;
  182. CombineSource _combine_rgb_source1;
  183. CombineOperand _combine_rgb_operand1;
  184. CombineSource _combine_rgb_source2;
  185. CombineOperand _combine_rgb_operand2;
  186. CombineMode _combine_alpha_mode;
  187. int _num_combine_alpha_operands;
  188. CombineSource _combine_alpha_source0;
  189. CombineOperand _combine_alpha_operand0;
  190. CombineSource _combine_alpha_source1;
  191. CombineOperand _combine_alpha_operand1;
  192. CombineSource _combine_alpha_source2;
  193. CombineOperand _combine_alpha_operand2;
  194. static PT(TextureStage) _default_stage;
  195. static UpdateSeq _sort_seq;
  196. public:
  197. // Datagram stuff
  198. static void register_with_read_factory();
  199. virtual void write_datagram(BamWriter *manager, Datagram &me);
  200. virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
  201. static TypedWritable *make_TextureStage(const FactoryParams &params);
  202. protected:
  203. void fillin(DatagramIterator& scan, BamReader* manager);
  204. public:
  205. static TypeHandle get_class_type() {
  206. return _type_handle;
  207. }
  208. static void init_type() {
  209. TypedWritableReferenceCount::init_type();
  210. register_type(_type_handle, "TextureStage",
  211. TypedWritableReferenceCount::get_class_type());
  212. }
  213. virtual TypeHandle get_type() const {
  214. return get_class_type();
  215. }
  216. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  217. private:
  218. static TypeHandle _type_handle;
  219. };
  220. INLINE ostream &operator << (ostream &out, const TextureStage &ts);
  221. EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::Mode mode);
  222. EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineMode cm);
  223. EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineSource cs);
  224. EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineOperand co);
  225. #include "textureStage.I"
  226. #endif