HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_LanguageContextTypeList.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_LanguageContextTypeList.h ( VOP Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __VOP_LanguageContextTypeList__
13 #define __VOP_LanguageContextTypeList__
14 
15 #include "VOP_API.h"
16 #include <SYS/SYS_Deprecated.h>
17 #include <UT/UT_StringHolder.h>
18 #include "VOP_Types.h"
19 #include "VOP_LanguageInfo.h"
20 class UT_StringArray;
21 class OP_Node;
22 
23 /// A class that abstracts shader types and shader context types.
24 /// It encapsulates shader types that make up a given vopnet node,
25 /// and also shader contexts conavailable inside that vopnet.
26 ///
27 /// This class is used to determine variables available in Global VOP
28 /// (as a menu of available context types), constituent shaders in
29 /// Vars Output VOP (as a menu of available shader type), and final form
30 /// of a shader source code n View VEX Code (as a menu of shader types), etc.
31 ///
32 /// A shader type represents a shader kind. It could be a surface,
33 /// a displacement, but also a geometry or a class. It corresponds to VOP_Type.
34 ///
35 /// A context type represents a language support for a given shader type.
36 /// Context determines global variables and functions available to implement
37 /// a given shader type in a given language.
38 /// But not all shader types have corresponding contexts, if they can't be
39 /// implemented in a given language, for example, like geometry shader type.
40 /// Context type is represented by VOP_ContextType.
42 {
43 public:
44  /// @{ Default c-tor de-tor.
47  /// @}
48 
49  /// Constructor for representing a shader type in a given language.
50  /// Some shader types (eg, a material or a class) may represent
51  /// a structured shader that consists of several sub-shader types.
52  /// In such cases the list of sub-shaders can be provided explicitly.
53  ///
54  /// @param language_type Shader's language type.
55  /// It determines the shader context types that are available,
56  /// which in turn determine global variables and functions
57  /// available to the shader. It is needed if (some) shader types
58  /// are implemented thru VOP networks.
59  ///
60  /// @param shader_type The shader type.
61  /// For a single-context node, it represents its shader type.
62  /// For multi-context nodes, it represents the master shader type
63  /// (eg, material or a class).
64  ///
65  /// @param sub_types For a multi-context node, this parameter
66  /// explicitly lists the constituent shader types that make up
67  /// the master shader. Eg, a material may allow surf and disp.
69  const VOP_LanguageInfo &language_info,
70  VOP_Type shader_type,
71  const VOP_ShaderTypeList *sub_types = nullptr);
72 
73  /// Deprecated. Uses VOP_LanguageType rather than VOP_LanguageInfo
74  /// which can't accurately identify a custom language.
75  SYS_DEPRECATED_HDK(20.0)
77  VOP_LanguageType language_type,
78  VOP_Type shader_type,
79  const VOP_ShaderTypeList *sub_types = nullptr);
80 
81  /// Deprecated. Uses old VOP_ContextType rather than VOP_Type shader type.
82  /// Eg, use VOP_CVEX_SHADER instead of VEX_CVEX_CONTEXT.
83  SYS_DEPRECATED_HDK(16.0)
85  VOP_LanguageType language_type,
86  VOP_ContextType context_type);
87 
88 
89  /// Sets the object data to reflect the node's shader types and contexts.
90  void setFromNode( OP_Node *node );
91 
92  /// Obtains the default context.
93  VOP_ContextType getDefaultContextType() const;
94 
95  /// Oringial overarching shader type (eg, class, material, surface).
97  { return myMasterType; }
98 
99  /// Returns the type of the language in which the context types are valid.
101  { return myLanguageInfo.getType(); }
103  { return myLanguageInfo; }
104 
105  /// Returns true if the list represetns a single-context list.
106  bool isSingleContextType() const
107  { return myShaderTypes.entries() == 1; }
108 
109  /// Returns true if the main shader is a class type.
110  bool isClassBasedShader() const;
111 
112  /// Returns a list of shader types that make up the master shader.
113  void getConstituentShaderTypes( VOP_ShaderTypeList &types ) const;
114 
115  /// Returns a list of shader context types which are valid in the list's
116  /// language and for which there is a source code that can be generated.
117  /// Some constituent shader types may not have a corresponding a shader
118  /// context (eg geometry shader type).
119  void getConstituentShaderContexts( VOP_ContextTypeList &ctxs ) const;
120 
121  /// Returns a list of shaders whose parameters can appear on the
122  /// master shader (material) node. Such parameters are tagged
123  /// for shader context so they can be used in renderer's shader string.
124  void getParmTagShaderTypes( VOP_ContextTypeList &contexts ) const;
125 
126  /// Returns a list of shaders contexts (and labels) for which the master
127  /// shader node provides source code. These usually correspond
128  /// to language contexts (surface, displacement), but this can also be just
129  /// a class. However, procedurals (geometry) usually is not in this list.
130  void getSourceCodeShaderTypes( UT_StringArray &labels,
131  VOP_ContextTypeList &contexts ) const;
132 
133 private:
134  /// Convenience helper to obtain a context type.
135  VOP_ContextType asContextType( VOP_Type type ) const
136  {
137  return VOPconvertToContextType( type,
138  myLanguageInfo.getType());
139  }
140 
141 private:
142  /// The language type in which the context types should be interpreted.
143  VOP_LanguageInfo myLanguageInfo;
144 
145  /// The original shader type consisting of shading context types.
146  VOP_Type myMasterType;
147 
148  /// The list of constituent shaders types. Some types (and in most
149  /// cases all types) map to shader contexts valid in the language.
150  /// These are the contexts for which a vopnet can generate source code for
151  /// a well-defined shader function. Other types, eg geometry, don't have
152  /// a corresponding context, but are part of the master shader nonetheless.
153  VOP_ShaderTypeList myShaderTypes;
154 };
155 
156 #endif
157 
VOP_LanguageInfo getLanguageInfo() const
VOP_LanguageType getLanguageType() const
Returns the type of the language in which the context types are valid.
int VOP_ContextType
Definition: VOP_Types.h:177
#define VOP_API
Definition: VOP_API.h:10
#define SYS_DEPRECATED_HDK(__V__)
VOP_Type
Enumeration of the built-in (basic) VOP data types.
Definition: VOP_Types.h:25
VOP_Type getMasterShaderType() const
Oringial overarching shader type (eg, class, material, surface).
GLsizei GLenum GLenum * types
Definition: glcorearb.h:2542
VOP_API VOP_ContextType VOPconvertToContextType(VOP_Type shader_type, VOP_LanguageType language)
type
Definition: core.h:1059
bool isSingleContextType() const
Returns true if the list represetns a single-context list.
VOP_LanguageType
Definition: VOP_Types.h:186