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