-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpostrender.cpp
207 lines (172 loc) · 6.37 KB
/
postrender.cpp
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
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF OUTRAGE
ENTERTAINMENT, INC. ("OUTRAGE"). OUTRAGE, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1996-2000 OUTRAGE ENTERTAINMENT, INC. ALL RIGHTS RESERVED.
*/
#ifdef NEWEDITOR // include first to get rid of ugly warning message about macro redfinitions
#include "..\neweditor\globals.h"
#endif
#include <stdlib.h>
#include "object.h"
#include "viseffect.h"
#include "render.h"
#include "renderobject.h"
#include "room.h"
#include "postrender.h"
#include "config.h"
#include "terrain.h"
#include "renderer.h"
postrender_struct Postrender_list[MAX_POSTRENDERS];
int Num_postrenders = 0;
static vector Viewer_eye;
static matrix Viewer_orient;
static int Viewer_roomnum;
// Resets out postrender list for a new frame
void ResetPostrenderList() { Num_postrenders = 0; }
// Compare function for room face sort
static int Postrender_sort_func(const postrender_struct *a, const postrender_struct *b) {
if (a->z < b->z)
return -1;
else if (a->z > b->z)
return 1;
else
return 0;
}
#define STATE_PUSH(val) \
{ \
state_stack[state_stack_counter] = val; \
state_stack_counter++; \
ASSERT(state_stack_counter < 2000); \
}
#define STATE_POP() \
{ \
state_stack_counter--; \
pop_val = state_stack[state_stack_counter]; \
}
// Sorts our texture states using the quicksort algorithm
void SortPostrenders() {
postrender_struct v, t;
int pop_val;
int i, j;
int l, r;
l = 0;
r = Num_postrenders - 1;
ushort state_stack_counter = 0;
ushort state_stack[MAX_POSTRENDERS];
while (1) {
while (r > l) {
i = l - 1;
j = r;
v = Postrender_list[r];
while (1) {
while (Postrender_list[++i].z < v.z)
;
while (Postrender_list[--j].z > v.z)
;
if (i >= j)
break;
t = Postrender_list[i];
Postrender_list[i] = Postrender_list[j];
Postrender_list[j] = t;
}
t = Postrender_list[i];
Postrender_list[i] = Postrender_list[r];
Postrender_list[r] = t;
if (i - l > r - i) {
STATE_PUSH(l);
STATE_PUSH(i - 1);
l = i + 1;
} else {
STATE_PUSH(i + 1);
STATE_PUSH(r);
r = i - 1;
}
}
if (!state_stack_counter)
break;
STATE_POP();
r = pop_val;
STATE_POP();
l = pop_val;
}
}
void SetupPostrenderRoom(room *rp) {
// Setup faces if this is a fogged room
if (rp->flags & RF_FOG)
SetupRoomFog(rp, &Viewer_eye, &Viewer_orient, Viewer_roomnum);
}
// Rotates a face, and then renders it
void DrawPostrenderFace(int roomnum, int facenum, bool change_z) {
int i;
// Always draw as non state limited
bool save_state = StateLimited;
StateLimited = false;
ASSERT(roomnum >= 0 && roomnum < (MAX_ROOMS + MAX_PALETTE_ROOMS));
ASSERT(Rooms[roomnum].used);
room *rp = &Rooms[roomnum];
ASSERT(facenum >= 0 && facenum < rp->num_faces);
face *fp = &rp->faces[facenum];
// Rotate points
rp->wpb_index = 0;
for (i = 0; i < fp->num_verts; i++) {
g3_RotatePoint((g3Point *)&World_point_buffer[fp->face_verts[i]], &rp->verts[fp->face_verts[i]]);
g3_ProjectPoint((g3Point *)&World_point_buffer[fp->face_verts[i]]);
}
SetupPostrenderRoom(rp);
// Render!
use_opengl_1555_format = 1; // DAJ
if (change_z)
rend_SetZBufferWriteMask(0);
RenderFace(rp, facenum);
use_opengl_1555_format = 0; // DAJ
// Render any effects for this face
if (Num_specular_faces_to_render > 0) {
RenderSpecularFacesFlat(rp);
Num_specular_faces_to_render = 0;
}
if (Num_fog_faces_to_render > 0) {
RenderFogFaces(rp);
Num_fog_faces_to_render = 0;
}
// Restore statelimited setting
StateLimited = save_state;
if (change_z)
rend_SetZBufferWriteMask(1);
}
// Renders all the objects/viseffects/walls we have in our postrender list
void PostRender(int roomnum) {
g3_GetViewPosition(&Viewer_eye);
g3_GetUnscaledMatrix(&Viewer_orient);
Viewer_roomnum = roomnum;
int i, index;
// Sort the objects
SortPostrenders();
// qsort(Postrender_list,Num_postrenders,sizeof(*Postrender_list),(int (cdecl *)(const void*,const
// void*))Postrender_sort_func);
for (i = Num_postrenders - 1; i >= 0; i--) {
if (Postrender_list[i].type == PRT_VISEFFECT) {
index = Postrender_list[i].visnum;
DrawVisEffect(&VisEffects[index]);
} else if (Postrender_list[i].type == PRT_OBJECT) {
object *objp = &Objects[Postrender_list[i].objnum];
if (!OBJECT_OUTSIDE(&Objects[Postrender_list[i].objnum]))
SetupPostrenderRoom(&Rooms[Objects[Postrender_list[i].objnum].roomnum]);
RenderObject(objp);
} else {
// Do room face
DrawPostrenderFace(Postrender_list[i].roomnum, Postrender_list[i].facenum);
}
}
Num_postrenders = 0;
rend_SetFogState(0);
use_opengl_1555_format = 2; // DAJ
RenderLightGlows();
use_opengl_1555_format = 0; // DAJ
}