1 //----------------------------------------------------------------------------
2 //  EDGE OpenGL Rendering (Definitions)
3 //----------------------------------------------------------------------------
4 //
5 //  Copyright (c) 1999-2009  The EDGE Team.
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //----------------------------------------------------------------------------
18 //
19 //  Based on the DOOM source code, released by Id Software under the
20 //  following copyright:
21 //
22 //    Copyright (C) 1993-1996 by id Software, Inc.
23 //
24 //----------------------------------------------------------------------------
25 
26 #ifndef __RGL_DEFS__
27 #define __RGL_DEFS__
28 
29 #include "ddf/main.h"
30 #include "ddf/image.h"
31 
32 #include "r_defs.h"
33 
34 #include <list>
35 #include <vector>
36 
37 
38 extern cvar_c r_colorlighting;
39 extern cvar_c r_colormaterial;
40 
41 extern cvar_c r_dumbsky;
42 extern cvar_c r_dumbmulti;
43 extern cvar_c r_dumbcombine;
44 extern cvar_c r_dumbclamp;
45 
46 
47 //
48 //  RGL_MAIN
49 //
50 
51 extern int glmax_lights;
52 extern int glmax_clip_planes;
53 extern int glmax_tex_size;
54 extern int glmax_tex_units;
55 
56 void RGL_Init(void);
57 void RGL_SoftInit(void);
58 void RGL_DrawProgress(int perc, int glbsp_perc);
59 void RGL_SetupMatrices2D(void);
60 void RGL_SetupMatrices3D(void);
61 
62 #define LT_RED(light)  (MIN(255,light) * ren_red_mul / 255.0f)
63 #define LT_GRN(light)  (MIN(255,light) * ren_grn_mul / 255.0f)
64 #define LT_BLU(light)  (MIN(255,light) * ren_blu_mul / 255.0f)
65 
66 
67 //
68 // RGL_TEX
69 //
70 const byte *RGL_LogoImage(int *w, int *h);
71 const byte *RGL_InitImage(int *w, int *h);
72 const byte *RGL_GlbspImage(int *w, int *h);
73 const byte *RGL_BuildImage(int *w, int *h);
74 const byte *RGL_BetaImage(int *w, int *h);
75 
76 
77 //
78 //  RGL_BSP
79 //
80 
81 void RGL_LoadLights(void);
82 
83 extern int ren_extralight;
84 
85 extern float ren_red_mul;
86 extern float ren_grn_mul;
87 extern float ren_blu_mul;
88 
89 extern const colourmap_c *ren_fx_colmap;
90 
91 extern int doom_fading;
92 
93 extern cvar_c r_aspect;
94 
95 extern cvar_c r_nearclip;
96 extern cvar_c r_farclip;
97 
98 #define APPROX_DIST2(dx,dy)  \
99 	((dx) + (dy) - 0.5f * MIN((dx),(dy)))
100 
101 #define APPROX_DIST3(dx,dy,dz)  \
102 	APPROX_DIST2(APPROX_DIST2(dx,dy),dz)
103 
104 
105 //----------------------------------------------------------------------------
106 
107 struct drawfloor_s;
108 
109 class drawsub_c;
110 
111 
112 typedef enum
113 {
114 	YCLIP_Never = 0,
115 	YCLIP_Soft  = 1, // only clip at translucent water
116 	YCLIP_Hard  = 2, // vertically clip sprites at all solid surfaces
117 }
118 y_clip_mode_e;
119 
120 
121 //
122 // DrawThing
123 //
124 // Stores the info about a single visible sprite in a subsector.
125 //
126 typedef struct drawthing_s
127 {
128 public:
129 	// link for list
130 	struct drawthing_s *next;
131 	struct drawthing_s *prev;
132 
133 	// actual map object
134 	mobj_t *mo;
135 
136 	bool is_model;
137 
138 	float mx, my, mz;  // mz only used for models
139 
140 	// vertical extent of sprite (world coords)
141 	float top;
142 	float bottom;
143 
144 	int y_clipping;
145 
146 	// sprite image to use
147 	const image_c *image;
148 	bool flip;
149 
150 	// translated coords
151 	float tx, tz;
152 
153 	// colourmap/lighting
154 	region_properties_t *props;
155 
156 	// world offsets for GL
157 	float left_dx,  left_dy;
158 	float right_dx, right_dy;
159 	float orig_top, orig_bottom;
160 
161 	// Rendering order
162 	struct drawthing_s *rd_l, *rd_r, *rd_prev, *rd_next;
163 
164 public:
Cleardrawthing_s165 	void Clear()
166 	{
167 		next = prev = NULL;
168 		mo = NULL;
169 		image = NULL;
170 		props = NULL;
171 		rd_l = rd_r = rd_prev = rd_next = NULL;
172 	}
173 }
174 drawthing_t;
175 
176 
177 //
178 // DrawFloor
179 //
180 // Stores all the information needed to draw a single on-screen
181 // floor of a subsector.
182 //
183 typedef struct drawfloor_s
184 {
185 public:
186 	short is_lowest;
187 	short is_highest;
188 
189 	// link for list, rendering order
190 	struct drawfloor_s *next_R, *prev_R;
191 
192 	// heights for this floor
193 	float f_h, c_h, top_h;
194 
195 	surface_t *floor, *ceil;
196 
197 	extrafloor_t *ef;
198 
199 	// properties used herein
200 	region_properties_t *props;
201 
202 	// list of things
203 	// (not sorted until R2_DrawFloor is called).
204 	drawthing_t *things;
205 
206 public:
Cleardrawfloor_s207 	void Clear()
208 	{
209 		is_highest = is_lowest = false;
210 		next_R = prev_R = NULL;
211 		floor = ceil = NULL;
212 		ef = NULL;
213 		props = NULL;
214 		things = NULL;
215 	}
216 }
217 drawfloor_t;
218 
219 
220 class drawmirror_c
221 {
222 public:
223 	seg_t *seg;
224 
225 	angle_t left, right;
226 
227 	bool is_portal;
228 
229 	std::list<drawsub_c *> drawsubs;
230 
231 public:
drawmirror_c()232 	drawmirror_c() : seg(NULL), is_portal(false), drawsubs()
233 	{ }
234 
~drawmirror_c()235 	~drawmirror_c()
236 	{ /* FIXME !!!! */ }
237 
Clear(seg_t * ss)238 	void Clear(seg_t *ss)
239 	{
240 		seg  = ss;
241 
242 		drawsubs.clear();
243 	}
244 };
245 
246 
247 class drawseg_c   // HOPEFULLY this can go away
248 {
249 public:
250 	seg_t *seg;
251 };
252 
253 
254 class drawsub_c
255 {
256 public:
257 	subsector_t *sub;
258 
259     // floors, sorted in height order (lowest to highest).
260 	std::vector<drawfloor_t *> floors;
261 
262 	// link list of floors, render order (furthest to closest)
263 	drawfloor_t *floors_R;
264 
265 	std::list<drawseg_c *> segs;
266 
267 	std::list<drawmirror_c *> mirrors;
268 
269 	bool visible;
270 	bool sorted;
271 
272 public:
drawsub_c()273 	drawsub_c() : sub(NULL), floors(), segs(), mirrors()
274 	{ }
275 
~drawsub_c()276 	~drawsub_c()
277 	{ /* !!!! FIXME */ }
278 
Clear(subsector_t * ss)279 	void Clear(subsector_t *ss)
280 	{
281 		sub = ss;
282 		visible = false;
283 		sorted  = false;
284 		floors_R = NULL;
285 
286 		floors.clear();
287 		segs.clear();
288 		mirrors.clear();
289 	}
290 };
291 
292 
293 extern int detail_level;
294 extern int use_dlights;
295 extern int sprite_kludge;
296 
297 const image_c * R2_GetThingSprite(mobj_t *mo, bool *flip);
298 const image_c * R2_GetOtherSprite(int sprite, int frame, bool *flip);
299 
300 
301 //
302 //  R2_UTIL
303 //
304 
305 void R2_InitUtil(void);
306 void R2_ClearBSP(void);
307 
308 drawthing_t  *R_GetDrawThing();
309 drawfloor_t  *R_GetDrawFloor();
310 drawseg_c    *R_GetDrawSeg();
311 drawsub_c    *R_GetDrawSub();
312 drawmirror_c *R_GetDrawMirror();
313 
314 
315 //
316 //  R2_DRAW
317 //
318 
319 void R2_Init(void);
320 
321 
322 //
323 //  MIRRORS
324 //
325 
326 extern int num_active_mirrors;
327 
328 void MIR_Coordinate(float& x, float& y);
329 void MIR_Height(float& z);
330 void MIR_Angle(angle_t& ang);
331 
332 bool MIR_Reflective(void);
333 float MIR_XYScale(void);
334 float MIR_ZScale(void);
335 
336 
337 #endif /* __RGL_DEFS_H__ */
338 
339 //--- editor settings ---
340 // vi:ts=4:sw=4:noexpandtab
341