-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderSet.cs
83 lines (75 loc) · 2.28 KB
/
RenderSet.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace Fractals
{
public class RenderSet
{
SortedDictionary<RenderOperation, object> renderSet = new SortedDictionary<RenderOperation, object>();
public IEnumerable<RenderOperation> RenderOperations {
get {
return renderSet.Keys;
}
}
public int Count {
get {
return renderSet.Count;
}
}
public RenderSet(RenderOperation root, int numberOfFragmentsToRender)
{
renderSet.Add(root, null);
while (renderSet.Count < numberOfFragmentsToRender) {
foreach (KeyValuePair<RenderOperation, object> kvp in renderSet) {
RenderOperation first = kvp.Key;
first.Fragment.MakeChilds();
renderSet.Remove(first);
AddOperation(first.LeftTopQuater);
AddOperation(first.RightTopQuater);
AddOperation(first.LeftBottomQuater);
AddOperation(first.RightBottomQuater);
break;
}
}
}
void AddOperation(RenderOperation op)
{
if (op.IsInViewFrustum) {
renderSet.Add(op, null);
}
}
public IEnumerable<RenderOperation> MakeRefineOperations(double pixelSize)
{
while(renderSet.Count > 0) {
foreach (KeyValuePair<RenderOperation, object> kvp in renderSet) {
RenderOperation first = kvp.Key;
renderSet.Remove(first);
// Terminate refinement?
double AAfactor = 1d + Math.Min(first.Fragment.MaxColorDifference / 16d, 3d);
if (first.TexelSize / 2 * AAfactor < pixelSize) break;
first.Fragment.MakeChilds();
if (first.LeftTopQuater.IsInViewFrustum) {
yield return first.LeftTopQuater;
renderSet.Add(first.LeftTopQuater, null);
}
if (first.RightTopQuater.IsInViewFrustum) {
yield return first.RightTopQuater;
renderSet.Add(first.RightTopQuater, null);
}
if (first.LeftBottomQuater.IsInViewFrustum) {
yield return first.LeftBottomQuater;
renderSet.Add(first.LeftBottomQuater, null);
}
if (first.RightBottomQuater.IsInViewFrustum) {
yield return first.RightBottomQuater;
renderSet.Add(first.RightBottomQuater, null);
}
break;
}
}
}
}
}