HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_ScriptMaterialInfo.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VOP_ScriptMaterialInfo.h ( VOP Library, C++)
7  *
8  * COMMENTS: This class represents information needed for the
9  * script-based vopnet materials (compiled multi-context vopnet
10  * material HDAs to match the behaviour of node-based vopnet
11  * materials from which they were created (eg, vopmaterial SHOP).
12  * This is usually information about the rendering properties
13  * and procedural vops within the vopnet material.
14  *
15  */
16 
17 #ifndef __VOP_ScriptMaterialInfo__
18 #define __VOP_ScriptMaterialInfo__
19 
20 #include "VOP_API.h"
21 #include <UT/UT_ValArray.h>
22 #include <UT/UT_StringMap.h>
23 #include "VOP_Types.h"
24 
25 class UT_StringArray;
26 class UT_StringHolder;
27 class UT_StringRef;
28 class PRM_Parm;
29 class PRM_ParmList;
30 class OP_Node;
31 class OP_Network;
33 class VOP_Node;
34 class VOP_PhantomNode;
35 class VOP_NodeChoice;
36 class UT_String;
37 class UT_IStream;
42 
43 // ===========================================================================
44 // Holds info about shader layer exports.
46 {
47 public:
48  void setInputsToCopy( const UT_IntArray &inputs )
49  { myInputsToCopy = inputs; }
50  const UT_IntArray & getInputsToCopy() const
51  { return myInputsToCopy; }
52 
54  { myExportsToAdd = add; }
56  { return myExportsToAdd; }
57 
58 private:
59  UT_IntArray myInputsToCopy;
60  UT_StringHolder myExportsToAdd;
61 };
62 
63 
64 // ===========================================================================
66 {
67 public:
68  /// Constructor. Takes an 'owner' as an argument, to make it possible
69  /// for phantom nodes to report their full path and shader code section
70  /// to be picked based on parameter value of the switch indices (top level
71  /// parameters on owner).
73  virtual ~VOP_ScriptMaterialInfo();
74 
75  /// Static function for encoding the relevant child nodes of the material
76  /// vopnet into a serialized stream, parsable by the instantiation
77  /// methods of this class.
78  /// Returns true if there was some relevant info to encode and
79  /// there were no errors while encoding that info.
80  /// @param buffer Outgoing argument that will contain the encoded
81  /// info in an XML form.
82  /// @param material Vopnet material node whose metadata needs to be
83  /// saved. The metadata is in the form of child nodes
84  /// that don't participate in the vex shader generation
85  /// (such as properties nodes and procedurals). However
86  /// information about such nodes is necessary for
87  /// proper functioning of the compiled material HDAs.
88  /// @param mapper Maps the operator paths of encapsulated shaders
89  /// found in the material node into the HDA section
90  /// names that contain vex code for these shader nodes.
91  static bool encodeInfo( UT_String & buffer, OP_Node & material,
93 
94 
95  /// Obtains the names of the HDA code sections that are used by this info.
96  static void getReferencedSectionNames( UT_IStream & is,
98 
99 
100  /// This method parses and loads information from the stream (created
101  /// with encodeInfo()). It initializes the internal data structures
102  /// so that it can properly handle all the other requests and queries from
103  /// other methods.
104  ///
105  /// It creates phantom nodes within an owner network.
106  /// Phantom nodes represent render properties, procedural shaders,
107  /// and encapsulated shaders that were part of the original material node,
108  /// but which cannot be part of the HDA since it is a compiled code (ie,
109  /// childless) node type. Houdini still considers myParentNode as a
110  /// childless node so users cannot dive it and see them, but the
111  /// phantom nodes are still present. Namely, when knowing their exact
112  /// node paths and searching for them with findNode(). So,
113  /// the 'parent' argument is necessary so that phantom nodes can report
114  /// a valid full path.
115  ///
116  /// It also parses the information about the code sections that are present
117  /// in the HDA. This info is used to pick a correct shader code from a
118  /// correct section, in case there are a few versions of the shader, each
119  /// corresponding to an Output VOP node, which are picked by Switch VOPs
120  /// connected as inputs to the Collect VOP.
121  bool loadInfo( UT_IStream & is );
122 
123  /// Returns true if the instance of this class contains relevant information
124  /// for the given shader type and can answer the queries for this type.
125  bool providesVopType( VOP_Type shader_type );
126 
127  /// Returns a name of the HDA section that has the vex code that should
128  /// be used for the shader of a given type. HDA materials may have several
129  /// code sections for the same shader type if the original node had several
130  /// Output VOP nodes connected to the Collect VOP node via Switch VOPs.
131  /// This method mimics the switch vop hierarchy to make a decision as to
132  /// which shader code to use.
133  bool getCodeSectionName( UT_String & section_name,
134  VOP_Type shader_type );
135 
136  /// Returns all known export parameters of a shader.
137  void getExportParmInfos(
138  UT_Array<VOP_FunctionArgInfo> &arg_infos,
139  VOP_Type shader_type ) const;
140 
141  /// @{ Returns info needed for constructing output variable tags for
142  /// describing shader layer exports.
143  UT_IntArray getShaderLayerExportsInputsToCopy(const char *out_name,
144  VOP_Type shader_type) const;
145  UT_StringHolder getShaderLayerExportsToAdd(const char *out_name,
146  VOP_Type shader_type) const;
147  /// @}
148 
149  /// Track down the parameter associated with a given property.
150  virtual bool getParameterOrProperty(
151  const UT_StringRef &name, fpreal now,
152  OP_Node *&op, PRM_Parm *&parm,
153  bool create_missing_multiparms,
154  PRM_ParmList *obsolete );
155 
156  /// Track down the parameter associated with a given a channel name.
157  virtual bool getParameterOrPropertyByChannel(
158  const UT_StringRef &chname,
159  fpreal now, OP_Node *&op, PRM_Parm *&parm,
160  int &vector_index, PRM_ParmList *obsolete );
161 
162  /// Track down the parameters or properties in the given list.
163  /// Fill out the property lookup list with parameters.
164  /// Returns the total of found and resolved parameters in the list (whether
165  /// they were resolved by previous calls or this particular call).
166  virtual int findParametersOrProperties(fpreal now,
167  OP_PropertyLookupList &list);
168 
169 
170  /// Returns a procedural shader node of a given type if it has one,
171  /// otherwise returns NULL.
172  virtual VOP_Node * getProcedural(VOP_Type type);
173 
174  /// Returns the phantom node of a given name or NULL if no such child found.
175  virtual OP_Node * getChild(const char *name, int *hint = NULL) const;
176 
177  /// Map: shader type -> list of exported parameters in that shader.
179 
180  /// Map: outupt name, shader type -> shader layer exports
181  using LayerExportsMap = UT_StringMap<
183 
184 private:
185  /// Gets the string data from the choice leaf node that is considered
186  /// to be currently selected based on the decision tree.
187  const char * getChoiceLeafData(VOP_Type type, const char *key) const;
188 
189  /// Uses switch info tree to access the node of a given type. If info
190  /// does not exist, looks for the first node of a given type in the
191  /// internal list.
192  VOP_PhantomNode * getNodeOfType( VOP_Type type ) const;
193 
194  /// Uses switch info tree to access the nodes of a given type. If info
195  /// does not exist, gathers all the nodes of a given type in the internal
196  /// list.
197  void getNodesOfType( VOP_PhantomNodeList & nodes,
198  VOP_Type type ) const;
199 
200 private:
201  /// The owner network of this material info.
202  OP_Network * myOwner;
203 
204  /// Phantom nodes that provide info about rendering properties values
205  /// and the procedrual shaders.
206  VOP_PhantomNodeList myNodes;
207 
208  /// The tree containing information about output nodes (mapped to HDA
209  /// code section names), properties phantom nodes, and procedural shader
210  /// phantom nodes.
211  /// This decision tree chooses the correct code section or node to use.
212  ///
213  /// Each code section corresponds to exactly one Output VOP that was used
214  /// to generate the shader code. However, in materials, there may be a
215  /// series of Switch and Null VOPs chained together from the Collect VOP
216  /// to the Output VOPs. Thus, there may be a few code sections for a given
217  /// type of a shader (eg, surface), and this tree helps to make a decision
218  /// as to which section should be used to provide the shader code. The root
219  /// in this tree represents the Collect VOP, the branches are Switch VOPs,
220  /// and the leaves are the Output VOPs. The branch nodes contain info
221  /// needed to choose a branch (swich input). The leaves contain the code
222  /// section name. Whole tree is used to choose the shader code section.
223  VOP_NodeChoice * myNodeChoiceTree;
224 
225  /// List of export parameters for each shader type.
226  ExportsMap myExportParametersMap;
227 
228  /// Shader Layer exports info for each output.
229  LayerExportsMap myLayerExportsMap;
230 };
231 
232 
233 /// Mapper that provides an HDA section name for a given shader node.
234 //
235 /// The shader may be a material component shader or an encapsulated shader.
236 /// The material component shader can be invoked by arbitrary caller (eg,
237 /// a renderer or another shader).
238 //
239 /// The encapsulated shaders are referenced by procedural geometry VOPs
240 /// inside the material, and are not really available to the outside world
241 /// for direct calls. They can be indirectly manipulated thru parameters
242 /// promoted to the parent material.
244 {
245 public:
246  // Standard virtul destructor.
248 
249  /// Maps the shader node to an HDA section name that contains the
250  /// code generated by that shader node. The shader node should generate
251  /// own code, because mapper may try to compile and store it in the section.
252  /// Returns, previously added mapped section name if already added,
253  /// or adds and returns a newly constructed shection name.
254  /// @param section_name The outgoing argument that will contain
255  /// the section name that contains the shader's
256  /// vex code.
257  /// @param shader_node The shader node whose code is in the mapped
258  /// section name.
259  /// @param shader_type The type of shader code to look for (one node
260  /// may be able to provide a few vex code chunks,
261  /// each for a different shader type).
262  /// @param is_encapsulated If true, the shader is mareked as encapsulated,
263  /// which influences how the shader node is treated with regards
264  // to generating the VEX code. Ie, it is is generated to suit the
265  /// purpose of calling it from the geometry procedurals (without
266  /// import directoves), rather than as an explicit VEX shader call
267  /// from another VEX shader (which require import directives, etc).
268  virtual void mapToVexCodeSection( UT_String & section_name,
269  VOP_Node * shader_node,
270  VOP_Type shader_type,
271  bool is_encapsulated) = 0;
272 
273  /// Checks if the shader node was added as part of the primary output
274  /// compilation phase. These nodes don't have phantom nodes, but rather
275  /// reference a saved code section directly.
276  virtual bool isPrimaryOutput( VOP_Node *shader_node,
277  VOP_Type shader_type ) const = 0;
278 };
279 
280 
281 #endif
282 
void setExportsToAdd(const UT_StringHolder &add)
UT_ValArray< VOP_Node * > VOP_NodeList
Unsorted map container.
Definition: UT_Map.h:83
GLuint const GLchar * name
Definition: glcorearb.h:785
GLuint buffer
Definition: glcorearb.h:659
void setInputsToCopy(const UT_IntArray &inputs)
const UT_IntArray & getInputsToCopy() const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
#define VOP_API
Definition: VOP_API.h:10
Mapper that provides an HDA section name for a given shader node.
GLuint const GLuint * names
Definition: glew.h:2695
fpreal64 fpreal
Definition: SYS_Types.h:277
const UT_StringHolder & getExportsToAdd() const
VOP_Type
Definition: VOP_Types.h:24
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
UT_ValArray< VOP_PhantomNode * > VOP_PhantomNodeList