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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HIO_GLSLFX_CONFIG_H
25 #define PXR_IMAGING_HIO_GLSLFX_CONFIG_H
26 
27 /// \file hio/glslfxConfig.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/hio/api.h"
31 #include "pxr/base/tf/token.h"
32 #include "pxr/base/vt/dictionary.h"
33 
34 #include <string>
35 
37 
38 /// \class HioGlslfxConfig
39 ///
40 /// A class representing the configuration of a glslfx file.
41 ///
42 /// HioGlslfxConfig provides an API for querying the configuration of a
43 /// glslfx file
44 ///
46 {
47 public:
48  /// Enumerates Roles that parameters can have.
49  ///
50  /// <b>enum Role:</b>
51  /// <ul>
52  /// <li><b><c> RoleNone = 0</c></b> None: the default role
53  /// <li><b><c> RoleColor = 1</c></b> Color: the role of a color
54  /// </ul>
55  ///
56  enum Role {
57  RoleNone = 0,
58  RoleColor = 1,
59  };
60 
61  /// \class Parameter
62  ///
63  /// A class representing a parameter.
64  ///
65  class Parameter {
66  public:
68  VtValue const & defaultValue,
69  std::string const & docString = "",
70  Role const & role = RoleNone) :
71  name(name),
72  defaultValue(defaultValue),
74  role(role) { }
75 
80  };
81 
82  typedef std::vector<Parameter> Parameters;
83 
84  /// \class Texture
85  ///
86  /// A class representing a texture.
87  ///
88  class Texture {
89  public:
91  VtValue const & defaultValue,
92  std::string const & docString = "") :
93  name(name),
94  defaultValue(defaultValue),
95  docString(docString) { }
96 
100  };
101 
102  typedef std::vector<Texture> Textures;
103 
104  /// \class Attribute
105  ///
106  /// A class representing an attribute.
107  ///
108  class Attribute {
109  public:
111  VtValue const & defaultValue,
112  std::string const & docString = "") :
113  name(name),
114  defaultValue(defaultValue),
115  docString(docString) { }
116 
120  };
121 
122  typedef std::vector<Attribute> Attributes;
123 
124  /// Create a new HioGlslfxConfig from an input string
125  ///
126  /// The \p filename parameter is only used for error reporting.
127  ///
128  HIO_API
129  static HioGlslfxConfig * Read(TfToken const & technique,
130  std::string const & input,
131  std::string const & filename,
132  std::string *errorStr);
133 
134  typedef std::vector<std::string> SourceKeys;
135 
137 
138  /// Return the set of source keys for a particular shader stage
139  HIO_API
140  SourceKeys GetSourceKeys(TfToken const & shaderStageKey) const;
141 
142  /// Return the parameters specified in the configuration
143  HIO_API
144  Parameters GetParameters() const;
145 
146  /// Return the textures specified in the configuration
147  HIO_API
148  Textures GetTextures() const;
149 
150  /// Returns the attributes specified in the configuration
151  HIO_API
152  Attributes GetAttributes() const;
153 
154  /// Returns the metadata specified in the configuration
155  HIO_API
157 
158 private:
159  // private ctor. should only be called by ::Read
160  HioGlslfxConfig(TfToken const& technique,
161  VtDictionary const & dict,
162  std::string *errorStr);
163 
164  void _Init(VtDictionary const & dict, std::string *errorStr);
165 
166  Parameters _GetParameters(VtDictionary const & dict,
167  std::string *errorStr) const;
168  Textures _GetTextures(VtDictionary const & dict,
169  std::string *errorStr) const;
170 
171  Attributes _GetAttributes(VtDictionary const & dict,
172  std::string *errorStr) const;
173 
174  MetadataDictionary _GetMetadata(VtDictionary const & dict,
175  std::string *errorStr) const;
176 
177  typedef std::map<std::string, SourceKeys> _SourceKeyMap;
178  _SourceKeyMap _GetSourceKeyMap(VtDictionary const & dict,
179  std::string *errorStr) const;
180 
181  TfToken _technique;
182  Parameters _params;
183  Textures _textures;
184  Attributes _attributes;
185  MetadataDictionary _metadata;
186  _SourceKeyMap _sourceKeyMap;
187 };
188 
189 
191 
192 #endif
GLenum GLenum GLenum input
Definition: glew.h:13879
GT_API const UT_StringHolder filename
GLuint const GLchar * name
Definition: glew.h:1814
std::vector< Attribute > Attributes
Definition: glslfxConfig.h:122
Attribute(std::string const &name, VtValue const &defaultValue, std::string const &docString="")
Definition: glslfxConfig.h:110
Parameter(std::string const &name, VtValue const &defaultValue, std::string const &docString="", Role const &role=RoleNone)
Definition: glslfxConfig.h:67
#define HIO_API
Definition: api.h:40
Texture(std::string const &name, VtValue const &defaultValue, std::string const &docString="")
Definition: glslfxConfig.h:90
HIO_API Textures GetTextures() const
Return the textures specified in the configuration.
std::vector< std::string > SourceKeys
Definition: glslfxConfig.h:134
HIO_API Parameters GetParameters() const
Return the parameters specified in the configuration.
Definition: token.h:87
std::vector< Parameter > Parameters
Definition: glslfxConfig.h:82
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
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:91
HIO_API Attributes GetAttributes() const
Returns the attributes specified in the configuration.
VtDictionary MetadataDictionary
Definition: glslfxConfig.h:136
std::vector< Texture > Textures
Definition: glslfxConfig.h:102
Definition: value.h:174
static HIO_API HioGlslfxConfig * Read(TfToken const &technique, std::string const &input, std::string const &filename, std::string *errorStr)