All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
commandBuffer.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_COMMAND_BUFFER_H
25 #define HDST_COMMAND_BUFFER_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/hdSt/drawItemInstance.h"
31 
32 #include "pxr/base/gf/vec2f.h"
33 #include "pxr/base/gf/matrix4f.h"
34 #include "pxr/base/gf/matrix4d.h"
35 
36 #include <boost/shared_ptr.hpp>
37 
38 #include <vector>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
43 class HdStDrawItem;
45 
46 typedef boost::shared_ptr<class HdStResourceRegistry>
47  HdStResourceRegistrySharedPtr;
48 typedef boost::shared_ptr<class HdStRenderPassState> HdStRenderPassStateSharedPtr;
49 typedef boost::shared_ptr<class HdSt_DrawBatch> HdSt_DrawBatchSharedPtr;
50 typedef std::vector<HdSt_DrawBatchSharedPtr> HdSt_DrawBatchSharedPtrVector;
51 
61 public:
62  HDST_API
64  HDST_API
65  ~HdStCommandBuffer();
66 
68  HDST_API
69  void PrepareDraw(HdStRenderPassStateSharedPtr const &renderPassState,
70  HdStResourceRegistrySharedPtr const &resourceRegistry);
71 
73  HDST_API
74  void ExecuteDraw(HdStRenderPassStateSharedPtr const &renderPassState,
75  HdStResourceRegistrySharedPtr const &resourceRegistry);
76 
78  HDST_API
79  void FrustumCull(GfMatrix4d const &cullMatrix);
80 
82  HDST_API
83  void SyncDrawItemVisibility(unsigned visChangeCount);
84 
87  HDST_API
88  void SwapDrawItems(std::vector<HdStDrawItem const*>* items,
89  unsigned currentBatchVersion);
90 
92  HDST_API
93  void RebuildDrawBatchesIfNeeded(unsigned currentBatchVersion);
94 
96  size_t GetTotalSize() const { return _drawItems.size(); }
97 
99  size_t GetVisibleSize() const { return _visibleSize; }
100 
102  size_t GetCulledSize() const {
103  return _drawItems.size() - _visibleSize;
104  }
105 
106  HDST_API
107  void SetEnableTinyPrimCulling(bool tinyPrimCulling);
108 
109 private:
110  void _RebuildDrawBatches();
111 
112  std::vector<HdStDrawItem const*> _drawItems;
113  std::vector<HdStDrawItemInstance> _drawItemInstances;
114  HdSt_DrawBatchSharedPtrVector _drawBatches;
115  size_t _visibleSize;
116  unsigned _visChangeCount;
117  unsigned _batchVersion;
118 };
119 
120 
121 PXR_NAMESPACE_CLOSE_SCOPE
122 
123 #endif //HDST_COMMAND_BUFFER_H
HDST_API void SyncDrawItemVisibility(unsigned visChangeCount)
Sync visibility state from RprimSharedState to DrawItemInstances.
HDST_API void RebuildDrawBatchesIfNeeded(unsigned currentBatchVersion)
Rebuild all draw batches if any underlying buffer array is invalidated.
HDST_API void PrepareDraw(HdStRenderPassStateSharedPtr const &renderPassState, HdStResourceRegistrySharedPtr const &resourceRegistry)
Prepare the command buffer for draw.
size_t GetVisibleSize() const
Returns the number of draw items, excluding culled items.
Definition: commandBuffer.h:99
A container to store instance state for a drawitem.
A buffer of commands (HdStDrawItem or HdComputeItem objects) to be executed.
Definition: commandBuffer.h:60
HDST_API void ExecuteDraw(HdStRenderPassStateSharedPtr const &renderPassState, HdStResourceRegistrySharedPtr const &resourceRegistry)
Execute the command buffer.
HDST_API void SwapDrawItems(std::vector< HdStDrawItem const * > *items, unsigned currentBatchVersion)
Destructively swaps the contents of items with the internal list of all draw items.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
size_t GetCulledSize() const
Returns the number of culled draw items.
HDST_API void FrustumCull(GfMatrix4d const &cullMatrix)
Cull drawItemInstances based on passed in combined view and projection matrix.
size_t GetTotalSize() const
Returns the total number of draw items, including culled items.
Definition: commandBuffer.h:96