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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_IMAGING_HGI_SHADERSECTION_H
9 #define PXR_IMAGING_HGI_SHADERSECTION_H
10 
11 #include "pxr/pxr.h"
12 #include "pxr/imaging/hgi/api.h"
13 #include <memory>
14 #include <ostream>
15 #include <string>
16 #include <vector>
17 
19 
20 //struct to hold attribute definitions
22 {
23  std::string identifier;
24  std::string index;
25 };
26 
28  std::vector<HgiShaderSectionAttribute>;
29 
30 /// \class HgiShaderSection
31 ///
32 /// A base class for a Shader Section.
33 /// In its simplest form then it is a construct that knows
34 /// how to declare itself, define and pass as param.
35 /// Can be subclassed to add more behaviour for complex cases
36 /// and to hook into the visitor tree.
37 ///
39 {
40 public:
41  HGI_API
42  virtual ~HgiShaderSection();
43 
44  /// Write out the type, shader section does not hold a type
45  /// string as how a type is defined is fully controlled
46  /// by sub classes and no assumptions are made
47  HGI_API
48  virtual void WriteType(std::ostream& ss) const;
49 
50  /// Writes the unique name of an instance of the section
51  HGI_API
52  virtual void WriteIdentifier(std::ostream& ss) const;
53 
54  /// Writes a decleration statement for a member or in global scope
55  HGI_API
56  virtual void WriteDeclaration(std::ostream& ss) const;
57 
58  /// Writes the section as a parameter to a function
59  HGI_API
60  virtual void WriteParameter(std::ostream& ss) const;
61 
62  /// Writes the arraySize to a function
63  HGI_API
64  virtual void WriteArraySize(std::ostream& ss) const;
65 
66  /// Writes the block instance name of an instance of the section
67  HGI_API
68  virtual void WriteBlockInstanceIdentifier(std::ostream& ss) const;
69 
70  /// Returns the identifier of the section
71  const std::string& GetIdentifier() const {
72  return _identifierVar;
73  }
74 
75  /// Returns the attributes of the section
76  HGI_API
78 
79  /// Returns the arraySize of the section
80  const std::string& GetArraySize() const {
81  return _arraySize;
82  }
83 
84  /// Returns whether the section has a block instance identifier
86  return !_blockInstanceIdentifier.empty();
87  }
88 
89 protected:
90  HGI_API
91  explicit HgiShaderSection(
92  const std::string &identifier,
93  const HgiShaderSectionAttributeVector& attributes = {},
94  const std::string &defaultValue = std::string(),
95  const std::string &arraySize = std::string(),
96  const std::string &blockInstanceIdentifier = std::string());
97 
98  HGI_API
99  const std::string& _GetDefaultValue() const;
100 
101 private:
102  const std::string _identifierVar;
103  const HgiShaderSectionAttributeVector _attributes;
104  const std::string _defaultValue;
105  const std::string _arraySize;
106  const std::string _blockInstanceIdentifier;
107 };
108 
110 
111 #endif
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:28
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:23
virtual HGI_API void WriteBlockInstanceIdentifier(std::ostream &ss) const
Writes the block instance name of an instance of the section.
const std::string & GetIdentifier() const
Returns the identifier of the section.
Definition: shaderSection.h:71
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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:85
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual HGI_API ~HgiShaderSection()
const std::string & GetArraySize() const
Returns the arraySize of the section.
Definition: shaderSection.h:80
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.