-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixelManager.h
257 lines (212 loc) · 7.52 KB
/
PixelManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#pragma once
#include <queue>
class RasterizingInterface {
public:
virtual ~RasterizingInterface();
virtual bool GetCoordinate(HRReal &Real, HRReal &Imaginary) = 0;
virtual void WriteResults(SRReal Value) = 0;
};
class GroupedRasterizingInterface {
public:
virtual ~GroupedRasterizingInterface();
virtual size_t GetCoordinate(HRReal *Real, HRReal *Imaginary) = 0;
virtual void WriteResults(SRReal *Values) = 0;
};
class DefaultGroupedRasterizerInterface : public GroupedRasterizingInterface {
friend class PixelManager;
size_t GroupSize;
size_t ValidCount;
size_t *ValidList;
RasterizingInterface **Interfaces;
public:
inline DefaultGroupedRasterizerInterface(size_t GroupSize, RasterizingInterface **Interfaces) : GroupSize(GroupSize), Interfaces(Interfaces) {
ValidList = new size_t[GroupSize];
}
virtual ~DefaultGroupedRasterizerInterface() override;
virtual size_t GetCoordinate(HRReal *Real, HRReal *Imaginary) override;
virtual void WriteResults(SRReal *Values) override;
};
class PixelManager {
public:
virtual ~PixelManager();
virtual void Clear() = 0;
virtual void SetResolution(int32_t Width, int32_t Height);
virtual void UpdateRelativeCoordinate(HRReal OffsetX, HRReal OffsetY) = 0;
virtual void SetLocation(RelLocation &Location) = 0;
virtual void Begin() = 0;
virtual RasterizingInterface &GetInterface() = 0;
virtual GroupedRasterizingInterface &GetGroupedInterface(size_t GroupSize);
virtual void FreeInterface(RasterizingInterface &Interface);
virtual void FreeInterface(GroupedRasterizingInterface &Interface);
virtual bool Completed() = 0;
virtual void Abort();
virtual void GetTextures(TextureDescription *TD, size_t NumDesired, size_t &NumObtained) = 0;
};
class StandardRI;
class StandardGRI;
class StandardPixelManager : public PixelManager, public ProgressTrackable {
public:
int32_t Width = 2048, Height = 1024;
int32_t TextureWidth, TextureHeight;
static constexpr size_t DoublingCount = 8;
static constexpr size_t PassCount = DoublingCount * 2 + 1;
static constexpr IntPix PixelGroupWidth = 2;
static constexpr IntPix PixelGroupHeight = 2;
static constexpr size_t PixelGroupSize = size_t(PixelGroupWidth) * PixelGroupHeight;
HRReal AspectRatio;
GLuint TextureID = 0;
GLuint PrevTextureID = 0;
size_t NumPrevTDs = 0;
TextureDescription PrevTDs[16];
RelRect TexRect = {};
RelLocation CurrentLocation = {};
RelLocation Origin;
HRReal OriginOffsetX, OriginOffsetY;
float *Data = nullptr;
std::atomic_uint i = 0;
bool PixelReused = false;
bool OverwriteReused = false;
bool PixelValid = false;
enum class PassType {
Full = 0,
//XDoubling,
//YDoubling,
XDoublingPos = 0b100,
XDoublingNeg = 0b101,
YDoublingPos = 0b110,
YDoublingNeg = 0b111,
};
struct PassInfo {
PassType Type;
int32_t Width, Height;
int32_t PixelSizeExpX, PixelSizeExpY;
uint32_t X, Y;
size_t Begin, End;
uint32_t PixelGroupSize;
int32_t CoordOffsetX, CoordOffsetY;
};
struct Coordinate {
int32_t X, Y;
};
HRReal PixelSize;
Coordinate *Coordinates = nullptr;
PassInfo Passes[PassCount];
size_t CurrentPass;
size_t MinPassBeforeAbort;
size_t PixelCount, PixelGroupCount;
bool idle = true;
bool abort = false;
bool NeedUpdateTexture = false;
size_t ReusedPass = 0;
std::mutex InterfaceListMutex;
StandardRI *FirstInterface = nullptr;
StandardRI *FirstCopyPendingInterface = nullptr;
StandardGRI *FirstVInterface = nullptr;
StandardGRI *FirstCopyPendingVInterface = nullptr;
private:
void Init();
void InvalidatePass(size_t Pass);
void AlignPass(size_t Pass, int32_t &DiffX, int32_t &DiffY);
void MovePass(size_t Pass, int32_t DiffX, int32_t DiffY);
void ShiftDownPass(size_t DstPass, int32_t DiffX, int32_t DiffY);
void ShiftUpPass(size_t DstPass, int32_t DiffX, int32_t DiffY);
void MoveImageStack(int32_t DiffX, int32_t DiffY);
void ShiftDownImageStack(int32_t DiffX, int32_t DiffY);
void ShiftUpImageStack(int32_t DiffX, int32_t DiffY);
public:
StandardPixelManager();
virtual ~StandardPixelManager() override;
void ChangeMaxit(uint64_t OldMaxIt);
virtual void Clear() override;
virtual void SetResolution(int32_t Width, int32_t Height) override;
virtual void UpdateRelativeCoordinate(HRReal OffsetX, HRReal OffsetY) override;
void RemovePrevTextures();
virtual void SetLocation(RelLocation &Location) override;
virtual void Begin() override;
virtual RasterizingInterface &GetInterface() override;
virtual GroupedRasterizingInterface &GetGroupedInterface(size_t GroupSize) override;
virtual void FreeInterface(RasterizingInterface &Interface) override;
virtual void FreeInterface(GroupedRasterizingInterface &Interface) override;
virtual bool Completed() override;
virtual void Abort() override;
virtual void GetTextures(TextureDescription *TD, size_t NumDesired, size_t &NumObtained) override;
virtual bool GetProgress(SRReal &Numerator, SRReal &Denoninator) const override;
};
class StandardRI : public RasterizingInterface {
friend class StandardPixelManager;
StandardPixelManager &R;
size_t Pass = 0;
size_t End = 0, j = 0;
StandardPixelManager::Coordinate Coord;
StandardRI *PrevInterface = nullptr;
StandardRI *NextInterface = nullptr;
IntPix XInGroup = 0, YInGroup = StandardPixelManager::PixelGroupHeight;
struct Copy {
size_t DstIndex, SrcIndex;
Copy() = default;
Copy(size_t dst, size_t src) :DstIndex(dst), SrcIndex(src) {}
};
std::queue<Copy> CopyQueue;
bool TryCopyData();
void CopyData();
public:
inline StandardRI(StandardPixelManager &r) : R(r) {}
~StandardRI() override;
virtual bool GetCoordinate(HRReal &Real, HRReal &Imaginary) override;
virtual void WriteResults(SRReal Value) override;
};
class StandardGRI : public GroupedRasterizingInterface {
friend class StandardPixelManager;
StandardPixelManager &R;
//int I;
size_t Pass = 0;
size_t i = 0, j = 0;
StandardPixelManager::Coordinate Coord[4];
StandardGRI *PrevInterface = nullptr;
StandardGRI *NextInterface = nullptr;
struct Copy {
size_t DstIndex, SrcIndex;
Copy() = default;
Copy(size_t dst, size_t src) :DstIndex(dst), SrcIndex(src) {}
};
std::queue<Copy> CopyQueue;
bool TryCopyData();
void CopyData();
public:
inline StandardGRI(StandardPixelManager &r) : R(r) {}
~StandardGRI() override;
virtual size_t GetCoordinate(HRReal *Real, HRReal *Imaginary) override;
virtual void WriteResults(SRReal *Values) override;
};
class BasicPixelManager : public PixelManager {
public:
GLuint TextureID = 0;
RelLocation CurrentLocation = {};
//RelRect TexRect = {};
float *Data = nullptr;
std::atomic_uint i = 0;
uint32_t Width = 2560, Height = 1440;
size_t PixelCount;
class Interface : public RasterizingInterface {
BasicPixelManager &R;
int32_t x, y;
public:
inline Interface(BasicPixelManager &r) : R(r) {}
virtual bool GetCoordinate(HRReal &Real, HRReal &Imaginary) override;
virtual void WriteResults(SRReal Value) override;
};
BasicPixelManager();
virtual ~BasicPixelManager() override;
virtual void Clear() override;
virtual void SetResolution(int32_t Width, int32_t Height) override;
virtual void UpdateRelativeCoordinate(HRReal OffsetX, HRReal OffsetY) override;
virtual void SetLocation(RelLocation &Location) override;
virtual void Begin() override;
virtual RasterizingInterface &GetInterface() override;
//virtual TempRasterizerInterfaceVec4 &GetInterfaceVec4();
//virtual void FreeInterface(RasterizingInterface &Interface) override;
//virtual void FreeInterface(TempRasterizerInterfaceVec4 &Interface);
virtual bool Completed() override;
virtual void Abort() override;
virtual void GetTextures(TextureDescription *TD, size_t NumDesired, size_t &NumObtained) override;
};