HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shaderSection.h
Go to the documentation of this file.
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 
36 
37 //struct to hold attribute definitions
39 {
42 };
43 
45  std::vector<HgiShaderSectionAttribute>;
46 
47 /// \class HgiShaderSection
48 ///
49 /// A base class for a Shader Section.
50 /// In its simplest form then it is a construct that knows
51 /// how to declare itself, define and pass as param.
52 /// Can be subclassed to add more behaviour for complex cases
53 /// and to hook into the visitor tree.
54 ///
56 {
57 public:
58  HGI_API
59  virtual ~HgiShaderSection();
60 
61  /// Write out the type, shader section does not hold a type
62  /// string as how a type is defined is fully controlled
63  /// by sub classes and no assumptions are made
64  HGI_API
65  virtual void WriteType(std::ostream& ss) const;
66 
67  /// Writes the unique name of an instance of the section
68  HGI_API
69  virtual void WriteIdentifier(std::ostream& ss) const;
70 
71  /// Writes a decleration statement for a member or in global scope
72  HGI_API
73  virtual void WriteDeclaration(std::ostream& ss) const;
74 
75  /// Writes the section as a parameter to a function
76  HGI_API
77  virtual void WriteParameter(std::ostream& ss) const;
78 
79  /// Writes the arraySize to a function
80  HGI_API
81  virtual void WriteArraySize(std::ostream& ss) const;
82 
83  /// Writes the block instance name of an instance of the section
84  HGI_API
85  virtual void WriteBlockInstanceIdentifier(std::ostream& ss) const;
86 
87  /// Returns the attributes of the section
88  HGI_API
90 
91  /// Returns the arraySize of the section
92  const std::string& GetArraySize() const {
93  return _arraySize;
94  }
95 
96  /// Returns whether the section has a block instance identifier
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 
122 
123 #endif
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
virtual HGI_API void WriteParameter(std::ostream &ss) const
Writes the section as a parameter to a function.
virtual HGI_API void WriteType(std::ostream &ss) const
std::vector< HgiShaderSectionAttribute > HgiShaderSectionAttributeVector
Definition: shaderSection.h:45
HGI_API HgiShaderSection(const std::string &identifier, const HgiShaderSectionAttributeVector &attributes={}, const std::string &defaultValue=std::string(), const std::string &arraySize=std::string(), const std::string &blockInstanceIdentifier=std::string())
virtual HGI_API void WriteArraySize(std::ostream &ss) const
Writes the arraySize to a function.
#define HGI_API
Definition: api.h:40
virtual HGI_API void WriteBlockInstanceIdentifier(std::ostream &ss) const
Writes the block instance name of an instance of the section.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
virtual HGI_API void WriteDeclaration(std::ostream &ss) const
Writes a decleration statement for a member or in global scope.
bool HasBlockInstanceIdentifier() const
Returns whether the section has a block instance identifier.
Definition: shaderSection.h:97
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual HGI_API ~HgiShaderSection()
const std::string & GetArraySize() const
Returns the arraySize of the section.
Definition: shaderSection.h:92
HGI_API const std::string & _GetDefaultValue() const
virtual HGI_API void WriteIdentifier(std::ostream &ss) const
Writes the unique name of an instance of the section.
HGI_API const HgiShaderSectionAttributeVector & GetAttributes() const
Returns the attributes of the section.