HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
geometricShader.h
Go to the documentation of this file.
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 PXR_IMAGING_HD_ST_GEOMETRIC_SHADER_H
25 #define PXR_IMAGING_HD_ST_GEOMETRIC_SHADER_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/hd/enums.h"
33 #include "pxr/usd/sdf/path.h"
35 #include "pxr/imaging/hio/glslfx.h"
36 
37 #include <memory>
38 
40 
42  std::shared_ptr<class HdSt_GeometricShader>;
43 struct HdSt_ShaderKey;
44 
45 /// \class HdSt_GeometricShader
46 ///
47 /// Storm breaks down the concept of a shader program into distinct
48 /// conceptual pieces that are then stitched together during code generation.
49 /// The pieces are:
50 /// (i) geometric shader
51 /// (ii) material shader
52 /// (iii) lighting shader
53 /// (iv) render pass shader
54 ///
55 /// The geometric shader contains the entry points for the relevant shader
56 /// stages and uses geometry opinions (such as cullstyle, double sided, etc)
57 /// to generate shader code variants via mixins.
58 ///
60 public:
61  /// Used in HdSt_CodeGen to generate the appropriate shader source
62  enum class PrimitiveType {
63  PRIM_POINTS,
64  PRIM_BASIS_CURVES_LINES, // when linear (or) non-refined cubic
65  PRIM_BASIS_CURVES_LINEAR_PATCHES, // refined linear curves
66  PRIM_BASIS_CURVES_CUBIC_PATCHES, // refined cubic curves
68  PRIM_MESH_REFINED_TRIANGLES, // e.g: loop subdiv
69  PRIM_MESH_COARSE_QUADS, // e.g: quadrangulation for ptex
70  PRIM_MESH_REFINED_QUADS, // e.g: catmark/bilinear subdiv
71  PRIM_MESH_BSPLINE, // e.g. catmark limit surface patches
72  PRIM_MESH_BOXSPLINETRIANGLE, // e.g. loop limit surface patches
73  PRIM_VOLUME // Simply draws triangles of bounding
74  // box of a volume.
75  };
76 
77  /// static query functions for PrimitiveType
78  static inline bool IsPrimTypePoints (PrimitiveType primType) {
79  return primType == PrimitiveType::PRIM_POINTS;
80  }
81 
82  static inline bool IsPrimTypeBasisCurves(PrimitiveType primType) {
83  return (primType == PrimitiveType::PRIM_BASIS_CURVES_LINES ||
86  }
87 
88  static inline bool IsPrimTypeMesh(PrimitiveType primType) {
89  return (primType == PrimitiveType::PRIM_MESH_COARSE_TRIANGLES ||
95  }
96 
97  static inline bool IsPrimTypeTriangles(PrimitiveType primType) {
98  return (primType == PrimitiveType::PRIM_MESH_COARSE_TRIANGLES ||
100  primType == PrimitiveType::PRIM_VOLUME);
101  }
102 
103  static inline bool IsPrimTypeQuads(PrimitiveType primType) {
104  return (primType == PrimitiveType::PRIM_MESH_COARSE_QUADS ||
106  }
107 
108  static inline bool IsPrimTypeRefinedMesh(PrimitiveType primType) {
109  return (primType == PrimitiveType::PRIM_MESH_REFINED_TRIANGLES ||
111  primType == PrimitiveType::PRIM_MESH_BSPLINE ||
113  }
114 
115  static inline bool IsPrimTypePatches(PrimitiveType primType) {
116  return primType == PrimitiveType::PRIM_MESH_BSPLINE ||
120  }
121 
122  // Face-varying patch type
123  enum class FvarPatchType {
130  PATCH_NONE
131  };
132 
133  HDST_API
134  HdSt_GeometricShader(std::string const &glslfxString,
135  PrimitiveType primType,
136  HdCullStyle cullStyle,
137  bool useHardwareFaceCulling,
138  bool hasMirroredTransform,
139  bool doubleSided,
140  HdPolygonMode polygonMode,
141  bool cullingPass,
142  FvarPatchType fvarPatchType,
143  SdfPath const &debugId = SdfPath(),
144  float lineWidth = 0);
145 
146  HDST_API
147  ~HdSt_GeometricShader() override;
148 
149  // HdShader overrides
150  HDST_API
151  ID ComputeHash() const override;
152  HDST_API
153  std::string GetSource(TfToken const &shaderStageKey) const override;
154  HDST_API
155  void BindResources(int program,
156  HdSt_ResourceBinder const &binder,
157  HdRenderPassState const &state) override;
158 
159  HDST_API
160  void UnbindResources(int program,
161  HdSt_ResourceBinder const &binder,
162  HdRenderPassState const &state) override;
163  HDST_API
164  void AddBindings(HdBindingRequestVector *customBindings) override;
165 
166  /// Returns true if this geometric shader is used for GPU frustum culling.
167  bool IsFrustumCullingPass() const {
168  return _frustumCullingPass;
169  }
170 
172  return _primType;
173  }
174 
175  /// member query functions for PrimitiveType
176  inline bool IsPrimTypePoints() const {
177  return IsPrimTypePoints(_primType);
178  }
179 
180  inline bool IsPrimTypeBasisCurves() const {
181  return IsPrimTypeBasisCurves(_primType);
182  }
183 
184  inline bool IsPrimTypeMesh() const {
185  return IsPrimTypeMesh(_primType);
186  }
187 
188  inline bool IsPrimTypeTriangles() const {
189  return IsPrimTypeTriangles(_primType);
190  }
191 
192  inline bool IsPrimTypeQuads() const {
193  return IsPrimTypeQuads(_primType);
194  }
195 
196  inline bool IsPrimTypePatches() const {
197  return IsPrimTypePatches(_primType);
198  }
199 
201  return _fvarPatchType;
202  }
203 
204  /// Return the GL primitive type of the draw item based on _primType
205  HDST_API
206  GLenum GetPrimitiveMode() const;
207 
208  // Returns the primitive index size based on the primitive mode
209  // 3 for triangles, 4 for quads, 16 for regular b-spline patches etc.
210  HDST_API
211  int GetPrimitiveIndexSize() const;
212 
213  // Returns the number of vertices output for patch evaluation,
214  // i.e. the number of tessellation control shader invocations.
215  HDST_API
216  int GetNumPatchEvalVerts() const;
217 
218  // Returns the primitive index size for the geometry shader shade
219  // 1 for points, 2 for lines, 3 for triangles, 4 for lines_adjacency
220  HDST_API
222 
223  // Factory for convenience.
225  HdSt_ShaderKey const &shaderKey,
226  HdStResourceRegistrySharedPtr const &resourceRegistry);
227 
228 private:
229  PrimitiveType _primType;
230  HdCullStyle _cullStyle;
231  bool _useHardwareFaceCulling;
232  bool _hasMirroredTransform;
233  bool _doubleSided;
234  HdPolygonMode _polygonMode;
235  float _lineWidth;
236 
237  std::unique_ptr<HioGlslfx> _glslfx;
238  bool _frustumCullingPass;
239  FvarPatchType _fvarPatchType;
240  ID _hash;
241 
242  // No copying
243  HdSt_GeometricShader(const HdSt_GeometricShader &) = delete;
244  HdSt_GeometricShader &operator =(const HdSt_GeometricShader &) = delete;
245 };
246 
247 
249 
250 #endif // PXR_IMAGING_HD_ST_GEOMETRIC_SHADER_H
FvarPatchType GetFvarPatchType() const
PrimitiveType GetPrimitiveType() const
HDST_API std::string GetSource(TfToken const &shaderStageKey) const override
static bool IsPrimTypeQuads(PrimitiveType primType)
HdCullStyle
Definition: enums.h:122
static bool IsPrimTypeTriangles(PrimitiveType primType)
HDST_API int GetNumPatchEvalVerts() const
HdPolygonMode
Definition: enums.h:137
bool IsPrimTypeTriangles() const
std::shared_ptr< class HdSt_GeometricShader > HdSt_GeometricShaderSharedPtr
Definition: drawItem.h:33
GLbitfield GLuint program
Definition: glcorearb.h:1930
unsigned int GLenum
Definition: cl.hpp:166
bool IsPrimTypeQuads() const
static bool IsPrimTypeMesh(PrimitiveType primType)
HDST_API void UnbindResources(int program, HdSt_ResourceBinder const &binder, HdRenderPassState const &state) override
Unbinds shader-specific resources.
bool IsPrimTypeMesh() const
HDST_API int GetPrimitiveIndexSize() const
PrimitiveType
Used in HdSt_CodeGen to generate the appropriate shader source.
HDST_API GLenum GetPrimitiveMode() const
Return the GL primitive type of the draw item based on _primType.
Definition: token.h:87
static bool IsPrimTypeRefinedMesh(PrimitiveType primType)
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
static bool IsPrimTypeBasisCurves(PrimitiveType primType)
bool IsPrimTypePoints() const
member query functions for PrimitiveType
bool IsPrimTypePatches() const
HDST_API ~HdSt_GeometricShader() override
static bool IsPrimTypePatches(PrimitiveType primType)
Definition: path.h:288
HDST_API HdSt_GeometricShader(std::string const &glslfxString, PrimitiveType primType, HdCullStyle cullStyle, bool useHardwareFaceCulling, bool hasMirroredTransform, bool doubleSided, HdPolygonMode polygonMode, bool cullingPass, FvarPatchType fvarPatchType, SdfPath const &debugId=SdfPath(), float lineWidth=0)
HDST_API ID ComputeHash() const override
static HdSt_GeometricShaderSharedPtr Create(HdSt_ShaderKey const &shaderKey, HdStResourceRegistrySharedPtr const &resourceRegistry)
HDST_API int GetNumPrimitiveVertsForGeometryShader() const
bool IsPrimTypeBasisCurves() const
HDST_API void BindResources(int program, HdSt_ResourceBinder const &binder, HdRenderPassState const &state) override
HDST_API void AddBindings(HdBindingRequestVector *customBindings) override
Add custom bindings (used by codegen)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
static bool IsPrimTypePoints(PrimitiveType primType)
static query functions for PrimitiveType
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool IsFrustumCullingPass() const
Returns true if this geometric shader is used for GPU frustum culling.
std::shared_ptr< class HdStResourceRegistry > HdStResourceRegistrySharedPtr
Definition: commandBuffer.h:47
std::vector< class HdBindingRequest > HdBindingRequestVector
Definition: binding.h:41