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 PXR_IMAGING_HIO_GLSLFX_H
25 #define PXR_IMAGING_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  (fragmentShader) \
49  (geometryShader) \
50  (geometryShaderInjection) \
51  (preamble) \
52  (tessControlShader) \
53  (tessEvalShader) \
54  (vertexShader) \
55  (vertexShaderInjection) \
56  \
57  (surfaceShader) \
58  (displacementShader) \
59  (volumeShader) \
60 
61 
62 TF_DECLARE_PUBLIC_TOKENS(HioGlslfxTokens, HIO_API, HIO_GLSLFX_TOKENS);
63 
140 {
141 public:
143  HIO_API
144  HioGlslfx();
145 
147  HIO_API
148  HioGlslfx(std::string const & filePath);
149 
151  HIO_API
152  HioGlslfx(std::istream &is);
153 
155  HIO_API
156  HioGlslfxConfig::Parameters GetParameters() const;
157 
159  HIO_API
160  HioGlslfxConfig::Textures GetTextures() const;
161 
163  HIO_API
164  HioGlslfxConfig::Attributes GetAttributes() const;
165 
167  HIO_API
169 
171  HIO_API
172  bool IsValid(std::string *reason=NULL) const;
173 
176 
178  HIO_API
179  std::string GetSurfaceSource() const;
180 
182  HIO_API
183  std::string GetDisplacementSource() const;
184 
186  HIO_API
187  std::string GetVolumeSource() const;
188 
190 
192  HIO_API
193  std::string GetSource(const TfToken &shaderStageKey) const;
194 
196  const std::string &GetFilePath() const { return _globalContext.filename; }
197 
202  const std::set<std::string>& GetFiles() const { return _seenFiles; }
203 
205  size_t GetHash() const { return _hash; }
206 
207 private:
208  class _ParseContext {
209  public:
210  _ParseContext() { }
211 
212  _ParseContext(std::string const & filePath) :
213  filename(filePath), lineNo(0), version(-1.0) { }
214 
215  std::string filename;
216  int lineNo;
217  double version;
218  std::string currentLine;
219  std::string currentSectionType;
220  std::string currentSectionId;
221  std::vector<std::string> imports;
222  };
223 
224 private:
225  bool _ProcessFile(std::string const & filePath,
226  _ParseContext & context);
227  bool _ProcessInput(std::istream * input,
228  _ParseContext & context);
229  bool _ProcessImport(_ParseContext & context);
230  bool _ParseSectionLine(_ParseContext & context);
231  bool _ParseGLSLSectionLine(std::vector<std::string> const &tokens,
232  _ParseContext & context);
233  bool _ParseVersionLine(std::vector<std::string> const &tokens,
234  _ParseContext & context);
235  bool _ParseConfigurationLine(_ParseContext & context);
236  bool _ComposeConfiguration(std::string *reason);
237  std::string _GetSource(const TfToken &shaderStageKey) const;
238 
239 private:
240  _ParseContext _globalContext;
241 
242  std::set<std::string> _importedFiles;
243 
244  typedef std::map<std::string, std::string> _SourceMap;
245 
246  _SourceMap _sourceMap;
247  _SourceMap _configMap;
248  std::vector<std::string> _configOrder;
249  std::set<std::string> _seenFiles;
250 
251  boost::scoped_ptr<HioGlslfxConfig> _config;
252 
253  bool _valid;
254  std::string _invalidReason; // if _valid is false, reason why
255  size_t _hash;
256 };
257 
258 
259 PXR_NAMESPACE_CLOSE_SCOPE
260 
261 #endif
262 
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.
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:205
HIO_API HioGlslfxConfig::Attributes GetAttributes() const
Return the attributes specified in the configuration.
const std::string & GetFilePath() const
Get the original file name passed to the constructor.
Definition: glslfx.h:196
#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:139
const std::set< std::string > & GetFiles() const
Return set of all files processed for this glslfx object.
Definition: glslfx.h:202
HIO_API std::string GetSource(const TfToken &shaderStageKey) const
Get the shader source associated with given key.