1 #pragma once 2 // Copyleft 2005 Chris Korda 3 // This program is free software; you can redistribute it and/or modify it 4 // under the terms of the GNU General Public License as published by the Free 5 // Software Foundation; either version 2 of the License, or any later version. 6 /* 7 chris korda 8 9 revision history: 10 rev date comments 11 00 10may05 initial version 12 01 05may06 add CreateSurface wrapper 13 14 DirectDraw back buffer for off-screen drawing 15 16 */ 17 #include "base.h" 18 #include "rect.h" 19 #include "vector4.h" 20 #include "wobject.h" 21 #include <ddraw.h> 22 #include <queue> 23 24 class CBackBufDD 25 { 26 public: 27 enum { 28 OPT_AUTO_MEMORY = 0x01, // automatically decide back buffer location; 29 // otherwise OPT_USE_VIDEO_MEM sets location 30 OPT_USE_VIDEO_MEM = 0x02, // if specified, create back buffer in video 31 // memory, else create it in system memory; 32 // ignored if OPT_AUTO_MEMORY is specified 33 OPT_MIRROR_PRECISE = 0x04 // make mirroring more precise at the expense 34 // of mirroring to an intermediate back buffer 35 }; 36 CBackBufDD(); 37 ~CBackBufDD(); 38 BOOL Create(HWND Main, HWND View, GUID *Driver = NULL, bool Exclusive = FALSE); 39 void Destroy(); 40 void DeleteSurface(); 41 bool CreateSurface(int Width, int Height); 42 void DrawQuad(const Base::Math::CRect &_rect, const Base::Math::CVector4 &_color, const Base::Math::CRect &_uvrect ); 43 void SetContexts(LPDIRECTDRAWSURFACE7 _tex, int _SrcWidth, int _SrcHeight); 44 HRESULT GetDC(HDC FAR *lphDC); 45 HRESULT ReleaseDC(HDC hDC); 46 bool Blt(); 47 HRESULT GetLastError() const; 48 LPCSTR GetLastErrorString() const; 49 bool IsCreated() const; 50 void SetMirror(bool Enable); 51 bool IsMirrored() const; 52 void SetOptions(int Options); 53 int GetOptions() const; 54 bool SetExclusive(HWND Main, HWND View, bool Enable); 55 SIZE GetSize() const; 56 bool IsExclusive() const; 57 bool IsSurface() const; 58 static HMONITOR GetFullScreenRect(HWND hWnd, RECT& rc); 59 static bool GetMonitorGUID(HMONITOR hMon, GUID& MonGuid); 60 static LPCSTR GetErrorString(HRESULT hr); 61 HRESULT CreateSurface(LPDDSURFACEDESC2 SurfaceDesc, LPDIRECTDRAWSURFACE7 FAR *Surface); 62 63 private: 64 typedef struct tagERRTRAN { 65 HRESULT Code; 66 LPCSTR Text; 67 } ERRTRAN; 68 typedef struct tagMONGUID { 69 HMONITOR Mon; 70 GUID Guid; 71 BOOL Valid; 72 } MONGUID; 73 static const ERRTRAN m_ErrTran[]; // map DirectDraw error codes to text 74 LPDIRECTDRAW7 m_dd; // pointer to DirectDraw instance 75 LPDIRECTDRAWSURFACE7 m_Front; // pointer to front buffer 76 LPDIRECTDRAWSURFACE7 m_Back; // pointer to back buffer surface 77 LPDIRECTDRAWSURFACE7 m_Mirror; // pointer to mirroring buffer 78 LPDIRECTDRAWSURFACE7 m_DrawBuf; // pointer to buffer we draw to 79 LPDIRECTDRAWCLIPPER m_Clipper; // pointer to clipper 80 HWND m_Main; // top-level owner 81 HWND m_View; // window to clip to 82 HRESULT m_hr; // most recent DirectDraw result code 83 int m_Width; // width of window, in client coords 84 int m_Height; // height of window, in client coords 85 bool m_IsMirrored; // true if we're mirroring 86 bool m_IsExclusive; // true if we're in full-screen exclusive mode 87 int m_Options; // display options; see enum above 88 89 std::queue<LPDIRECTDRAWSURFACE7> m_Tex; 90 std::queue<int> m_SrcWidth; 91 std::queue<int> m_SrcHeight; 92 bool m_ContextsUsed; 93 WINDOWPLACEMENT m_PreExcl; // window placement before exclusive mode 94 95 static BOOL WINAPI DDEnumCallbackEx(GUID FAR *lpGUID, LPTSTR lpDriverDescription, 96 LPTSTR lpDriverName, LPVOID lpContext, HMONITOR hm); 97 };