1 /* -*- c++ -*- 2 FILE: WrapDD.h 3 RCS REVISION: $Revision: 1.8 $ 4 5 COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software 6 7 LICENSE: Free to use and modify for non-commercial purposes as long as the 8 following conditions are adhered to: 9 1) Obvious credit for the source of this code and the designs it embodies 10 are clearly made, and 11 2) Ports and derived versions of 4D Magic Cube programs are not distributed 12 without the express written permission of the authors. 13 14 DESCRIPTION: 15 Abstraction on top of Direct Draw 16 */ 17 18 #ifndef WrapDD_h 19 #define WrapDD_h 20 21 #ifndef STRICT 22 #define STRICT 1 23 #endif 24 25 #define NOMINMAX // to avoid conflict with STL 26 #include <ddraw.h> 27 28 // client needs to: 29 // when WM_SIZE: query WrapDD (IgnorewWM_SIZE()) if it should ignore it 30 31 class WrapDD 32 { 33 public: 34 typedef void (*ErrorHandler) (const char *, HRESULT, void *); 35 struct Mode 36 { 37 int width; 38 int height; 39 int bitsPerPixel; 40 41 int operator == (const Mode & rMode)const { 42 return ((width == rMode.width) && 43 (height == rMode.height) && 44 (bitsPerPixel == rMode.bitsPerPixel)); 45 } 46 }; 47 48 public: 49 WrapDD (); 50 virtual ~ WrapDD (); 51 52 virtual BOOL Create(HWND, 53 BOOL fullScreen, 54 int width, int height, int bpp, 55 const PALETTEENTRY * pPaletteEntries, 56 int pPaletteEntryCount); 57 virtual void Destroy(); 58 virtual void DestroyButNotDirectDraw(); 59 HWnd()60 HWND HWnd() 61 { 62 return m_hWndMain; 63 } DirectDraw()64 IDirectDraw *DirectDraw() 65 { 66 return m_pDirectDraw; 67 } FrontBuffer()68 IDirectDrawSurface *FrontBuffer() 69 { 70 return m_pFrontBuffer; 71 } BackBuffer()72 IDirectDrawSurface *BackBuffer() 73 { 74 return m_pBackBuffer; 75 } ZBuffer()76 IDirectDrawSurface *ZBuffer() 77 { 78 return m_pZBuffer; 79 } Palette()80 IDirectDrawPalette *Palette() 81 { 82 return m_pPalette; 83 } 84 IsFullScreen()85 BOOL IsFullScreen() const 86 { 87 return m_bFullScreen; 88 } CurrentMode()89 const Mode & CurrentMode() const 90 { 91 return m_currentMode; 92 } 93 ModeCount()94 int ModeCount() const 95 { 96 return m_modeCount; 97 } GetMode(int i)98 const Mode & GetMode(int i) const 99 { 100 return m_modes[i]; 101 } 102 BOOL IsSupportedMode(int width, int height, int bpp); 103 IgnoreWM_SIZE()104 BOOL IgnoreWM_SIZE() const 105 { 106 return m_bIgnoreWM_SIZE; 107 } 108 109 BOOL Activate(); 110 BOOL Pause(BOOL); 111 BOOL RestoreSurfaces(); 112 BOOL Flip(); 113 BOOL BltBackBuffer(RECT &to, RECT &from); 114 115 BOOL TextToTextSurface1(const char *); 116 BOOL TextToTextSurface2(const char *); 117 BOOL TextSurface1ToBackBuffer(); 118 BOOL TextSurface2ToBackBuffer(); 119 120 void SetFatalErrorHandler(ErrorHandler, void *); 121 void SetErrorHandler(ErrorHandler, void *); 122 123 virtual const char *ErrorToString(HRESULT); 124 void Error(const char *, HRESULT); 125 void FatalError(const char *, HRESULT); 126 127 128 protected: 129 BOOL SetPaletteEntries(const PALETTEENTRY * 130 pPaletteEntries, 131 int paletteEntryCount, 132 BOOL fullScreen); 133 BOOL CacheOriginalPaletteEntries(); 134 BOOL RestoreOriginalPaletteEntries(); 135 BOOL RestorePaletteEntries(); 136 BOOL FlipToGDISurface(); 137 138 BOOL DDCreate(); 139 BOOL DDInit(BOOL fullScreen); 140 BOOL DDSetMode(int width, int height, int bpp); 141 BOOL DDCreateSurfaces(); 142 HRESULT CreateDDSurface(LPDDSURFACEDESC, LPDIRECTDRAWSURFACE *, 143 IUnknown *); 144 BOOL GetDDSurfaceDesc(LPDDSURFACEDESC, LPDIRECTDRAWSURFACE); 145 BOOL EnumerateDisplayModes(); 146 HRESULT EnumDisplayModesCallback(LPDDSURFACEDESC); 147 BOOL EnumDirectDrawCallback(GUID *, char *, char *); 148 long FreeVideoMemory(); 149 long TotalVideoMemory(); 150 BOOL CreateZBuffer(DWORD memorytype, DWORD depth); 151 BOOL GetHardwareCaps(DDCAPS &rDriverCaps, DDCAPS &rHELCaps); 152 153 BOOL CreateTextSurfaces(); 154 BOOL TextToTextSurface(const char *, IDirectDrawSurface *, SIZE &); 155 BOOL TextSurfaceToBackBuffer(IDirectDrawSurface *, SIZE &, int); 156 157 static HRESULT CALLBACK EnumDisplayModesCallback(LPDDSURFACEDESC, void *); 158 static BOOL CALLBACK EnumDirectDrawCallback(GUID *, char *, char *, 159 void *); 160 161 static int _cdecl CompareModes(const void *, const void *); 162 163 virtual BOOL FilterDisplayModes(LPDDSURFACEDESC); 164 165 protected: 166 BOOL m_bOnlySoftRender; 167 168 private: 169 IDirectDraw * m_pDirectDraw; 170 IDirectDrawSurface *m_pFrontBuffer; 171 IDirectDrawSurface *m_pBackBuffer; 172 IDirectDrawSurface *m_pZBuffer; 173 IDirectDrawSurface *m_pText1Surface; // top 174 IDirectDrawSurface *m_pText2Surface; // bottom 175 IDirectDrawClipper *m_pClipper; 176 IDirectDrawPalette *m_pPalette; 177 PALETTEENTRY m_paletteEntries[256]; 178 PALETTEENTRY m_originalPaletteEntries[256]; 179 DDSCAPS m_HWddsCaps; 180 181 SIZE m_text1SizeOnSurface; 182 SIZE m_text2SizeOnSurface; 183 184 HWND m_hWndMain; 185 HFONT m_hFont; 186 Mode m_currentMode; 187 Mode m_modes[32]; 188 int m_modeCount; 189 BOOL m_bIgnoreWM_SIZE; 190 191 GUID m_guid; 192 BOOL m_bIsOnPrimaryDevice; 193 BOOL m_bPrimaryPalettized; 194 BOOL m_bFullScreen; 195 BOOL m_bLastWasFullScreen; 196 BOOL m_bOnlySystemMemory; 197 198 long m_totalVideoMemory; 199 200 ErrorHandler m_pErrorHandler; 201 ErrorHandler m_pFatalErrorHandler; 202 void *m_pErrorHandlerArg; 203 void *m_pFatalErrorHandlerArg; 204 205 int m_pauseCount; 206 }; 207 208 #endif /* WrapDD_h */ 209 210 // Local Variables: 211 // c-basic-offset: 4 212 // c-comment-only-line-offset: 0 213 // c-file-offsets: ((defun-block-intro . +) (block-open . 0) (substatement-open . 0) (statement-cont . +) (statement-case-open . +4) (arglist-intro . +) (arglist-close . +) (inline-open . 0)) 214 // indent-tabs-mode: nil 215 // End: 216