-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderOperation.cs
127 lines (108 loc) · 2.95 KB
/
RenderOperation.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
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
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Fractals
{
public class RenderOperation: IComparable<RenderOperation>
{
static long nextFreeId = 0;
long id;
RenderOperation parent;
Fragment fragment;
RectangleD dataSource;
RectangleD renderDestination;
Matrix rotation;
float distanceFromScreenCentre;
double priority;
public RenderOperation Parent {
get {
return parent;
}
}
public Fragment Fragment {
get {
return fragment;
}
}
public RectangleD DataSource {
get {
return dataSource;
}
}
public RectangleD RenderDestination {
get {
return renderDestination;
}
}
public Matrix Rotation {
get {
return rotation;
}
}
public RenderOperation LeftTopQuater {
get {
return new RenderOperation(this, fragment.ChildLT, dataSource.LeftTopQuater, renderDestination.LeftTopQuater, rotation);
}
}
public RenderOperation RightTopQuater {
get {
return new RenderOperation(this, fragment.ChildRT, dataSource.RightTopQuater, renderDestination.RightTopQuater, rotation);
}
}
public RenderOperation LeftBottomQuater {
get {
return new RenderOperation(this, fragment.ChildLB, dataSource.LeftBottomQuater , renderDestination.LeftBottomQuater, rotation);
}
}
public RenderOperation RightBottomQuater {
get {
return new RenderOperation(this, fragment.ChildRB, dataSource.RightBottomQuater, renderDestination.RightBottomQuater, rotation);
}
}
public double Priority {
get {
return priority;
}
}
float DistanceFromScreenCentre {
get {
return distanceFromScreenCentre;
}
}
public double TexelSize {
get {
return renderDestination.Width / Fragment.FragmentSize * 1.0d;
}
}
public bool IsInViewFrustum {
get {
return DistanceFromScreenCentre < 1 + 0.72d * renderDestination.Size;
}
}
public RenderOperation(RenderOperation parent, Fragment fragment, RectangleD dataSource, RectangleD renderDestination, Matrix rotation)
{
this.parent = parent;
this.fragment = fragment;
this.dataSource = dataSource;
this.renderDestination = renderDestination;
this.rotation = rotation;
this.id = nextFreeId++;
PointF[] center = new PointF[] {renderDestination.CentreF};
rotation.TransformPoints(center);
distanceFromScreenCentre = Math.Max(Math.Abs(center[0].X), Math.Abs(center[0].Y));
// Small means high-priority; big means low-priority
this.priority = fragment.Depth +
Math.Min(DistanceFromScreenCentre, 1d) * 0.5d +
-Math.Min(fragment.MaxColorDifference / 64d, 1d) * 2.5d;
}
public int CompareTo(RenderOperation op)
{
int comp = Priority.CompareTo(op.Priority);
if (comp == 0) {
return id.CompareTo(op.id);
} else {
return comp;
}
}
}
}