Panda3D
 All Classes Functions Variables Enumerations
shaderInput.h
1 // Filename: shaderInput.h
2 // Created by: jyelon (01Sep05)
3 // Updated by: fperazzi, PandaSE (06Apr10)
4 //
5 ////////////////////////////////////////////////////////////////////
6 //
7 // PANDA 3D SOFTWARE
8 // Copyright (c) Carnegie Mellon University. All rights reserved.
9 //
10 // All use of this software is subject to the terms of the revised BSD
11 // license. You should have received a copy of this license along
12 // with this source code in a file named "LICENSE."
13 //
14 ////////////////////////////////////////////////////////////////////
15 
16 #ifndef SHADERINPUT_H
17 #define SHADERINPUT_H
18 
19 #include "pandabase.h"
20 #include "typedWritableReferenceCount.h"
21 #include "pointerTo.h"
22 #include "internalName.h"
23 #include "paramValue.h"
24 #include "pta_float.h"
25 #include "pta_double.h"
26 #include "pta_LMatrix4.h"
27 #include "pta_LMatrix3.h"
28 #include "pta_LVecBase4.h"
29 #include "pta_LVecBase3.h"
30 #include "pta_LVecBase2.h"
31 #include "samplerState.h"
32 #include "shader.h"
33 #include "texture.h"
34 
35 ////////////////////////////////////////////////////////////////////
36 // Class : ShaderInput
37 // Description : This is a small container class that can hold any
38 // one of the value types that can be passed as input
39 // to a shader.
40 ////////////////////////////////////////////////////////////////////
41 class EXPCL_PANDA_PGRAPH ShaderInput : public TypedWritableReferenceCount {
42 public:
43  INLINE ~ShaderInput();
44 
45 PUBLISHED:
46  // Used when binding texture images.
47  enum AccessFlags {
48  A_read = 0x01,
49  A_write = 0x02,
50  A_layered = 0x04,
51  };
52 
53  static const ShaderInput *get_blank();
54  INLINE ShaderInput(CPT_InternalName name, int priority=0);
55  INLINE ShaderInput(CPT_InternalName name, Texture *tex, int priority=0);
56  INLINE ShaderInput(CPT_InternalName name, Texture *tex, const SamplerState &sampler, int priority=0);
57  INLINE ShaderInput(CPT_InternalName name, Texture *tex, bool read, bool write, int z=-1, int n=0, int priority=0);
58  INLINE ShaderInput(CPT_InternalName name, ParamValueBase *param, int priority=0);
59  INLINE ShaderInput(CPT_InternalName name, const PTA_float &ptr, int priority=0);
60  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase4f &ptr, int priority=0);
61  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase3f &ptr, int priority=0);
62  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase2f &ptr, int priority=0);
63  INLINE ShaderInput(CPT_InternalName name, const PTA_LMatrix4f &ptr, int priority=0);
64  INLINE ShaderInput(CPT_InternalName name, const PTA_LMatrix3f &ptr, int priority=0);
65  INLINE ShaderInput(CPT_InternalName name, const LVecBase4f &vec, int priority=0);
66  INLINE ShaderInput(CPT_InternalName name, const LVecBase3f &vec, int priority=0);
67  INLINE ShaderInput(CPT_InternalName name, const LVecBase2f &vec, int priority=0);
68  INLINE ShaderInput(CPT_InternalName name, const LMatrix4f &mat, int priority=0);
69  INLINE ShaderInput(CPT_InternalName name, const LMatrix3f &mat, int priority=0);
70 
71  INLINE ShaderInput(CPT_InternalName name, const PTA_double &ptr, int priority=0);
72  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase4d &ptr, int priority=0);
73  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase3d &ptr, int priority=0);
74  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase2d &ptr, int priority=0);
75  INLINE ShaderInput(CPT_InternalName name, const PTA_LMatrix4d &ptr, int priority=0);
76  INLINE ShaderInput(CPT_InternalName name, const PTA_LMatrix3d &ptr, int priority=0);
77  INLINE ShaderInput(CPT_InternalName name, const LVecBase4d &vec, int priority=0);
78  INLINE ShaderInput(CPT_InternalName name, const LVecBase3d &vec, int priority=0);
79  INLINE ShaderInput(CPT_InternalName name, const LVecBase2d &vec, int priority=0);
80  INLINE ShaderInput(CPT_InternalName name, const LMatrix4d &mat, int priority=0);
81  INLINE ShaderInput(CPT_InternalName name, const LMatrix3d &mat, int priority=0);
82 
83  INLINE ShaderInput(CPT_InternalName name, const PTA_int &ptr, int priority=0);
84  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase4i &ptr, int priority=0);
85  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase3i &ptr, int priority=0);
86  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase2i &ptr, int priority=0);
87  INLINE ShaderInput(CPT_InternalName name, const LVecBase4i &vec, int priority=0);
88  INLINE ShaderInput(CPT_InternalName name, const LVecBase3i &vec, int priority=0);
89  INLINE ShaderInput(CPT_InternalName name, const LVecBase2i &vec, int priority=0);
90 
91  ShaderInput(CPT_InternalName name, const NodePath &np, int priority=0);
92 
93  enum ShaderInputType {
94  M_invalid = 0,
95  M_texture,
96  M_nodepath,
97  M_vector,
98  M_numeric,
99  M_texture_sampler,
100  M_param
101  };
102 
103  INLINE const InternalName *get_name() const;
104 
105  INLINE int get_value_type() const;
106  INLINE int get_priority() const;
107  INLINE Texture *get_texture() const;
108  INLINE const LVecBase4 &get_vector() const;
109  INLINE const Shader::ShaderPtrData &get_ptr() const;
110  INLINE const SamplerState &get_sampler() const;
111 
112  const NodePath &get_nodepath() const;
113 
114 public:
115  INLINE ParamValueBase *get_param() const;
116 
117  static void register_with_read_factory();
118 
119 private:
120  SamplerState _sampler;
121  LVecBase4 _stored_vector;
122  Shader::ShaderPtrData _stored_ptr;
123  CPT_InternalName _name;
124  PT(TypedWritableReferenceCount) _value;
125  int _priority;
126 
127 public:
128  int _type : 8;
129  int _access : 8;
130  int _bind_level : 16;
131  int _bind_layer;
132 
133 public:
134  static TypeHandle get_class_type() {
135  return _type_handle;
136  }
137  static void init_type() {
138  ReferenceCount::init_type();
139  register_type(_type_handle, "ShaderInput",
140  TypedWritableReferenceCount::get_class_type());
141  }
142  virtual TypeHandle get_type() const {
143  return get_class_type();
144  }
145  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
146 
147 private:
148  static TypeHandle _type_handle;
149 };
150 
151 
152 #include "shaderInput.I"
153 
154 #endif // SHADERINPUT_H
155 
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 a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:1241
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
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:2328
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1661
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 the base class for all three-component vectors and points.
Definition: lvecBase4.h:3162
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:4375
A non-template base class of ParamValue (below), which serves mainly to define the placeholder for th...
Definition: paramValue.h:34
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 is the base class for all three-component vectors and points.
Definition: lvecBase3.h:1455
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
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
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:2756
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