OPTPiX SpriteStudio SDK
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
d3dsimple.h
1 #ifndef __RS_DX9__
2 #define __RS_DX9__
3 
4 //#include "Draw.h"
5 //#include "DirectDraw_Font.h"
6 
7 
8 
9 #include <d3d9.h>
10 #include <vector>
11 #include <string>
12 
13 
14 
15 #pragma comment(lib, "d3d9.lib")
16 //#pragma comment(lib, "d3dx9.lib")
17 
18 
19 #define RELEASE(o) if (o){o->Release();o=NULL;}
20 #define PI (3.1415926f)
21 #define DEGtoRAD(deg) ((float)deg * 0.017453292f)
22 #define RADtoDEG(rad) ((float)rad * 57.29578049f)
23 #define SAFE_DELETE(p) { if(p){ delete (p); (p)=NULL; } }
24 #define SAFE_DELETE_ARRAY(p) { if(p){ delete [](p); (p)=NULL; } }
25 #define SAFE_RELEASE(p) { if(p){ (p)->Release(); (p)=NULL; } }
26 
27 
28 //---------------------------------------------------------------------------------------------------------
29 //
30 //
31 //---------------------------------------------------------------------------------------------------------
32 typedef void (*CDirectDrawCALLBACK)(); //ハッシュ値作成
33 
35 {
36  virtual BOOL Dispose() = 0;
37  virtual BOOL Restore() = 0;
38  virtual BOOL Release() = 0;
39 };
40 
41 #if 0
42 class CDirectDraw_RenderState
43 {
44 private:
45  DWORD m_valuePrevious[300];
46  DWORD m_valueNew[300];
47 
48 public:
49  void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value)
50  {
51  m_valueNew[(int)State] = Value;
52  }
53  void Update()
54  {
55  HRESULT hr;
56 // LPDIRECT3DDEVICE9 Device = GetD3DDevice();
57  DWORD valueNew;
58  for(int i=0; i<300; i++)
59  {
60  valueNew = m_valueNew[i];
61  if((DWORD)0x7fffffff != valueNow)
62  {
63  if(m_valuePrevious[i] != valueNew)
64  { /* 値が同じ時には書き換えない */
65 // hr = Device->SetRenderState((D3DRENDERSTATETYPE)i, valueNew);
66  }
67  }
68  m_valuePrevious[i] = valueNew;
69  }
70  }
71  void Clear()
72  {
73  for(int i=0; i<300; i++)
74  {
75  m_valuePrevious[i] = (DWORD)0x7fffffff;
76  m_valueNew[i] = (DWORD)0x7fffffff;
77  }
78  }
79 
80  CDirectDraw_RenderState()
81  {
82  Clear();
83  }
84  ~CDirectDraw_RenderState()
85  {
86  }
87 };
88 #endif
89 
91 {
92 public:
94  {
98  };
99 
100 private:
101  static CDirectDrawSimple* myInst;
102  LPDIRECT3D9 m_pD3D;
103 
104  int m_dwWidth;
105  int m_dwHeight;
106 
107  DWORD m_VertexShaderVersion;
108  DWORD m_PixelShaderVersion;
109 
110  D3DPRESENT_PARAMETERS m_d3dParam_current;
111  D3DPRESENT_PARAMETERS m_d3dParam_window;
112  D3DPRESENT_PARAMETERS m_d3dParam_full;
113 
114  LPDIRECT3DDEVICE9 m_pd3dDev;
115  LPDIRECT3DSURFACE9 m_pBackBuffer;
116  LPDIRECT3DSURFACE9 m_currentRenderTarget;
117 
118  HWND m_hwnd;
119  int m_Vertextype;
120  static bool m_DeviceLost;
121 
122  bool m_pause;
123  DISPLAYMODE m_current_displaymode;
124 
125  RECT g_rectWindow;
126 
127  BYTE bgcolorR;
128  BYTE bgcolorG;
129  BYTE bgcolorB;
130 
131 
132  CDirectDrawCALLBACK m_ReleaseDeviceCallback;
133  CDirectDrawCALLBACK m_RestoreDeviceCallback;
134 
135 private:
136  void CreateCaps();
137  BOOL Create( void* HWND , int ScreenWidth , int ScreenHeight );
138 
139 public:
141  {
142  m_pause = false;
143  }
144 
146  HWND HWND ,
147  int ScreenWidth ,
148  int ScreenHeight,
150  {
151  m_pBackBuffer = 0;
152  m_DeviceLost = false;
153  m_current_displaymode = displaymode;
154  Create( HWND , ScreenWidth , ScreenHeight );
155  m_hwnd = HWND;
156  m_pause = false;
157  myInst = this;
158 
159  }
160 
162  {
163  Cleanup();
164  myInst = 0;
165  }
166 
167  BOOL Cleanup();
168 
169  virtual HRESULT BeginScene();
170  virtual HRESULT EndScene();
171 
172  HWND GetHWnd(){ return m_hwnd; }
173  LPDIRECT3D9 GetD3D(){ return m_pD3D; }
174  LPDIRECT3DDEVICE9 GetDevice(){ return m_pd3dDev;}
175 
176  static CDirectDrawSimple* GetInstance(){return myInst;}
177 
178 
179  int GetScreenWidth(){ return m_dwWidth;}
180  int GetScreenHeight(){ return m_dwHeight;}
181  void SetScreenWidth( int w ) { m_dwWidth = w;}
182  void SetScreenHeight( int h ) { m_dwHeight = h;}
183 
184 
185 
186  LPDIRECT3DSURFACE9 getBackBuffer();
187 
188  void SetRenderTarget(int index , LPDIRECT3DSURFACE9 surface , LPDIRECT3DSURFACE9 depath = 0)
189  {
190  m_currentRenderTarget = surface;
191  m_pd3dDev->SetRenderTarget( index , surface );
192  if ( depath )
193  {
194  m_pd3dDev->SetDepthStencilSurface( depath );
195  }
196  }
197 
198  LPDIRECT3DSURFACE9 GetRenderTarget()
199  {
200  return m_currentRenderTarget;
201  }
202 
203  void SetPause( bool flag )
204  {
205  m_pause = flag;
206  }
207 
208  virtual void ChangeDisplayMode( DISPLAYMODE mode );
209  DISPLAYMODE GetCurrentDisplayMode(){ return m_current_displaymode; }
210  virtual BOOL DeviceChk();
211 
212  void SetBackGroundColor( BYTE r , BYTE g , BYTE b )
213  {
214  bgcolorR = r;
215  bgcolorG = g;
216  bgcolorB = b;
217 
218  }
219 
220  DWORD GetVSVersion(){return m_VertexShaderVersion; }
221  DWORD GetPSVersion(){return m_PixelShaderVersion; }
222  void SetReleaseDeviceCallBackFunc(CDirectDrawCALLBACK func ) { m_ReleaseDeviceCallback = func; }
223  void SetRestoreDeviceCallBackFunc(CDirectDrawCALLBACK func ) { m_RestoreDeviceCallback = func; }
224 
225 // CDirectDraw_RenderState* GetRenderState();
226 
227  void DeviceReset();
228 };
229 
230 /*
231 void Setup2DMatrix( int width , int height , float center_posx , float center_posy );
232 void Setup2DMatrix( int width , int height );
233 */
234 
235 
236 #endif