Odamex
Setting the Standard in Multiplayer Doom
common/v_video.h
Go to the documentation of this file.
00001 // Emacs style mode select   -*- C++ -*- 
00002 //-----------------------------------------------------------------------------
00003 //
00004 // $Id: v_video.h 1788 2010-08-24 04:42:57Z russellrice $
00005 //
00006 // Copyright (C) 1993-1996 by id Software, Inc.
00007 // Copyright (C) 2006-2010 by The Odamex Team.
00008 //
00009 // This source is available for distribution and/or modification
00010 // only under the terms of the DOOM Source Code License as
00011 // published by id Software. All rights reserved.
00012 //
00013 // The source is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
00016 // for more details.
00017 //
00018 // DESCRIPTION:
00019 //      Gamma correction LUT.
00020 //      Functions to draw patches (by post) directly to screen.
00021 //      Functions to blit a block to the screen.
00022 //
00023 //-----------------------------------------------------------------------------
00024 
00025 
00026 #ifndef __V_VIDEO_H__
00027 #define __V_VIDEO_H__
00028 
00029 #include <string>
00030 
00031 #include "doomtype.h"
00032 
00033 #include "v_palette.h"
00034 
00035 #include "doomdef.h"
00036 
00037 // Needed because we are refering to patches.
00038 #include "r_data.h"
00039 
00040 extern int CleanWidth, CleanHeight, CleanXfac, CleanYfac;
00041 
00042 extern BOOL    gotconback;
00043 
00044 extern int DisplayWidth, DisplayHeight, DisplayBits;
00045 
00046 //
00047 // VIDEO
00048 //
00049 // [RH] Made screens more implementation-independant:
00050 //
00051 // V_LockScreen() must be called before drawing on a
00052 // screen, and V_UnlockScreen() must be called when
00053 // drawing is finished. As far as ZDoom is concerned,
00054 // there are only two display depths: 8-bit indexed and
00055 // 32-bit RGBA. The video driver is expected to be able
00056 // to convert these to a format supported by the hardware.
00057 // As such, the bits field is only used as an indicator
00058 // of the output display depth and not as the screen's
00059 // display depth (use is8bit for that).
00060 class DCanvas : DObject
00061 {
00062         DECLARE_CLASS (DCanvas, DObject)
00063 public:
00064         enum EWrapperCode
00065         {
00066                 EWrapper_Normal = 0,            // Just draws the patch as is
00067                 EWrapper_Lucent = 1,            // Mixes the patch with the background
00068                 EWrapper_Translated = 2,        // Color translates the patch and draws it
00069                 EWrapper_TlatedLucent = 3,      // Translates the patch and mixes it with the background
00070                 EWrapper_Colored = 4,           // Fills the patch area with a solid color
00071                 EWrapper_ColoredLucent = 5      // Mixes a solid color in the patch area with the background
00072         };
00073 
00074         DCanvas ();
00075         virtual ~DCanvas ();
00076 
00077         int bits;
00078         byte *buffer;
00079         int width;
00080         int height;
00081         int pitch;
00082         inline bool is8bit() const { return bits == 8; };
00083 
00084         int m_LockCount;
00085         palette_t *m_Palette;
00086         void *m_Private;
00087 
00088         // Copy blocks from one canvas to another
00089         void Blit (int srcx, int srcy, int srcwidth, int srcheight, DCanvas *dest, int destx, int desty, int destwidth, int destheight);
00090         void CopyRect (int srcx, int srcy, int width, int height, int destx, int desty, DCanvas *destscrn);
00091 
00092         // Draw a linear block of pixels into the view buffer.
00093         void DrawBlock (int x, int y, int width, int height, const byte *src) const;
00094 
00095         // Reads a linear block of pixels into the view buffer.
00096         void GetBlock (int x, int y, int width, int height, byte *dest) const;
00097 
00098         // Darken the entire canvas
00099         void Dim () const;
00100 
00101         // Fill an area with a 64x64 flat texture
00102         void FlatFill (int left, int top, int right, int bottom, const byte *src) const;
00103 
00104         // Set an area to a specified color
00105         void Clear (int left, int top, int right, int bottom, int color) const;
00106 
00107         // Access control
00108         void Lock ();
00109         void Unlock ();
00110 
00111         // Palette control (unused)
00112         void AttachPalette (palette_t *pal);
00113         void DetachPalette ();
00114 
00115         // Text drawing functions
00116         // Output a line of text using the console font
00117         void PrintStr (int x, int y, const char *s, int count) const;
00118         void PrintStr2 (int x, int y, const char *s, int count) const;
00119 
00120         // Output some text with wad heads-up font
00121         inline void DrawText (int normalcolor, int x, int y, const byte *string) const;
00122         inline void DrawTextLuc (int normalcolor, int x, int y, const byte *string) const;
00123         inline void DrawTextClean (int normalcolor, int x, int y, const byte *string) const;            // Does not adjust x and y
00124         inline void DrawTextCleanLuc (int normalcolor, int x, int y, const byte *string) const;         // ditto
00125         inline void DrawTextCleanMove (int normalcolor, int x, int y, const byte *string) const;        // This one does
00126 
00127         inline void DrawText (int normalcolor, int x, int y, const char *string) const;
00128         inline void DrawTextLuc (int normalcolor, int x, int y, const char *string) const;
00129         inline void DrawTextClean (int normalcolor, int x, int y, const char *string) const;
00130         inline void DrawTextCleanLuc (int normalcolor, int x, int y, const char *string) const;
00131         inline void DrawTextCleanMove (int normalcolor, int x, int y, const char *string) const;
00132 
00133         // Patch drawing functions
00134         void DrawPatchFlipped (const patch_t *patch, int x, int y) const;
00135 
00136         inline void DrawPatch (const patch_t *patch, int x, int y) const;
00137         inline void DrawPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
00138         inline void DrawPatchDirect (const patch_t *patch, int x, int y) const;
00139         inline void DrawPatchIndirect (const patch_t *patch, int x, int y) const;
00140         inline void DrawPatchClean (const patch_t *patch, int x, int y) const;
00141         inline void DrawPatchCleanNoMove (const patch_t *patch, int x, int y) const;
00142 
00143         inline void DrawLucentPatch (const patch_t *patch, int x, int y) const;
00144         inline void DrawLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
00145         inline void DrawLucentPatchDirect (const patch_t *patch, int x, int y) const;
00146         inline void DrawLucentPatchIndirect (const patch_t *patch, int x, int y) const;
00147         inline void DrawLucentPatchClean (const patch_t *patch, int x, int y) const;
00148         inline void DrawLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const;
00149 
00150         inline void DrawTranslatedPatch (const patch_t *patch, int x, int y) const;
00151         inline void DrawTranslatedPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
00152         inline void DrawTranslatedPatchDirect (const patch_t *patch, int x, int y) const;
00153         inline void DrawTranslatedPatchIndirect (const patch_t *patch, int x, int y) const;
00154         inline void DrawTranslatedPatchClean (const patch_t *patch, int x, int y) const;
00155         inline void DrawTranslatedPatchCleanNoMove (const patch_t *patch, int x, int y) const;
00156 
00157         inline void DrawTranslatedLucentPatch (const patch_t *patch, int x, int y) const;
00158         inline void DrawTranslatedLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
00159         inline void DrawTranslatedLucentPatchDirect (const patch_t *patch, int x, int y) const;
00160         inline void DrawTranslatedLucentPatchIndirect (const patch_t *patch, int x, int y) const;
00161         inline void DrawTranslatedLucentPatchClean (const patch_t *patch, int x, int y) const;
00162         inline void DrawTranslatedLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const;
00163 
00164         inline void DrawColoredPatch (const patch_t *patch, int x, int y) const;
00165         inline void DrawColoredPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
00166         inline void DrawColoredPatchDirect (const patch_t *patch, int x, int y) const;
00167         inline void DrawColoredPatchIndirect (const patch_t *patch, int x, int y) const;
00168         inline void DrawColoredPatchClean (const patch_t *patch, int x, int y) const;
00169         inline void DrawColoredPatchCleanNoMove (const patch_t *patch, int x, int y) const;
00170 
00171         inline void DrawColoredLucentPatch (const patch_t *patch, int x, int y) const;
00172         inline void DrawColoredLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const;
00173         inline void DrawColoredLucentPatchDirect (const patch_t *patch, int x, int y) const;
00174         inline void DrawColoredLucentPatchIndirect (const patch_t *patch, int x, int y) const;
00175         inline void DrawColoredLucentPatchClean (const patch_t *patch, int x, int y) const;
00176         inline void DrawColoredLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const;
00177 
00178 protected:
00179         void TextWrapper (EWrapperCode drawer, int normalcolor, int x, int y, const byte *string) const;
00180         void TextSWrapper (EWrapperCode drawer, int normalcolor, int x, int y, const byte *string) const;
00181 
00182         void DrawWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y) const;
00183         void DrawSWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y, int destwidth, int destheight) const;
00184         void DrawIWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y) const;
00185         void DrawCWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y) const;
00186         void DrawCNMWrapper (EWrapperCode drawer, const patch_t *patch, int x, int y) const;
00187 
00188         static void DrawPatchP (const byte *source, byte *dest, int count, int pitch);
00189         static void DrawLucentPatchP (const byte *source, byte *dest, int count, int pitch);
00190         static void DrawTranslatedPatchP (const byte *source, byte *dest, int count, int pitch);
00191         static void DrawTlatedLucentPatchP (const byte *source, byte *dest, int count, int pitch);
00192         static void DrawColoredPatchP (const byte *source, byte *dest, int count, int pitch);
00193         static void DrawColorLucentPatchP (const byte *source, byte *dest, int count, int pitch);
00194 
00195         static void DrawPatchSP (const byte *source, byte *dest, int count, int pitch, int yinc);
00196         static void DrawLucentPatchSP (const byte *source, byte *dest, int count, int pitch, int yinc);
00197         static void DrawTranslatedPatchSP (const byte *source, byte *dest, int count, int pitch, int yinc);
00198         static void DrawTlatedLucentPatchSP (const byte *source, byte *dest, int count, int pitch, int yinc);
00199 
00200         static void DrawPatchD (const byte *source, byte *dest, int count, int pitch);
00201         static void DrawLucentPatchD (const byte *source, byte *dest, int count, int pitch);
00202         static void DrawTranslatedPatchD (const byte *source, byte *dest, int count, int pitch);
00203         static void DrawTlatedLucentPatchD (const byte *source, byte *dest, int count, int pitch);
00204         static void DrawColoredPatchD (const byte *source, byte *dest, int count, int pitch);
00205         static void DrawColorLucentPatchD (const byte *source, byte *dest, int count, int pitch);
00206 
00207         static void DrawPatchSD (const byte *source, byte *dest, int count, int pitch, int yinc);
00208         static void DrawLucentPatchSD (const byte *source, byte *dest, int count, int pitch, int yinc);
00209         static void DrawTranslatedPatchSD (const byte *source, byte *dest, int count, int pitch, int yinc);
00210         static void DrawTlatedLucentPatchSD (const byte *source, byte *dest, int count, int pitch, int yinc);
00211 
00212         typedef void (*vdrawfunc) (const byte *source, byte *dest, int count, int pitch);
00213         typedef void (*vdrawsfunc) (const byte *source, byte *dest, int count, int pitch, int yinc);
00214 
00215         // Palettized versions of the column drawers
00216         static vdrawfunc Pfuncs[6];
00217         static vdrawsfunc Psfuncs[6];
00218 
00219         // Direct (true-color) versions of the column drawers
00220         static vdrawfunc Dfuncs[6];
00221         static vdrawsfunc Dsfuncs[6];
00222 
00223         // The current set of column drawers (set in V_SetResolution)
00224         static vdrawfunc *m_Drawfuncs;
00225         static vdrawsfunc *m_Drawsfuncs;
00226 };
00227 
00228 inline void DCanvas::DrawText (int normalcolor, int x, int y, const byte *string) const
00229 {
00230         TextWrapper (EWrapper_Translated, normalcolor, x, y, string);
00231 }
00232 inline void DCanvas::DrawTextLuc (int normalcolor, int x, int y, const byte *string) const
00233 {
00234         TextWrapper (EWrapper_TlatedLucent, normalcolor, x, y, string);
00235 }
00236 inline void DCanvas::DrawTextClean (int normalcolor, int x, int y, const byte *string) const
00237 {
00238         TextSWrapper (EWrapper_Translated, normalcolor, x, y, string);
00239 }
00240 inline void DCanvas::DrawTextCleanLuc (int normalcolor, int x, int y, const byte *string) const
00241 {
00242         TextSWrapper (EWrapper_TlatedLucent, normalcolor, x, y, string);
00243 }
00244 inline void DCanvas::DrawTextCleanMove (int normalcolor, int x, int y, const byte *string) const
00245 {
00246         TextSWrapper (EWrapper_Translated, normalcolor,
00247                 (x - 160) * CleanXfac + width / 2,
00248                 (y - 100) * CleanYfac + height / 2,
00249                 string);
00250 }
00251 
00252 inline void DCanvas::DrawText (int normalcolor, int x, int y, const char *string) const
00253 {
00254         TextWrapper (EWrapper_Translated, normalcolor, x, y, (const byte *)string);
00255 }
00256 inline void DCanvas::DrawTextLuc (int normalcolor, int x, int y, const char *string) const
00257 {
00258         TextWrapper (EWrapper_TlatedLucent, normalcolor, x, y, (const byte *)string);
00259 }
00260 inline void DCanvas::DrawTextClean (int normalcolor, int x, int y, const char *string) const
00261 {
00262         TextSWrapper (EWrapper_Translated, normalcolor, x, y, (const byte *)string);
00263 }
00264 inline void DCanvas::DrawTextCleanLuc (int normalcolor, int x, int y, const char *string) const
00265 {
00266         TextSWrapper (EWrapper_TlatedLucent, normalcolor, x, y, (const byte *)string);
00267 }
00268 inline void DCanvas::DrawTextCleanMove (int normalcolor, int x, int y, const char *string) const
00269 {
00270         TextSWrapper (EWrapper_Translated, normalcolor,
00271                 (x - 160) * CleanXfac + width / 2,
00272                 (y - 100) * CleanYfac + height / 2,
00273                 (const byte *)string);
00274 }
00275 
00276 inline void DCanvas::DrawPatch (const patch_t *patch, int x, int y) const
00277 {
00278         DrawWrapper (EWrapper_Normal, patch, x, y);
00279 }
00280 inline void DCanvas::DrawPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
00281 {
00282         DrawSWrapper (EWrapper_Normal, patch, x, y, dw, dh);
00283 }
00284 inline void DCanvas::DrawPatchDirect (const patch_t *patch, int x, int y) const
00285 {
00286         DrawWrapper (EWrapper_Normal, patch, x, y);
00287 }
00288 inline void DCanvas::DrawPatchIndirect (const patch_t *patch, int x, int y) const
00289 {
00290         DrawIWrapper (EWrapper_Normal, patch, x, y);
00291 }
00292 inline void DCanvas::DrawPatchClean (const patch_t *patch, int x, int y) const
00293 {
00294         DrawCWrapper (EWrapper_Normal, patch, x, y);
00295 }
00296 inline void DCanvas::DrawPatchCleanNoMove (const patch_t *patch, int x, int y) const
00297 {
00298         DrawCNMWrapper (EWrapper_Normal, patch, x, y);
00299 }
00300 
00301 inline void DCanvas::DrawLucentPatch (const patch_t *patch, int x, int y) const
00302 {
00303         DrawWrapper (EWrapper_Lucent, patch, x, y);
00304 }
00305 inline void DCanvas::DrawLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
00306 {
00307         DrawSWrapper (EWrapper_Lucent, patch, x, y, dw, dh);
00308 }
00309 inline void DCanvas::DrawLucentPatchDirect (const patch_t *patch, int x, int y) const
00310 {
00311         DrawWrapper (EWrapper_Lucent, patch, x, y);
00312 }
00313 inline void DCanvas::DrawLucentPatchIndirect (const patch_t *patch, int x, int y) const
00314 {
00315         DrawIWrapper (EWrapper_Lucent, patch, x, y);
00316 }
00317 inline void DCanvas::DrawLucentPatchClean (const patch_t *patch, int x, int y) const
00318 {
00319         DrawCWrapper (EWrapper_Lucent, patch, x, y);
00320 }
00321 inline void DCanvas::DrawLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const
00322 {
00323         DrawCNMWrapper (EWrapper_Lucent, patch, x, y);
00324 }
00325 
00326 inline void DCanvas::DrawTranslatedPatch (const patch_t *patch, int x, int y) const
00327 {
00328         DrawWrapper (EWrapper_Translated, patch, x, y);
00329 }
00330 inline void DCanvas::DrawTranslatedPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
00331 {
00332         DrawSWrapper (EWrapper_Translated, patch, x, y, dw, dh);
00333 }
00334 inline void DCanvas::DrawTranslatedPatchDirect (const patch_t *patch, int x, int y) const
00335 {
00336         DrawWrapper (EWrapper_Translated, patch, x, y);
00337 }
00338 inline void DCanvas::DrawTranslatedPatchIndirect (const patch_t *patch, int x, int y) const
00339 {
00340         DrawIWrapper (EWrapper_Translated, patch, x, y);
00341 }
00342 inline void DCanvas::DrawTranslatedPatchClean (const patch_t *patch, int x, int y) const
00343 {
00344         DrawCWrapper (EWrapper_Translated, patch, x, y);
00345 }
00346 inline void DCanvas::DrawTranslatedPatchCleanNoMove (const patch_t *patch, int x, int y) const
00347 {
00348         DrawCNMWrapper (EWrapper_Translated, patch, x, y);
00349 }
00350 
00351 inline void DCanvas::DrawTranslatedLucentPatch (const patch_t *patch, int x, int y) const
00352 {
00353         DrawWrapper (EWrapper_TlatedLucent, patch, x, y);
00354 }
00355 inline void DCanvas::DrawTranslatedLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
00356 {
00357         DrawSWrapper (EWrapper_TlatedLucent, patch, x, y, dw, dh);
00358 }
00359 inline void DCanvas::DrawTranslatedLucentPatchDirect (const patch_t *patch, int x, int y) const
00360 {
00361         DrawWrapper (EWrapper_TlatedLucent, patch, x, y);
00362 }
00363 inline void DCanvas::DrawTranslatedLucentPatchIndirect (const patch_t *patch, int x, int y) const
00364 {
00365         DrawIWrapper (EWrapper_TlatedLucent, patch, x, y);
00366 }
00367 inline void DCanvas::DrawTranslatedLucentPatchClean (const patch_t *patch, int x, int y) const
00368 {
00369         DrawCWrapper (EWrapper_TlatedLucent, patch, x, y);
00370 }
00371 inline void DCanvas::DrawTranslatedLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const
00372 {
00373         DrawCNMWrapper (EWrapper_TlatedLucent, patch, x, y);
00374 }
00375 
00376 inline void DCanvas::DrawColoredPatch (const patch_t *patch, int x, int y) const
00377 {
00378         DrawWrapper (EWrapper_Colored, patch, x, y);
00379 }
00380 inline void DCanvas::DrawColoredPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
00381 {
00382         DrawSWrapper (EWrapper_Colored, patch, x, y, dw, dh);
00383 }
00384 inline void DCanvas::DrawColoredPatchDirect (const patch_t *patch, int x, int y) const
00385 {
00386         DrawWrapper (EWrapper_Colored, patch, x, y);
00387 }
00388 inline void DCanvas::DrawColoredPatchIndirect (const patch_t *patch, int x, int y) const
00389 {
00390         DrawIWrapper (EWrapper_Colored, patch, x, y);
00391 }
00392 inline void DCanvas::DrawColoredPatchClean (const patch_t *patch, int x, int y) const
00393 {
00394         DrawCWrapper (EWrapper_Colored, patch, x, y);
00395 }
00396 inline void DCanvas::DrawColoredPatchCleanNoMove (const patch_t *patch, int x, int y) const
00397 {
00398         DrawCNMWrapper (EWrapper_Colored, patch, x, y);
00399 }
00400 
00401 inline void DCanvas::DrawColoredLucentPatch (const patch_t *patch, int x, int y) const
00402 {
00403         DrawWrapper (EWrapper_ColoredLucent, patch, x, y);
00404 }
00405 inline void DCanvas::DrawColoredLucentPatchStretched (const patch_t *patch, int x, int y, int dw, int dh) const
00406 {
00407         DrawSWrapper (EWrapper_ColoredLucent, patch, x, y, dw, dh);
00408 }
00409 inline void DCanvas::DrawColoredLucentPatchDirect (const patch_t *patch, int x, int y) const
00410 {
00411         DrawWrapper (EWrapper_ColoredLucent, patch, x, y);
00412 }
00413 inline void DCanvas::DrawColoredLucentPatchIndirect (const patch_t *patch, int x, int y) const
00414 {
00415         DrawIWrapper (EWrapper_ColoredLucent, patch, x, y);
00416 }
00417 inline void DCanvas::DrawColoredLucentPatchClean (const patch_t *patch, int x, int y) const
00418 {
00419         DrawCWrapper (EWrapper_ColoredLucent, patch, x, y);
00420 }
00421 inline void DCanvas::DrawColoredLucentPatchCleanNoMove (const patch_t *patch, int x, int y) const
00422 {
00423         DrawCNMWrapper (EWrapper_ColoredLucent, patch, x, y);
00424 }
00425 
00426 extern "C" palette_t *DefaultPalette;
00427 
00428 // This is the screen updated by I_FinishUpdate.
00429 extern  DCanvas *screen;
00430 
00431 extern  DBoundingBox    dirtybox;
00432 
00433 extern byte newgamma[256];
00434 EXTERN_CVAR (gammalevel)
00435 
00436 // Translucency tables
00437 extern unsigned int Col2RGB8[65][256];
00438 extern byte RGB32k[32][32][32];
00439 
00440 // Allocates buffer screens, call before R_Init.
00441 void V_Init (void);
00442 
00443 // The color to fill with for #4 and #5 above
00444 extern int V_ColorFill;
00445 
00446 // The color map for #1 and #2 above
00447 extern byte *V_ColorMap;
00448 
00449 // The palette lookup table to be used with for direct modes
00450 extern unsigned int *V_Palette;
00451 
00452 void V_MarkRect (int x, int y, int width, int height);
00453 
00454 // BestColor
00455 byte BestColor (const DWORD *palette, const int r, const int g, const int b, const int numcolors);
00456 // Returns the closest color to the one desired. String
00457 // should be of the form "rr gg bb".
00458 int V_GetColorFromString (const DWORD *palette, const char *colorstring);
00459 // Scans through the X11R6RGB lump for a matching color
00460 // and returns a color string suitable for V_GetColorFromString.
00461 std::string V_GetColorStringByName (const char *name);
00462 
00463 
00464 BOOL V_SetResolution (int width, int height, int bpp);
00465 
00466 
00467 #ifdef USEASM
00468 extern "C" void ASM_PatchPitch (void);
00469 extern "C" void ASM_PatchColSize (void);
00470 #endif
00471 
00472 #endif // __V_VIDEO_H__
00473 
00474 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends