1 //**************************************************************************
2 //**
3 //**	##   ##    ##    ##   ##   ####     ####   ###     ###
4 //**	##   ##  ##  ##  ##   ##  ##  ##   ##  ##  ####   ####
5 //**	 ## ##  ##    ##  ## ##  ##    ## ##    ## ## ## ## ##
6 //**	 ## ##  ########  ## ##  ##    ## ##    ## ##  ###  ##
7 //**	  ###   ##    ##   ###    ##  ##   ##  ##  ##       ##
8 //**	   #    ##    ##    #      ####     ####   ##       ##
9 //**
10 //**	$Id: r_shared.h 4342 2010-12-16 20:24:23Z dj_jl $
11 //**
12 //**	Copyright (C) 1999-2006 Jānis Legzdiņš
13 //**
14 //**	This program is free software; you can redistribute it and/or
15 //**  modify it under the terms of the GNU General Public License
16 //**  as published by the Free Software Foundation; either version 2
17 //**  of the License, or (at your option) any later version.
18 //**
19 //**	This program is distributed in the hope that it will be useful,
20 //**  but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 //**  GNU General Public License for more details.
23 //**
24 //**************************************************************************
25 //**
26 //**	Defines shared by refresh and drawer
27 //**
28 //**************************************************************************
29 
30 #ifndef _R_SHARED_H
31 #define _R_SHARED_H
32 
33 // HEADER FILES ------------------------------------------------------------
34 
35 #include "fmd2defs.h"
36 #include "drawer.h"
37 
38 // MACROS ------------------------------------------------------------------
39 
40 //	Colour maps
41 enum
42 {
43 	CM_Default,
44 	CM_Inverse,
45 	CM_Gold,
46 	CM_Red,
47 	CM_Green,
48 
49 	CM_Max
50 };
51 
52 //  Simulate light fading using dark fog
53 enum
54 {
55 	FADE_LIGHT = 0xff010101
56 };
57 
58 // TYPES -------------------------------------------------------------------
59 
60 class TClipPlane : public TPlane
61 {
62 public:
63 	TClipPlane		*next;
64 
65 	int				clipflag;
66 	TVec			enter;
67 	TVec			exit;
68 	int				entered;
69 	int				exited;
70 };
71 
72 struct texinfo_t
73 {
74 	TVec			saxis;
75 	float			soffs;
76 	TVec			taxis;
77 	float			toffs;
78 	VTexture*		Tex;
79 	//	1.1 for solid surfaces
80 	// Alpha for masked surfaces
81 	float			Alpha;
82 	bool			Additive;
83 	vuint8			ColourMap;
84 };
85 
86 struct surface_t
87 {
88 	surface_t*		next;
89 	surface_t*		DrawNext;
90 	texinfo_t*		texinfo;
91 	TPlane*			plane;
92 	sec_plane_t*	HorizonPlane;
93 	vuint32			Light;		//	Light level and colour.
94 	vuint32			Fade;
95 	vuint8*			lightmap;
96 	rgb_t*			lightmap_rgb;
97 	int				dlightframe;
98 	int				dlightbits;
99 	int				count;
100 	short			texturemins[2];
101 	short			extents[2];
102 	surfcache_t*	CacheSurf;
103 	TVec			verts[1];
104 };
105 
106 //
107 //	Camera texture.
108 //
109 class VCameraTexture : public VTexture
110 {
111 public:
112 	vuint8*		Pixels;
113 	bool		bNeedsUpdate;
114 	bool		bUpdated;
115 
116 	VCameraTexture(VName, int, int);
117 	~VCameraTexture();
118 	bool CheckModified();
119 	vuint8* GetPixels();
120 	void Unload();
121 	void CopyImage();
122 	VTexture* GetHighResolutionTexture();
123 };
124 
125 class VRenderLevelShared;
126 
127 //
128 //	Base class for portals.
129 //
130 class VPortal
131 {
132 public:
133 	VRenderLevelShared*		RLev;
134 	TArray<surface_t*>		Surfs;
135 	int						Level;
136 
137 	VPortal(VRenderLevelShared* ARLev);
138 	virtual ~VPortal();
139 	virtual bool NeedsDepthBuffer() const;
140 	virtual bool IsSky() const;
141 	virtual bool MatchSky(class VSky*) const;
142 	virtual bool MatchSkyBox(VEntity*) const;
143 	virtual bool MatchMirror(TPlane*) const;
144 	void Draw(bool);
145 	virtual void DrawContents() = 0;
146 
147 protected:
148 	void SetUpRanges(VViewClipper&, bool);
149 };
150 
151 struct VMeshFrame
152 {
153 	TVec*			Verts;
154 	TVec*			Normals;
155 	TPlane*			Planes;
156 	vuint32			VertsOffset;
157 	vuint32			NormalsOffset;
158 };
159 
160 struct VMeshSTVert
161 {
162 	float			S;
163 	float			T;
164 };
165 
166 struct VMeshTri
167 {
168 	vuint16				VertIndex[3];
169 };
170 
171 struct VMeshEdge
172 {
173 	vuint16				Vert1;
174 	vuint16				Vert2;
175 	vint16				Tri1;
176 	vint16				Tri2;
177 };
178 
179 struct VMeshModel
180 {
181 	VStr				Name;
182 	mmdl_t*				Data;		// only access through Mod_Extradata
183 	TArray<VName>		Skins;
184 	TArray<VMeshFrame>	Frames;
185 	TArray<TVec>		AllVerts;
186 	TArray<TVec>		AllNormals;
187 	TArray<TPlane>		AllPlanes;
188 	TArray<VMeshSTVert>	STVerts;
189 	TArray<VMeshTri>	Tris;
190 	TArray<VMeshEdge>	Edges;
191 	bool				Uploaded;
192 	vuint32				VertsBuffer;
193 	vuint32				IndexBuffer;
194 };
195 
196 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
197 
198 void R_DrawViewBorder();
199 
200 // PUBLIC DATA DECLARATIONS ------------------------------------------------
201 
202 //
203 // POV related.
204 //
205 extern TVec				vieworg;
206 extern TVec				viewforward;
207 extern TVec				viewright;
208 extern TVec				viewup;
209 extern TAVec			viewangles;
210 
211 extern VCvarI			r_fog;
212 extern VCvarF			r_fog_r;
213 extern VCvarF			r_fog_g;
214 extern VCvarF			r_fog_b;
215 extern VCvarF			r_fog_start;
216 extern VCvarF			r_fog_end;
217 extern VCvarF			r_fog_density;
218 
219 extern VCvarI			r_vsync;
220 
221 extern VCvarI			r_fade_light;
222 extern VCvarF			r_fade_factor;
223 
224 extern VCvarF			r_sky_bright_factor;
225 
226 extern TClipPlane		view_clipplanes[5];
227 
228 extern bool				MirrorFlip;
229 extern bool				MirrorClip;
230 
231 extern int				r_dlightframecount;
232 extern bool				r_light_add;
233 extern vuint32			blocklights[18 * 18];
234 extern vuint32			blocklightsr[18 * 18];
235 extern vuint32			blocklightsg[18 * 18];
236 extern vuint32			blocklightsb[18 * 18];
237 extern vuint32			blockaddlightsr[18 * 18];
238 extern vuint32			blockaddlightsg[18 * 18];
239 extern vuint32			blockaddlightsb[18 * 18];
240 
241 extern rgba_t			r_palette[256];
242 extern vuint8			r_black_colour;
243 
244 extern vuint8			r_rgbtable[32 * 32 * 32 + 4];
245 
246 extern int				usegamma;
247 extern vuint8			gammatable[5][256];
248 
249 extern float			PixelAspect;
250 
251 extern VTextureTranslation	ColourMaps[CM_Max];
252 
253 enum { SHADEDOT_QUANT = 16 };
254 extern float			r_avertexnormal_dots[SHADEDOT_QUANT][256];
255 
256 //==========================================================================
257 //
258 //	R_LookupRBG
259 //
260 //==========================================================================
261 
R_LookupRGB(vuint8 r,vuint8 g,vuint8 b)262 inline int R_LookupRGB(vuint8 r, vuint8 g, vuint8 b)
263 {
264 	return r_rgbtable[((r << 7) & 0x7c00) + ((g << 2) & 0x3e0) +
265 		((b >> 3) & 0x1f)];
266 }
267 
268 #endif
269