Panda3D
shaderInput.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file shaderInput.h
10  * @author jyelon
11  * @date 2005-09-01
12  * @author fperazzi, PandaSE
13  * @date 2010-04-06
14  */
15 
16 #ifndef SHADERINPUT_H
17 #define SHADERINPUT_H
18 
19 #include "pandabase.h"
20 #include "pointerTo.h"
21 #include "internalName.h"
22 #include "paramValue.h"
23 #include "pta_float.h"
24 #include "pta_double.h"
25 #include "pta_LMatrix4.h"
26 #include "pta_LMatrix3.h"
27 #include "pta_LVecBase4.h"
28 #include "pta_LVecBase3.h"
29 #include "pta_LVecBase2.h"
30 #include "samplerState.h"
31 #include "shader.h"
32 #include "texture.h"
33 #include "shaderBuffer.h"
34 #include "extension.h"
35 
36 /**
37  * This is a small container class that can hold any one of the value types
38  * that can be passed as input to a shader.
39  */
40 class EXPCL_PANDA_PGRAPH ShaderInput {
41 PUBLISHED:
42  // Used when binding texture images.
43  enum AccessFlags {
44  A_read = 0x01,
45  A_write = 0x02,
46  A_layered = 0x04,
47  };
48 
49  static const ShaderInput &get_blank();
50  INLINE explicit ShaderInput(CPT_InternalName name, int priority=0);
51 
52  EXTENSION(explicit ShaderInput(CPT_InternalName name, PyObject *value, int priority=0));
53 
54 public:
55  INLINE ShaderInput(CPT_InternalName name, Texture *tex, int priority=0);
56  INLINE ShaderInput(CPT_InternalName name, ParamValueBase *param, int priority=0);
57  INLINE ShaderInput(CPT_InternalName name, ShaderBuffer *buf, int priority=0);
58  INLINE ShaderInput(CPT_InternalName name, const PTA_float &ptr, int priority=0);
59  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase4f &ptr, int priority=0);
60  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase3f &ptr, int priority=0);
61  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase2f &ptr, int priority=0);
62  INLINE ShaderInput(CPT_InternalName name, const PTA_LMatrix4f &ptr, int priority=0);
63  INLINE ShaderInput(CPT_InternalName name, const PTA_LMatrix3f &ptr, int priority=0);
64  INLINE ShaderInput(CPT_InternalName name, const LVecBase4f &vec, int priority=0);
65  INLINE ShaderInput(CPT_InternalName name, const LVecBase3f &vec, int priority=0);
66  INLINE ShaderInput(CPT_InternalName name, const LVecBase2f &vec, int priority=0);
67  INLINE ShaderInput(CPT_InternalName name, const LMatrix4f &mat, int priority=0);
68  INLINE ShaderInput(CPT_InternalName name, const LMatrix3f &mat, int priority=0);
69 
70  INLINE ShaderInput(CPT_InternalName name, const PTA_double &ptr, int priority=0);
71  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase4d &ptr, int priority=0);
72  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase3d &ptr, int priority=0);
73  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase2d &ptr, int priority=0);
74  INLINE ShaderInput(CPT_InternalName name, const PTA_LMatrix4d &ptr, int priority=0);
75  INLINE ShaderInput(CPT_InternalName name, const PTA_LMatrix3d &ptr, int priority=0);
76  INLINE ShaderInput(CPT_InternalName name, const LVecBase4d &vec, int priority=0);
77  INLINE ShaderInput(CPT_InternalName name, const LVecBase3d &vec, int priority=0);
78  INLINE ShaderInput(CPT_InternalName name, const LVecBase2d &vec, int priority=0);
79  INLINE ShaderInput(CPT_InternalName name, const LMatrix4d &mat, int priority=0);
80  INLINE ShaderInput(CPT_InternalName name, const LMatrix3d &mat, int priority=0);
81 
82  INLINE ShaderInput(CPT_InternalName name, const PTA_int &ptr, int priority=0);
83  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase4i &ptr, int priority=0);
84  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase3i &ptr, int priority=0);
85  INLINE ShaderInput(CPT_InternalName name, const PTA_LVecBase2i &ptr, int priority=0);
86  INLINE ShaderInput(CPT_InternalName name, const LVecBase4i &vec, int priority=0);
87  INLINE ShaderInput(CPT_InternalName name, const LVecBase3i &vec, int priority=0);
88  INLINE ShaderInput(CPT_InternalName name, const LVecBase2i &vec, int priority=0);
89 
90  ShaderInput(CPT_InternalName name, const NodePath &np, int priority=0);
91 
92 PUBLISHED:
93  explicit ShaderInput(CPT_InternalName name, Texture *tex, bool read, bool write, int z=-1, int n=0, int priority=0);
94  explicit ShaderInput(CPT_InternalName name, Texture *tex, const SamplerState &sampler, int priority=0);
95 
96  enum ShaderInputType {
97  M_invalid = 0,
98  M_texture,
99  M_nodepath,
100  M_vector,
101  M_numeric,
102  M_texture_sampler,
103  M_param,
104  M_texture_image,
105  M_buffer,
106  };
107 
108  INLINE operator bool() const;
109  INLINE bool operator == (const ShaderInput &other) const;
110  INLINE bool operator != (const ShaderInput &other) const;
111  INLINE bool operator < (const ShaderInput &other) const;
112 
113  size_t add_hash(size_t hash) const;
114 
115  INLINE const InternalName *get_name() const;
116 
117  INLINE int get_value_type() const;
118  INLINE int get_priority() const;
119  INLINE const LVecBase4 &get_vector() const;
120  INLINE const Shader::ShaderPtrData &get_ptr() const;
121 
122  const NodePath &get_nodepath() const;
123  Texture *get_texture() const;
124  const SamplerState &get_sampler() const;
125 
126 public:
127  ShaderInput() = default;
128 
129  INLINE ParamValueBase *get_param() const;
130  INLINE TypedWritableReferenceCount *get_value() const;
131 
132  static void register_with_read_factory();
133 
134 private:
135  LVecBase4 _stored_vector;
136  Shader::ShaderPtrData _stored_ptr;
137  CPT_InternalName _name;
138  PT(TypedWritableReferenceCount) _value;
139  int _priority;
140  int _type;
141 
142  friend class ShaderAttrib;
143  friend class Extension<ShaderInput>;
144 };
145 
146 #include "shaderInput.I"
147 
148 #endif // SHADERINPUT_H
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:193
This is a generic buffer object that lives in graphics memory.
Definition: shaderBuffer.h:33
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a small container class that can hold any one of the value types that can be passed as input ...
Definition: shaderInput.h:40
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A non-template base class of ParamValue (below), which serves mainly to define the placeholder for th...
Definition: paramValue.h:31
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The default class template does not define any methods.
Definition: extension.h:34
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents a set of settings that indicate how a texture is sampled.
Definition: samplerState.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.