Panda3D

shaderAttrib.h

00001 // Filename: shaderAttrib.h
00002 // Created by: jyelon (01Sep05)
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 SHADERATTRIB_H
00016 #define SHADERATTRIB_H
00017 
00018 #include "pandabase.h"
00019 #include "renderAttrib.h"
00020 #include "pointerTo.h"
00021 #include "shaderInput.h"
00022 #include "shader.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : ShaderAttrib
00026 // Description : 
00027 ////////////////////////////////////////////////////////////////////
00028 
00029 class EXPCL_PANDA_PGRAPH ShaderAttrib: public RenderAttrib {
00030 
00031 private:
00032   INLINE ShaderAttrib();
00033   INLINE ShaderAttrib(const ShaderAttrib &copy);
00034 
00035 PUBLISHED:
00036   static CPT(RenderAttrib) make();
00037   static CPT(RenderAttrib) make_off();
00038   static CPT(RenderAttrib) make_default();
00039   
00040   enum {
00041     F_disable_alpha_write = 0,  // Suppress writes to color buffer alpha channel.
00042     F_subsume_alpha_test  = 1,  // Shader promises to subsume the alpha test using TEXKILL
00043   };
00044 
00045   INLINE bool               has_shader() const;
00046   INLINE bool               auto_shader() const;
00047   INLINE int                get_shader_priority() const;
00048   INLINE int                get_instance_count() const;
00049   
00050   CPT(RenderAttrib) set_shader(const Shader *s, int priority=0) const;
00051   CPT(RenderAttrib) set_shader_off(int priority=0) const;
00052   CPT(RenderAttrib) set_shader_auto(int priority=0) const;
00053   CPT(RenderAttrib) clear_shader() const;
00054   CPT(RenderAttrib) set_shader_input(const ShaderInput *inp) const;
00055   CPT(RenderAttrib) set_shader_input(InternalName *id, Texture *tex,       int priority=0) const;
00056   CPT(RenderAttrib) set_shader_input(InternalName *id, const NodePath &np, int priority=0) const;
00057   CPT(RenderAttrib) set_shader_input(InternalName *id, const LVector4f &v, int priority=0) const;
00058   CPT(RenderAttrib) set_shader_input(InternalName *id, double n1=0, double n2=0, double n3=0, double n4=1,
00059                                      int priority=0) const;
00060   CPT(RenderAttrib) set_shader_input(const string &id, Texture *tex,       int priority=0) const;
00061   CPT(RenderAttrib) set_shader_input(const string &id, const NodePath &np, int priority=0) const;
00062   CPT(RenderAttrib) set_shader_input(const string &id, const LVector4f &v, int priority=0) const;
00063   CPT(RenderAttrib) set_shader_input(const string &id, double n1=0, double n2=0, double n3=0, double n4=1,
00064                                      int priority=0) const;
00065 
00066   CPT(RenderAttrib) set_instance_count(int instance_count) const;
00067 
00068   CPT(RenderAttrib) set_flag(int flag, bool value) const;
00069   CPT(RenderAttrib) clear_flag(int flag) const;
00070 
00071   CPT(RenderAttrib) clear_shader_input(InternalName *id) const;
00072   CPT(RenderAttrib) clear_shader_input(const string &id) const;
00073   
00074   CPT(RenderAttrib) clear_all_shader_inputs() const;
00075 
00076   INLINE bool        get_flag(int flag) const;
00077   
00078   const Shader      *get_shader() const;
00079   const ShaderInput *get_shader_input(InternalName *id) const;
00080   const ShaderInput *get_shader_input(const string &id) const;
00081 
00082   const NodePath    &get_shader_input_nodepath(InternalName *id) const;
00083   const LVector4f   &get_shader_input_vector(InternalName *id) const;
00084   Texture*           get_shader_input_texture(InternalName *id) const;
00085   
00086   static void register_with_read_factory();
00087   
00088 public:
00089 
00090 protected:
00091   virtual int compare_to_impl(const RenderAttrib *other) const;
00092   virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
00093   
00094 private:
00095 
00096   CPT(Shader) _shader;
00097   int         _shader_priority;
00098   bool        _auto_shader;
00099   bool        _has_shader;
00100   int         _flags;
00101   int         _has_flags;
00102   int         _instance_count;
00103   typedef pmap < CPT(InternalName), CPT(ShaderInput) > Inputs;
00104   Inputs _inputs;
00105 
00106 PUBLISHED:
00107   static int get_class_slot() {
00108     return _attrib_slot;
00109   }
00110   virtual int get_slot() const {
00111     return get_class_slot();
00112   }
00113 
00114 public:
00115   static TypeHandle get_class_type() {
00116     return _type_handle;
00117   }
00118   static void init_type() {
00119     RenderAttrib::init_type();
00120     register_type(_type_handle, "ShaderAttrib",
00121                   RenderAttrib::get_class_type());
00122     _attrib_slot = register_slot(_type_handle, 10, make_default);
00123   }
00124   virtual TypeHandle get_type() const {
00125     return get_class_type();
00126   }
00127   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00128 
00129 private:
00130   static TypeHandle _type_handle;
00131   static int _attrib_slot;
00132 };
00133 
00134 
00135 #include "shaderAttrib.I"
00136 
00137 #endif  // SHADERATTRIB_H
00138 
00139 
00140 
 All Classes Functions Variables Enumerations