-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRenderCommon.h
More file actions
166 lines (140 loc) · 3.8 KB
/
RenderCommon.h
File metadata and controls
166 lines (140 loc) · 3.8 KB
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
#ifndef RENDERCOMMON_H
#define RENDERCOMMON_H
#include "Config.h"
namespace P3D
{
enum RenderFlags : unsigned int
{
NoFlags = 0ul,
ZTest = 1ul,
ZWrite = 2ul,
ZBuffer = ZTest | ZWrite,
AlphaTest = 4ul,
FullPerspectiveMapping = 16ul,
SubdividePerspectiveMapping = 32ul,
BackFaceCulling = 64ul,
FrontFaceCulling = 128ul,
Fog = 512ul,
VertexLight = 1024ul,
};
typedef enum FogMode : unsigned int
{
FogLinear = 0u, //Linear fog
FogExponential = 1u, //Exponential Fog
FogExponential2 = 2u, //Exponential Squared Fog
} FogMode;
class Material
{
public:
Material() {color = 0;};
enum MaterialType : unsigned int
{
Color = 0u,
Texture = 1u
};
MaterialType type = Color;
union
{
struct
{
const pixel* pixels;
bool alpha; //If pixel == 0. Don't draw.
};
struct
{
pixel color;
};
};
static constexpr unsigned int width = TEX_SIZE;
static constexpr unsigned int height = TEX_SIZE;
};
class RenderStats
{
public:
unsigned int vertex_transformed;
unsigned int triangles_submitted;
unsigned int triangles_drawn;
unsigned int scanlines_drawn;
unsigned int span_checks;
unsigned int span_count;
unsigned int triangles_clipped;
void ResetToZero()
{
vertex_transformed = 0;
triangles_submitted = 0;
triangles_drawn = 0;
scanlines_drawn = 0;
span_checks = 0;
span_count = 0;
triangles_clipped = 0;
}
};
namespace Internal
{
class RenderTargetViewport
{
public:
pixel* start = nullptr;
unsigned int width = 0;
unsigned int height = 0;
unsigned int y_pitch = 0;
z_val* z_start = nullptr;
unsigned int z_y_pitch;
};
class RenderDeviceNearFarPlanes
{
public:
fp z_near = 0;
fp z_far = 0;
fp z_ratio_1; // (far) / (far - near)
fp z_ratio_2; // (-far * near) / (far - near)
fp z_ratio_3; // (1/(far-near))
};
class RenderDeviceFogParameters
{
public:
RenderDeviceFogParameters() {}
fp fog_start;
fp fog_end;
fp fog_density;
FogMode mode = FogLinear;
pixel fog_color = 0;
};
typedef enum ClipPlane : unsigned int
{
NoClip = 0u,
W_Near = 1u,
X_W_Left = 2u,
X_W_Right = 4u,
Y_W_Top = 8u,
Y_W_Bottom = 16u,
W_Far = 32u,
} ClipPlane;
typedef enum ClipOperation : unsigned int
{
Accept = 0u, //No clip required.
Clip = 1u, //Clip required.
Reject = 2u //All out. Reject polygon.
} ClipOperation;
class Vertex4d
{
public:
V4<fp> pos;
V2<fp> uv;
fp fog_factor;
fp light_factor;
void toPerspectiveCorrect(const fp scale = fp(1))
{
pos.w = fp(scale) / pos.w;
uv.x = uv.x * pos.w;
uv.y = uv.y * pos.w;
}
};
class TransformedTriangle
{
public:
Vertex4d verts[8];
};
};
};
#endif // RENDERCOMMON_H