Panda3D
 All Classes Functions Variables Enumerations
shaderAttrib.h
00001 // Filename: shaderAttrib.h
00002 // Created by: jyelon (01Sep05)
00003 // Updated by:  fperazzi, PandaSE (06Apr10) (added more overloads
00004 //   for set_shader_input)
00005 // Updated by: weifengh, PandaSE(15Apr10)
00006 //
00007 ////////////////////////////////////////////////////////////////////
00008 //
00009 // PANDA 3D SOFTWARE
00010 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00011 //
00012 // All use of this software is subject to the terms of the revised BSD
00013 // license.  You should have received a copy of this license along
00014 // with this source code in a file named "LICENSE."
00015 //
00016 ////////////////////////////////////////////////////////////////////
00017 
00018 #ifndef SHADERATTRIB_H
00019 #define SHADERATTRIB_H
00020 
00021 #include "pandabase.h"
00022 #include "renderAttrib.h"
00023 #include "pointerTo.h"
00024 #include "shaderInput.h"
00025 #include "shader.h"
00026 #include "pta_float.h"
00027 #include "pta_double.h"
00028 #include "pta_LMatrix4.h"
00029 #include "pta_LMatrix3.h"
00030 #include "pta_LVecBase4.h"
00031 #include "pta_LVecBase3.h"
00032 #include "pta_LVecBase2.h"
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //       Class : ShaderAttrib
00036 // Description : 
00037 ////////////////////////////////////////////////////////////////////
00038 
00039 class EXPCL_PANDA_PGRAPH ShaderAttrib: public RenderAttrib {
00040 
00041 private:
00042   INLINE ShaderAttrib();
00043   INLINE ShaderAttrib(const ShaderAttrib &copy);
00044 
00045 PUBLISHED:
00046   static CPT(RenderAttrib) make();
00047   static CPT(RenderAttrib) make_off();
00048   static CPT(RenderAttrib) make_default();
00049   
00050   enum {
00051     F_disable_alpha_write = 0,  // Suppress writes to color buffer alpha channel.
00052     F_subsume_alpha_test  = 1,  // Shader promises to subsume the alpha test using TEXKILL
00053   };
00054 
00055   INLINE bool               has_shader() const;
00056   INLINE bool               auto_shader() const;
00057   INLINE int                get_shader_priority() const;
00058   INLINE int                get_instance_count() const;
00059   INLINE bool               auto_normal_on() const;
00060   INLINE bool               auto_glow_on() const;
00061   INLINE bool               auto_gloss_on() const;
00062   INLINE bool               auto_ramp_on() const;
00063   INLINE bool               auto_shadow_on() const;
00064 
00065   CPT(RenderAttrib) set_shader(const Shader *s, int priority=0) const;
00066   CPT(RenderAttrib) set_shader_off(int priority=0) const;
00067   CPT(RenderAttrib) set_shader_auto(int priority=0) const;
00068 
00069   CPT(RenderAttrib) set_shader_auto(BitMask32 shader_switch, int priority=0) const;
00070 
00071   CPT(RenderAttrib) clear_shader() const;
00072   // Shader Inputs
00073   CPT(RenderAttrib) set_shader_input(const ShaderInput *inp) const;
00074   
00075   // InternalName* id
00076   CPT(RenderAttrib) set_shader_input(const InternalName *id, Texture *tex,       int priority=0) const;
00077   CPT(RenderAttrib) set_shader_input(const InternalName *id, const NodePath &np, int priority=0) const;
00078   CPT(RenderAttrib) set_shader_input(const InternalName *id, const PTA_float &v, int priority=0) const;
00079   CPT(RenderAttrib) set_shader_input(const InternalName *id, const PTA_double &v, int priority=0) const;
00080   CPT(RenderAttrib) set_shader_input(const InternalName *id, const PTA_LMatrix4 &v, int priority=0) const;
00081   CPT(RenderAttrib) set_shader_input(const InternalName *id, const PTA_LMatrix3 &v, int priority=0) const;
00082   CPT(RenderAttrib) set_shader_input(const InternalName *id, const PTA_LVecBase4 &v, int priority=0) const;
00083   CPT(RenderAttrib) set_shader_input(const InternalName *id, const PTA_LVecBase3 &v, int priority=0) const;
00084   CPT(RenderAttrib) set_shader_input(const InternalName *id, const PTA_LVecBase2 &v, int priority=0) const;
00085   CPT(RenderAttrib) set_shader_input(const InternalName *id, const LVecBase4 &v, int priority=0) const;
00086   CPT(RenderAttrib) set_shader_input(const InternalName *id, const LVecBase3 &v, int priority=0) const;
00087   CPT(RenderAttrib) set_shader_input(const InternalName *id, const LVecBase2 &v, int priority=0) const;
00088   CPT(RenderAttrib) set_shader_input(const InternalName *id, const LMatrix4 &v, int priority=0) const;
00089   CPT(RenderAttrib) set_shader_input(const InternalName *id, const LMatrix3 &v, int priority=0) const;
00090   CPT(RenderAttrib) set_shader_input(const InternalName *id, double n1=0, double n2=0, double n3=0, double n4=1,
00091                                      int priority=0) const; 
00092 
00093   CPT(RenderAttrib) set_instance_count(int instance_count) const;
00094 
00095   CPT(RenderAttrib) set_flag(int flag, bool value) const;
00096   CPT(RenderAttrib) clear_flag(int flag) const;
00097 
00098   CPT(RenderAttrib) clear_shader_input(const InternalName *id) const;
00099   CPT(RenderAttrib) clear_shader_input(const string &id) const;
00100   
00101   CPT(RenderAttrib) clear_all_shader_inputs() const;
00102 
00103   INLINE bool get_flag(int flag) const;
00104   
00105   const Shader *get_shader() const;
00106   const ShaderInput *get_shader_input(const InternalName *id) const;
00107   const ShaderInput *get_shader_input(const string &id) const;
00108 
00109   const NodePath &get_shader_input_nodepath(const InternalName *id) const;
00110   const LVecBase4 &get_shader_input_vector(InternalName *id) const;
00111   Texture *get_shader_input_texture(const InternalName *id) const;
00112   const Shader::ShaderPtrData *get_shader_input_ptr(const InternalName *id) const;
00113 
00114   static void register_with_read_factory();
00115   
00116 public:
00117 
00118 protected:
00119   virtual int compare_to_impl(const RenderAttrib *other) const;
00120   virtual size_t get_hash_impl() const;
00121   virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
00122   virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
00123   
00124 private:
00125 
00126   CPT(Shader) _shader;
00127   int         _shader_priority;
00128   bool        _auto_shader;
00129   bool        _has_shader;
00130   int         _flags;
00131   int         _has_flags;
00132   int         _instance_count;
00133 
00134   bool        _auto_normal_on;
00135   bool        _auto_glow_on;
00136   bool        _auto_gloss_on;
00137   bool        _auto_ramp_on;
00138   bool        _auto_shadow_on;
00139 
00140   typedef pmap < CPT(InternalName), CPT(ShaderInput) > Inputs;
00141   Inputs _inputs;
00142 
00143 PUBLISHED:
00144   static int get_class_slot() {
00145     return _attrib_slot;
00146   }
00147   virtual int get_slot() const {
00148     return get_class_slot();
00149   }
00150 
00151 public:
00152   static TypeHandle get_class_type() {
00153     return _type_handle;
00154   }
00155   static void init_type() {
00156     RenderAttrib::init_type();
00157     register_type(_type_handle, "ShaderAttrib",
00158                   RenderAttrib::get_class_type());
00159     _attrib_slot = register_slot(_type_handle, 10, make_default);
00160   }
00161   virtual TypeHandle get_type() const {
00162     return get_class_type();
00163   }
00164   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00165 
00166 private:
00167   static TypeHandle _type_handle;
00168   static int _attrib_slot;
00169 };
00170 
00171 
00172 #include "shaderAttrib.I"
00173 
00174 #endif  // SHADERATTRIB_H
00175 
00176 
00177 
 All Classes Functions Variables Enumerations