1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id: v_video.h 4651 2014-03-14 14:56:15Z dr_sean $
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 // Copyright (C) 2006-2014 by The Odamex Team.
8 //
9 // This source is available for distribution and/or modification
10 // only under the terms of the DOOM Source Code License as
11 // published by id Software. All rights reserved.
12 //
13 // The source is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
16 // for more details.
17 //
18 // DESCRIPTION:
19 // Gamma correction LUT.
20 // Functions to draw patches (by post) directly to screen.
21 // Functions to blit a block to the screen.
22 //
23 //-----------------------------------------------------------------------------
24
25
26 #ifndef __V_VIDEO_H__
27 #define __V_VIDEO_H__
28
29 #include <string>
30
31 #include "doomtype.h"
32
33 #include "v_palette.h"
34
35 #include "doomdef.h"
36
37 // Needed because we are refering to patches.
38 #include "r_data.h"
39
40 extern int CleanXfac, CleanYfac;
41
42 extern BOOL gotconback;
43
44 extern int DisplayWidth, DisplayHeight, DisplayBits;
45 extern int SquareWidth;
46
47 #define APART(c) (screen->alphaPart(c))
48 #define RPART(c) (screen->redPart(c))
49 #define GPART(c) (screen->greenPart(c))
50 #define BPART(c) (screen->bluePart(c))
51
52 #define MAKERGB(r, g, b) (screen->makeRGB(r, g, b))
53 #define MAKEARGB(a, r, g, b) (screen->makeARGB(a, r, g, b))
54
55 //
56 // VIDEO
57 //
58 // [RH] Made screens more implementation-independant:
59 //
60 // V_LockScreen() must be called before drawing on a
61 // screen, and V_UnlockScreen() must be called when
62 // drawing is finished. As far as ZDoom is concerned,
63 // there are only two display depths: 8-bit indexed and
64 // 32-bit RGBA. The video driver is expected to be able
65 // to convert these to a format supported by the hardware.
66 // As such, the bits field is only used as an indicator
67 // of the output display depth and not as the screen's
68 // display depth (use is8bit for that).
69 class DCanvas : DObject
70 {
71 DECLARE_CLASS (DCanvas, DObject)
72 public:
73 enum EWrapperCode
74 {
75 EWrapper_Normal = 0, // Just draws the patch as is
76 EWrapper_Lucent = 1, // Mixes the patch with the background
77 EWrapper_Translated = 2, // Color translates the patch and draws it
78 EWrapper_TlatedLucent = 3, // Translates the patch and mixes it with the background
79 EWrapper_Colored = 4, // Fills the patch area with a solid color
80 EWrapper_ColoredLucent = 5 // Mixes a solid color in the patch area with the background
81 };
82
DCanvas()83 DCanvas() :
84 buffer(NULL), m_LockCount(0), m_Private(NULL),
85 ashift(24), rshift(16), gshift(8), bshift(0)
86 { }
87
~DCanvas()88 virtual ~DCanvas ()
89 { }
90
91 int bits;
92 byte *buffer;
93 int width;
94 int height;
95 int pitch;
is8bit()96 inline bool is8bit() const { return bits == 8; }
97
98 // [ML] If this is 320x200 or 640x400, the resolutions
99 // "protected" from aspect ratio correction.
isProtectedRes()100 inline bool isProtectedRes() const
101 {
102 return (width == 320 && height == 200) || (width == 640 && height == 400);
103 }
104
setAlphaShift(byte n)105 inline void setAlphaShift(byte n)
106 { ashift = n; }
107
setRedShift(byte n)108 inline void setRedShift(byte n)
109 { rshift = n; }
110
setGreenShift(byte n)111 inline void setGreenShift(byte n)
112 { gshift = n; }
113
setBlueShift(byte n)114 inline void setBlueShift(byte n)
115 { bshift = n; }
116
getAlphaShift()117 inline byte getAlphaShift() const
118 { return ashift; }
119
getRedShift()120 inline byte getRedShift() const
121 { return rshift; }
122
getGreenShift()123 inline byte getGreenShift() const
124 { return gshift; }
125
getBlueShift()126 inline byte getBlueShift() const
127 { return bshift; }
128
alphaPart(argb_t color)129 inline argb_t alphaPart(argb_t color) const
130 { return (color >> ashift) & 0xFF; }
131
redPart(argb_t color)132 inline argb_t redPart(argb_t color) const
133 { return (color >> rshift) & 0xFF; }
134
greenPart(argb_t color)135 inline argb_t greenPart(argb_t color) const
136 { return (color >> gshift) & 0xFF; }
137
bluePart(argb_t color)138 inline argb_t bluePart(argb_t color) const
139 { return (color >> bshift) & 0xFF; }
140
makeRGB(unsigned int r,unsigned int g,unsigned int b)141 inline argb_t makeRGB(unsigned int r, unsigned int g, unsigned int b) const
142 {
143 return (r << rshift) | (g << gshift) | (b << bshift);
144 }
145
makeARGB(unsigned int a,unsigned int r,unsigned int g,unsigned int b)146 inline argb_t makeARGB(unsigned int a, unsigned int r, unsigned int g, unsigned int b) const
147 {
148 return (a << ashift) | (r << rshift) | (g << gshift) | (b << bshift);
149 }
150
151 int m_LockCount;
152 palette_t *m_Palette;
153 void *m_Private;
154
155 // Copy blocks from one canvas to another
156 void Blit (int srcx, int srcy, int srcwidth, int srcheight, DCanvas *dest, int destx, int desty, int destwidth, int destheight);
157 void CopyRect (int srcx, int srcy, int width, int height, int destx, int desty, DCanvas *destscrn);
158
159 // Draw a linear block of pixels into the view buffer.
160 void DrawBlock (int x, int y, int width, int height, const byte *src) const;
161
162 // Reads a linear block of pixels from the view buffer.
163 void GetBlock (int x, int y, int width, int height, byte *dest) const;
164
165 // Reads a transposed block of pixels from the view buffer
166 void GetTransposedBlock(int x, int y, int _width, int _height, byte* dest) const;
167
168 // Darken a rectangle of th canvas
169 void Dim (int x, int y, int width, int height, const char* color, float amount) const;
170 void Dim (int x, int y, int width, int height) const;
171
172 // Fill an area with a 64x64 flat texture
173 void FlatFill (int left, int top, int right, int bottom, const byte *src) const;
174
175 // Set an area to a specified color
176 void Clear (int left, int top, int right, int bottom, int color) const;
177
178 // Access control
179 void Lock ();
180 void Unlock ();
181
182 // Palette control (unused)
183 void AttachPalette (palette_t *pal);
184 void DetachPalette ();
185
186 // Text drawing functions
187 // Output a line of text using the console font
188 void PrintStr (int x, int y, const char *s, int count) const;
189 void PrintStr2 (int x, int y, const char *s, int count) const;
190
191 // Output some text with wad heads-up font
192 inline void DrawText (int normalcolor, int x, int y, const byte *string) const;
193 inline void DrawTextLuc (int normalcolor, int x, int y, const byte *string) const;
194 inline void DrawTextClean (int normalcolor, int x, int y, const byte *string) const; // Does not adjust x and y
195 inline void DrawTextCleanLuc (int normalcolor, int x, int y, const byte *string) const; // ditto
196 inline void DrawTextCleanMove (int normalcolor, int x, int y, const byte *string) const; // This one does
197 inline void DrawTextStretched (int normalcolor, int x, int y, const byte *string, int scalex, int scaley) const;
198 inline void DrawTextStretchedLuc (int normalcolor, int x, int y, const byte *string, int scalex, int scaley) const;
199
200 inline void DrawText (int normalcolor, int x, int y, const char *string) const;
201 inline void DrawTextLuc (int normalcolor, int x, int y, const char *string) const;
202 inline void DrawTextClean (int normalcolor, int x, int y, const char *string) const;
203 inline void DrawTextCleanLuc (int normalcolor, int x, int y, const char *string) const;
204 inline void DrawTextCleanMove (int normalcolor, int x, int y, const char *string) const;
205 inline void DrawTextStretched (int normalcolor, int x, int y, const char *string, int scalex, int scaley) const;
206 inline void DrawTextStretchedLuc (int normalcolor, int x, int y, const char *string, int scalex, int scaley) const;
207
208 // Patch drawing functions
209 void DrawPatchFlipped (const patch_t *patch, int x, int y) const;
210
211 inline void DrawPatch (const patch_t *patch, int x, int y) const;
212 inline void DrawPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
213 inline void DrawPatchDirect (const patch_t *patch, int x, int y) const;
214 inline void DrawPatchIndirect (const patch_t *patch, int x, int y) const;
215 inline void DrawPatchClean (const patch_t *patch, int x, int y) const;
216 inline void DrawPatchCleanNoMove (const patch_t *patch, int x, int y) const;
217
218 void DrawPatchFullScreen(const patch_t* patch) const;
219
220 inline void DrawLucentPatch (const patch_t *patch, int x, int y) const;
221 inline void DrawLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
222 inline void DrawLucentPatchDirect (const patch_t *patch, int x, int y) const;
223 inline void DrawLucentPatchIndirect (const patch_t *patch, int x, int y) const;
224 inline void DrawLucentPatchClean (const patch_t *patch, int x, int y) const;
225 inline void DrawLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const;
226
227 inline void DrawTranslatedPatch (const patch_t *patch, int x, int y) const;
228 inline void DrawTranslatedPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
229 inline void DrawTranslatedPatchDirect (const patch_t *patch, int x, int y) const;
230 inline void DrawTranslatedPatchIndirect (const patch_t *patch, int x, int y) const;
231 inline void DrawTranslatedPatchClean (const patch_t *patch, int x, int y) const;
232 inline void DrawTranslatedPatchCleanNoMove (const patch_t *patch, int x, int y) const;
233
234 inline void DrawTranslatedLucentPatch (const patch_t *patch, int x, int y) const;
235 inline void DrawTranslatedLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
236 inline void DrawTranslatedLucentPatchDirect (const patch_t *patch, int x, int y) const;
237 inline void DrawTranslatedLucentPatchIndirect (const patch_t *patch, int x, int y) const;
238 inline void DrawTranslatedLucentPatchClean (const patch_t *patch, int x, int y) const;
239 inline void DrawTranslatedLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const;
240
241 inline void DrawColoredPatch (const patch_t *patch, int x, int y) const;
242 inline void DrawColoredPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
243 inline void DrawColoredPatchDirect (const patch_t *patch, int x, int y) const;
244 inline void DrawColoredPatchIndirect (const patch_t *patch, int x, int y) const;
245 inline void DrawColoredPatchClean (const patch_t *patch, int x, int y) const;
246 inline void DrawColoredPatchCleanNoMove (const patch_t *patch, int x, int y) const;
247
248 inline void DrawColoredLucentPatch (const patch_t *patch, int x, int y) const;
249 inline void DrawColoredLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
250 inline void DrawColoredLucentPatchDirect (const patch_t *patch, int x, int y) const;
251 inline void DrawColoredLucentPatchIndirect (const patch_t *patch, int x, int y) const;
252 inline void DrawColoredLucentPatchClean (const patch_t *patch, int x, int y) const;
253 inline void DrawColoredLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const;
254
255 protected:
256 void TextWrapper (EWrapperCode drawer, int normalcolor, int x, int y, const byte *string) const;
257 void TextSWrapper (EWrapperCode drawer, int normalcolor, int x, int y, const byte *string) const;
258 void TextSWrapper (EWrapperCode drawer, int normalcolor, int x, int y, const byte *string, int scalex, int scaley) const;
259
260 void DrawWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y) const;
261 void DrawSWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y, int destwidth, int destheight) const;
262 void DrawIWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y) const;
263 void DrawCWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y) const;
264 void DrawCNMWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y) const;
265
266 static void DrawPatchP (const byte *source, byte *dest, int count, int pitch);
267 static void DrawLucentPatchP (const byte *source, byte *dest, int count, int pitch);
268 static void DrawTranslatedPatchP (const byte *source, byte *dest, int count, int pitch);
269 static void DrawTlatedLucentPatchP (const byte *source, byte *dest, int count, int pitch);
270 static void DrawColoredPatchP (const byte *source, byte *dest, int count, int pitch);
271 static void DrawColorLucentPatchP (const byte *source, byte *dest, int count, int pitch);
272
273 static void DrawPatchSP (const byte *source, byte *dest, int count, int pitch, int yinc);
274 static void DrawLucentPatchSP (const byte *source, byte *dest, int count, int pitch, int yinc);
275 static void DrawTranslatedPatchSP (const byte *source, byte *dest, int count, int pitch, int yinc);
276 static void DrawTlatedLucentPatchSP (const byte *source, byte *dest, int count, int pitch, int yinc);
277
278 static void DrawPatchD (const byte *source, byte *dest, int count, int pitch);
279 static void DrawLucentPatchD (const byte *source, byte *dest, int count, int pitch);
280 static void DrawTranslatedPatchD (const byte *source, byte *dest, int count, int pitch);
281 static void DrawTlatedLucentPatchD (const byte *source, byte *dest, int count, int pitch);
282 static void DrawColoredPatchD (const byte *source, byte *dest, int count, int pitch);
283 static void DrawColorLucentPatchD (const byte *source, byte *dest, int count, int pitch);
284
285 static void DrawPatchSD (const byte *source, byte *dest, int count, int pitch, int yinc);
286 static void DrawLucentPatchSD (const byte *source, byte *dest, int count, int pitch, int yinc);
287 static void DrawTranslatedPatchSD (const byte *source, byte *dest, int count, int pitch, int yinc);
288 static void DrawTlatedLucentPatchSD (const byte *source, byte *dest, int count, int pitch, int yinc);
289
290 typedef void (*vdrawfunc) (const byte *source, byte *dest, int count, int pitch);
291 typedef void (*vdrawsfunc) (const byte *source, byte *dest, int count, int pitch, int yinc);
292
293 // Palettized versions of the column drawers
294 static vdrawfunc Pfuncs[6];
295 static vdrawsfunc Psfuncs[6];
296
297 // Direct (true-color) versions of the column drawers
298 static vdrawfunc Dfuncs[6];
299 static vdrawsfunc Dsfuncs[6];
300
301 // The current set of column drawers (set in V_SetResolution)
302 static vdrawfunc *m_Drawfuncs;
303 static vdrawsfunc *m_Drawsfuncs;
304
305 byte ashift;
306 byte rshift;
307 byte gshift;
308 byte bshift;
309 };
310
DrawText(int normalcolor,int x,int y,const byte * string)311 inline void DCanvas::DrawText (int normalcolor, int x, int y, const byte *string) const
312 {
313 TextWrapper (EWrapper_Translated, normalcolor, x, y, string);
314 }
DrawTextLuc(int normalcolor,int x,int y,const byte * string)315 inline void DCanvas::DrawTextLuc (int normalcolor, int x, int y, const byte *string) const
316 {
317 TextWrapper (EWrapper_TlatedLucent, normalcolor, x, y, string);
318 }
DrawTextClean(int normalcolor,int x,int y,const byte * string)319 inline void DCanvas::DrawTextClean (int normalcolor, int x, int y, const byte *string) const
320 {
321 TextSWrapper (EWrapper_Translated, normalcolor, x, y, string);
322 }
DrawTextCleanLuc(int normalcolor,int x,int y,const byte * string)323 inline void DCanvas::DrawTextCleanLuc (int normalcolor, int x, int y, const byte *string) const
324 {
325 TextSWrapper (EWrapper_TlatedLucent, normalcolor, x, y, string);
326 }
DrawTextCleanMove(int normalcolor,int x,int y,const byte * string)327 inline void DCanvas::DrawTextCleanMove (int normalcolor, int x, int y, const byte *string) const
328 {
329 TextSWrapper (EWrapper_Translated, normalcolor,
330 (x - 160) * CleanXfac + width / 2,
331 (y - 100) * CleanYfac + height / 2,
332 string);
333 }
DrawTextStretched(int normalcolor,int x,int y,const byte * string,int scalex,int scaley)334 inline void DCanvas::DrawTextStretched (int normalcolor, int x, int y, const byte *string, int scalex, int scaley) const
335 {
336 TextSWrapper (EWrapper_Translated, normalcolor, x, y, string, scalex, scaley);
337 }
338
DrawTextStretchedLuc(int normalcolor,int x,int y,const byte * string,int scalex,int scaley)339 inline void DCanvas::DrawTextStretchedLuc (int normalcolor, int x, int y, const byte *string, int scalex, int scaley) const
340 {
341 TextSWrapper (EWrapper_TlatedLucent, normalcolor, x, y, string, scalex, scaley);
342 }
343
DrawText(int normalcolor,int x,int y,const char * string)344 inline void DCanvas::DrawText (int normalcolor, int x, int y, const char *string) const
345 {
346 TextWrapper (EWrapper_Translated, normalcolor, x, y, (const byte *)string);
347 }
DrawTextLuc(int normalcolor,int x,int y,const char * string)348 inline void DCanvas::DrawTextLuc (int normalcolor, int x, int y, const char *string) const
349 {
350 TextWrapper (EWrapper_TlatedLucent, normalcolor, x, y, (const byte *)string);
351 }
DrawTextClean(int normalcolor,int x,int y,const char * string)352 inline void DCanvas::DrawTextClean (int normalcolor, int x, int y, const char *string) const
353 {
354 TextSWrapper (EWrapper_Translated, normalcolor, x, y, (const byte *)string);
355 }
DrawTextCleanLuc(int normalcolor,int x,int y,const char * string)356 inline void DCanvas::DrawTextCleanLuc (int normalcolor, int x, int y, const char *string) const
357 {
358 TextSWrapper (EWrapper_TlatedLucent, normalcolor, x, y, (const byte *)string);
359 }
DrawTextCleanMove(int normalcolor,int x,int y,const char * string)360 inline void DCanvas::DrawTextCleanMove (int normalcolor, int x, int y, const char *string) const
361 {
362 TextSWrapper (EWrapper_Translated, normalcolor,
363 (x - 160) * CleanXfac + width / 2,
364 (y - 100) * CleanYfac + height / 2,
365 (const byte *)string);
366 }
DrawTextStretched(int normalcolor,int x,int y,const char * string,int scalex,int scaley)367 inline void DCanvas::DrawTextStretched (int normalcolor, int x, int y, const char *string, int scalex, int scaley) const
368 {
369 TextSWrapper (EWrapper_Translated, normalcolor, x, y, (const byte *)string, scalex, scaley);
370 }
DrawTextStretchedLuc(int normalcolor,int x,int y,const char * string,int scalex,int scaley)371 inline void DCanvas::DrawTextStretchedLuc (int normalcolor, int x, int y, const char *string, int scalex, int scaley) const
372 {
373 TextSWrapper (EWrapper_TlatedLucent, normalcolor, x, y, (const byte *)string, scalex, scaley);
374 }
375
DrawPatch(const patch_t * patch,int x,int y)376 inline void DCanvas::DrawPatch (const patch_t *patch, int x, int y) const
377 {
378 DrawWrapper (EWrapper_Normal, patch, x, y);
379 }
DrawPatchStretched(const patch_t * patch,int x,int y,int dw,int dh)380 inline void DCanvas::DrawPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
381 {
382 DrawSWrapper (EWrapper_Normal, patch, x, y, dw, dh);
383 }
DrawPatchDirect(const patch_t * patch,int x,int y)384 inline void DCanvas::DrawPatchDirect (const patch_t *patch, int x, int y) const
385 {
386 DrawWrapper (EWrapper_Normal, patch, x, y);
387 }
DrawPatchIndirect(const patch_t * patch,int x,int y)388 inline void DCanvas::DrawPatchIndirect (const patch_t *patch, int x, int y) const
389 {
390 DrawIWrapper (EWrapper_Normal, patch, x, y);
391 }
DrawPatchClean(const patch_t * patch,int x,int y)392 inline void DCanvas::DrawPatchClean (const patch_t *patch, int x, int y) const
393 {
394 DrawCWrapper (EWrapper_Normal, patch, x, y);
395 }
DrawPatchCleanNoMove(const patch_t * patch,int x,int y)396 inline void DCanvas::DrawPatchCleanNoMove (const patch_t *patch, int x, int y) const
397 {
398 DrawCNMWrapper (EWrapper_Normal, patch, x, y);
399 }
400
DrawLucentPatch(const patch_t * patch,int x,int y)401 inline void DCanvas::DrawLucentPatch (const patch_t *patch, int x, int y) const
402 {
403 DrawWrapper (EWrapper_Lucent, patch, x, y);
404 }
DrawLucentPatchStretched(const patch_t * patch,int x,int y,int dw,int dh)405 inline void DCanvas::DrawLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
406 {
407 DrawSWrapper (EWrapper_Lucent, patch, x, y, dw, dh);
408 }
DrawLucentPatchDirect(const patch_t * patch,int x,int y)409 inline void DCanvas::DrawLucentPatchDirect (const patch_t *patch, int x, int y) const
410 {
411 DrawWrapper (EWrapper_Lucent, patch, x, y);
412 }
DrawLucentPatchIndirect(const patch_t * patch,int x,int y)413 inline void DCanvas::DrawLucentPatchIndirect (const patch_t *patch, int x, int y) const
414 {
415 DrawIWrapper (EWrapper_Lucent, patch, x, y);
416 }
DrawLucentPatchClean(const patch_t * patch,int x,int y)417 inline void DCanvas::DrawLucentPatchClean (const patch_t *patch, int x, int y) const
418 {
419 DrawCWrapper (EWrapper_Lucent, patch, x, y);
420 }
DrawLucentPatchCleanNoMove(const patch_t * patch,int x,int y)421 inline void DCanvas::DrawLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const
422 {
423 DrawCNMWrapper (EWrapper_Lucent, patch, x, y);
424 }
425
DrawTranslatedPatch(const patch_t * patch,int x,int y)426 inline void DCanvas::DrawTranslatedPatch (const patch_t *patch, int x, int y) const
427 {
428 DrawWrapper (EWrapper_Translated, patch, x, y);
429 }
DrawTranslatedPatchStretched(const patch_t * patch,int x,int y,int dw,int dh)430 inline void DCanvas::DrawTranslatedPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
431 {
432 DrawSWrapper (EWrapper_Translated, patch, x, y, dw, dh);
433 }
DrawTranslatedPatchDirect(const patch_t * patch,int x,int y)434 inline void DCanvas::DrawTranslatedPatchDirect (const patch_t *patch, int x, int y) const
435 {
436 DrawWrapper (EWrapper_Translated, patch, x, y);
437 }
DrawTranslatedPatchIndirect(const patch_t * patch,int x,int y)438 inline void DCanvas::DrawTranslatedPatchIndirect (const patch_t *patch, int x, int y) const
439 {
440 DrawIWrapper (EWrapper_Translated, patch, x, y);
441 }
DrawTranslatedPatchClean(const patch_t * patch,int x,int y)442 inline void DCanvas::DrawTranslatedPatchClean (const patch_t *patch, int x, int y) const
443 {
444 DrawCWrapper (EWrapper_Translated, patch, x, y);
445 }
DrawTranslatedPatchCleanNoMove(const patch_t * patch,int x,int y)446 inline void DCanvas::DrawTranslatedPatchCleanNoMove (const patch_t *patch, int x, int y) const
447 {
448 DrawCNMWrapper (EWrapper_Translated, patch, x, y);
449 }
450
DrawTranslatedLucentPatch(const patch_t * patch,int x,int y)451 inline void DCanvas::DrawTranslatedLucentPatch (const patch_t *patch, int x, int y) const
452 {
453 DrawWrapper (EWrapper_TlatedLucent, patch, x, y);
454 }
DrawTranslatedLucentPatchStretched(const patch_t * patch,int x,int y,int dw,int dh)455 inline void DCanvas::DrawTranslatedLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
456 {
457 DrawSWrapper (EWrapper_TlatedLucent, patch, x, y, dw, dh);
458 }
DrawTranslatedLucentPatchDirect(const patch_t * patch,int x,int y)459 inline void DCanvas::DrawTranslatedLucentPatchDirect (const patch_t *patch, int x, int y) const
460 {
461 DrawWrapper (EWrapper_TlatedLucent, patch, x, y);
462 }
DrawTranslatedLucentPatchIndirect(const patch_t * patch,int x,int y)463 inline void DCanvas::DrawTranslatedLucentPatchIndirect (const patch_t *patch, int x, int y) const
464 {
465 DrawIWrapper (EWrapper_TlatedLucent, patch, x, y);
466 }
DrawTranslatedLucentPatchClean(const patch_t * patch,int x,int y)467 inline void DCanvas::DrawTranslatedLucentPatchClean (const patch_t *patch, int x, int y) const
468 {
469 DrawCWrapper (EWrapper_TlatedLucent, patch, x, y);
470 }
DrawTranslatedLucentPatchCleanNoMove(const patch_t * patch,int x,int y)471 inline void DCanvas::DrawTranslatedLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const
472 {
473 DrawCNMWrapper (EWrapper_TlatedLucent, patch, x, y);
474 }
475
DrawColoredPatch(const patch_t * patch,int x,int y)476 inline void DCanvas::DrawColoredPatch (const patch_t *patch, int x, int y) const
477 {
478 DrawWrapper (EWrapper_Colored, patch, x, y);
479 }
DrawColoredPatchStretched(const patch_t * patch,int x,int y,int dw,int dh)480 inline void DCanvas::DrawColoredPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
481 {
482 DrawSWrapper (EWrapper_Colored, patch, x, y, dw, dh);
483 }
DrawColoredPatchDirect(const patch_t * patch,int x,int y)484 inline void DCanvas::DrawColoredPatchDirect (const patch_t *patch, int x, int y) const
485 {
486 DrawWrapper (EWrapper_Colored, patch, x, y);
487 }
DrawColoredPatchIndirect(const patch_t * patch,int x,int y)488 inline void DCanvas::DrawColoredPatchIndirect (const patch_t *patch, int x, int y) const
489 {
490 DrawIWrapper (EWrapper_Colored, patch, x, y);
491 }
DrawColoredPatchClean(const patch_t * patch,int x,int y)492 inline void DCanvas::DrawColoredPatchClean (const patch_t *patch, int x, int y) const
493 {
494 DrawCWrapper (EWrapper_Colored, patch, x, y);
495 }
DrawColoredPatchCleanNoMove(const patch_t * patch,int x,int y)496 inline void DCanvas::DrawColoredPatchCleanNoMove (const patch_t *patch, int x, int y) const
497 {
498 DrawCNMWrapper (EWrapper_Colored, patch, x, y);
499 }
500
DrawColoredLucentPatch(const patch_t * patch,int x,int y)501 inline void DCanvas::DrawColoredLucentPatch (const patch_t *patch, int x, int y) const
502 {
503 DrawWrapper (EWrapper_ColoredLucent, patch, x, y);
504 }
DrawColoredLucentPatchStretched(const patch_t * patch,int x,int y,int dw,int dh)505 inline void DCanvas::DrawColoredLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
506 {
507 DrawSWrapper (EWrapper_ColoredLucent, patch, x, y, dw, dh);
508 }
DrawColoredLucentPatchDirect(const patch_t * patch,int x,int y)509 inline void DCanvas::DrawColoredLucentPatchDirect (const patch_t *patch, int x, int y) const
510 {
511 DrawWrapper (EWrapper_ColoredLucent, patch, x, y);
512 }
DrawColoredLucentPatchIndirect(const patch_t * patch,int x,int y)513 inline void DCanvas::DrawColoredLucentPatchIndirect (const patch_t *patch, int x, int y) const
514 {
515 DrawIWrapper (EWrapper_ColoredLucent, patch, x, y);
516 }
DrawColoredLucentPatchClean(const patch_t * patch,int x,int y)517 inline void DCanvas::DrawColoredLucentPatchClean (const patch_t *patch, int x, int y) const
518 {
519 DrawCWrapper (EWrapper_ColoredLucent, patch, x, y);
520 }
DrawColoredLucentPatchCleanNoMove(const patch_t * patch,int x,int y)521 inline void DCanvas::DrawColoredLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const
522 {
523 DrawCNMWrapper (EWrapper_ColoredLucent, patch, x, y);
524 }
525
526 // This is the screen updated by I_FinishUpdate.
527 extern DCanvas *screen;
528
529 extern DBoundingBox dirtybox;
530
531 // Translucency tables
532 extern argb_t Col2RGB8[65][256];
533 extern palindex_t RGB32k[32][32][32];
534
535 // Allocates buffer screens, call before R_Init.
536 void V_Init (void);
537
538 // The color to fill with for #4 and #5 above
539 extern int V_ColorFill;
540
541 // The color map for #1 and #2 above
542 extern translationref_t V_ColorMap;
543
544 // The palette lookup table to be used with for direct modes
545 extern shaderef_t V_Palette;
546
547 void V_MarkRect (int x, int y, int width, int height);
548
549 // BestColor
550 byte BestColor (const argb_t *palette, const int r, const int g, const int b, const int numcolors);
551 byte BestColor2 (const argb_t *palette, const argb_t color, const int numcolors);
552 // Returns the closest color to the one desired. String
553 // should be of the form "rr gg bb".
554 int V_GetColorFromString (const argb_t *palette, const char *colorstring);
555 // Scans through the X11R6RGB lump for a matching color
556 // and returns a color string suitable for V_GetColorFromString.
557 std::string V_GetColorStringByName (const char *name);
558
559
560 bool V_SetResolution (int width, int height, int bpp);
561
562 template<>
rt_blend2(const palindex_t bg,const int bga,const palindex_t fg,const int fga)563 forceinline palindex_t rt_blend2(const palindex_t bg, const int bga, const palindex_t fg, const int fga)
564 {
565 // Crazy 8bpp alpha-blending using lookup tables and bit twiddling magic
566 argb_t bgARGB = Col2RGB8[bga >> 2][bg];
567 argb_t fgARGB = Col2RGB8[fga >> 2][fg];
568
569 argb_t mix = (fgARGB + bgARGB) | 0x1f07c1f;
570 return RGB32k[0][0][mix & (mix >> 15)];
571 }
572
573 template<>
rt_blend2(const argb_t bg,const int bga,const argb_t fg,const int fga)574 forceinline argb_t rt_blend2(const argb_t bg, const int bga, const argb_t fg, const int fga)
575 {
576 return alphablend2a(bg, bga, fg, fga);
577 }
578
579 bool V_UsePillarBox();
580 bool V_UseLetterBox();
581 bool V_UseWidescreen();
582
583 // Alpha blend between two RGB colors with only dest alpha value
584 // 0 <= toa <= 255
alphablend1a(const argb_t from,const argb_t to,const int toa)585 forceinline argb_t alphablend1a(const argb_t from, const argb_t to, const int toa)
586 {
587 const int fr = RPART(from);
588 const int fg = GPART(from);
589 const int fb = BPART(from);
590
591 const int dr = RPART(to) - fr;
592 const int dg = GPART(to) - fg;
593 const int db = BPART(to) - fb;
594
595 return MAKERGB(
596 fr + ((dr * toa) >> 8),
597 fg + ((dg * toa) >> 8),
598 fb + ((db * toa) >> 8)
599 );
600 }
601
602 // Alpha blend between two RGB colors with two alpha values
603 // 0 <= froma <= 255
604 // 0 <= toa <= 255
alphablend2a(const argb_t from,const int froma,const argb_t to,const int toa)605 forceinline argb_t alphablend2a(const argb_t from, const int froma, const argb_t to, const int toa)
606 {
607 return MAKERGB(
608 (RPART(from) * froma + RPART(to) * toa) >> 8,
609 (GPART(from) * froma + GPART(to) * toa) >> 8,
610 (BPART(from) * froma + BPART(to) * toa) >> 8
611 );
612 }
613
614 void V_DrawFPSWidget();
615 void V_DrawFPSTicker();
616
617 #endif // __V_VIDEO_H__
618
619
620