Panda3D
shaderAttrib.h
1 // Filename: shaderAttrib.h
2 // Created by: jyelon (01Sep05)
3 // Updated by: fperazzi, PandaSE (06Apr10) (added more overloads
4 // for set_shader_input)
5 // Updated by: weifengh, PandaSE(15Apr10)
6 //
7 ////////////////////////////////////////////////////////////////////
8 //
9 // PANDA 3D SOFTWARE
10 // Copyright (c) Carnegie Mellon University. All rights reserved.
11 //
12 // All use of this software is subject to the terms of the revised BSD
13 // license. You should have received a copy of this license along
14 // with this source code in a file named "LICENSE."
15 //
16 ////////////////////////////////////////////////////////////////////
17 
18 #ifndef SHADERATTRIB_H
19 #define SHADERATTRIB_H
20 
21 #include "pandabase.h"
22 #include "renderAttrib.h"
23 #include "pointerTo.h"
24 #include "shaderInput.h"
25 #include "shader.h"
26 #include "pta_float.h"
27 #include "pta_double.h"
28 #include "pta_LMatrix4.h"
29 #include "pta_LMatrix3.h"
30 #include "pta_LVecBase4.h"
31 #include "pta_LVecBase3.h"
32 #include "pta_LVecBase2.h"
33 
34 ////////////////////////////////////////////////////////////////////
35 // Class : ShaderAttrib
36 // Description :
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDA_PGRAPH ShaderAttrib: public RenderAttrib {
39 private:
40  INLINE ShaderAttrib();
41  INLINE ShaderAttrib(const ShaderAttrib &copy);
42 
43 PUBLISHED:
44  static CPT(RenderAttrib) make(const Shader *shader = NULL);
45  static CPT(RenderAttrib) make_off();
46  static CPT(RenderAttrib) make_default();
47 
48  enum {
49  F_disable_alpha_write = 0, // Suppress writes to color buffer alpha channel.
50  F_subsume_alpha_test = 1, // Shader promises to subsume the alpha test using TEXKILL
51  F_hardware_skinning = 2, // Shader needs pre-animated vertices
52  };
53 
54  INLINE bool has_shader() const;
55  INLINE bool auto_shader() const;
56  INLINE int get_shader_priority() const;
57  INLINE int get_instance_count() const;
58  INLINE bool auto_normal_on() const;
59  INLINE bool auto_glow_on() const;
60  INLINE bool auto_gloss_on() const;
61  INLINE bool auto_ramp_on() const;
62  INLINE bool auto_shadow_on() const;
63 
64  CPT(RenderAttrib) set_shader(const Shader *s, int priority=0) const;
65  CPT(RenderAttrib) set_shader_off(int priority=0) const;
66  CPT(RenderAttrib) set_shader_auto(int priority=0) const;
67 
68  CPT(RenderAttrib) set_shader_auto(BitMask32 shader_switch, int priority=0) const;
69 
70  CPT(RenderAttrib) clear_shader() const;
71  // Shader Inputs
72  CPT(RenderAttrib) set_shader_input(const ShaderInput *inp) const;
73 
74  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, Texture *tex, int priority=0) const;
75  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const NodePath &np, int priority=0) const;
76  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_float &v, int priority=0) const;
77  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_double &v, int priority=0) const;
78  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LMatrix4 &v, int priority=0) const;
79  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LMatrix3 &v, int priority=0) const;
80  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LVecBase4 &v, int priority=0) const;
81  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LVecBase3 &v, int priority=0) const;
82  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LVecBase2 &v, int priority=0) const;
83  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LVecBase4 &v, int priority=0) const;
84  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LVecBase3 &v, int priority=0) const;
85  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LVecBase2 &v, int priority=0) const;
86  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LMatrix4 &v, int priority=0) const;
87  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LMatrix3 &v, int priority=0) const;
88  INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, double n1=0, double n2=0, double n3=0, double n4=1,
89  int priority=0) const;
90 
91  CPT(RenderAttrib) set_instance_count(int instance_count) const;
92 
93  CPT(RenderAttrib) set_flag(int flag, bool value) const;
94  CPT(RenderAttrib) clear_flag(int flag) const;
95 
96  CPT(RenderAttrib) clear_shader_input(const InternalName *id) const;
97  CPT(RenderAttrib) clear_shader_input(const string &id) const;
98 
99  CPT(RenderAttrib) clear_all_shader_inputs() const;
100 
101  INLINE bool get_flag(int flag) const;
102  INLINE bool has_shader_input(CPT_InternalName id) const;
103 
104  const Shader *get_shader() const;
105  const ShaderInput *get_shader_input(const InternalName *id) const;
106  const ShaderInput *get_shader_input(const string &id) const;
107 
108  const NodePath &get_shader_input_nodepath(const InternalName *id) const;
109  LVecBase4 get_shader_input_vector(InternalName *id) const;
110  Texture *get_shader_input_texture(const InternalName *id) const;
111  const SamplerState &get_shader_input_sampler(const InternalName *id) const;
112  const Shader::ShaderPtrData *get_shader_input_ptr(const InternalName *id) const;
113  const LMatrix4 &get_shader_input_matrix(const InternalName *id, LMatrix4 &matrix) const;
114 
115  static void register_with_read_factory();
116 
117 public:
118 
119 protected:
120  virtual int compare_to_impl(const RenderAttrib *other) const;
121  virtual size_t get_hash_impl() const;
122  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
123  virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
124 
125 private:
126 
127  CPT(Shader) _shader;
128  int _shader_priority;
129  bool _auto_shader;
130  bool _has_shader;
131  int _flags;
132  int _has_flags;
133  int _instance_count;
134 
135  bool _auto_normal_on;
136  bool _auto_glow_on;
137  bool _auto_gloss_on;
138  bool _auto_ramp_on;
139  bool _auto_shadow_on;
140 
142  Inputs _inputs;
143 
144 PUBLISHED:
145  static int get_class_slot() {
146  return _attrib_slot;
147  }
148  virtual int get_slot() const {
149  return get_class_slot();
150  }
151 
152 public:
153  static TypeHandle get_class_type() {
154  return _type_handle;
155  }
156  static void init_type() {
157  RenderAttrib::init_type();
158  register_type(_type_handle, "ShaderAttrib",
159  RenderAttrib::get_class_type());
160  _attrib_slot = register_slot(_type_handle, 10, make_default);
161  }
162  virtual TypeHandle get_type() const {
163  return get_class_type();
164  }
165  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
166 
167 private:
168  static TypeHandle _type_handle;
169  static int _attrib_slot;
170 };
171 
172 
173 #include "shaderAttrib.I"
174 
175 #endif // SHADERATTRIB_H
176 
177 
178 
static int register_slot(TypeHandle type_handle, int sort, RenderAttribRegistry::MakeDefaultFunc *make_default_func)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:163
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:197
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
Definition: shader.h:50
This is a small container class that can hold any one of the value types that can be passed as input ...
Definition: shaderInput.h:41
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:105
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
Represents a set of settings that indicate how a texture is sampled.
Definition: samplerState.h:39
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165