All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cache.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 USDKATANA_CACHE_H
25 #define USDKATANA_CACHE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/stage.h"
29 #include "pxr/usd/sdf/declareHandles.h"
30 #include "pxr/usdImaging/usdImagingGL/engine.h"
31 #include "pxr/base/tf/singleton.h"
32 
33 #include <boost/shared_ptr.hpp>
34 
35 #include <map>
36 #include <string>
37 
38 #include <FnAttribute/FnAttribute.h>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
43 // Forward declare pointers.
44 SDF_DECLARE_HANDLES(SdfLayer);
46 typedef boost::shared_ptr<class UsdImagingGLEngine> UsdImagingGLEngineSharedPtr;
47 class SdfPath;
48 class UsdPrim;
49 
50 /*
51  * Custom cache singleton class for katana. Hold the usd stage and renderer.
52  * The stage returned by this cache helper is meant to be read only. The
53  * session layer will be locked for editing.
54  */
55 class UsdKatanaCache : public TfSingleton<UsdKatanaCache>
56 {
57  friend class TfSingleton<UsdKatanaCache>;
58 
59  UsdKatanaCache();
60 
63  SdfLayerRefPtr& _FindOrCreateSessionLayer(
64  FnAttribute::GroupAttribute sessionAttr,
65  const std::string& rootLocation);
66 
67 
69  static void _SetMutedLayers(
70  const UsdStageRefPtr &stage, const std::string &layerRegex);
71 
72  typedef std::map<std::string, UsdImagingGLEngineSharedPtr> _RendererCache;
73 
74  std::string _ComputeCacheKey(FnAttribute::GroupAttribute sessionAttr,
75  const std::string& rootLocation);
76 
77  std::map<std::string, SdfLayerRefPtr> _sessionKeyCache;
78  _RendererCache _rendererCache;
79 
80 public:
81 
82  static UsdKatanaCache& GetInstance() {
84  }
85 
87  void Flush();
88 
89 
92  UsdStageRefPtr GetStage(std::string const& fileName,
93  FnAttribute::GroupAttribute sessionAttr,
94  const std::string & sessionRootLocation,
95  std::string const& ignoreLayerRegex,
96  bool forcePopulate);
97 
98  // Equivalent to GetStage above but without caching
99  UsdStageRefPtr GetUncachedStage(std::string const& fileName,
100  FnAttribute::GroupAttribute sessionAttr,
101  const std::string & sessionRootLocation,
102  std::string const& ignoreLayerRegex,
103  bool forcePopulate);
104 
106  void FlushStage(const UsdStageRefPtr & stage);
107 
108 
109 
110 
112  UsdImagingGLEngineSharedPtr const& GetRenderer(UsdStageRefPtr const& stage,
113  UsdPrim const& root,
114  std::string const& sessionKey);
115 
117  SdfLayerRefPtr FindSessionLayer(
118  FnAttribute::GroupAttribute sessionAttr,
119  const std::string& rootLocation);
120 
121 
122  SdfLayerRefPtr FindSessionLayer(
123  const std::string& cacheKey) ;
124 
125 
126  SdfLayerRefPtr FindOrCreateSessionLayer(
127  const std::string& sessionAttrXML,
128  const std::string& rootLocation);
129 
130 
131 
132 };
133 
134 
135 PXR_NAMESPACE_CLOSE_SCOPE
136 
137 #endif // USDKATANA_CACHE_H
A unit of scene description that you combine with other units of scene description to form a shot...
Definition: layer.h:93
Manage a single instance of an object (see.
Definition: singleton.h:122
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:137