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"
34 #include "pxr/imaging/garch/gl.h"
35 #include "pxr/imaging/hio/glslfx.h"
36 
37 #include <memory>
38 
40 
42  std::shared_ptr<class HdSt_GeometricShader>;
43 class 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 IsPrimTypePatches(PrimitiveType primType) {
109  return primType == PrimitiveType::PRIM_MESH_BSPLINE ||
113  }
114 
115  HDST_API
116  HdSt_GeometricShader(std::string const &glslfxString,
117  PrimitiveType primType,
118  HdCullStyle cullStyle,
119  HdPolygonMode polygonMode,
120  bool cullingPass,
121  SdfPath const &debugId = SdfPath(),
122  float lineWidth = 0);
123 
124  HDST_API
125  virtual ~HdSt_GeometricShader();
126 
127  // HdShader overrides
128  HDST_API
129  virtual ID ComputeHash() const;
130  HDST_API
131  virtual std::string GetSource(TfToken const &shaderStageKey) const;
132  HDST_API
133  virtual void BindResources(int program,
134  HdSt_ResourceBinder const &binder,
135  HdRenderPassState const &state) override;
136 
137  HDST_API
138  virtual void UnbindResources(int program,
139  HdSt_ResourceBinder const &binder,
140  HdRenderPassState const &state) override;
141  HDST_API
142  virtual void AddBindings(HdBindingRequestVector *customBindings);
143 
144  /// Returns true if this geometric shader is used for GPU frustum culling.
145  bool IsFrustumCullingPass() const {
146  return _frustumCullingPass;
147  }
148 
150  return _primType;
151  }
152 
153  /// member query functions for PrimitiveType
154  inline bool IsPrimTypePoints() const {
155  return IsPrimTypePoints(_primType);
156  }
157 
158  inline bool IsPrimTypeBasisCurves() const {
159  return IsPrimTypeBasisCurves(_primType);
160  }
161 
162  inline bool IsPrimTypeMesh() const {
163  return IsPrimTypeMesh(_primType);
164  }
165 
166  inline bool IsPrimTypeTriangles() const {
167  return IsPrimTypeTriangles(_primType);
168  }
169 
170  inline bool IsPrimTypeQuads() const {
171  return IsPrimTypeQuads(_primType);
172  }
173 
174  inline bool IsPrimTypePatches() const {
175  return IsPrimTypePatches(_primType);
176  }
177 
178  /// Return the GL primitive type of the draw item based on _primType
179  HDST_API
180  GLenum GetPrimitiveMode() const;
181 
182  // Returns the primitive index size based on the primitive mode
183  // 3 for triangles, 4 for quads, 16 for regular b-spline patches etc.
184  HDST_API
185  int GetPrimitiveIndexSize() const;
186 
187  // Returns the primitive index size for the geometry shader shade
188  // 1 for points, 2 for lines, 3 for triangles, 4 for lines_adjacency
189  HDST_API
191 
192  // Factory for convenience.
194  HdSt_ShaderKey const &shaderKey,
195  HdStResourceRegistrySharedPtr const &resourceRegistry);
196 
197 private:
198  PrimitiveType _primType;
199  HdCullStyle _cullStyle;
200  HdPolygonMode _polygonMode;
201  float _lineWidth;
202 
203  std::unique_ptr<HioGlslfx> _glslfx;
204  bool _frustumCullingPass;
205  ID _hash;
206 
207  // No copying
208  HdSt_GeometricShader(const HdSt_GeometricShader &) = delete;
209  HdSt_GeometricShader &operator =(const HdSt_GeometricShader &) = delete;
210 };
211 
212 
214 
215 #endif // PXR_IMAGING_HD_ST_GEOMETRIC_SHADER_H
virtual HDST_API ID ComputeHash() const
PrimitiveType GetPrimitiveType() const
static bool IsPrimTypeQuads(PrimitiveType primType)
HdCullStyle
Definition: enums.h:122
static bool IsPrimTypeTriangles(PrimitiveType primType)
HdPolygonMode
Definition: enums.h:137
bool IsPrimTypeTriangles() const
std::shared_ptr< class HdSt_GeometricShader > HdSt_GeometricShaderSharedPtr
Definition: drawItem.h:33
unsigned int GLenum
Definition: cl.hpp:166
bool IsPrimTypeQuads() const
static bool IsPrimTypeMesh(PrimitiveType primType)
virtual 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.
virtual HDST_API ~HdSt_GeometricShader()
HDST_API GLenum GetPrimitiveMode() const
Return the GL primitive type of the draw item based on _primType.
Definition: token.h:87
static bool IsPrimTypeBasisCurves(PrimitiveType primType)
bool IsPrimTypePoints() const
member query functions for PrimitiveType
bool IsPrimTypePatches() const
virtual HDST_API std::string GetSource(TfToken const &shaderStageKey) const
static bool IsPrimTypePatches(PrimitiveType primType)
Definition: path.h:288
static HdSt_GeometricShaderSharedPtr Create(HdSt_ShaderKey const &shaderKey, HdStResourceRegistrySharedPtr const &resourceRegistry)
HDST_API int GetNumPrimitiveVertsForGeometryShader() const
bool IsPrimTypeBasisCurves() const
virtual HDST_API void BindResources(int program, HdSt_ResourceBinder const &binder, HdRenderPassState const &state) override
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
static bool IsPrimTypePoints(PrimitiveType primType)
static query functions for PrimitiveType
virtual HDST_API void AddBindings(HdBindingRequestVector *customBindings)
Add custom bindings (used by codegen)
#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.
GLuint program
Definition: glew.h:5881
HDST_API HdSt_GeometricShader(std::string const &glslfxString, PrimitiveType primType, HdCullStyle cullStyle, HdPolygonMode polygonMode, bool cullingPass, SdfPath const &debugId=SdfPath(), float lineWidth=0)
std::shared_ptr< class HdStResourceRegistry > HdStResourceRegistrySharedPtr
Definition: commandBuffer.h:47
std::vector< class HdBindingRequest > HdBindingRequestVector
Definition: binding.h:39