Panda3D

textureStage.h

00001 // Filename: textureStage.h
00002 // Created by:  drose (14Jul04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef TEXTURESTAGE_H
00016 #define TEXTURESTAGE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "internalName.h"
00021 #include "pointerTo.h"
00022 #include "typedWritableReferenceCount.h"
00023 #include "updateSeq.h"
00024 #include "luse.h"
00025 
00026 class FactoryParams;
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : TextureStage
00030 // Description : Defines the properties of a named stage of the
00031 //               multitexture pipeline.  The TextureAttrib will
00032 //               associated a number of these stages with Texture
00033 //               objects, and the GSG will render geometry by sorting
00034 //               all of the currently active TextureStages in order
00035 //               and then issuing the appropriate rendering calls to
00036 //               activate them.
00037 ////////////////////////////////////////////////////////////////////
00038 class EXPCL_PANDA_GOBJ TextureStage : public TypedWritableReferenceCount {
00039 PUBLISHED:
00040   TextureStage(const string &name);
00041   INLINE TextureStage(TextureStage &copy);
00042   void operator = (const TextureStage &copy);
00043 
00044   virtual ~TextureStage();
00045 
00046   enum Mode {
00047     // Modes that pertain to the fixed-function pipeline.
00048     
00049     M_modulate,
00050     M_decal,
00051     M_blend,
00052     M_replace,
00053     M_add,
00054     M_combine,
00055     M_blend_color_scale,
00056     
00057     M_modulate_glow,  // When fixed-function, equivalent to modulate.
00058     M_modulate_gloss, // When fixed-function, equivalent to modulate.
00059     
00060     // Modes that are only relevant to shader-based rendering.
00061     
00062     M_normal,
00063     M_normal_height,
00064     M_glow,         // Rarely used: modulate_glow  is more efficient.
00065     M_gloss,        // Rarely used: modulate_gloss is more efficient.
00066     M_height,       // Rarely used: normal_height  is more efficient.
00067     M_selector,
00068   };
00069   
00070   enum CombineMode {
00071     CM_undefined,
00072     CM_replace,
00073     CM_modulate,
00074     CM_add,
00075     CM_add_signed,
00076     CM_interpolate,
00077     CM_subtract,
00078 
00079     // The following are valid only for combine_rgb, not
00080     // combine_alpha.
00081     CM_dot3_rgb,
00082     CM_dot3_rgba,
00083   };
00084 
00085   enum CombineSource {
00086     CS_undefined,
00087     CS_texture,
00088     CS_constant,
00089     CS_primary_color,
00090     CS_previous,
00091     CS_constant_color_scale,
00092     CS_last_saved_result,
00093   };
00094 
00095   enum CombineOperand {
00096     CO_undefined,
00097     CO_src_color,
00098     CO_one_minus_src_color,
00099     CO_src_alpha,
00100     CO_one_minus_src_alpha,
00101   };
00102 
00103   INLINE void set_name(const string &name);
00104   INLINE const string &get_name() const;
00105 
00106   INLINE void set_sort(int sort);
00107   INLINE int get_sort() const;
00108 
00109   INLINE void set_priority(int priority);
00110   INLINE int get_priority() const;
00111 
00112   INLINE void set_texcoord_name(InternalName *name);
00113   INLINE void set_texcoord_name(const string &texcoord_name);
00114   INLINE InternalName *get_texcoord_name() const;
00115   
00116   INLINE void set_mode(Mode mode);
00117   INLINE Mode get_mode() const;
00118   
00119   INLINE bool is_fixed_function() const;
00120   
00121   INLINE void set_color(const Colorf &color);
00122   INLINE Colorf get_color() const;
00123 
00124   INLINE void set_rgb_scale(int rgb_scale);
00125   INLINE int get_rgb_scale() const;
00126 
00127   INLINE void set_alpha_scale(int alpha_scale);
00128   INLINE int get_alpha_scale() const;
00129 
00130   INLINE void set_saved_result(bool saved_result);
00131   INLINE bool get_saved_result() const;
00132 
00133   INLINE void set_combine_rgb(CombineMode mode, 
00134                               CombineSource source0, CombineOperand operand0);
00135   INLINE void set_combine_rgb(CombineMode mode, 
00136                               CombineSource source0, CombineOperand operand0,
00137                               CombineSource source1, CombineOperand operand1);
00138   INLINE void set_combine_rgb(CombineMode mode, 
00139                               CombineSource source0, CombineOperand operand0,
00140                               CombineSource source1, CombineOperand operand1,
00141                               CombineSource source2, CombineOperand operand2);
00142   INLINE CombineMode get_combine_rgb_mode() const;
00143   INLINE int get_num_combine_rgb_operands() const;
00144   INLINE CombineSource get_combine_rgb_source0() const;
00145   INLINE CombineOperand get_combine_rgb_operand0() const;
00146   INLINE CombineSource get_combine_rgb_source1() const;
00147   INLINE CombineOperand get_combine_rgb_operand1() const;
00148   INLINE CombineSource get_combine_rgb_source2() const;
00149   INLINE CombineOperand get_combine_rgb_operand2() const;
00150 
00151   INLINE void set_combine_alpha(CombineMode mode, 
00152                                 CombineSource source0, CombineOperand operand0);
00153   INLINE void set_combine_alpha(CombineMode mode, 
00154                                 CombineSource source0, CombineOperand operand0,
00155                                 CombineSource source1, CombineOperand operand1);
00156   INLINE void set_combine_alpha(CombineMode mode, 
00157                                 CombineSource source0, CombineOperand operand0,
00158                                 CombineSource source1, CombineOperand operand1,
00159                                 CombineSource source2, CombineOperand operand2);
00160   INLINE CombineMode get_combine_alpha_mode() const;
00161   INLINE int get_num_combine_alpha_operands() const;
00162   INLINE CombineSource get_combine_alpha_source0() const;
00163   INLINE CombineOperand get_combine_alpha_operand0() const;
00164   INLINE CombineSource get_combine_alpha_source1() const;
00165   INLINE CombineOperand get_combine_alpha_operand1() const;
00166   INLINE CombineSource get_combine_alpha_source2() const;
00167   INLINE CombineOperand get_combine_alpha_operand2() const;
00168 
00169   INLINE bool involves_color_scale() const;
00170   INLINE bool uses_color() const;
00171   INLINE bool uses_primary_color() const;
00172   INLINE bool uses_last_saved_result() const;
00173 
00174   INLINE bool operator == (const TextureStage &other) const;
00175   INLINE bool operator != (const TextureStage &other) const;
00176   INLINE bool operator < (const TextureStage &other) const;
00177 
00178   int compare_to(const TextureStage &other) const;
00179 
00180   void write(ostream &out) const;
00181   void output(ostream &out) const;
00182 
00183   INLINE static TextureStage *get_default();
00184 
00185 public:
00186   INLINE static UpdateSeq get_sort_seq();
00187 
00188 private:
00189   INLINE void update_color_flags();
00190 
00191   static int get_expected_num_combine_operands(CombineMode cm);
00192   static bool operand_valid_for_rgb(CombineOperand co);
00193   static bool operand_valid_for_alpha(CombineOperand co);
00194 
00195   string _name;
00196   int _sort;
00197   int _priority;
00198   PT(InternalName) _texcoord_name;
00199   Mode _mode;
00200   Colorf _color;
00201   int _rgb_scale;
00202   int _alpha_scale;
00203   bool _saved_result;
00204   bool _involves_color_scale;
00205   bool _uses_color;
00206   bool _uses_primary_color;
00207   bool _uses_last_saved_result;
00208 
00209   CombineMode _combine_rgb_mode;
00210   int _num_combine_rgb_operands;
00211   CombineSource _combine_rgb_source0;
00212   CombineOperand _combine_rgb_operand0;
00213   CombineSource _combine_rgb_source1;
00214   CombineOperand _combine_rgb_operand1;
00215   CombineSource _combine_rgb_source2;
00216   CombineOperand _combine_rgb_operand2;
00217 
00218   CombineMode _combine_alpha_mode;
00219   int _num_combine_alpha_operands;
00220   CombineSource _combine_alpha_source0;
00221   CombineOperand _combine_alpha_operand0;
00222   CombineSource _combine_alpha_source1;
00223   CombineOperand _combine_alpha_operand1;
00224   CombineSource _combine_alpha_source2;
00225   CombineOperand _combine_alpha_operand2;
00226 
00227   static PT(TextureStage) _default_stage;
00228   static UpdateSeq _sort_seq;
00229   
00230 public:
00231   // Datagram stuff
00232   static void register_with_read_factory();
00233   virtual void write_datagram(BamWriter *manager, Datagram &me);
00234   virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00235 
00236   static TypedWritable *make_TextureStage(const FactoryParams &params);
00237 
00238 protected:
00239   void fillin(DatagramIterator& scan, BamReader* manager);
00240 
00241 public:
00242   static TypeHandle get_class_type() {
00243     return _type_handle;
00244   }
00245   static void init_type() {
00246     TypedWritableReferenceCount::init_type();
00247     register_type(_type_handle, "TextureStage",
00248                   TypedWritableReferenceCount::get_class_type());
00249   }
00250   virtual TypeHandle get_type() const {
00251     return get_class_type();
00252   }
00253   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00254 
00255 private:
00256   static TypeHandle _type_handle;
00257 };
00258 
00259 INLINE ostream &operator << (ostream &out, const TextureStage &ts);
00260 
00261 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::Mode mode);
00262 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineMode cm);
00263 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineSource cs);
00264 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineOperand co);
00265 
00266 
00267 #include "textureStage.I"
00268 
00269 #endif
00270 
00271 
00272   
 All Classes Functions Variables Enumerations