HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glslfxConfig.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HIO_GLSLFX_CONFIG_H
8 #define PXR_IMAGING_HIO_GLSLFX_CONFIG_H
9 
10 /// \file hio/glslfxConfig.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/imaging/hio/api.h"
14 #include "pxr/base/tf/token.h"
15 #include "pxr/base/vt/dictionary.h"
16 
17 #include <string>
18 
20 
21 /// \class HioGlslfxConfig
22 ///
23 /// A class representing the configuration of a glslfx file.
24 ///
25 /// HioGlslfxConfig provides an API for querying the configuration of a
26 /// glslfx file
27 ///
29 {
30 public:
31  /// Enumerates Roles that parameters can have.
32  ///
33  /// <b>enum Role:</b>
34  /// <ul>
35  /// <li><b><c> RoleNone = 0</c></b> None: the default role
36  /// <li><b><c> RoleColor = 1</c></b> Color: the role of a color
37  /// </ul>
38  ///
39  enum Role {
40  RoleNone = 0,
41  RoleColor = 1,
42  };
43 
44  /// \class Parameter
45  ///
46  /// A class representing a parameter.
47  ///
48  class Parameter {
49  public:
50  Parameter(std::string const & name,
51  VtValue const & defaultValue,
52  std::string const & docString = "",
53  Role const & role = RoleNone) :
54  name(name),
55  defaultValue(defaultValue),
57  role(role) { }
58 
59  std::string name;
61  std::string docString;
63  };
64 
65  typedef std::vector<Parameter> Parameters;
66 
67  /// \class Texture
68  ///
69  /// A class representing a texture.
70  ///
71  class Texture {
72  public:
73  Texture(std::string const & name,
74  VtValue const & defaultValue,
75  std::string const & docString = "") :
76  name(name),
77  defaultValue(defaultValue),
78  docString(docString) { }
79 
80  std::string name;
82  std::string docString;
83  };
84 
85  typedef std::vector<Texture> Textures;
86 
87  /// \class Attribute
88  ///
89  /// A class representing an attribute.
90  ///
91  class Attribute {
92  public:
93  Attribute(std::string const & name,
94  VtValue const & defaultValue,
95  std::string const & docString = "") :
96  name(name),
97  defaultValue(defaultValue),
98  docString(docString) { }
99 
100  std::string name;
102  std::string docString;
103  };
104 
105  typedef std::vector<Attribute> Attributes;
106 
107  /// Create a new HioGlslfxConfig from an input string
108  ///
109  /// The \p filename parameter is only used for error reporting.
110  ///
111  HIO_API
112  static HioGlslfxConfig * Read(TfToken const & technique,
113  std::string const & input,
114  std::string const & filename,
115  std::string *errorStr);
116 
117  typedef std::vector<std::string> SourceKeys;
118 
120 
121  /// Return the set of source keys for a particular shader stage
122  HIO_API
123  SourceKeys GetSourceKeys(TfToken const & shaderStageKey) const;
124 
125  /// Return the parameters specified in the configuration
126  HIO_API
127  Parameters GetParameters() const;
128 
129  /// Return the textures specified in the configuration
130  HIO_API
131  Textures GetTextures() const;
132 
133  /// Returns the attributes specified in the configuration
134  HIO_API
135  Attributes GetAttributes() const;
136 
137  /// Returns the metadata specified in the configuration
138  HIO_API
140 
141 private:
142  // private ctor. should only be called by ::Read
143  HioGlslfxConfig(TfToken const& technique,
144  VtDictionary const & dict,
145  std::string *errorStr);
146 
147  void _Init(VtDictionary const & dict, std::string *errorStr);
148 
149  Parameters _GetParameters(VtDictionary const & dict,
150  std::string *errorStr) const;
151  Textures _GetTextures(VtDictionary const & dict,
152  std::string *errorStr) const;
153 
154  Attributes _GetAttributes(VtDictionary const & dict,
155  std::string *errorStr) const;
156 
157  MetadataDictionary _GetMetadata(VtDictionary const & dict,
158  std::string *errorStr) const;
159 
160  typedef std::map<std::string, SourceKeys> _SourceKeyMap;
161  _SourceKeyMap _GetSourceKeyMap(VtDictionary const & dict,
162  std::string *errorStr) const;
163 
164  TfToken _technique;
165  Parameters _params;
166  Textures _textures;
167  Attributes _attributes;
168  MetadataDictionary _metadata;
169  _SourceKeyMap _sourceKeyMap;
170 };
171 
172 
174 
175 #endif
GT_API const UT_StringHolder filename
std::vector< Attribute > Attributes
Definition: glslfxConfig.h:105
Attribute(std::string const &name, VtValue const &defaultValue, std::string const &docString="")
Definition: glslfxConfig.h:93
Parameter(std::string const &name, VtValue const &defaultValue, std::string const &docString="", Role const &role=RoleNone)
Definition: glslfxConfig.h:50
#define HIO_API
Definition: api.h:23
Texture(std::string const &name, VtValue const &defaultValue, std::string const &docString="")
Definition: glslfxConfig.h:73
HIO_API Textures GetTextures() const
Return the textures specified in the configuration.
std::vector< std::string > SourceKeys
Definition: glslfxConfig.h:117
HIO_API Parameters GetParameters() const
Return the parameters specified in the configuration.
Definition: token.h:70
std::vector< Parameter > Parameters
Definition: glslfxConfig.h:65
GLuint const GLchar * name
Definition: glcorearb.h:786
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HIO_API MetadataDictionary GetMetadata() const
Returns the metadata specified in the configuration.
HIO_API SourceKeys GetSourceKeys(TfToken const &shaderStageKey) const
Return the set of source keys for a particular shader stage.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HIO_API Attributes GetAttributes() const
Returns the attributes specified in the configuration.
VtDictionary MetadataDictionary
Definition: glslfxConfig.h:119
std::vector< Texture > Textures
Definition: glslfxConfig.h:85
Definition: value.h:146
static HIO_API HioGlslfxConfig * Read(TfToken const &technique, std::string const &input, std::string const &filename, std::string *errorStr)