shaderSection.h
1 //
2 // Copyright 2020 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 
25 #ifndef PXR_IMAGING_HGI_SHADERSECTION_H
26 #define PXR_IMAGING_HGI_SHADERSECTION_H
27 
28 #include "pxr/pxr.h"
29 #include "pxr/imaging/hgi/api.h"
30 #include <memory>
31 #include <ostream>
32 #include <string>
33 #include <vector>
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 //struct to hold attribute definitions
38 struct HgiShaderSectionAttribute
39 {
40  std::string identifier;
41  std::string index;
42 };
43 
44 using HgiShaderSectionAttributeVector =
45  std::vector<HgiShaderSectionAttribute>;
46 
56 {
57 public:
58  HGI_API
59  virtual ~HgiShaderSection();
60 
64  HGI_API
65  virtual void WriteType(std::ostream& ss) const;
66 
68  HGI_API
69  virtual void WriteIdentifier(std::ostream& ss) const;
70 
72  HGI_API
73  virtual void WriteDeclaration(std::ostream& ss) const;
74 
76  HGI_API
77  virtual void WriteParameter(std::ostream& ss) const;
78 
80  HGI_API
81  virtual void WriteArraySize(std::ostream& ss) const;
82 
84  HGI_API
85  virtual void WriteBlockInstanceIdentifier(std::ostream& ss) const;
86 
88  HGI_API
89  const HgiShaderSectionAttributeVector& GetAttributes() const;
90 
92  const std::string& GetArraySize() const {
93  return _arraySize;
94  }
95 
98  return !_blockInstanceIdentifier.empty();
99  }
100 
101 protected:
102  HGI_API
103  explicit HgiShaderSection(
104  const std::string &identifier,
105  const HgiShaderSectionAttributeVector& attributes = {},
106  const std::string &defaultValue = std::string(),
107  const std::string &arraySize = std::string(),
108  const std::string &blockInstanceIdentifier = std::string());
109 
110  HGI_API
111  const std::string& _GetDefaultValue() const;
112 
113 private:
114  const std::string _identifierVar;
115  const HgiShaderSectionAttributeVector _attributes;
116  const std::string _defaultValue;
117  const std::string _arraySize;
118  const std::string _blockInstanceIdentifier;
119 };
120 
121 PXR_NAMESPACE_CLOSE_SCOPE
122 
123 #endif
const std::string & GetArraySize() const
Returns the arraySize of the section.
Definition: shaderSection.h:92
virtual HGI_API void WriteBlockInstanceIdentifier(std::ostream &ss) const
Writes the block instance name of an instance of the section.
virtual HGI_API void WriteDeclaration(std::ostream &ss) const
Writes a decleration statement for a member or in global scope.
HGI_API const HgiShaderSectionAttributeVector & GetAttributes() const
Returns the attributes of the section.
virtual HGI_API void WriteParameter(std::ostream &ss) const
Writes the section as a parameter to a function.
virtual HGI_API void WriteArraySize(std::ostream &ss) const
Writes the arraySize to a function.
bool HasBlockInstanceIdentifier() const
Returns whether the section has a block instance identifier.
Definition: shaderSection.h:97
A base class for a Shader Section.
Definition: shaderSection.h:55
virtual HGI_API void WriteIdentifier(std::ostream &ss) const
Writes the unique name of an instance of the section.
virtual HGI_API void WriteType(std::ostream &ss) const
Write out the type, shader section does not hold a type string as how a type is defined is fully cont...