Panda3D
|
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 ©); 00042 void operator = (const TextureStage ©); 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 M_normal_gloss, 00069 }; 00070 00071 enum CombineMode { 00072 CM_undefined, 00073 CM_replace, 00074 CM_modulate, 00075 CM_add, 00076 CM_add_signed, 00077 CM_interpolate, 00078 CM_subtract, 00079 00080 // The following are valid only for combine_rgb, not 00081 // combine_alpha. 00082 CM_dot3_rgb, 00083 CM_dot3_rgba, 00084 }; 00085 00086 enum CombineSource { 00087 CS_undefined, 00088 CS_texture, 00089 CS_constant, 00090 CS_primary_color, 00091 CS_previous, 00092 CS_constant_color_scale, 00093 CS_last_saved_result, 00094 }; 00095 00096 enum CombineOperand { 00097 CO_undefined, 00098 CO_src_color, 00099 CO_one_minus_src_color, 00100 CO_src_alpha, 00101 CO_one_minus_src_alpha, 00102 }; 00103 00104 INLINE void set_name(const string &name); 00105 INLINE const string &get_name() const; 00106 00107 INLINE void set_sort(int sort); 00108 INLINE int get_sort() const; 00109 00110 INLINE void set_priority(int priority); 00111 INLINE int get_priority() const; 00112 00113 INLINE void set_texcoord_name(InternalName *name); 00114 INLINE void set_texcoord_name(const string &texcoord_name); 00115 INLINE InternalName *get_texcoord_name() const; 00116 00117 INLINE void set_mode(Mode mode); 00118 INLINE Mode get_mode() const; 00119 00120 INLINE bool is_fixed_function() const; 00121 00122 INLINE void set_color(const LColor &color); 00123 INLINE LColor get_color() const; 00124 00125 INLINE void set_rgb_scale(int rgb_scale); 00126 INLINE int get_rgb_scale() const; 00127 00128 INLINE void set_alpha_scale(int alpha_scale); 00129 INLINE int get_alpha_scale() const; 00130 00131 INLINE void set_saved_result(bool saved_result); 00132 INLINE bool get_saved_result() const; 00133 00134 INLINE void set_tex_view_offset(int tex_view_offset); 00135 INLINE int get_tex_view_offset() const; 00136 00137 INLINE void set_combine_rgb(CombineMode mode, 00138 CombineSource source0, CombineOperand operand0); 00139 INLINE void set_combine_rgb(CombineMode mode, 00140 CombineSource source0, CombineOperand operand0, 00141 CombineSource source1, CombineOperand operand1); 00142 INLINE void set_combine_rgb(CombineMode mode, 00143 CombineSource source0, CombineOperand operand0, 00144 CombineSource source1, CombineOperand operand1, 00145 CombineSource source2, CombineOperand operand2); 00146 INLINE CombineMode get_combine_rgb_mode() const; 00147 INLINE int get_num_combine_rgb_operands() const; 00148 INLINE CombineSource get_combine_rgb_source0() const; 00149 INLINE CombineOperand get_combine_rgb_operand0() const; 00150 INLINE CombineSource get_combine_rgb_source1() const; 00151 INLINE CombineOperand get_combine_rgb_operand1() const; 00152 INLINE CombineSource get_combine_rgb_source2() const; 00153 INLINE CombineOperand get_combine_rgb_operand2() const; 00154 00155 INLINE void set_combine_alpha(CombineMode mode, 00156 CombineSource source0, CombineOperand operand0); 00157 INLINE void set_combine_alpha(CombineMode mode, 00158 CombineSource source0, CombineOperand operand0, 00159 CombineSource source1, CombineOperand operand1); 00160 INLINE void set_combine_alpha(CombineMode mode, 00161 CombineSource source0, CombineOperand operand0, 00162 CombineSource source1, CombineOperand operand1, 00163 CombineSource source2, CombineOperand operand2); 00164 INLINE CombineMode get_combine_alpha_mode() const; 00165 INLINE int get_num_combine_alpha_operands() const; 00166 INLINE CombineSource get_combine_alpha_source0() const; 00167 INLINE CombineOperand get_combine_alpha_operand0() const; 00168 INLINE CombineSource get_combine_alpha_source1() const; 00169 INLINE CombineOperand get_combine_alpha_operand1() const; 00170 INLINE CombineSource get_combine_alpha_source2() const; 00171 INLINE CombineOperand get_combine_alpha_operand2() const; 00172 00173 INLINE bool involves_color_scale() const; 00174 INLINE bool uses_color() const; 00175 INLINE bool uses_primary_color() const; 00176 INLINE bool uses_last_saved_result() const; 00177 00178 INLINE bool operator == (const TextureStage &other) const; 00179 INLINE bool operator != (const TextureStage &other) const; 00180 INLINE bool operator < (const TextureStage &other) const; 00181 00182 int compare_to(const TextureStage &other) const; 00183 00184 void write(ostream &out) const; 00185 void output(ostream &out) const; 00186 00187 INLINE static TextureStage *get_default(); 00188 00189 public: 00190 INLINE static UpdateSeq get_sort_seq(); 00191 00192 private: 00193 INLINE void update_color_flags(); 00194 00195 static int get_expected_num_combine_operands(CombineMode cm); 00196 static bool operand_valid_for_rgb(CombineOperand co); 00197 static bool operand_valid_for_alpha(CombineOperand co); 00198 00199 string _name; 00200 int _sort; 00201 int _priority; 00202 PT(InternalName) _texcoord_name; 00203 Mode _mode; 00204 LColor _color; 00205 int _rgb_scale; 00206 int _alpha_scale; 00207 bool _saved_result; 00208 int _tex_view_offset; 00209 bool _involves_color_scale; 00210 bool _uses_color; 00211 bool _uses_primary_color; 00212 bool _uses_last_saved_result; 00213 00214 CombineMode _combine_rgb_mode; 00215 int _num_combine_rgb_operands; 00216 CombineSource _combine_rgb_source0; 00217 CombineOperand _combine_rgb_operand0; 00218 CombineSource _combine_rgb_source1; 00219 CombineOperand _combine_rgb_operand1; 00220 CombineSource _combine_rgb_source2; 00221 CombineOperand _combine_rgb_operand2; 00222 00223 CombineMode _combine_alpha_mode; 00224 int _num_combine_alpha_operands; 00225 CombineSource _combine_alpha_source0; 00226 CombineOperand _combine_alpha_operand0; 00227 CombineSource _combine_alpha_source1; 00228 CombineOperand _combine_alpha_operand1; 00229 CombineSource _combine_alpha_source2; 00230 CombineOperand _combine_alpha_operand2; 00231 00232 static PT(TextureStage) _default_stage; 00233 static UpdateSeq _sort_seq; 00234 00235 public: 00236 // Datagram stuff 00237 static void register_with_read_factory(); 00238 virtual void write_datagram(BamWriter *manager, Datagram &me); 00239 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00240 00241 static TypedWritable *make_TextureStage(const FactoryParams ¶ms); 00242 00243 protected: 00244 void fillin(DatagramIterator& scan, BamReader* manager); 00245 00246 public: 00247 static TypeHandle get_class_type() { 00248 return _type_handle; 00249 } 00250 static void init_type() { 00251 TypedWritableReferenceCount::init_type(); 00252 register_type(_type_handle, "TextureStage", 00253 TypedWritableReferenceCount::get_class_type()); 00254 } 00255 virtual TypeHandle get_type() const { 00256 return get_class_type(); 00257 } 00258 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00259 00260 private: 00261 static TypeHandle _type_handle; 00262 }; 00263 00264 INLINE ostream &operator << (ostream &out, const TextureStage &ts); 00265 00266 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::Mode mode); 00267 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineMode cm); 00268 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineSource cs); 00269 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStage::CombineOperand co); 00270 00271 00272 #include "textureStage.I" 00273 00274 #endif 00275 00276 00277