-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMundus.Types.pas
151 lines (122 loc) · 3 KB
/
Mundus.Types.pas
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
unit Mundus.Types;
interface
uses
Mundus.Math;
type
TRGB32 = packed record
B, G, R, A: Byte;
end;
PRGB32 = ^TRGB32;
TRGB32Array = packed array[0..MaxInt div SizeOf(TRGB32)-1] of TRGB32;
PRGB32Array = ^TRGB32Array;
TDepthBuffer = array of array of Single;
PDepthsBuffer = ^TDepthBuffer;
TVertexAttributeBuffer = TArray<Byte>;
TRasterizer = procedure(
AMaxResolutionX, AMaxResolutionY: Integer;
const AVerctorA, AvectorB, AvectorC: TFloat4;
const AAttributesA, AAttributesB, AAttributesC: TVertexAttributeBuffer;
AShader: TObject;
APixelBuffer: PRGB32Array;
ADepthBuffer: PDepthsBuffer;
ABlockOffset, ABlockStep: Integer);
TVector = record
X, Y, Z: Integer;
constructor Create(AX, AY, AZ: Integer);
end;
TUV = record
U, V: Single;
end;
TTriangle = record
VertexA, VertexB, VertexC: Integer;
UVA, UVB, UVC: TUV;
end;
PTriangle = ^TTriangle;
TVectorClass = class
private
FX, FY, FZ: Integer;
public
constructor Create(AX, AY, AZ: Integer);
property X: Integer read FX write FX;
property Y: Integer read FY write FY;
property Z: Integer read FZ write FZ;
end;
TTriangleClass = class
private
FVertexA, FVertexB, FVertexC: Integer;
FUVB: TUV;
FUVC: TUV;
FUVA: TUV;
public
constructor Create(AVertexA, AvertexB, AvertexC: Integer);
procedure SetUV(AUVA, AUVB, AUVC: TUV);
property VertexA: Integer read FVertexA write FVertexA;
property VertexB: Integer read FVertexB write FVertexB;
property VertexC: Integer read FVertexC write FVertexC;
property UVA: TUV read FUVA write FUVA;
property UVB: TUV read FUVB write FUVB;
property UVC: TUV read FUVC write FUVC;
end;
function Vector(AX, AY, AZ: Integer): TVector;
function UV(AU, AV: Single): TUV;
function Triangle(AVertexA, AVertexB, AVertexC: Integer): TTriangle;
function RGB32(R, G, B, A: Byte): TRGB32;
const
CQuadSize = 8;
implementation
{ TTriangleClass }
constructor TTriangleClass.Create(AVertexA, AvertexB, AvertexC: Integer);
begin
FVertexA := AVertexA;
FVertexB := AvertexB;
FVertexC := AvertexC;
FUVA := UV(0, 0);
FUVB := UV(0, 0);
FUVC := UV(0, 0);
end;
procedure TTriangleClass.SetUV(AUVA, AUVB, AUVC: TUV);
begin
FUVA := AUVA;
FUVB := AUVB;
FUVC := AUVC;
end;
{ TVectorClass }
constructor TVectorClass.Create(AX, AY, AZ: Integer);
begin
FX := AX;
FY := AY;
FZ := AZ;
end;
{ Some Functions }
function Vector(AX, AY, AZ: Integer): TVector;
begin
Result.X := AX;
Result.Y := AY;
Result.Z := AZ;
end;
function Triangle(AVertexA, AVertexB, AVertexC: Integer): TTriangle;
begin
Result.VertexA := AVertexA;
Result.VertexB := AVertexB;
Result.VertexC := AVertexC;
end;
function UV(AU, AV: Single): TUV;
begin
Result.U := AU;
Result.V := AV;
end;
{ TVector }
constructor TVector.Create(AX, AY, AZ: Integer);
begin
X := AX;
Y := AY;
Z := AZ;
end;
function RGB32(R, G, B, A: Byte): TRGB32;
begin
Result.R := R;
Result.G := G;
Result.B := B;
Result.A := A;
end;
end.