Nameless Engine
Loading...
Searching...
No Matches
ShaderArrayIndexManager.h
1#pragma once
2
3// Standard.
4#include <string>
5#include <queue>
6#include <mutex>
7#include <memory>
8
9namespace ne {
10 class ShaderArrayIndexManager;
11
19
20 public:
21 ShaderArrayIndex() = delete;
22
23 ShaderArrayIndex(const ShaderArrayIndex&) = delete;
24 ShaderArrayIndex& operator=(const ShaderArrayIndex&) = delete;
25
27 ShaderArrayIndex& operator=(ShaderArrayIndex&&) = delete;
28
34 unsigned int getActualIndex() const;
35
38
39 private:
47
50
53 };
54
62 // Indices notify the manager in their destructor about no longer being used.
63 friend class ShaderArrayIndex;
64
65 public:
66 ShaderArrayIndexManager() = delete;
67
77 ShaderArrayIndexManager(const std::string& sName, unsigned int iArraySize);
78
81
87 std::unique_ptr<ShaderArrayIndex> reserveIndex();
88
89 private:
95 void onIndexNoLongerUsed(unsigned int iIndex);
96
98 struct InternalData {
99 InternalData() = default;
100
102 std::queue<unsigned int> noLongerUsedIndices;
103
105 unsigned int iNextFreeIndex = 0;
106
112 };
113
115 std::pair<std::recursive_mutex, InternalData> mtxData;
116
121 const unsigned int iArraySize = 0;
122
124 const std::string sName;
125 };
126}
Definition: ShaderArrayIndexManager.h:61
std::pair< std::recursive_mutex, InternalData > mtxData
Definition: ShaderArrayIndexManager.h:115
const std::string sName
Definition: ShaderArrayIndexManager.h:124
const unsigned int iArraySize
Definition: ShaderArrayIndexManager.h:121
~ShaderArrayIndexManager()
Definition: ShaderArrayIndexManager.cpp:19
std::unique_ptr< ShaderArrayIndex > reserveIndex()
Definition: ShaderArrayIndexManager.cpp:36
void onIndexNoLongerUsed(unsigned int iIndex)
Definition: ShaderArrayIndexManager.cpp:77
Definition: ShaderArrayIndexManager.h:16
unsigned int getActualIndex() const
Definition: ShaderArrayIndexManager.cpp:103
~ShaderArrayIndex()
Definition: ShaderArrayIndexManager.cpp:105
ShaderArrayIndexManager * pManager
Definition: ShaderArrayIndexManager.h:49
unsigned int iIndexIntoShaderArray
Definition: ShaderArrayIndexManager.h:52
Definition: ShaderArrayIndexManager.h:98
std::queue< unsigned int > noLongerUsedIndices
Definition: ShaderArrayIndexManager.h:102
unsigned int iNextFreeIndex
Definition: ShaderArrayIndexManager.h:105
size_t iActiveIndexCount
Definition: ShaderArrayIndexManager.h:111