HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shaderGenerator.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_IMAGING_HGI_SHADERGENERATOR_H
9 #define PXR_IMAGING_HGI_SHADERGENERATOR_H
10 
11 #include "pxr/pxr.h"
12 #include "pxr/imaging/hgi/api.h"
13 #include "pxr/imaging/hgi/enums.h"
14 
15 #include <iosfwd>
16 #include <string>
17 
19 
21 
22 /// \class HgiShaderGenerator
23 ///
24 /// Base class for shader function generation
25 /// Given a descriptor, converts glslfx domain language to concrete shader
26 /// languages. Can be extended with new types of code sections and specialized
27 /// for different APIs. It's main role is to make GLSLFX a write once language,
28 /// no matter the API
29 ///
31 {
32 public:
33  HGI_API
34  virtual ~HgiShaderGenerator();
35 
36  // Execute shader generation.
37  HGI_API
38  void Execute();
39 
40  // Return generated shader source.
41  HGI_API
42  const char *GetGeneratedShaderCode() const;
43 
44 protected:
45  HGI_API
46  explicit HgiShaderGenerator(const HgiShaderFunctionDesc &descriptor);
47 
48  HGI_API
49  virtual void _Execute(std::ostream &ss) = 0;
50 
51  HGI_API
52  const char *_GetShaderCodeDeclarations() const;
53 
54  HGI_API
55  const char *_GetShaderCode() const;
56 
57  HGI_API
59 
60 private:
61  const HgiShaderFunctionDesc &_descriptor;
62 
63  // This is used if the descriptor does not specify a string
64  // to be used as the destination for generated output.
65  std::string _localGeneratedShaderCode;
66 
67  HgiShaderGenerator() = delete;
68  HgiShaderGenerator & operator=(const HgiShaderGenerator&) = delete;
69  HgiShaderGenerator(const HgiShaderGenerator&) = delete;
70 };
71 
73 
74 #endif
virtual HGI_API ~HgiShaderGenerator()
HGI_API const char * _GetShaderCodeDeclarations() const
HGI_API HgiShaderStage _GetShaderStage() const
HGI_API void Execute()
#define HGI_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual HGI_API void _Execute(std::ostream &ss)=0
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HgiBits HgiShaderStage
Definition: enums.h:357
HGI_API const char * _GetShaderCode() const
HGI_API const char * GetGeneratedShaderCode() const