HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_Node.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 Library (C++)
7  *
8  * COMMENTS: The base class for all VOP operators
9  *
10  */
11 
12 #ifndef __VOP_Node_h__
13 #define __VOP_Node_h__
14 
15 #include <set>
16 #include <map>
17 #include <iosfwd>
18 
19 #include "VOP_API.h"
20 #include "VOP_DataMicroNode.h"
21 #include "VOP_Error.h"
22 #include "VOP_Language.h"
23 #include "VOP_TypeInfo.h"
24 #include "VOP_OperatorInfo.h"
25 #include "VOP_OutputInfoManager.h"
26 #include <OP/OP_Director.h>
27 #include <OP/OP_Network.h>
28 #include <UT/UT_UniquePtr.h>
29 #include <UT/UT_BitArray.h>
30 #include <UT/UT_ValArray.h>
31 #include <UT/UT_SymbolTable.h>
32 #include <UT/UT_Array.h>
33 #include <UT/UT_Map.h>
34 #include <SYS/SYS_Types.h>
35 #include <utility>
36 #include <vector>
37 
38 class UT_StringRef;
39 
40 #define VOP_OPT_LOW_FLAG 'L'
41 #define VOP_OPT_MEDIUM_FLAG 'M'
42 #define VOP_OPT_HIGH_FLAG 'H'
43 #define VOP_DEBUG_FLAG 'D'
44 #define VOP_MATERIAL_FLAG 'E'
45 
46 // The name of the parameter that contains the ordering of the
47 // VOPNET Parameters.
48 #define VOP_PARMORDER_NAME "parmorder"
49 #define VOP_BIND_NAME "bind"
50 #define VOP_GLOBAL_NODE_NAME "global"
51 #define VOP_ILLUM_NODE_NAME "illuminance"
52 #define VOP_PARM_NODE_NAME "parameter"
53 #define VOP_CONST_NODE_NAME "constant"
54 #define VOP_PARMRAMP_NODE_NAME "rampparm"
55 #define VOP_INLINE_CODE_NODE_NAME "inline"
56 #define VOP_SNIPPET_NODE_NAME "snippet"
57 #define VOP_MATERIAL_BUILDER_NODE_NAME "materialbuilder"
58 #define VOP_RSL_PREFIX "rsl_"
59 #define VOP_VARIABLE_INOUT_MAX 2048
60 
61 /// Prefix given to the subnet input variables.
62 #define VOP_SUBNET_VARIABLE_PREFIX "_"
63 
65 {
67 };
68 
69 class TIL_Thumbnail;
70 class VCC_DiagnosticInfo;
71 class VOP_Node;
72 class VOP_GlobalVarData;
73 class VOP_ParmGenerator;
74 class VOP_OutputVar;
75 class VOP_Bind;
76 class VOP_Block;
77 class VOP_AutoNode;
78 class VOP_CodeGenContext;
81 class VOP_VariableTags;
82 class VOP_SubnetBase;
84 
85 extern "C" {
87 };
88 
92 
96 
98 {
99  VOP_AutoNode* myAutoVopNode; // Auto-node that provides VEX code to adjust VOP's code.
100  int myIndex; // Index of the input on the node the auto-node connects to.
101 };
103 
104 //=============================================================================
106 {
107 public:
108  UT_StringHolder myName; // variable name
109  UT_StringHolder myDescription; // variable description
110  VOP_ContextType myContextType; // context type in which var exists
111  int myVarIndex; // index in the context's var table
112  VOP_TypeInfo myTypeInfo; // variable type (int, float, etc)
113  bool myReadable; // can read from variable?
114  bool myWritable; // can write to variable?
115  bool myIlluminanceVar; // is illuminance?
116 };
117 
118 //=============================================================================
120 {
121 public:
122  VOP_GlobalVarData( const char * name, const VOP_VarInfo & info );
124  void appendInfo( const VOP_VarInfo & info );
125 
126  const UT_StringHolder & getName() const
127  { return myName; }
128 
130  const VOP_TypeInfo & getTypeInfo( VOP_ContextType type ) const;
131  int getVarIndex( VOP_ContextType type ) const;
132  bool isReadable( VOP_ContextType type ) const;
133  bool isWriteable( VOP_ContextType type ) const;
134  bool isIlluminance( VOP_ContextType type ) const;
135  bool isValidInContext( VOP_ContextType type ) const;
136 
137  const VOP_TypeInfo & getAnyTypeInfo() const
138  {
139  return myInfos(0).myTypeInfo;
140  }
141 
142 private:
143  template<typename T> T getInfoMember( VOP_ContextType ctx_type,
144  T VOP_VarInfo::*member,
145  T default_val ) const;
146  template<typename T> const T &getInfoMemberRef( VOP_ContextType ctx_type,
147  T VOP_VarInfo::*member,
148  const T & default_val ) const;
149  int getIndexForContextType( VOP_ContextType type) const;
150 
151 private:
152  UT_StringHolder myName; // variable name
153  UT_Array<VOP_VarInfo> myInfos; // infos for applicable contexts
154 };
155 
156 //=============================================================================
158 {
159 public:
160  virtual ~VOP_OutputNameEditorSource();
161  virtual int getNumInputsFromParent() const = 0;
162  virtual void NAMEFROMPARM(UT_String &str, int idx) const = 0;
163  virtual void LABELFROMPARM(UT_String &str, int idx) const = 0;
164  virtual void setNAMEFROMPARM(UT_String &str, int idx) = 0;
165  virtual void setLABELFROMPARM(UT_String &str, int idx) = 0;
166 };
167 
168 // ============================================================================
169 /// Abstracts information about shader function parameters/arguments.
170 /// It has two use cases: when declaring and defining a shader function, and
171 /// when calling a shader function. It always stores shader parameter type and
172 /// name, but may not store some of the other information for some use cases.
174 {
175 public:
177 
178  /// Argument type.
179  void setTypeInfo( const VOP_TypeInfo &type_info );
180  const VOP_TypeInfo & getTypeInfo() const
181  { return myTypeInfo; }
182 
183  /// Argument name.
184  void setName( const char *name );
185  const UT_StringHolder & getName() const
186  { return myName; }
187 
188  /// Local variable name to use when calling the function.
189  void setVarName( const char *var_name );
190  const UT_StringHolder & getVarName() const;
191 
192  /// Expression (ie, RHS of the assignment) to use for initialization
193  /// of the argument when calling the shader function.
194  void setInitCodeStr( const char *init_code );
196  { return myInitCodeStr; }
197 
198  /// Node input index, if argument corresponds to an input; otherwise -1.
199  void setInputIndex( int input_index );
200  int getInputIndex() const
201  { return myInputIdx; }
202 
203  /// Node output index, if argument corresponds to an input; otherwise -1.
204  void setOutputIndex( int output_index );
205  int getOutputIndex() const
206  { return myOutputIdx; }
207 
208  /// True if it's an export (output) shader function parameter.
209  void setExported( bool exported );
210  bool isExported() const
211  { return myIsExported; }
212 
213 private:
214  VOP_TypeInfo myTypeInfo; // Argument type
215  UT_StringHolder myName; // Argument name
216  UT_StringHolder myVarName; // Variable name to use in function call
217  UT_StringHolder myInitCodeStr; // Expression code to init an arg to.
218  int myInputIdx; // Input index this variable corresponds to
219  int myOutputIdx; // Output index this var corresponds to
220  bool myIsExported; // Is an output argument
221 };
222 
223 //=============================================================================
225 {
226 public:
227  vop_Connector(int groups_above,
228  int index = -1)
229  : myIndex(index),
230  myGroupsAbove(groups_above),
231  myIsExpanded(false),
232  myIsGroup(false)
233  { }
234  vop_Connector(int groups_above,
235  const UT_StringHolder &group_name,
236  int index,
237  bool expanded)
238  : myGroupName(group_name),
239  myIndex(index),
240  myGroupsAbove(groups_above),
241  myIsExpanded(expanded),
242  myIsGroup(true)
243  { }
245  { }
246 
247  int myIndex;
251  bool myIsGroup;
252 };
254 
255 //=============================================================================
256 /// The allowed name formats when asking for shader name.
258 {
259  PLAIN, // Straight forward name only.
260  ALLOW_HDA_SECTION, // Allow paths to HDA sections in name.
261  RELAXED_AUTO // For potential auto shaders, Parm & Const
262  // input VOPs don't trigger auto-wrapping.
263  // Note, this implies allowing HDA sections.
264 };
265 
266 //=============================================================================
268 {
269 public:
270  static const char *theChildTableName;
271  const char *getChildType() const override;
272  const char *getOpType() const override;
273 
274  OP_OpTypeId getChildTypeID() const override;
275  OP_OpTypeId getOpTypeID() const override;
276 
277  /// Nobody should have to override this, but it's public for other people
278  OP_DataType getCookedDataType() const override;
279 
280  /// Whenever a variable type parm changes, we have to send out an event
281  /// to get our tile to update.
282  void opChanged(OP_EventType reason, void *data=0) override;
283  void referencedParmChanged(int pi) override;
284 
285  static void buildOperatorTable(OP_OperatorTable &table);
286 
287  /// Get the parm block information that will go in the dialog script
288  /// for our VOPNET. The shader_contexts argument is a list of
289  /// contexts, in which the parameter is a shader argument.
290  virtual void getParameterBlock(UT_String &parmstr,
291  const char *shader_contexts);
292 
293  /// The parameter variable declaration using the syntax of a given language.
294  virtual void getParameterDeclaration(UT_String &parmdecl,
295  const VOP_Language *language,
296  const VOP_CodeGenContext &context);
297 
298  /// Obtains the parameter declaration code comment, which is appended
299  /// after the declaration in the generated source code.
300  virtual void getParameterComment(UT_String &parm_comment,
301  const VOP_Language *language,
302  const VOP_CodeGenContext &context);
303 
304  /// If false, getShaderExtraParameters is not invoked as it is assumed
305  /// to return an empty list
306  virtual bool definesShaderExtraParameters() const;
307 
308  /// Returns a list of the attributes that we want to bind or export.
309  /// These are added to the vex functions parameter list, but not to the
310  /// UI as they are only expected to be overridden. If they match
311  /// an existing value, they do not replace.
312  /// The shader type is used only in a very specific cases of material
313  /// builder, when extra parameters may depend on a shader type.
314  virtual int getShaderExtraParameters(UT_Array<VOP_Type> &types,
315  UT_IntArray &doexport, UT_StringArray &names,
316  UT_StringArray &def,
317  VOP_Type shader_type = VOP_TYPE_UNDEF ) const;
318 
319  /// Get compiler pragmas for thi snode.
320  virtual void getPragmas(UT_String &pragmastr,
321  const VOP_CodeGenContext &context);
322 
323  /// If the node generates a shader call, get the modules names to import.
324  virtual void getModulesToImport(UT_StringArray &modules,
325  const VOP_CodeGenContext &context);
326 
327  /// Get the code fragment to be included in the outer code,
328  /// before the main shader code.
329  virtual void getOuterCode(UT_String &codestr,
330  const VOP_CodeGenContext &context);
331 
332  /// Get the code fragment to be included in the shader code.
333  virtual void getCode(UT_String &codestr,
334  const VOP_CodeGenContext &context);
335 
336  /// Get the constant code that encodes the value of the node parameter.
337  virtual bool getParmConstantString(const char *parmname,
338  const VOP_TypeInfo &type_info,
339  UT_String &str,
340  bool expand_string,
341  const VOP_Language *l=0);
342  /// Returns the code name of the type, such as "float" from VOP_TYPE_FLOAT
343  /// Threadsafe but not re-entrant.
344  static const char *getTypeNameFromType(const VOP_TypeInfo &type_info,
345  const VOP_Language *lang);
346  /// Returns a UI friendly version of the string, with NiceNumber
347  /// type effects embedded.
348  bool getParmPrintableString(const char *parmname,
349  VOP_Type type,
350  UT_String &str,
351  bool expand_string) const;
352 
353 
354 
355  /// Returns true if this VOP is a VOP_ParmGenerator or subclass.
356  virtual bool getIsParmGenerator() const;
357 
358  /// @{
359  /// Virtual methods to avoid dynamic_casts
360 #define VOP_IMPLEMENT_CASTS(NAME) \
361  static const VOP_##NAME *castTo##NAME(const OP_Node *node) { \
362  const VOP_Node *vop = CAST_VOPNODE(node); \
363  return vop ? vop->castTo##NAME() : nullptr; } \
364  static VOP_##NAME *castTo##NAME(OP_Node *node) { \
365  VOP_Node *vop = CAST_VOPNODE(node); \
366  return vop ? vop->castTo##NAME() : nullptr; } \
367  virtual const VOP_##NAME *castTo##NAME() const { return nullptr; } \
368  virtual VOP_##NAME *castTo##NAME() { return nullptr; }
369 
370  VOP_IMPLEMENT_CASTS(ParmGenerator)
371  VOP_IMPLEMENT_CASTS(SubnetBase)
372  VOP_IMPLEMENT_CASTS(OutputVar)
373  VOP_IMPLEMENT_CASTS(Bind)
374  VOP_IMPLEMENT_CASTS(Block)
375 #undef VOP_IMPLEMENT_CASTS
376  /// @}
377 
378  /// Moves a visualizer into our output list.
379  bool addOrMoveVisualizerToOutput(int outputidx) override;
380 
381  /// Creates a code generator for the VOP, if it needs one.
382  /// When a VOP is placed in a non-shaer container node that does not have
383  /// an overarching code generator, this method may be called to create one
384  /// for a VOP to act as a stand-alone shader.
385  void createAutoCodeGenerator();
386 
387  /// Utility method to create explicit children inside that node.
388  /// The children correspond to the epilogue in auto-generated shader.
389  void createAutoShaderChildren();
390 
391  /// @{ Obtains a code generator that provides shader code associated
392  /// with a node. Usually, vopnet shader VOPs have their own dedicated
393  /// code generator for shader constructed fom their children.
394  /// However, also, all VOP nodes inside a Shader Network container node
395  /// have their own auto-generator for automatically constructing temporary
396  /// shader from their inputs (siblings).
399  const VOP_CodeGenerator
400  *getVopAutoCodeGenerator() const override;
401  /// @}
402 
403  /// Gives the node a chance to initialize itself when it is first created.
404  /// This is only used for VOP_ParmGenerator nodes.
405  virtual void initializeNode();
406 
407  /// Called by VOP_CodeGenerator::afterAddNode to ensure that nodes
408  /// have been properly initialized. Some nodes weren't calling their
409  /// base class' initializeNode() resulting in only partial initialization.
410  bool isInitialized() const { return myInitialized; }
411 
412  /// Make sure that our parmname parameter (if we have one) doesn't
413  /// conflict with any other parmname parameter values.
414  virtual void ensureParametersAreValid();
415  static void incrementVariableName(UT_String &varname);
416 
417  /// @{ Some variable names may contain characters that are illegal in
418  /// C-style variable names. Eg, Snippet VOP may allow colons to indicate
419  /// namespaced attributes which get bound to VEX parameters/variables.
420  /// To ensure the variable name is valid, such characters are encoded
421  /// using only alphanumeric (and underscore) characters.
422  /// The decode function reverses such encoding.
423  static UT_StringHolder ensureValidVarName(const UT_StringHolder &var);
424  static UT_StringHolder decodeVarName(const UT_StringHolder &var);
425  /// @}
426 
427  /// Functions to get information about our operator outputs.
428  /// These just call the getOutputXXXSubclass functions.
429  void getOutputName(UT_String &out, int idx) const override;
430  void getOutputName(UT_StringHolder &out, int idx) const
431  { UT_String tmp; getOutputName(tmp, idx); out.adoptFromString(tmp); }
432  int getOutputFromName(const UT_String &out) const override;
433  VOP_Type getOutputType(int idx);
434  void getOutputTypeInfo(VOP_TypeInfo &type_info,
435  int idx) const;
436  VOP_Type getNamedOutputType(const OP_ConnectorId& output_name);
437  void getNamedOutputTypeInfo(VOP_TypeInfo &type_info,
438  const OP_ConnectorId& output_name);
439  /// Obtains annotations (tags) for the variable value pushed out on
440  /// the given output connector. The tags are arbitrary, but are primarily
441  /// used to denote the contents of arrays (ie, export name for the value).
442  VOP_VariableTagsHandle getOutputVariableTags(int idx,
443  VOP_Type shader_type) const;
444  VOP_VariableTagsHandle getNamedOutputVariableTags(
445  const OP_ConnectorId& output_name,
446  VOP_Type shader_type) const;
447 
448  /// Returns variable tags provided by an input node on the given input idx.
449  VOP_VariableTagsHandle getVariableTagsFromInputNode( int idx,
450  VOP_Type shader_type) const;
451 
452  /// @{ Virtuals for obtaining inputs from which to copy shader layer
453  /// exports variable tags and which exports to add, for a given output.
454  virtual UT_IntArray getShaderLayerExportsInputsToCopy(int out_idx,
455  VOP_Type shader_type);
456  virtual UT_StringHolder getShaderLayerExportsToAdd(int out_idx,
457  VOP_Type shader_type);
458  /// @}
459 
460 
461  /// Returns the variable name associated with a given input number.
462  /// These just call the getInputXXXSubclass functions.
463  void getInputName(UT_String &in, int idx) const override;
464  void getInputName(UT_StringHolder &in, int idx) const
465  { UT_String tmp; getInputName(tmp, idx); in.adoptFromString(tmp); }
466  int getInputFromName(const UT_String &in) const override;
467 
468  /// will_autoconvert_out, if not null, is set to true if autoconversion
469  /// will be needed, to false otherwise.
470  VOP_Type getInputType(int idx) const;
471  void getInputTypeInfo(VOP_TypeInfo &type_info,
472  int idx) const;
473  VOP_Type getNamedInputType(const OP_ConnectorId& input_name);
474  void getNamedInputTypeInfo(VOP_TypeInfo &type_info,
475  const OP_ConnectorId& input_name);
476 
477  // Whether the visibility flag has been set in the operator type property.
478  // This is not the same flag as the one in OP_Input.
479  bool getIsInputVisibleDefault(int idx) override;
480 
481  /// Returns currently allowed input types for a given input, regardless
482  /// of what is connected to that input at the moment.
483  /// These do not include types to which autoconversion is possible.
484  virtual void getAllowedInputTypeInfos(unsigned idx,
485  VOP_VopTypeInfoArray &typeinfos);
486  virtual void getAllowedInputTypes(unsigned idx,
487  VOP_VopTypeArray &voptypes);
488 
489  /// Returns all allowed types for a given input, regardless of what is
490  /// currently wired to that input *and* regardless of what subset of all
491  /// these types is currently legal due to pruning of invalid signatures
492  /// (input types) on a script node (etc).
493  /// This is similar to getAllowedInputTypeInfos(), but unlike it, this
494  /// method returns types belonging to invalid signatures.
495  void getAllAllowedInputTypeInfos(unsigned idx,
496  VOP_VopTypeInfoArray &typeinfos);
497 
498  /// Get the nuber of signatures that the node has, and obtain the i-th
499  /// signature name.
500  /// The VOP signatures apply mostly to the VOP HDAs,
501  /// where a user can define several signatures for the operator (a
502  /// signature is a set of input types, and the user provides a name
503  /// associated with each such set). The build-in operators ususally have
504  /// only a single signature, and thus don't bother to provide any
505  /// distinguishing name for it (but they may).
506  virtual int getSignatureCount() const;
507  virtual void getSignatureName(UT_String &name, int index) const;
508 
509  /// Sets the current signature. The name must be a valid signature
510  /// recognized by the node. Also it should be possible to switch to that
511  /// signature, which may not be possible due to the types of connected
512  /// inputs, which limit the aplicability of some signatures.
513  virtual void setCurrentSignature(const char *name);
514  /// Obtains the current signature name.
515  virtual bool getCurrentSignatureName(UT_String &name);
516 
517  /// Some variables associated with vop inputs can be overriden or set
518  /// without an explicit wire to that input.
519  /// The override comes from an output connector of another node,
520  /// encoded as <node, output index> pair.
521  using InputVariableOverride = std::pair<VOP_Node*, int>;
522  void setInputVariableOverride(int input_index,
523  const InputVariableOverride &var_override);
524  InputVariableOverride getInputVariableOverride(int input_index) const;
525 
526  /// Returns true if the output variables of this node should not be
527  /// renamed in the code (in an attempt to avoid name collisions);
528  /// it usually applies to the shader output parameters in a given context.
529  /// If so, the second function returns the name of this output variable.
530  /// The version with VOP_CodeGenContext argument should be used.
531  virtual bool areOutputVariablesFixed(const VOP_CodeGenContext &ctx);
532  virtual bool areOutputVariablesFixed(VOP_ContextType context_type);
533  virtual void getFixedOutputVariable(UT_String &var, int idx);
534 
535  /// Returns the variable name (in the generated code) that corresponds to
536  /// the node's idx-th output. Usually it's just the output name.
537  virtual void getOutputVariableName(UT_String &var, int idx) const;
538 
539  /// If node explicitly declares variables by itself (eg, subnet), it should
540  /// report such types with this method, in case it uses some custom
541  /// data type that needs to be defined in the shader code (eg, struct).
542  /// Most nodes don't need to override this, since code generator knows
543  /// what types it used for this node's (output connector) variables.
544  virtual void getExtraTypesToDefine( UT_Array<VOP_TypeInfo> &types );
545 
546  /// Returns true if the methods below should consider only the inputs
547  /// of this node that belong to the given shader context.
548  /// Most nodes indiscriminately merge all their inputs, but some (like
549  /// Material Buider VOP) need pick inuts that belong to the given context.
550  virtual bool shouldCheckInputContextForMergeInputNodeList() const;
551 
552  /// Recurse through our inputs and add them in order to the given list.
553  /// Note this this might create new auto-conversion nodes in this list,
554  /// and these will have to be deallocated by the caller (using
555  /// the utility function deleteAutoNodesIn())
556  void mergeInputNodeList(VOP_NodeList &nodes,
557  const VOP_CodeGenContext *context = nullptr);
558  void mergeInputNodeListInternal(VOP_NodeList &nodes,
559  VOP_NodeList &extraterminals,
560  const VOP_CodeGenContext *context = nullptr);
561 
562  /// Scans the node list and deletes the auto convert nodes (and replaces
563  /// them with NULLs in the list). Also, clears any auto-convert information
564  /// for all other nodes in the list. Note, thet the node list is usually
565  /// constructed with mergeInputNodeList() method.
566  static void deleteAutoNodesIn(VOP_NodeList& nodes);
567 
568  /// Determines if this is a terminal node. Ie, whether this node is a
569  /// code sink that culminates (one of) the shader calculations.
570  /// The culmination may be in the form of setting the global variable,
571  /// setting an export parameter, or a general reqest by a user to
572  /// ensure the node is part of the shader (eg, print vop).
573  /// The code code generator determines all the nodes that participate
574  /// in the shader definition by by recursively traversing the inputs
575  /// starting from this node.
576  /// @param check_shader_context Is true when the node should consider
577  /// the shader context name/type contained in the code gen context
578  /// parameter; the node should return true only if it really
579  /// is a terminal node for the given shader type.
580  /// Otherwise, if false, the node can disregard the shader type
581  /// most likely because it lives in a single-context vopnet.
582  virtual bool forceCodeGenerationOfInputs(
583  const VOP_CodeGenContext &context,
584  bool check_shader_context) const;
585 
586  /// Returns true if the node can and should initiate generation of code
587  /// in the given context. If, if the node is a terminal node.
588  bool forceCodeGenerationInContext(
589  const VOP_CodeGenContext &context)const;
590 
591  /// Returns true if the given output represents an export variable for
592  /// a shader of a type specified by context.
593  bool isInputForShaderType(int input_idx,
594  const VOP_CodeGenContext &context)const;
595  bool isOutputForShaderType(int output_idx,
596  const VOP_CodeGenContext &context)const;
597 
598  /// @ Returns a node that implements or represents the given shader type.
599  /// The returned node may be a stand-alone (self-contained) shader node,
600  /// or a building-block node from which a shader of a given type can
601  /// be generated.
602  virtual VOP_Node *findShader(VOP_Type shader_type, fpreal now);
603 
604  /// Returns all applicable shader nodes and their corresponding shader
605  /// types, and if applicable output names.
606  /// Output names become important when a VOP node is a subnetwork
607  /// containing a few surface shaders, one for different renderer.
608  /// Note, some returned output names may correspond to a AOV data (eg,
609  /// the output type may be float or a vector rather than a shader type),
610  /// in which case the shader type will be reflect that.
611  virtual void findAllShaders( VOP_NodeList &shader_nodes,
612  VOP_ShaderTypeList &shader_types,
613  UT_StringArray &output_names );
614  /// @}
615 
616  /// Returns true if the VOP can represent a shader. Ie,
617  /// whether it can be converted into a shader.
618  virtual bool canDefineShader() const;
619 
620  /// Returns true if the VOP is a stand-alone shader (and not
621  /// a building-block for a shader).
622  /// The VOP may generate the code from its children VOPs, point to
623  /// an external file, or store the code in the HDA section.
624  /// But, it represents a self-contained shader code, which can be invoked
625  /// for shading an object (surface), used as an encapsulated shader (CVEX
626  /// shader for geometry procedurals, like fur), or called from another
627  /// shader (as a shader function call).
628  virtual bool isShader() const;
629 
630  /// Returns true if the VOP is a stand-alone shader (and not a
631  /// building-block for a shader), and can provide the shader code for
632  /// a shader of the given type. Note, material VOP may return true for
633  /// several shader types, such as both surface and displacement.
634  virtual bool isShader(VOP_Type shader_type) const;
635 
636  /// Returns true if the VOP is directly translatable to a USD primitive.
637  /// Ie, it is not a shader code building-block VOP.
638  virtual bool translatesDirectlyToUSD() const;
639 
640  /// Returns ture if the node represents a USD NodeGraph, and false
641  /// if it is a USD Material.
642  virtual bool isUSDNodeGraph() const;
643 
644  /// Returns true if the node has pre-generated shader code and is not
645  /// using network to generate it. This mainly applies to digital assets
646  /// that store shader code in their sections (whether or not they also
647  /// store the network contents).
648  virtual bool isCachedShader() const;
649 
650  /// Returns true if the operator represents an externally defined shader
651  /// such as a Geometry Shader, or a shader whose code is saved in a file
652  /// on disk separately from the operator or HDA definition.
653  bool isExternalShader() const;
654 
655  /// Returns true if this is a subnetwork which generates an encapsulated
656  /// shader. For example the SubnetCVEX VOP. Parent material passes
657  /// encapsulated shaders as shader string to other shaders (usually,
658  /// geometry procedurals) to calculate certain properties dynamically.
659  /// And to construct shader string there are some restrictions on
660  /// encapsulated shaders (eg, their inputs can be only wired to constants
661  /// and parameter VOPs).
662  // TODO: But there is little distinction between them and regular shaders,
663  // so remove this method. The difference is really how they are used
664  // (ie, whether the shader string of the main shader like fur
665  // procedural contains the shader string for this cvex 'encapsulated'
666  // shader. But, to distinguis that, the clerk calls
667  // hou.VopNode.shaderString(as_encapsulated=True)
668  virtual bool isEncapsulatedShader() const;
669 
670  /// Material VOP may be able to return a procedural node.
671  virtual VOP_Node *getProcedural(VOP_Type type);
672 
673  /// @{ Returns the name, type, and render mask of the VOP shader.
674  virtual UT_StringHolder getShaderName(
675  VOP_ShaderNameStyle style,
676  VOP_Type shader_type) const;
677  UT_StringHolder getShaderName(bool forvex,
678  VOP_Type shader_type) const;
679  virtual UT_StringHolder getShaderNameForSignature(
680  const UT_StringRef &signature) const;
681 
682  virtual VOP_Type getShaderType() const;
683  const char * getRenderMask() const;
684  /// @}
685 
686  /// @{ For expanding compiler string used in auto code generator.
687  bool evalVariableValue(
688  UT_String &v, int index, int thread) override;
690  fpreal &v, int i, int thr) override
691  { return OP_Network::evalVariableValue(v,i,thr); }
692  /// @}
693 
694  /// @{
695  /// Obtains a coshader node (or array of nodes) associated with the parm.
696  /// Usually, the co-shader computes the value for the parameter, and
697  /// is represented as a wired input to the main shader node.
698  /// If no coshaders are wired in, the output list is empty.
699  void getCoShaderNodes(UT_ValArray<VOP_Node *> &coshaders,
700  const char* parm_name);
701  void getCoShaderNodesOutputNames(UT_StringArray &outputs,
702  const char* parm_name);
703  /// @}
704 
705  /// Writes out the shader code from the cache to the given output stream.
706  /// Returns true if successful, otherwise, returns false, if there's no
707  /// cached shader code for this context.
708  virtual bool getCachedShaderCode(std::ostream &os,
709  VOP_ContextType context_type) const;
710 
711  /// @{
712  /// To be able to use Cvex VOP in Attribute SOP, etc.
713  using VexBuildFn1 = void (*)(VOP_Node*, UT_String&, fpreal, OP_Node*,
717  static void setBuildVexScriptCB(VexBuildFn1 fn1, VexBuildFn2 fn2);
718  void buildVexScript(
719  UT_String &result,
720  fpreal t,
721  OP_Node *parent,
722  UT_Map<int, bool> *visited) override;
723  void buildVexScript(
724  UT_String &result,
725  fpreal t,
726  DEP_MicroNode *depnode,
727  UT_Map<int, bool> *v) override;
728  /// @}
729 
730 
731  /// @{ Returns true if the VOP represents a method inside a class.
732  virtual bool isVopMethod() const;
733  virtual bool isVopMethodPublic() const;
734  /// @}
735 
736  /// @{ If the node represents a function, a method, or a shader,
737  /// then these functions return the info (name, return type, args) about
738  /// the function or a shader function as it appears in the source code.
739  virtual void getVopFunctionName(UT_String &function_name) const;
740  virtual void getVopFunctionReturnInfo(VOP_FunctionArgInfo &i) const;
741  virtual void getVopFunctionArgInfos(
742  UT_Array<VOP_FunctionArgInfo> &arg_infos);
743  /// @}
744 
745  /// Obtains shader parameters information.
746  void getShaderArgInfos(
748  VOP_Type shader_type);
749 
750  /// Checks whether the given parm belongs to the shader of a given type.
751  bool isParmForShaderType(const PRM_Parm &parm,
752  VOP_Type shader_type, bool check_context_tag);
753 
754  /// Helper method for getVopFunctionArgInfos() to obtain shader function
755  /// parameter infos based on the node inputs and outputs.
756  /// Optionally, the method can prefix function argument names with an
757  /// underscore, which is customary for shaders based on subnets. If so,
758  /// the variable name will be also implicitly prefixed (otherwise,
759  /// it would most likely be resolved to an input value).
760  /// If argument name is not prefixed, the local variable used in a call
761  /// may still be optionally prefixed (when needed to avoid var replacement).
762  void getVopFunctionArgInfosFromInputsAndOutputs(
763  UT_Array<VOP_FunctionArgInfo> &arg_infos,
764  int first_input, int last_input,
765  int first_output, int last_output,
766  bool prefix_input_arg_and_var_names,
767  bool prefix_input_var_names = false,
768  const VOP_CodeGenContext *context = nullptr);
769 
770  /// Helper method to obtain shader function parameter infos based on
771  /// the node parameters.
772  void getVopFunctionArgInfosFromNodeParameters(
774  const VOP_CodeGenContext *context = nullptr);
775  void getVopFunctionArgInfosFromNodeParameters(
777  VOP_Type shader_type);
778 
779  /// Helper method to obtain shader function parameter infos based on
780  /// the node inputs, outputs, and parameters.
781  void getVopFunctionArgInfosFromInputsOutputsAndParms(
782  UT_Array<VOP_FunctionArgInfo> &arg_infos,
783  int first_input, int last_input,
784  int first_output, int last_output,
785  bool prefix_input_arg_and_var_names,
786  bool prefix_input_var_names = false,
787  const VOP_CodeGenContext *context = nullptr);
788 
789  /// Helper method to obtain shader function parameter infos based
790  /// on writable global variables in the shader's context.
791  /// Used for shader call, that explicitly binds shader parameters
792  /// to callee's globals, by listing them as arguments.
793  void getVopFunctionArgInfosFromGlobals(
794  UT_Array<VOP_FunctionArgInfo> &arg_infos,
795  VOP_Type shader_type );
796 
797  /// Helper method to obtain all known export parameters from a shader node.
798  virtual void getVopFunctionArgInfosFromExports(
799  UT_Array<VOP_FunctionArgInfo> &arg_infos,
800  VOP_Type shader_type );
801 
802  /// Gives this node a chance to register an interest in a varialbe that
803  /// the upstream vop computes, but only optionally when explicitly asked.
804  virtual void registerExtraVarRequests(
805  VOP_ExtraVarRequests &extra_var_requests,
806  const VOP_CodeGenContext &context);
807 
808  /// Removes entries that correspond to a shader function parameters
809  /// at a default value (or unconnected).
810  /// If @p keep_export_args is true, all exports args are kept, even
811  /// if they are at default. Otherwise, at-default exports are pruned.
812  void pruneVopFunctionArgInfos(
814  bool keep_all_export_args = false );
815 
816  /// Returns true if the parameter of a given name is at default value.
817  /// If the parameter template is also given, it is used for default value,
818  /// otherwise the parameter's template is used.
819  bool isParmAtDefaultValue( const char *parm,
820  const PRM_Template *tplate = nullptr ) const;
821 
822  /// Writes declarations of variables used as argument to a function call.
823  /// @param[out] buffer
824  /// Outgoing argument that is filled with variable declarations.
825  /// @parm[in] arg_infos
826  /// Information about inputs/output variables to write out.
827  /// @parm[in] use_defined_input_defaults
828  /// Flags whether the input variables should be initialized to
829  /// special defaults defined by the owner subnet. If true, any
830  /// unconnected inputs will be initialized to such specially defined
831  /// defaults (connected inputs will be initialized to incoming
832  /// variables corresponding to the incoming wire). If false, the
833  /// input defaults defined by owner subnet are not used, and all
834  /// inputs are initialized to incoming variables, which resolve to
835  /// the value if input is connected or to the empty constant or node
836  /// parm value.
837  void outputVopFunctionVariableDeclarations(UT_WorkBuffer &buffer,
838  const UT_Array<VOP_FunctionArgInfo> & arg_infos,
839  bool use_defined_input_defaults);
840 
841  /// @{ Constructs a shader call, assuming this node represents a shader.
842  UT_StringHolder getVopFunctionCallName(const VOP_CodeGenContext &ctx);
843  void getVopFunctionCallCode(UT_String &codestr,
844  const VOP_CodeGenContext &ctx);
845  void getVopFunctionCallModules(UT_StringArray &modules,
846  const VOP_CodeGenContext &ctx);
847  void appendVopFunctionArgument(UT_StringArray &arg_names,
848  UT_StringArray &arg_vals,
849  const VOP_FunctionArgInfo &arg_info);
850  /// @}
851 
852  /// Returns true if the code generator should declare local variables
853  /// for this node's outputs. Returns false, if node declares them itself.
854  virtual bool shouldOutputNodeVariableDeclarations() const;
855 
856  /// Get or set the table of global or local variables for this context.
857  /// The global variables are defined solely by the VEX context. The
858  /// data associated with each entry is the VEX_Type of the variable.
859  /// The local variables are those defined by Parameter ops. This
860  /// table provides a common place to look for variable name conflicts.
861  const VOP_GlobalVarMap *getGlobalVariables() const;
862  const VOP_ParmGeneratorMap *getLocalVariables() const;
863  const VOP_LocalChannelMap *getLocalChannels() const;
864  void setTables(const VOP_GlobalVarMap *globals,
865  VOP_ParmGeneratorMap *locals,
867  void setTablesFromVop(VOP_Node *vop);
868  void addLocalVariable(const UT_StringRef &varname,
869  VOP_ParmGenerator *definer);
870  void deleteLocalVariable(const UT_StringRef &varname);
871  void deleteLocalChannelDefiner( VOP_ParmGenerator *definer);
872  void getSortedGlobalVariableList(VOP_GlobalVarList &vars,
874  bool mustBeReadable,
875  bool mustBeWritable);
876 
877  /// Similar to getLocalVariables() but it returns a table of Parameter ops
878  /// that define subnet inputs rather than shader parameters.
879  virtual VOP_ParmGeneratorMap* getSubnetVariables();
880  VOP_ParmGeneratorMap* getParentSubnetVariables() const;
881  void addParentSubnetVariable(const char *varname,
882  VOP_ParmGenerator *definer);
883  void deleteParentSubnetVariable(const char *varname);
884 
885  /// Returns true if input variables should be prefixed inside the subnet.
886  virtual bool shouldPrefixInputVariablesInsideSubnet() const;
887 
888  /// Returns true if parm nodes that define subnet connectors are treated
889  /// as shader parms. This is true for subnet material (or shader) nodes.
890  virtual bool usesSubnetConnectorsAsShaderParms() const;
891 
892  /// Returns true if shader parameters should be displayed as node inputs
893  /// and outputs. This is true for subnet shader nodes.
894  virtual bool showsShaderParmsAsSubnetConnectors() const;
895 
896  /// Informs this node that some descendant (but not immediate child)
897  /// was added and it represents a shader input or output.
898  virtual void shaderParmGrandChildAdded(VOP_Node *grand_child);
899  virtual void shaderParmGrandChildChanged(VOP_Node *grand_child);
900  virtual void shaderParmGrandChildDeleted(VOP_Node *grand_child);
901 
902  /// Functions for getting and setting the in/out LOD value, using the
903  /// OP_NodeFlag mechanism.
904  void setFlag(char flag, int8 val) override;
905  bool setInOutLOD(int level, bool inoff);
906  bool getInOutLOD(int level) const;
907  static int &getLODPref() { return theLODPref; }
908  static void setLODPref(int value);
909 
910  /// Override the setInput functions so that we can send notification to
911  /// the nodes that are our inputs when we disconnect from them.
912  OP_ERROR setInput(unsigned idx, OP_Node *op,
913  unsigned outputIdx = 0) override;
915  unsigned idx,
916  const char *label,
917  int keeppos,
918  unsigned outputIdx = 0) override;
919 
921  const OP_ConnectorId &input_name,
922  OP_Node *op,
923  const OP_ConnectorId* output_name = nullptr
924  ) override;
926  const OP_ConnectorId &input_name,
927  const char *label, int,
928  const OP_ConnectorId* output_name = nullptr
929  ) override;
930 
931  /// For subnet VOPs, when moving an input, we want to go in and
932  /// reorganize the connections to our subinput and suboutput nodes
933  /// so that the internal connections remain the same.
934  void moveInput(int srcidx, int dstidx,
935  bool forcesubnet = false) override;
936 
937  /// Return our input node for the give index. If recursive is true and we
938  /// are in a subnet and the direct input for inputidx is a subnet input
939  /// node, travel up the parent chain until no longer in a subnet or the
940  /// input node is not a subnet input node. Basically, we want to know if we
941  /// are connected to anything meaningful.
942  virtual bool isConnected(int inputidx, bool recursive);
943 
944  /// Returns a pointer used by OPUI_OutputNameEditor to get and set data.
946  { return 0; }
947 
948 
949  /// Some material vops cache a list of shader that needs to be dirtied.
950  virtual void dirtyShaderList();
951 
952  /// Used by subnet type operators which must always have an output node.
953  /// However, some specialty subnets, such as volume sampler, may return
954  /// NULL, since its output node is not a regular subnet output node that
955  /// determines subnet output connectors (which is for what the subnet base
956  /// class uses the output node returned by this method).
957  virtual VOP_Node *getSubnetOutputNode() const;
958 
959  /// Returns true if this node is immediatly inside a non-shader subnet.
960  bool isInNonShaderSubNetwork() const;
961 
962  /// Returns true if the node is considered a subnet's input node.
963  virtual bool isSubnetInput() const
964  { return false; }
965 
966  /// Returns the node from which to transfer information about local
967  /// variables used in source code generated by this node.
969  { return nullptr; }
970 
971  /// Returns true if code generator should attempt to copy info about
972  /// a variable corresponding to the i-th output connector.
973  virtual bool shouldPreResolveOutput(int output_index) const
974  { return true; }
975 
976  /// Returns true if the node is consdered an output node that represents
977  /// a shader or a function that connects to a Collect node.
978  virtual bool isOutputVopNode() const
979  { return false; }
980 
981  /// Retruns true if the node is an internal auto node used only during
982  /// code generation.
983  virtual bool isAutoVopNode() const
984  { return false; }
985 
986  /// Retruns true if the node is an internal auto-convert node.
987  virtual bool isAutoConvertNode() const
988  { return false; }
989 
990  /// Defines the different nodes that can be created and automatically
991  /// connected to a VOP node's input.
993  {
994  // Create a const VOP to connect to the input.
996  // Create a parm VOP to connect to the input.
998  // Create a subnet-scoped parm VOP to connect to the input.
1000  };
1001 
1002  /// Create a Parameter or Constant VOP that matches the type, name and
1003  /// value of one of our inputs, and connect it to that input. 'parm'
1004  /// specifies whether to build a Parameter or a Constant.
1005  VOP_Node *insertParmGenerator(int inputidx,
1006  InputParmGenType type);
1007  VOP_Node *insertNode(int inputidx, const char* nodetype,
1008  bool connect_to_input,
1009  const char* undo_string = NULL);
1010 
1011  int inputParmTypeIndex(int inputidx,
1012  const PRM_Parm* parm) const;
1013  const char *inputParmTypeString(int inputidx,
1014  const PRM_Parm *parm) const;
1015 
1016  /// When inserting a parameter (i.e. Promote Parameter), the source VOP is
1017  /// allowed to give us a source VOP_ParmGenerator if there's no
1018  /// corresponding parameter found. The source parm generator is used to
1019  /// initialize settings on the new parameter node.
1020  virtual VOP_ParmGenerator *getInsertParmGeneratorSource(int inputidx);
1021 
1022  /// Create Parameter or Constant VOPs for all inputs of this node. We
1023  /// don't create nodes for inputs that are already connected.
1024  /// If `created_vops` is not NULL, then the method will populate the table
1025  /// with the input names for the keys and the created VOP nodes for the
1026  /// values.
1027  void insertParmGeneratorsForAllInputs(
1028  InputParmGenType type,
1029  UT_SymbolMap<VOP_Node *> *created_vops=NULL);
1030 
1031  /// Create Bind Export VOPs for all outputs of this node.
1032  /// Set `subnet` to true to create subnet-scoped Bind Export VOPs that
1033  /// produce output connectors on the owner subnetwork.
1034  void insertBindExportsForAllOutputs(bool subnet);
1035  VOP_Node *insertBindExport(int outputidx, bool subnet);
1036 
1037  /// Updates the output connections based on the correspondence
1038  /// between old and new output names.
1039  void rewireOutputConnections(
1040  const UT_StringArray &old_names,
1041  const UT_StringArray &new_names );
1042 
1043  /// The following method is needed to obtain the parameter name to be
1044  /// associated with an input. It is possible that the parameter name
1045  /// differs from the input name.
1046  virtual void getParmNameFromInput(UT_String &parmname,
1047  int inputidx) const;
1048  virtual void getParmNameFromOutput(UT_String &parmname,
1049  int outputidx) const;
1050 
1051  /// Find the parameter associated with an input, if any
1052  const PRM_Parm *getParmFromInput(int inputidx) const;
1053  const PRM_Parm *getParmFromOutput(int outputidx) const;
1054 
1055  /// Based on the specified input index, output a parm definition block
1056  /// appropriate for a dialog script. The parm definition provides a
1057  /// default value for the input if it is not connected. If the input is
1058  /// VEX_TYPE_UNDEF, we output nothing and return false. Otherwise we return
1059  /// true.
1060  bool outputDefaultParmDefinition(std::ostream &os, int idx);
1061 
1062  /// Writes out the input and output connector definitions.
1063  void saveNodeInputAndOutputDefinitions(std::ostream &os);
1064 
1065  void saveDialogScriptExtraInfo(std::ostream &os) override;
1066 
1067  /// Saves the parameter values to the output stream.
1068  bool saveParmValues(std::ostream &os);
1069  /// Loads the parameter values to the output stream.
1070  bool loadParmValues(UT_IStream &is);
1071 
1072  /// This virtual is overridden by VOP_ParmGenerator so we can find out
1073  /// which VOP defines the actual parameter attributes.
1075  { return 0; }
1076 
1077 
1078  /// Returns the shader language used by this node.
1079  const VOP_Language *getLanguage() const
1080  { return myLanguage; }
1081 
1082  /// @{ Sets the specific language for this node.
1083  void setLanguage(const VOP_Language *language);
1084  bool setLanguage(const UT_StringRef &language_name);
1085  /// @}
1086 
1087  /// Resets the language used by this node to the default one
1088  /// (deduced from a render mask, code gen, or the parent).
1089  void setDefaultLanguage();
1090 
1091 
1092  /// Absolute width
1093  fpreal getW() const override;
1094  /// Absolute height
1095  fpreal getH() const override;
1096 
1097  /// Override clearInterrupted so that we don't recook the whole DOP Network
1098  /// when the user interrupts a cook. The clearInterrupted on the containing
1099  /// VOP Network willb be enough.
1100  void clearInterrupted() override;
1101 
1102  /// Calls cacheParmName on all VOP_ParmGenerator nodes under root.
1103  static void cacheAllParmNames(OP_Node *root);
1104  /// Calls recalculateParmDefiner on all VOP_ParmGenerator nodes under root.
1105  static void recalculateAllParmDefiners(OP_Node *root,
1106  bool dive_into_subnets = true,
1107  const UT_StringRef &target_parm_name
1108  = UT_StringRef());
1109 
1110  /// Returns true if the input will be auto-converetd, false otherwise.
1111  bool willAutoconvertInputType(int input_idx) override;
1112 
1113  /// Returns the type to which the input will be auto-convert. This is
1114  /// necessary because some inputs can take in a range of various types,
1115  /// and we need to know which one will be converting to. This function
1116  /// assumes that autoconversion is necessary. If it is not possible, or
1117  /// not needed, it returns VOP_TYPE_UNDEF.
1118  VOP_TypeInfo getAutoConvertTargetTypeInfo(int input_idx);
1119  VOP_Type getAutoConvertTargetType(int input_idx);
1120 
1121  // Similar to the getAutoConvertTargetType(), but takes in an input type
1122  // instead of trying to read it from the connected node. This is useful
1123  // when one needs to know what the incoming type will be converted to
1124  // before it is actually connected.
1125  VOP_TypeInfo getAutoConvertTypeInfoFromType(int input_idx,
1126  const VOP_TypeInfo &source_type);
1127  VOP_Type getAutoConvertTypeFromType(int input_idx,
1128  VOP_Type source_type);
1129 
1130  /// Do not call this method directly.
1131  void addAutoVopNodePointer(VOP_AutoNode* auto_node,
1132  int input_index);
1133  void clearAutoVopNodeInfos();
1134  VOP_AutoNode *getAutoVopNode(int input_idx);
1135  const VOP_AutoNode *getAutoVopNode(int input_idx) const;
1136  int getAutoVopNodeCount();
1137 
1138  // Returns the output information manager. The manager is responsible for
1139  // manipulating VOP_OutputInfo objects for each output. These objects
1140  // dictate how an output behaves when the node is in debug or bypass mode.
1141  // See VOP_OutputInfo for more information. Please note that by default,
1142  // an output info does not exist for any outputs, and is only created when
1143  // a debug/bypass value is changed.
1144  VOP_OutputInfoManager* getOutputInfoManager();
1145 
1146  // Appends code which overrides output values if necessary (uses
1147  // myOutputInfos below to determine this).
1148  void appendOutputOverrideCode(UT_String& str_code);
1149 
1150  // If this returns false, getCode() will not be called during code
1151  // generation on this node (appendOutputOverrideCode() still will). This is
1152  // useful when all outputs of this node are overriden, and no execution is
1153  // necessary.
1154  bool needToExecute();
1155 
1156  /// Do not call this method directly.
1157  void onNodeChange(OP_EventType type);
1158 
1159  OP_ERROR save(std::ostream &os,
1160  const OP_SaveFlags &flags,
1161  const char *path_prefix = "",
1162  const UT_String &name_override = UT_String()
1163  ) override;
1164  bool load(UT_IStream &is, const char *ext="",
1165  const char *path=0) override;
1166 
1167  /// Gets/sets the value of the debug flag on this node.
1168  bool getDebug() const override;
1169  bool setDebug(bool on_off) override;
1170 
1171  /// Gets/sets the value of the material flag on this node.
1172  bool getMaterialFlag() const;
1173  bool setMaterialFlag(bool on_off);
1174  virtual void initMaterialFlag();
1175 
1176  void getSubOutputAndSubInputs(OP_Node *&outputnode,
1177  OP_NodeList &inputnodes) const;
1178 
1179  void hideInput(int input_index, bool hide);
1180  void setReferenceTargetDefaults(int input_index,bool do_set);
1181  bool getAllowEditingParmDefaults(int input_index);
1182 
1183  /// Determine the VEX context type if the node is single-context type.
1184  /// For nodes in a multi-context vopnet returns
1185  /// VEX_INVALID_CONTEXT, because the specific VEX context cannot be
1186  /// reliably and unambiguously determined.
1187  // TODO: remove these methods
1188  VEX_ContextType getVexContextType() const;
1189  RSL_ContextType getRslContextType() const;
1190  OSL_ContextType getOslContextType() const;
1191 
1192  /// Determines if the vop can be interpreted as a single or several RSL/VEX
1193  /// context types (surface, disp, ..), by looking at code generator.
1194  /// Returns true if the vop node is multi-type and false if single-type.
1195  virtual bool isSingleContextType() const;
1196 
1197  /// Gets the context type (VEX_ContextType or RSL_ContextType) to which
1198  /// this node subscribes.
1199  /// In single-type vopnets, it is equal to the node's VEX/RSL context type.
1200  /// In multi-type vopnets, the exact type is variable and usually
1201  /// depends on the node's parameter value.
1202  VOP_ContextType getShaderContextType() const;
1203 
1204  /// Returns a parmmap string array where alternate entries contain key and
1205  /// value, where key is the vop parameter name and the value is the
1206  /// parameter name specified by the Parm VOP connected to the input
1207  /// corresponding to that vop parameter.
1208  virtual void getFixedParameterMap(UT_StringArray &parmmap);
1209 
1210  /// Returns an input map string array where alternate entries contain
1211  /// key and value, where key is the vop parameter name and the value is the
1212  /// node path specified for that parameter (usually connected into an
1213  /// input corresponding to that vop parameter).
1214  virtual void getShaderInputMap(UT_StringArray &inputmap);
1215 
1216  /// Utility function to check if a parm by a given name is a cvex shader.
1217  bool isCVEXPathParm(const char *parm_name) const;
1218 
1219  /// Obtains the template array for shader parameters.
1220  const PRM_Template *getShaderParmTemplates() override;
1221  static void refreshShaderParmTemplatesIfNeeded(OP_Node *n);
1222 
1223  /// Returns node parameters that should be authored as input attributes
1224  /// (shader parameters) on a USD shader prim.
1225  /// Usually the returned list excludes parameters that are at default value,
1226  /// but if 'force_parms_at_default' is true, they are included too.
1227  UT_ValArray<PRM_Parm *> getUSDShaderParms(
1228  bool force_parms_at_default = false);
1229 
1230  /// Returns node parameters used to author a standard USD preview shader.
1231  UT_ValArray<PRM_Parm *> getUSDPreviewShaderParms();
1232 
1233  /// Returns true if the given parameter should currently be included
1234  /// in the USD shader parameters.
1235  /// Note, this is a dynamic test, and some nodes will consider a given
1236  /// parameter to be a USD shader parm under certain conditions but not
1237  /// under the others (eg, depending on signature).
1238  virtual bool allowUSDShaderParm(PRM_Parm &parm);
1239 
1240  /// Returns a set of parm tags relevant to authoring the USD preview shader.
1241  static const UT_Set<UT_StringHolder> &getUSDPreviewShaderTags();
1242 
1243  /// Deletes the input nodes for a given input (recursively), but
1244  /// only if none of them depend on anything other than this node.
1245  /// Returns true if any nodes were deleted, false otherwise.
1246  bool deleteIndependentInputNodes(int input_index);
1247 
1248  void getInputsRecursive(OP_NodeList& nodes_out);
1249  bool doesDependOnlyOn(const VOP_Node* other_node,
1250  int max_connections, bool recurse);
1251 
1252  /// Search through this node's inputs and return a list of parameter VOPs
1253  /// that appear in the input network. Recursively search through
1254  /// subnetworks as well. If this node is a parameter VOP, then add
1255  /// it to the list.
1256  void getParmInputs(VOP_ParmGeneratorList &parm_vops);
1257 
1258  /// Returns the node wired to this VOP's 'index' input tracing past
1259  /// simple VOPs like the Switch or Null VOP.
1260  VOP_Node *findSimpleInput(int index);
1261  /// Virtual helper to findSimpleInput() which returns the simple input
1262  /// node (ie the final node we look for) based on the request coming
1263  /// from the node connected to on the output of a given index.
1264  virtual VOP_Node *findSimpleInputFromOutput(int output_index)
1265  { return this; }
1266  /// A method that reports which immediate input connectors are considered
1267  /// by findSimpleInputFromOutput() method. This is useful when analyzing
1268  /// the simple input decision tree.
1269  virtual void findSimpleInputCandidatesFromOutput(int output_index,
1270  UT_IntArray & input_indices )
1271  { input_indices.clear(); }
1272 
1273  /// Gets a default value of an explicitly defined input (applies to subnets)
1274  virtual void getInputDefaultValue(UT_String &def, int idx) const;
1275 
1276  /// Gets number of outputs provided by a subnet, in addition to the outputs
1277  /// defined by wires connected to sub output.
1278  virtual int getNumNodeDefinedOutputs() const;
1279 
1280  /// @{ VOP subnets may restrict which inputs should show up in the
1281  /// Subnet Input and Subnet Output VOPs. These two methods control that.
1282  /// Gets number of subnet inputs available to subnet input/output children.
1283  /// Gets the subnet input index corresponding to the given index of
1284  /// (limited number of) input available to subnet input/output children.
1285  virtual int getNumSubnetInputsForChildren() const;
1286  virtual int getSubnetInputIndexForChildren(int child_input) const;
1287  int getChildConnectorIndexFromParent(int parent_input) const;
1288  virtual void getSubnetOutputTerminalChild(
1289  VOP_Node * &output_vop, int &input_idx,
1290  int subnet_output_idx ) const;
1291  /// @}
1292 
1293  /// Obtains additional nodes that should be copied or deleted when this
1294  /// node is copied or deleted.
1296  OP_NodeList &extras)const override;
1297 
1298  /// Some clerks add own stuff on creation. Any such action can be
1299  /// registered with this method.
1300  static void setRunCreateScriptCB( void (*)(const char *node_path,
1301  const char*render_mask, VOP_Type shader_type ));
1302 
1303  // Runs the creation script (if there is one). The return value is false
1304  // if the node was deleted while running the script. In this case
1305  // obviously the node pointer becomes invalid and should not be used
1306  // any more. It returns true if the node still exists.
1307  bool runCreateScript() override;
1308 
1309  void updateInputFlagsFromOperator(
1310  VOP_OperatorInfo *type_info,
1311  bool keep_visible);
1312 
1313  void onCreated() override;
1314  void hideNamedInput(const OP_ConnectorId& connector_name,
1315  bool hide);
1316 
1317  /// Returns all allowed input types on a given input, regardless of what
1318  /// is currently connected to that input. These do not include types
1319  /// to which autoconversion is possible.
1320  virtual void getAllowedNamedInputTypeInfos(
1321  const OP_ConnectorId& input_name,
1322  VOP_VopTypeInfoArray &typeinfos);
1323  virtual void getAllowedNamedInputTypes(
1324  const OP_ConnectorId& input_name,
1325  VOP_VopTypeArray &voptypes);
1326 
1327  VOP_TypeInfo getNamedAutoConvertTargetTypeInfo(
1328  const OP_ConnectorId& input_name);
1329  VOP_Type getNamedAutoConvertTargetType(
1330  const OP_ConnectorId& input_name);
1331  VOP_TypeInfo getNamedAutoConvertTypeInfoFromType(
1332  const OP_ConnectorId& input_name,
1333  const VOP_TypeInfo &source_type);
1334  VOP_Type getNamedAutoConvertTypeFromType(
1335  const OP_ConnectorId& input_name,
1336  VOP_Type source_type);
1337 
1339  const OP_ConnectorId& input_name
1340  ) override;
1341  VOP_Node *insertNamedNode(const OP_ConnectorId& input_name,
1342  const char* nodetype,
1343  bool connect_to_input,
1344  const char* undo_string = NULL);
1345 
1346  const OP_DataMicroNode &dataMicroNodeConst() const override
1347  { return myVopDataMicroNode; }
1348 
1349  /// Exposes protected method for taking over the errors from global manager.
1350  /// Should be used only by cerain helpers.
1352  { stealGlobalErrors(); }
1353 
1354  /// @{ Manipulate cook error dirty state
1355  void setErrorsDirty();
1356  void setErrorsClean(const OP_Context &context);
1357  bool areErrorsDirty(const OP_Context &context);
1358  /// @}
1359 
1360  /// Obtains the idx-th input type info from the connected input node.
1361  /// If not connected, type info is set to undefined.
1362  /// @param type_info The type info to fill out.
1363  /// @parm idx The index of the input from where to take the type.
1364  /// @param grow_inputs_to_idx
1365  /// If true and the the requested idx is larger than
1366  /// the input list size, then the list is expanded
1367  /// to make the requested index legal. Otherwise,
1368  /// list is kept constant and input is treated as NULL,
1369  /// resulting in an info for an undefined type.
1370  /// @return True if the info was obtained from the vop,
1371  /// otherwise false (info is set to undef, by default).
1372  bool getInputTypeInfoFromInputNode(
1373  VOP_TypeInfo &type_info, int idx,
1374  bool grow_inputs_to_idx = false) const;
1375 
1376  /// Obtains the idx-th input name based on a connected input node.
1377  /// If not connected, the name is "next".
1378  /// It's ensured that the name is unique even if many input nodes
1379  /// provide the same name.
1380  /// If check_output_names is true, the input name is ensured to be unique
1381  /// and different from the all the output names too.
1382  void getInputNameFromInputNode(UT_String &in, int idx,
1383  bool check_output_names)const;
1384 
1385  /// @{ Virtual overrides for evaluating parameters as render properties,
1386  /// in case the VOP node is a shader or a material.
1388  const UT_StringRef &name, fpreal now,
1389  OP_Node *&op, PRM_Parm *&parm,
1390  bool create_missing_multiparms,
1391  PRM_ParmList *obsolete = 0) override;
1393  const UT_StringRef &chname,
1394  fpreal now, OP_Node *&op,
1395  PRM_Parm *&parm, int &vector_index,
1396  PRM_ParmList *obsolete = 0) override;
1398  OP_PropertyLookupList &list) override;
1399  /// @}
1400 
1401  /// Queries information about visible connectors. This takes into account
1402  /// grouping of inputs, the current LOD flag, etc.
1403  int getInputVisibleIndex(int idx);
1404  const vop_ConnectorArray &getVisibleInputConnectors();
1405  int getOutputVisibleIndex(int idx);
1406  const vop_ConnectorArray &getVisibleOutputConnectors();
1407 
1408  /// Get or set the expansion state of an input group for this node.
1409  /// The information is stored in the user data.
1410  void setInputGroupExpanded(const UT_StringHolder &group,
1411  bool expanded);
1412  void setAllInputGroupsExpanded(bool expanded);
1413  bool getInputGroupExpanded(const UT_StringHolder &group);
1414 
1415  /// Fetches grouping information for all inputs whether they
1416  /// are visible or not. All inputs not in a group will be
1417  /// returned in the map with an empty string as the key.
1418  void getAllInputsGrouped(UT_StringArray &groups,
1419  UT_StringMap<UT_IntArray> &mapping);
1420 
1421  /// Give this VOP ownership of a TIL_Thumbnail object. Deletes any
1422  /// thumbnail that was already here.
1423  void setThumbnail(TIL_Thumbnail *thumbnail);
1424  /// Returns a pointer to our thumbnail if we have one.
1425  TIL_Thumbnail *getThumbnail() const;
1426  /// Handle changes to our user data. This may require a redraw.
1427  void userDataChanged(const UT_StringHolder &key) override;
1428 
1429  // Global preferences controlled by the pref dialog.
1430  static bool getShowPreviewPref();
1431  static void setShowPreviewPref(bool show);
1432 
1433 protected:
1434  VOP_Node(OP_Network *parent, const char *name, OP_Operator *entry);
1435  ~VOP_Node() override;
1436 
1438  OP_Context &context,
1439  OP_NodeInfoParms &iparms) override;
1441  UT_InfoTree &tree,
1442  const OP_NodeInfoTreeParms &parms) override;
1443 
1444  void deleteCookedData() override;
1445  int saveCookedData(std::ostream &, OP_Context &,
1446  int binary = 0) override;
1447  int saveCookedData(const char *, OP_Context &) override;
1448  const char *getFileExtension(int) const override;
1449 
1450  OP_ERROR cookMe(OP_Context &) override;
1451  OP_ERROR bypassMe(OP_Context &, int &) override;
1452 
1453  virtual void preOpChanged(OP_EventType, void *)
1454  { }
1455  virtual void postOpChanged(OP_EventType, void *)
1456  { }
1457 
1458  /// @{ Helpers for getParameterOrProperty() and
1459  /// getParameterOrPropertyByChannel()
1460  bool getPropertyFromNode(
1461  const UT_StringRef &name, fpreal now,
1462  OP_Node *&op, PRM_Parm *&parm,
1463  bool add_missing_mparms, PRM_ParmList *obsolet);
1464  bool getPropertyFromNode(
1465  const UT_StringRef &chname, fpreal now,
1466  OP_Node *&op, PRM_Parm *&parm, int &vec_index,
1467  PRM_ParmList *obsolete);
1468  bool getPropertyFromCodeGen(
1469  const UT_StringRef &name, fpreal now,
1470  OP_Node *&op, PRM_Parm *&parm,
1471  bool add_missing_mparms, PRM_ParmList *obsolet);
1472  bool getPropertyFromCodeGen(
1473  const UT_StringRef &chname, fpreal now,
1474  OP_Node *&op, PRM_Parm *&parm, int &vec_index,
1475  PRM_ParmList *obsolete);
1476  bool getPropertyFromInputs(
1477  const UT_StringRef &name, fpreal now,
1478  OP_Node *&op, PRM_Parm *&parm,
1479  bool add_missing_mparms, PRM_ParmList *obsolet);
1480  bool getPropertyFromInputs(
1481  const UT_StringRef &chname, fpreal now,
1482  OP_Node *&op, PRM_Parm *&parm, int &vec_index,
1483  PRM_ParmList *obsolete);
1484  /// @}
1485 
1486  /// Gets the shader context type (VEX_ContextType
1487  /// or RSL_ContextType) to which a node belongs to.
1488  ///
1489  /// This method is meant to be overriden by nodes that can specify a single
1490  /// concrete context type when they are created in a multi-context vopnet.
1491  /// This method is invoked by getShaderContextType() to obtain the concrete
1492  /// type, if possible
1493  ///
1494  /// In multi-context vopnets, for nodes that explicitly specify a single
1495  /// context (such as an output node, usually determined from the node's
1496  /// parameter), this method returns such explicltly selected context
1497  /// type. For other nodes that don't explicltly choose a context, this
1498  /// method returns an invalid type, meaning such nodes don't have control
1499  /// over a specific type, and they belong to a type specified during code
1500  /// generation.
1501  virtual VOP_ContextType getSpecificShaderContextType() const;
1502 
1503  /// Obtains a list of shading contexts in which this node wants to initiate
1504  /// the generation of code.
1505  virtual void getContextsForCodeGeneration(
1506  UT_StringArray & context_names ) const;
1507 
1508  /// Functions to get information about our operator outputs.
1509  /// These functions are used for variable name replacement and for
1510  /// creating output labels on the op tiles.
1511  virtual void getOutputNameSubclass(UT_String &out, int idx) const;
1512  virtual VOP_Type getOutputTypeSubclass(int idx);
1513  virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info,
1514  int idx);
1515  virtual VOP_VariableTagsHandle getOutputVariableTagsSubclass(int idx,
1516  VOP_Type shader_type);
1517 
1518  /// Clears the cached info (name and type) about output connectors.
1519  void dirtyCachedOutputData();
1520 
1521  /// Returns the variable name associated with a given input number.
1522  /// Implementers of this function should also implement the reverse
1523  /// function.
1524  virtual void getInputNameSubclass(UT_String &in, int idx) const;
1525  virtual int getInputFromNameSubclass(const UT_String &in) const;
1526  int findInputFromInputName(const UT_String &in) const;
1527  virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info,
1528  int idx);
1529  // Depreciated in favour of getInputTypeInfoSubclass():
1530  virtual VOP_Type getInputTypeSubclass(int idx);
1531  virtual bool getIsInputVisibleDefaultSubclass(int idx);
1532 
1533  /// @{ One of these two methods should be overriden in most VOP nodes.
1534  /// It is preferable to override the one that gets type infos, since
1535  /// they can encode complex types.
1536  /// They should fill in voptypes vector with vop types that are allowed to
1537  /// be connected to this node at the input at index idx.
1538  /// Note that this method should return valid vop types even when nothing
1539  /// is connected to the corresponding input.
1540  virtual void getAllowedInputTypeInfosSubclass(unsigned idx,
1541  VOP_VopTypeInfoArray &infos);
1542  virtual void getAllowedInputTypesSubclass(unsigned idx,
1543  VOP_VopTypeArray &voptypes);
1544  /// @}
1545 
1546  /// If the can only accept parameters as inputs, this method should return
1547  /// true. By default, this method checks the operator to see whether the
1548  /// VOP relies on external code (i.e. geometry procedurals)
1549  virtual bool getRequiresInputParameters() const;
1550 
1551  /// Disables parameters whose corresponding inputs are connected.
1552  bool disableConnectedParameters();
1553  bool updateParmsFlags() override;
1554  bool preUpdateParmsFlags() override;
1555  bool updateParmsActiveState(bool active);
1556 
1557  void addError(VOP_ErrorCodes code, const char *msg=0,
1558  const UT_SourceLocation *loc=0)
1559  { UTaddError("VOP", code, msg, loc); }
1560  void addMessage(VOP_ErrorCodes code, const char *msg=0,
1561  const UT_SourceLocation *loc=0)
1562  { UTaddMessage("VOP", code, msg, loc); }
1563  void addWarning(VOP_ErrorCodes code, const char *msg=0,
1564  const UT_SourceLocation *loc=0)
1565  { UTaddWarning("VOP", code, msg, loc); }
1566  void addFatal(VOP_ErrorCodes code, const char *msg=0,
1567  const UT_SourceLocation *loc=0)
1568  { UTaddFatal("VOP", code, msg, loc); }
1569 
1570  virtual void addDiagnosticInfo(const VCC_DiagnosticInfo &diag);
1571 
1572  /// This function is used to rewire nodes when we do a moveInput.
1573  static void rewireInputs(OP_Network *parent, OP_NodeList &inputs,
1574  int srcidx, int dstidx);
1575 
1577 
1578  void getAdditionalUndoNodes(const OP_NodeList& orig_list,
1579  OP_NodeList& nodes_for_input_undo) override;
1580 
1581  /// Save and load VOP version numbers
1583  std::ostream &os,
1584  const OP_SaveFlags &flags) override;
1585  bool loadPacket(
1586  UT_IStream &is,
1587  short class_id,
1588  short sig,
1589  const char *path = 0) override;
1590  bool loadPacket(
1591  UT_IStream &is,
1592  const char *token,
1593  const char *path = 0) override;
1594 
1595  /// If a subclass has VOP versioning, it should return a value greater
1596  /// than 0 for the latest version.
1597  virtual int getLatestVopVersion() const
1598  { return 0; }
1599 
1600  void getInputsRecursiveHelper(OP_NodeList& nodes_out,
1601  UT_Array<int> &array);
1602 
1603  bool doesDependOnlyOnHelper(const VOP_Node* other_node,
1604  int max_connections,
1605  bool recurse,
1606  UT_Array<int> &array);
1607 
1608  void onInputAllocated(
1609  OP_Input* new_input, int index) override;
1610 
1612  bool is_child_call = false) override;
1613 
1614  OP_ERROR getErrorSeverity() override;
1615  void ensureErrorsAreUpdatedSubclass() override;
1616 
1617  /// Generate the node errors.
1618  /// Return true if an error was generated and false otherwise.
1619  /// This method can be overridden to generate errors
1620  /// specific to the subclass.
1621  virtual bool generateErrorsSubclass();
1622 
1623  /// Returns true if the node should attempt testing its parameters
1624  /// for time dependence during the error generation pass.
1625  virtual bool shouldCheckTimeDependence() const;
1626 
1628 
1629  /// This returns true if it is okay to modify parms based on input changing
1630  /// and false otherwise. The decision is based on things like whether or
1631  /// not we are being loaded or running in a creation script.
1632  bool allowedToChangeParms();
1633 
1634  /// @{ Represents this node as a co-shader. Usually it just adds itself
1635  /// to the list, but some VOPs may represent a co-shader array, in which
1636  /// chase, they add a bunch of other VOPs that make up the array.
1637  virtual void representAsCoShader(UT_ValArray<VOP_Node*> &coshader);
1638  virtual void representAsCoShaderOutputName(UT_StringArray &name,
1639  int output_index);
1640  /// @}
1641 
1642  /// Ensures the given connector name does not have any conflicts
1643  /// with other connectors and is safe to use.
1644  /// If check_outputs' is true, the output names are checked for conflicts
1645  /// too, otherwise only inputs are tested.
1646  void findSafeConnectorNameBase(UT_String &in,
1647  bool check_outputs ) const;
1648 
1649  /// Returns the name the input connector would prefer to have,
1650  /// if we did not need to worry about multiple inputs having the same name.
1651  virtual void getTentativeInputName(UT_String &in, int idx) const;
1652 
1653  /// Returns the name the output connector would prefer to have,
1654  /// if we did not need to worry about multiple outputs having the same name.
1655  virtual void getTentativeOutputName(UT_String &out, int idx) const;
1656 
1657  /// Flag our visible connector info as dirty so it will be rebuilt the
1658  /// next time anyone asks for it.
1659  void setVisibleConnectorsDirty();
1660 
1661 private:
1662  /// Generate the node errors.
1663  void generateErrors(const OP_Context &context);
1664 
1665  /// Returns true if this node can access illuminance global variables.
1666  bool getIncludeIllumVars() const;
1667 
1668  /// Helper method for opChanged().
1669  /// Propagates the node change to the VOP code generator
1670  /// so that the code is re-generated and the exported parameters
1671  /// are updated.
1672  void propagateOpChangeToCodeGenerator(
1673  OP_EventType reason) const;
1674 
1675  /// Report a recursive loop error.
1676  void reportRecursiveLoopError();
1677 
1678  /// Get node type that should be used for promoting input at given index.
1679  const char *getParameterOpName(int input_index);
1680  const char *getConstantOpName(int input_index);
1681  bool isInputRampRBG(int input_index);
1682 
1683  /// Get the output index that should be used as parameter value.
1684  virtual int getParameterOpOutputIndex();
1685 
1686  /// Create Parameter VOPs for all inputs of this node. We
1687  /// don't create nodes for inputs that are already connected.
1688  /// If `created_vops` is not NULL, then the method will populate the table
1689  /// with the input names for the keys and the created VOP nodes for the
1690  /// values.
1691  void insertParmVOPsForAllInputs(
1693  UT_SymbolMap<VOP_Node *> *created_vops);
1694 
1695  /// Create Constant VOPs for all inputs of this node. We
1696  /// don't create nodes for inputs that are already connected.
1697  /// If `created_vops` is not NULL, then the method will populate the table
1698  /// with the input names for the keys and the created VOP nodes for the
1699  /// values.
1700  void insertConstantVOPsForAllInputs(
1701  UT_SymbolMap<VOP_Node *> *created_vops);
1702 
1703 
1704  /// Add entries to the string array for each struct member. These entries
1705  /// values come from the given parameter. The values use correct syntax
1706  /// for the given language.
1707  void getParmConstantStringForStruct(UT_StringArray &values,
1708  const VOP_TypeInfo &type_info,
1709  PRM_Parm &parm,
1710  const VOP_Language *language);
1711 
1712  /// Update our internal mapping of visible connectors to group names, input
1713  /// indices, etc.
1714  void updateVisibleConnectorInfo();
1715  void getParameterGroups(UT_StringMap<int> &group_map,
1716  UT_StringArray &group_names);
1717 
1718  const VOP_GlobalVarMap *myGlobalVariables;
1719  VOP_ParmGeneratorMap *myLocalVariables;
1720  VOP_LocalChannelMap *myLocalChannels;
1721  UT_UniquePtr<TIL_Thumbnail> myThumbnail;
1722  exint myLatestOpChangedId;
1723  unsigned int myMakingInputList : 1,
1724  myIsSearchingForParmInputs : 1,
1725  myInitialized : 1,
1726  myLanguageExplicitlySet : 1;
1727 
1728  static VOP_Node *theOriginalOpChanged;
1729  static exint theLatestOpChangedId;
1730  static int theLODPref;
1731  static bool theShowPreviewPref;
1732 
1733  using IntPair = std::pair<int, int>;
1734 
1735  VOP_AutoNodeInfoList myAutoVopNodeInfos;
1736  VOP_OutputInfoManager myOutputInfos;
1737  UT_Array<IntPair> myInputVariableOverrides;
1738 
1739  mutable UT_Lock myCachedDataLock;
1740  mutable int myCachedOutputNodeId;
1741  mutable UT_SymbolMap<int> myCachedOutputNames;
1742  mutable UT_ValArray< VOP_TypeInfo* > myCachedOutputTypeInfos;
1743 
1744  VOP_DataMicroNode myVopDataMicroNode;
1745  VOP_CodeGenerator *myAutoCodeGenerator;
1746  UT_Map<int, int> myVisibleInputIndexMap;
1747  vop_ConnectorArray myVisibleInputConnectors;
1748  UT_Map<int, int> myVisibleOutputIndexMap;
1749  vop_ConnectorArray myVisibleOutputConnectors;
1750  bool myVisibleConnectorsDirty;
1751 };
1752 
1753 #endif
virtual int saveCookedData(std::ostream &os, OP_Context &, int binary=0)=0
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:29
UT_StringHolder myName
Definition: VOP_Node.h:108
virtual void buildVexScript(UT_String &script, fpreal t, OP_Node *owner, UT_Map< int, bool > *visitlist=0)
int getOutputIndex() const
Definition: VOP_Node.h:205
virtual bool getParameterOrProperty(const UT_StringRef &name, fpreal now, OP_Node *&op, PRM_Parm *&parm, bool create_missing_multiparms, PRM_ParmList *obsolete=0)
void adoptFromString(UT_String &str)
virtual bool updateParmsFlags()
GLbitfield flags
Definition: glcorearb.h:1596
PXL_API const char * getDescription(const ColorSpace *space)
Return the description of the color space.
fpreal getH() const override
Node position/scale is used by the UI.
VOP_ContextType myContextType
Definition: VOP_Node.h:110
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
std::pair< VOP_Node *, int > InputVariableOverride
Definition: VOP_Node.h:521
fpreal getW() const override
Node position/scale is used by the UI.
virtual void getInputName(UT_String &in, int idx) const
virtual bool willAutoconvertNamedInputType(const OP_ConnectorId &input_name)
Unsorted map container.
Definition: UT_Map.h:107
virtual bool isAutoVopNode() const
Definition: VOP_Node.h:983
#define SYS_VISIBILITY_EXPORT
const UT_StringHolder & getName() const
Definition: VOP_Node.h:185
#define VOP_IMPLEMENT_CASTS(NAME)
Definition: VOP_Node.h:360
void
Definition: png.h:1083
const GLdouble * v
Definition: glcorearb.h:837
virtual void setFlag(char tag, int8 val)
bool myIsGroup
Definition: VOP_Node.h:251
UT_API UT_ErrorSeverity UTaddFatal(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
const VOP_TypeInfo & getTypeInfo() const
Definition: VOP_Node.h:180
virtual void moveInput(int srcidx, int dstidx, bool forcesubnet=false)
int64 exint
Definition: SYS_Types.h:125
virtual bool preUpdateParmsFlags()
GLint level
Definition: glcorearb.h:108
vop_Connector(int groups_above, const UT_StringHolder &group_name, int index, bool expanded)
Definition: VOP_Node.h:234
virtual void finishedLoadingNetwork(bool is_child_call=false)
UT_ErrorSeverity
Definition: UT_Error.h:25
virtual bool isOutputVopNode() const
Definition: VOP_Node.h:978
Parameters for OP_Node::getInfoText()/OP_Node::getNodeSpecificInfoText()
UT_SymbolMap< VOP_ParmGeneratorList * > VOP_LocalChannelMap
Definition: VOP_Node.h:95
UT_SymbolMap< VOP_ParmGenerator * > VOP_ParmGeneratorMap
Definition: VOP_Node.h:94
**But if you need a result
Definition: thread.h:613
virtual void getNodeSpecificInfoText(OP_Context &context, OP_NodeInfoParms &parms)
VOP_TypeInfo myTypeInfo
Definition: VOP_Node.h:112
UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
virtual OP_ERROR cookMe(OP_Context &context)=0
int VOP_ContextType
Definition: VOP_Types.h:177
void addFatal(VOP_ErrorCodes code, const char *msg=0, const UT_SourceLocation *loc=0)
Definition: VOP_Node.h:1566
static int & getLODPref()
Definition: VOP_Node.h:907
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
virtual void clearInterrupted()
Definition: OP_Node.h:2498
virtual int getLatestVopVersion() const
Definition: VOP_Node.h:1597
virtual void saveDialogScriptExtraInfo(std::ostream &os)
GLdouble n
Definition: glcorearb.h:2008
void stealGlobalErrors()
const VOP_Language * myLanguage
Definition: VOP_Node.h:1576
void(*)(VOP_Node *, UT_String &, fpreal, OP_Node *, UT_Map< int, bool > *) VexBuildFn1
Definition: VOP_Node.h:714
int myVopVersion
Definition: VOP_Node.h:1627
virtual void findSimpleInputCandidatesFromOutput(int output_index, UT_IntArray &input_indices)
Definition: VOP_Node.h:1269
Definition: core.h:760
virtual VOP_Node * getPreResolveVariableSrc() const
Definition: VOP_Node.h:968
#define VOP_API
Definition: VOP_API.h:10
bool isInitialized() const
Definition: VOP_Node.h:410
const VOP_TypeInfo & getAnyTypeInfo() const
Definition: VOP_Node.h:137
bool myIlluminanceVar
Definition: VOP_Node.h:115
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
virtual OP_ERROR setInput(unsigned idx, OP_Node *op, unsigned outputIdx=0)
Sets a given input to connect to an output of a particular node.
virtual OP_ERROR setNamedInput(const OP_ConnectorId &input_name, OP_Node *op, const OP_ConnectorId *output_name=nullptr)
New input functions that use names instead of indices.
void opChanged(OP_EventType reason, void *data=0) override
bool myIsExpanded
Definition: VOP_Node.h:250
virtual void preOpChanged(OP_EventType, void *)
Definition: VOP_Node.h:1453
virtual OP_ERROR saveIntrinsic(std::ostream &os, const OP_SaveFlags &flags)
virtual bool addOrMoveVisualizerToOutput(int outputidx)
Definition: OP_Node.h:3134
bool myWritable
Definition: VOP_Node.h:114
int myVarIndex
Definition: VOP_Node.h:111
const UT_StringHolder & getInitCodeStr() const
Definition: VOP_Node.h:195
virtual int getOutputFromName(const UT_String &out) const
virtual void userDataChanged(const UT_StringHolder &key)
UT_StringHolder myDescription
Definition: VOP_Node.h:109
UT_ValArray< VOP_ParmGenerator * > VOP_ParmGeneratorList
Definition: VOP_Node.h:91
virtual bool isSubnetInput() const
Returns true if the node is considered a subnet's input node.
Definition: VOP_Node.h:963
SYS_VISIBILITY_EXPORT void newVopOperator(OP_OperatorTable *table)
Definition: VOP_Switch.C:38
OP_OpTypeId
Definition: OP_OpTypeId.h:18
virtual bool getParameterOrPropertyByChannel(const UT_StringRef &chname, fpreal now, OP_Node *&op, PRM_Parm *&parm, int &vector_index, PRM_ParmList *obsolete=0)
int getInputIndex() const
Definition: VOP_Node.h:200
GLuint const GLchar * name
Definition: glcorearb.h:786
signed char int8
Definition: SYS_Types.h:35
bool evalVariableValue(fpreal &v, int i, int thr) override
For expanding compiler string used in auto code generator.
Definition: VOP_Node.h:689
bool myReadable
Definition: VOP_Node.h:113
virtual OP_DataType getCookedDataType() const =0
OSL_ContextType
RenderMan shader context types.
Definition: VEX_OslTypes.h:25
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
virtual OP_OpTypeId getOpTypeID() const
Definition: OP_Node.h:532
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
GLdouble t
Definition: glad.h:2397
virtual void ensureErrorsAreUpdatedSubclass()
UT_Array< vop_Connector > vop_ConnectorArray
Definition: VOP_Node.h:253
virtual VOP_Node * findSimpleInputFromOutput(int output_index)
Definition: VOP_Node.h:1264
virtual bool getIsInputVisibleDefault(int idx)
virtual bool isAutoConvertNode() const
Retruns true if the node is an internal auto-convert node.
Definition: VOP_Node.h:987
virtual OP_ERROR setNamedInputReference(const OP_ConnectorId &input_name, const char *label, int, const OP_ConnectorId *output_name=nullptr)
virtual const char * getChildType() const
void addError(VOP_ErrorCodes code, const char *msg=0, const UT_SourceLocation *loc=0)
Definition: VOP_Node.h:1557
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
virtual VOP_OutputNameEditorSource * getOutputNameEditorSource()
Returns a pointer used by OPUI_OutputNameEditor to get and set data.
Definition: VOP_Node.h:945
virtual const char * getFileExtension(int binary) const =0
virtual int findParametersOrProperties(fpreal now, OP_PropertyLookupList &list)
virtual void getExtraNodesForCopyOrDelete(OP_NodeList &extras) const
void addWarning(VOP_ErrorCodes code, const char *msg=0, const UT_SourceLocation *loc=0)
Definition: VOP_Node.h:1563
Parameters for OP_Node::fillInfoTree()/OP_Node::fillInfoTreeNodeSpecific()
virtual void fillInfoTreeNodeSpecific(UT_InfoTree &tree, const OP_NodeInfoTreeParms &parms)
UT_ValArray< VOP_GlobalVarData * > VOP_GlobalVarList
Definition: VOP_Node.h:90
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
int myGroupsAbove
Definition: VOP_Node.h:248
__hostdev__ constexpr T pi()
Pi constant taken from Boost to match old behaviour.
Definition: NanoVDB.h:976
void getInputName(UT_StringHolder &in, int idx) const
Definition: VOP_Node.h:464
fpreal64 fpreal
Definition: SYS_Types.h:277
OP_ERROR getErrorSeverity() override
GLuint index
Definition: glcorearb.h:786
virtual void referencedParmChanged(int pi)
void addMessage(VOP_ErrorCodes code, const char *msg=0, const UT_SourceLocation *loc=0)
Definition: VOP_Node.h:1560
vop_Connector(int groups_above, int index=-1)
Definition: VOP_Node.h:227
virtual const char * getOpType() const
UT_API UT_ErrorSeverity UTaddWarning(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
GLuint GLfloat * val
Definition: glcorearb.h:1608
virtual bool loadPacket(UT_IStream &is, short class_id, short sig, const char *path=0)
OP_EventType
Definition: OP_Value.h:22
virtual int getInputFromName(const UT_String &in) const
VOP_Type
Enumeration of the built-in (basic) VOP data types.
Definition: VOP_Types.h:25
UT_SharedPtr< const VOP_VariableTags > VOP_VariableTagsHandle
Definition: VOP_Node.h:83
OP_DataType
Definition: OP_DataTypes.h:28
virtual OP_OpTypeId getChildTypeID() const =0
const OP_DataMicroNode & dataMicroNodeConst() const override
Definition: VOP_Node.h:1346
virtual bool runCreateScript()
virtual bool evalVariableValue(UT_String &val, int index, int thread)
bool isExported() const
Definition: VOP_Node.h:210
VOP_ErrorCodes
Definition: VOP_Error.h:11
bool load(UT_IStream &is, const char *ext="", const char *path=0) override
Definition: core.h:1131
virtual OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags, const char *path_prefix="", const UT_String &name_override=UT_String())
VOP_ShaderNameStyle
The allowed name formats when asking for shader name.
Definition: VOP_Node.h:257
RSL_ContextType
RenderMan shader context types.
Definition: VEX_RslTypes.h:25
virtual void getOutputName(UT_String &out, int idx) const
virtual bool shouldPreResolveOutput(int output_index) const
Definition: VOP_Node.h:973
UT_SymbolMap< VOP_GlobalVarData * > VOP_GlobalVarMap
Definition: VOP_Node.h:93
UT_ValArray< VOP_Node * > VOP_NodeList
Definition: VOP_Node.h:87
virtual bool getDebug() const
Definition: OP_Node.h:1359
GLsizei GLenum GLenum * types
Definition: glcorearb.h:2542
virtual bool willAutoconvertInputType(int input_idx)
VOP_UIChangeType
Definition: VOP_Node.h:64
virtual VOP_CodeGenerator * getVopCodeGenerator()
Definition: OP_Node.h:2718
virtual void getAdditionalUndoNodes(const OP_NodeList &orig_list, OP_NodeList &nodes_for_input_undo)
Definition: OP_Network.h:913
void clear()
Resets list to an empty list.
Definition: UT_Array.h:729
VEX_ContextType
Definition: VEX_VexTypes.h:60
virtual VOP_Node * getRealDefinition()
Definition: VOP_Node.h:1074
void getOutputName(UT_StringHolder &out, int idx) const
Definition: VOP_Node.h:430
static const char * theChildTableName
Definition: VOP_Node.h:270
type
Definition: core.h:1059
virtual void onInputAllocated(OP_Input *new_input, int index)
Overriden in VOPs.
Definition: OP_Node.h:3697
const UT_StringHolder & getName() const
Definition: VOP_Node.h:126
UT_Array< VOP_AutoNodeInfo > VOP_AutoNodeInfoList
Definition: VOP_Node.h:102
virtual OP_ERROR bypassMe(OP_Context &context, int &copied_input)=0
const VOP_Language * getLanguage() const
Returns the shader language used by this node.
Definition: VOP_Node.h:1079
virtual const PRM_Template * getShaderParmTemplates()
Definition: format.h:895
void stealGlobalErrorsForHelper()
Definition: VOP_Node.h:1351
UT_StringHolder myGroupName
Definition: VOP_Node.h:249
virtual VOP_CodeGenerator * getVopAutoCodeGenerator()
Definition: OP_Node.h:2719
UT_API UT_ErrorSeverity UTaddError(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
virtual void onCreated()
Overriden in VOPs.
Definition: OP_Node.h:3059
virtual bool setDebug(bool on_off)
Definition: OP_Node.h:1315
void(*)(VOP_Node *, UT_String &, fpreal, DEP_MicroNode *, UT_Map< int, bool > *) VexBuildFn2
Definition: VOP_Node.h:716
VOP_AutoNode * myAutoVopNode
Definition: VOP_Node.h:99
virtual void deleteCookedData()=0
InputParmGenType
Definition: VOP_Node.h:992
virtual OP_ERROR setInputReference(unsigned idx, const char *label, int keeppos, unsigned outputIdx=0)
Connects an input to particular node by name in the network.
virtual void postOpChanged(OP_EventType, void *)
Definition: VOP_Node.h:1455