All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
drawBatch.h
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 HDST_DRAW_BATCH_H
25 #define HDST_DRAW_BATCH_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/version.h"
30 
31 #include "pxr/imaging/hdSt/resourceBinder.h"
32 #include "pxr/imaging/hd/repr.h"
33 #include "pxr/imaging/hdSt/shaderCode.h"
34 
35 #include <boost/shared_ptr.hpp>
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 
41 class HdStDrawItem;
43 
44 typedef boost::shared_ptr<class HdSt_DrawBatch> HdSt_DrawBatchSharedPtr;
45 typedef boost::shared_ptr<class HdSt_GeometricShader> HdSt_GeometricShaderSharedPtr;
46 typedef boost::shared_ptr<class HdStGLSLProgram> HdStGLSLProgramSharedPtr;
47 typedef boost::shared_ptr<class HdStRenderPassState> HdStRenderPassStateSharedPtr;
48 typedef std::vector<HdSt_DrawBatchSharedPtr> HdSt_DrawBatchSharedPtrVector;
49 typedef std::vector<class HdBindingRequest> HdBindingRequestVector;
50 typedef boost::shared_ptr<class HdStResourceRegistry>
51  HdStResourceRegistrySharedPtr;
52 
61 class HdSt_DrawBatch {
62 public:
63  HDST_API
64  HdSt_DrawBatch(HdStDrawItemInstance * drawItemInstance);
65 
66  HDST_API
67  virtual ~HdSt_DrawBatch();
68 
72  HDST_API
73  bool Append(HdStDrawItemInstance * drawItemInstance);
74 
77  HDST_API
78  bool Rebuild();
79 
82  virtual bool Validate(bool deepValidation) = 0;
83 
85  virtual void PrepareDraw(
86  HdStRenderPassStateSharedPtr const &renderPassState,
87  HdStResourceRegistrySharedPtr const &resourceRegistry) = 0;
88 
90  virtual void ExecuteDraw(
91  HdStRenderPassStateSharedPtr const &renderPassState,
92  HdStResourceRegistrySharedPtr const & resourceRegistry) = 0;
93 
97  HDST_API
98  virtual void DrawItemInstanceChanged(HdStDrawItemInstance const* instance);
99 
101  HDST_API
102  virtual void SetEnableTinyPrimCulling(bool tinyPrimCulling);
103 
104 protected:
105  HDST_API
106  virtual void _Init(HdStDrawItemInstance * drawItemInstance);
107 
113  class _DrawingProgram {
114  public:
115  _DrawingProgram() {}
116 
117  HDST_API
118  bool CompileShader(
119  HdStDrawItem const *drawItem,
120  bool indirect,
121  HdStResourceRegistrySharedPtr const &resourceRegistry);
122 
123  HdStGLSLProgramSharedPtr GetGLSLProgram() const {
124  return _glslProgram;
125  }
126 
129  const HdSt_ResourceBinder &GetBinder() const {
130  return _resourceBinder;
131  }
132 
133  void Reset() {
134  _glslProgram.reset();
135  _surfaceShader.reset();
136  _geometricShader.reset();
137  _resourceBinder = HdSt_ResourceBinder();
138  _shaders.clear();
139  }
140 
141  void SetSurfaceShader(HdStShaderCodeSharedPtr shader) {
142  _surfaceShader = shader;
143  }
144 
145  const HdStShaderCodeSharedPtr &GetSurfaceShader() {
146  return _surfaceShader;
147  }
148 
149  void SetGeometricShader(HdSt_GeometricShaderSharedPtr shader) {
150  _geometricShader = shader;
151  }
152 
153  const HdSt_GeometricShaderSharedPtr &GetGeometricShader() {
154  return _geometricShader;
155  }
156 
159  void SetShaders(HdStShaderCodeSharedPtrVector shaders) {
160  _shaders = shaders;
161  }
162 
165  const HdStShaderCodeSharedPtrVector &GetShaders() const {
166  return _shaders;
167  }
168 
171  HdStShaderCodeSharedPtrVector GetComposedShaders() const {
172  HdStShaderCodeSharedPtrVector shaders = _shaders;
173  if (_surfaceShader) {
174  shaders.push_back(_surfaceShader);
175  }
176  return shaders;
177  }
178 
179  protected:
180  // overrides populate customBindings and enableInstanceDraw which
181  // will be used to determine if glVertexAttribDivisor needs to be
182  // enabled or not.
183  HDST_API
184  virtual void _GetCustomBindings(
185  HdBindingRequestVector *customBindings,
186  bool *enableInstanceDraw) const;
187 
188  HDST_API
189  virtual bool _Link(HdStGLSLProgramSharedPtr const & glslProgram);
190 
191  private:
192  HdStGLSLProgramSharedPtr _glslProgram;
193  HdSt_ResourceBinder _resourceBinder;
194  HdStShaderCodeSharedPtrVector _shaders;
195  HdSt_GeometricShaderSharedPtr _geometricShader;
196  HdStShaderCodeSharedPtr _surfaceShader;
197  };
198 
199  HDST_API
200  _DrawingProgram & _GetDrawingProgram(
201  HdStRenderPassStateSharedPtr const &state,
202  bool indirect,
203  HdStResourceRegistrySharedPtr const &resourceRegistry);
204 
205 protected:
206  HDST_API
207  static bool _IsAggregated(HdStDrawItem const *drawItem0,
208  HdStDrawItem const *drawItem1);
209 
210  std::vector<HdStDrawItemInstance const*> _drawItemInstances;
211 
212 private:
213  _DrawingProgram _program;
214  HdStShaderCode::ID _shaderHash;
215 };
216 
217 
218 PXR_NAMESPACE_CLOSE_SCOPE
219 
220 #endif // HDST_DRAW_BATCH_H
A container to store instance state for a drawitem.