Loading...
Searching...
No Matches
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
35PXR_NAMESPACE_OPEN_SCOPE
36
37//struct to hold attribute definitions
38struct HgiShaderSectionAttribute
39{
40 std::string identifier;
41 std::string index;
42};
43
44using HgiShaderSectionAttributeVector =
45 std::vector<HgiShaderSectionAttribute>;
46
56{
57public:
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 const std::string& GetIdentifier() const {
89 return _identifierVar;
90 }
91
93 HGI_API
94 const HgiShaderSectionAttributeVector& GetAttributes() const;
95
97 const std::string& GetArraySize() const {
98 return _arraySize;
99 }
100
103 return !_blockInstanceIdentifier.empty();
104 }
105
106protected:
107 HGI_API
108 explicit HgiShaderSection(
109 const std::string &identifier,
110 const HgiShaderSectionAttributeVector& attributes = {},
111 const std::string &defaultValue = std::string(),
112 const std::string &arraySize = std::string(),
113 const std::string &blockInstanceIdentifier = std::string());
114
115 HGI_API
116 const std::string& _GetDefaultValue() const;
117
118private:
119 const std::string _identifierVar;
120 const HgiShaderSectionAttributeVector _attributes;
121 const std::string _defaultValue;
122 const std::string _arraySize;
123 const std::string _blockInstanceIdentifier;
124};
125
126PXR_NAMESPACE_CLOSE_SCOPE
127
128#endif
A base class for a Shader Section.
Definition: shaderSection.h:56
HGI_API const HgiShaderSectionAttributeVector & GetAttributes() const
Returns the attributes 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...
const std::string & GetIdentifier() const
Returns the identifier of the section.
Definition: shaderSection.h:88
virtual HGI_API void WriteIdentifier(std::ostream &ss) const
Writes the unique name of an instance of the section.
virtual HGI_API void WriteArraySize(std::ostream &ss) const
Writes the arraySize to a function.
const std::string & GetArraySize() const
Returns the arraySize of the section.
Definition: shaderSection.h:97
virtual HGI_API void WriteBlockInstanceIdentifier(std::ostream &ss) const
Writes the block instance name of an instance of the section.
virtual HGI_API void WriteParameter(std::ostream &ss) const
Writes the section as a parameter to a function.
bool HasBlockInstanceIdentifier() const
Returns whether the section has a block instance identifier.
virtual HGI_API void WriteDeclaration(std::ostream &ss) const
Writes a decleration statement for a member or in global scope.