VTK  9.7.1
vtkOpenGLArrayTextureBufferCache.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
18 #ifndef vtkOpenGLArrayTextureBufferCache_h
19 #define vtkOpenGLArrayTextureBufferCache_h
20 
21 #include "vtkObject.h"
22 #include "vtkOpenGLBufferObject.h" // for entry ivar
23 #include "vtkRenderingOpenGL2Module.h" // For export macro
24 #include "vtkSmartPointer.h" // for entry ivars
25 #include "vtkTextureObject.h" // for entry ivar
26 
27 #include <cstddef> // for std::size_t
28 #include <cstdint> // for std::uint64_t
29 #include <map> // for cache map
30 #include <memory> // for shared_ptr
31 #include <tuple> // for composite key
32 
33 VTK_ABI_NAMESPACE_BEGIN
34 class vtkDataArray;
35 class vtkWindow;
36 
37 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLArrayTextureBufferCache : public vtkObject
38 {
39 public:
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
52  struct Entry
53  {
57  vtkMTimeType UploadTime = 0;
60  std::uint64_t LastAccess = 0;
61  };
62 
70  std::shared_ptr<Entry> GetTextureBuffer(
71  vtkDataArray* array, bool scalarComponents, bool integerTexture);
72 
79  std::size_t GetNumberOfCachedTextureBuffers() const { return this->Cache.size(); }
80 
85  unsigned long GetCPUMemorySize() const;
86 
88 
95  vtkSetMacro(MaximumCacheSize, std::size_t);
96  vtkGetMacro(MaximumCacheSize, std::size_t);
98 
104  std::size_t GetCurrentCacheSize() const;
105 
119  void RemoveUnusedTextureBuffers(vtkWindow* window);
120 
126  std::size_t RemoveTextureBuffer(vtkDataArray* array, vtkWindow* window);
127 
132  void ReleaseGraphicsResources(vtkWindow* window);
133 
134 protected:
137 
140  static std::size_t GetEntrySize(const Entry& entry);
141 
145  static bool EntryIsPinned(const Entry& entry);
146 
148  static void ReleaseEntry(Entry& entry, vtkWindow* window);
149 
150  using Key = std::tuple<vtkDataArray*, bool, bool>;
151  std::map<Key, std::shared_ptr<Entry>> Cache;
152 
153  std::size_t MaximumCacheSize = 256 * 1024 * 1024;
155  std::uint64_t AccessCounter = 0;
156 
157 private:
159  void operator=(const vtkOpenGLArrayTextureBufferCache&) = delete;
160 };
161 
162 VTK_ABI_NAMESPACE_END
163 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
vtkSmartPointer< vtkOpenGLBufferObject > Buffer
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
manage texture-buffer-backed data arrays shared within a context
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
std::size_t GetNumberOfCachedTextureBuffers() const
Return the number of distinct (array, role) texture buffers currently cached.
A cached texture buffer for one (array, role).
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
std::map< Key, std::shared_ptr< Entry > > Cache
std::tuple< vtkDataArray *, bool, bool > Key