VTK  9.7.20260805
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
17
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
33VTK_ABI_NAMESPACE_BEGIN
34class vtkDataArray;
35class vtkWindow;
36
37class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLArrayTextureBufferCache : public vtkObject
38{
39public:
42 void PrintSelf(ostream& os, vtkIndent indent) override;
43
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
120
126 std::size_t RemoveTextureBuffer(vtkDataArray* array, vtkWindow* window);
127
133
134protected:
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
157private:
159 void operator=(const vtkOpenGLArrayTextureBufferCache&) = delete;
160};
161
162VTK_ABI_NAMESPACE_END
163#endif
a simple class to control print indentation
Definition vtkIndent.h:29
std::size_t GetCurrentCacheSize() const
Sum of GPU bytes held by all cached entries, computed on demand (the owning adapters may reallocate a...
std::tuple< vtkDataArray *, bool, bool > Key
std::uint64_t AccessCounter
Monotonic clock for Entry::LastAccess stamps.
static bool EntryIsPinned(const Entry &entry)
True when the entry's Texture or Buffer is referenced outside the entry itself (the entry accounts fo...
std::size_t GetNumberOfCachedTextureBuffers() const
Return the number of distinct (array, role) texture buffers currently cached.
std::size_t RemoveTextureBuffer(vtkDataArray *array, vtkWindow *window)
Erase every unpinned entry keyed on the given array (all layout variants).
static std::size_t GetEntrySize(const Entry &entry)
GPU bytes held by one entry: exact buffer size on desktop, computed from the emulation texture's dime...
static vtkOpenGLArrayTextureBufferCache * New()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void ReleaseGraphicsResources(vtkWindow *window)
Release the GL resources held by every cached entry and forget them.
unsigned long GetCPUMemorySize() const
Return the host-side memory, in KiB, consumed by the source arrays the cached entries keep alive.
std::shared_ptr< Entry > GetTextureBuffer(vtkDataArray *array, bool scalarComponents, bool integerTexture)
Return the shared entry for the given (array, scalarComponents, integerTexture), creating an empty en...
static void ReleaseEntry(Entry &entry, vtkWindow *window)
Release the entry's GL objects and reset it to the never-uploaded state.
void RemoveUnusedTextureBuffers(vtkWindow *window)
Eviction ladder is:
std::map< Key, std::shared_ptr< Entry > > Cache
Hold a reference to a vtkObjectBase instance.
window superclass for vtkRenderWindow
Definition vtkWindow.h:43
A cached texture buffer for one (array, role).
vtkSmartPointer< vtkOpenGLBufferObject > Buffer
std::uint64_t LastAccess
Monotonic stamp of the last GetTextureBuffer() that returned this entry; orders entries least-recentl...
#define vtkDataArray
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:318