All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
codeGen.h
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 HDST_CODE_GEN_H
25 #define HDST_CODE_GEN_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hdSt/resourceBinder.h"
31 #include "pxr/imaging/hdSt/glslProgram.h"
32 
33 #include <boost/shared_ptr.hpp>
34 
35 #include <map>
36 #include <vector>
37 #include <sstream>
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 
42 typedef boost::shared_ptr<class HdStShaderCode> HdStShaderCodeSharedPtr;
43 typedef boost::shared_ptr<class HdSt_GeometricShader> HdSt_GeometricShaderPtr;
44 typedef std::vector<HdStShaderCodeSharedPtr> HdStShaderCodeSharedPtrVector;
45 
51 class HdSt_CodeGen
52 {
53 public:
54  typedef size_t ID;
55 
57  HDST_API
58  HdSt_CodeGen(HdSt_GeometricShaderPtr const &geometricShader,
59  HdStShaderCodeSharedPtrVector const &shaders);
60 
64  HDST_API
65  HdSt_CodeGen(HdStShaderCodeSharedPtrVector const &shaders);
66 
68  HDST_API
69  ID ComputeHash() const;
70 
72  HDST_API
73  HdStGLSLProgramSharedPtr Compile();
74 
90  HDST_API
91  HdStGLSLProgramSharedPtr CompileComputeProgram();
92 
94  const std::string &GetVertexShaderSource() const { return _vsSource; }
95 
97  const std::string &GetTessControlShaderSource() const { return _tcsSource; }
98 
100  const std::string &GetTessEvalShaderSource() const { return _tesSource; }
101 
103  const std::string &GetGeometryShaderSource() const { return _gsSource; }
104 
106  const std::string &GetFragmentShaderSource() const { return _fsSource; }
107 
109  const std::string &GetComputeShaderSource() const { return _csSource; }
110 
112  HdSt_ResourceBinder::MetaData *GetMetaData() { return &_metaData; }
113 
114 private:
115  void _GenerateDrawingCoord();
116  void _GenerateConstantPrimvar();
117  void _GenerateInstancePrimvar();
118  void _GenerateElementPrimvar();
119  void _GenerateVertexAndFaceVaryingPrimvar(bool hasGS);
120  void _GenerateShaderParameters();
121  void _GenerateTopologyVisibilityParameters();
122 
123  HdSt_ResourceBinder::MetaData _metaData;
124  HdSt_GeometricShaderPtr _geometricShader;
125  HdStShaderCodeSharedPtrVector _shaders;
126 
127  // source buckets
128  std::stringstream _genCommon, _genVS, _genTCS, _genTES;
129  std::stringstream _genGS, _genFS, _genCS;
130  std::stringstream _procVS, _procTCS, _procTES, _procGS;
131 
132  // generated sources (for diagnostics)
133  std::string _vsSource;
134  std::string _tcsSource;
135  std::string _tesSource;
136  std::string _gsSource;
137  std::string _fsSource;
138  std::string _csSource;
139 };
140 
141 
142 PXR_NAMESPACE_CLOSE_SCOPE
143 
144 #endif // HDST_CODE_GEN_H