All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glslfx.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 HIO_GLSLFX_H
25 #define HIO_GLSLFX_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/hio/api.h"
31 #include "pxr/imaging/hio/glslfxConfig.h"
32 
33 #include "pxr/base/tf/token.h"
34 #include "pxr/base/tf/staticTokens.h"
35 
36 #include <boost/scoped_ptr.hpp>
37 
38 #include <string>
39 #include <vector>
40 #include <set>
41 #include <map>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
45 #define HIO_GLSLFX_TOKENS \
46  (glslfx)
47 
48 TF_DECLARE_PUBLIC_TOKENS(HioGlslfxTokens, HIO_API, HIO_GLSLFX_TOKENS);
49 
126 {
127 public:
129  HIO_API
130  HioGlslfx();
131 
133  HIO_API
134  HioGlslfx(std::string const & filePath);
135 
137  HIO_API
138  HioGlslfx(std::istream &is);
139 
141  HIO_API
142  HioGlslfxConfig::Parameters GetParameters() const;
143 
145  HIO_API
146  HioGlslfxConfig::Textures GetTextures() const;
147 
149  HIO_API
150  HioGlslfxConfig::Attributes GetAttributes() const;
151 
153  HIO_API
155 
157  HIO_API
158  bool IsValid(std::string *reason=NULL) const;
159 
162 
164  HIO_API
165  std::string GetVertexSource() const;
166 
168  HIO_API
169  std::string GetTessControlSource() const;
170 
172  HIO_API
173  std::string GetTessEvalSource() const;
174 
176  HIO_API
177  std::string GetGeometrySource() const;
178 
180  HIO_API
181  std::string GetFragmentSource() const;
182 
184  HIO_API
185  std::string GetVolumeSource() const;
186 
188 
191 
193  HIO_API
194  std::string GetPreambleSource() const;
195 
197  HIO_API
198  std::string GetSurfaceSource() const;
199 
201  HIO_API
202  std::string GetDisplacementSource() const;
203 
205  HIO_API
206  std::string GetVertexInjectionSource() const;
207 
209  HIO_API
210  std::string GetGeometryInjectionSource() const;
211 
213 
215  HIO_API
216  std::string GetSource(const TfToken &shaderStageKey) const;
217 
219  const std::string &GetFilePath() const { return _globalContext.filename; }
220 
225  const std::set<std::string>& GetFiles() const { return _seenFiles; }
226 
228  size_t GetHash() const { return _hash; }
229 
230 private:
231  class _ParseContext {
232  public:
233  _ParseContext() { }
234 
235  _ParseContext(std::string const & filePath) :
236  filename(filePath), lineNo(0), version(-1.0) { }
237 
238  std::string filename;
239  int lineNo;
240  double version;
241  std::string currentLine;
242  std::string currentSectionType;
243  std::string currentSectionId;
244  std::vector<std::string> imports;
245  };
246 
247 private:
248  bool _ProcessFile(std::string const & filePath,
249  _ParseContext & context);
250  bool _ProcessInput(std::istream * input,
251  _ParseContext & context);
252  bool _ProcessImport(_ParseContext & context);
253  bool _ParseSectionLine(_ParseContext & context);
254  bool _ParseGLSLSectionLine(std::vector<std::string> const &tokens,
255  _ParseContext & context);
256  bool _ParseVersionLine(std::vector<std::string> const &tokens,
257  _ParseContext & context);
258  bool _ParseConfigurationLine(_ParseContext & context);
259  bool _ComposeConfiguration(std::string *reason);
260  std::string _GetSource(const TfToken &shaderStageKey) const;
261 
262 private:
263  _ParseContext _globalContext;
264 
265  std::set<std::string> _importedFiles;
266 
267  typedef std::map<std::string, std::string> _SourceMap;
268 
269  _SourceMap _sourceMap;
270  _SourceMap _configMap;
271  std::vector<std::string> _configOrder;
272  std::set<std::string> _seenFiles;
273 
274  boost::scoped_ptr<HioGlslfxConfig> _config;
275 
276  bool _valid;
277  std::string _invalidReason; // if _valid is false, reason why
278  size_t _hash;
279 };
280 
281 
282 PXR_NAMESPACE_CLOSE_SCOPE
283 
284 #endif
285 
HIO_API std::string GetTessEvalSource() const
Get the tess eval source string.
HIO_API HioGlslfxConfig::MetadataDictionary GetMetadata() const
Return the metadata specified in the configuration.
HIO_API std::string GetDisplacementSource() const
Get the displacement source string.
A map with string keys and VtValue values.
Definition: dictionary.h:61
HIO_API bool IsValid(std::string *reason=NULL) const
Returns true if this is a valid glslfx file.
HIO_API HioGlslfxConfig::Textures GetTextures() const
Return the textures specified in the configuration.
HIO_API std::string GetPreambleSource() const
Get the preamble (osd uniform definitions)
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
HIO_API std::string GetSurfaceSource() const
Get the surface source string.
size_t GetHash() const
Return the computed hash value based on the string.
Definition: glslfx.h:228
HIO_API HioGlslfxConfig::Attributes GetAttributes() const
Return the attributes specified in the configuration.
HIO_API std::string GetGeometryInjectionSource() const
Get the geometry injection source string.
const std::string & GetFilePath() const
Get the original file name passed to the constructor.
Definition: glslfx.h:219
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
HIO_API HioGlslfxConfig::Parameters GetParameters() const
Return the parameters specified in the configuration.
HIO_API std::string GetVolumeSource() const
Get the volume source string.
HIO_API HioGlslfx()
Create an invalid glslfx object.
A class representing the config and shader source of a glslfx file.
Definition: glslfx.h:125
HIO_API std::string GetGeometrySource() const
Get the geometry source string.
const std::set< std::string > & GetFiles() const
Return set of all files processed for this glslfx object.
Definition: glslfx.h:225
HIO_API std::string GetVertexSource() const
Get the vertex source string.
HIO_API std::string GetVertexInjectionSource() const
Get the vertex injection source string.
HIO_API std::string GetTessControlSource() const
Get the tess control source string.
HIO_API std::string GetSource(const TfToken &shaderStageKey) const
Get the shader source associated with given key.
HIO_API std::string GetFragmentSource() const
Get the fragment source string.