]> icculus.org git repositories - btb/d2x.git/blob - arch/win32/d3dframe/d3dframe.h
implement -nomusic for linux hmiplay (d1x r1.8)
[btb/d2x.git] / arch / win32 / d3dframe / d3dframe.h
1 //-----------------------------------------------------------------------------
2 // File: D3DFrame.h
3 //
4 // Desc: Class to manage the Direct3D environment objects such as buffers,
5 //       viewports, and 3D devices.
6 //
7 //       The class is initialized with the Initialize() function, after which
8 //       the Get????() functions can be used to access the objects needed for
9 //       rendering. If the device or display needs to be changed, the
10 //       ChangeDevice() function can be called. If the display window is moved
11 //       the changes need to be reported with the Move() function.
12 //
13 //       After rendering a frame, the ShowFrame() function filps or blits the
14 //       backbuffer contents to the primary. If surfaces are lost, they can be
15 //       restored with the RestoreSurfaces() function. Finally, if normal
16 //       Windows output is needed, the FlipToGDISurface() provides a GDI
17 //       surface to draw on.
18 //
19 //
20 // Copyright (C) 1997 Microsoft Corporation. All rights reserved
21 //-----------------------------------------------------------------------------
22
23
24 #ifndef D3DFRAME_H
25 #define D3DFRAME_H
26
27 #include <ddraw.h>
28 #include <d3d.h>
29
30
31
32
33 //-----------------------------------------------------------------------------
34 // Name: CD3DFramework
35 // Desc: The Direct3D sample framework class. Maintains the D3D surfaces,
36 //       device, and viewport used for 3D rendering.
37 //-----------------------------------------------------------------------------
38 class CD3DFramework
39 {
40     // Internal variables for the framework class
41     HWND                 m_hWnd;             // The window object
42     BOOL                 m_bIsFullscreen;    // Fullscreen vs. windowed
43     RECT                 m_rcViewportRect;   // Offscreen rect for VPort
44     LPDIRECTDRAWSURFACE4 m_pddsFrontBuffer;  // The primary surface
45     LPDIRECTDRAWSURFACE4 m_pddsBackBuffer;   // The backbuffer surface
46     LPDIRECTDRAWSURFACE4 m_pddsRenderTarget; // The render target surface
47     LPDIRECTDRAWSURFACE4 m_pddsZBuffer;      // The zbuffer surface
48     LPDIRECT3DDEVICE3    m_pd3dDevice;       // The D3D device
49     LPDIRECT3DVIEWPORT3  m_pvViewport;       // The D3D viewport
50     LPDIRECTDRAW4        m_pDD;              // The DirectDraw object
51     LPDIRECT3D3          m_pD3D;             // The Direct3D object
52     D3DDEVICEDESC        m_ddDeviceDesc;
53     DWORD                m_dwDeviceMemType;
54     DDPIXELFORMAT        m_ddpfZBuffer;      // Enumerated zbuffer format
55
56     // Internal functions for the framework class
57     HRESULT CreateViewport();
58     HRESULT Create3DDevice( GUID* );
59     HRESULT CreateZBuffer();
60     HRESULT CreateBuffers( DDSURFACEDESC2*, DWORD );
61     HRESULT CreateDirectDraw( GUID*, DWORD );
62     HRESULT CreateDirect3D( GUID*, DWORD );
63     HRESULT CreateEnvironment( GUID*, GUID*, DDSURFACEDESC2*, DWORD );
64
65 public:
66     DWORD                m_dwRenderWidth;    // Dimensions of the render target
67     DWORD                m_dwRenderHeight;
68     RECT                 m_rcScreenRect;     // Screen rect for window
69
70     // Access functions for DirectX objects
71     LPDIRECTDRAW4        GetDirectDraw()     { return m_pDD; }
72     LPDIRECT3D3          GetDirect3D()       { return m_pD3D; }
73     LPDIRECT3DDEVICE3    GetD3DDevice()      { return m_pd3dDevice; }
74     LPDIRECT3DVIEWPORT3  GetViewport()       { return m_pvViewport; }
75     LPDIRECTDRAWSURFACE4 GetFrontBuffer()    { return m_pddsFrontBuffer; }
76     LPDIRECTDRAWSURFACE4 GetBackBuffer()     { return m_pddsBackBuffer; }
77     LPDIRECTDRAWSURFACE4 GetRenderSurface()  { return m_pddsRenderTarget; }
78
79     // Functions to aid rendering
80     HRESULT RestoreSurfaces();
81     HRESULT ShowFrame();
82     HRESULT FlipToGDISurface( BOOL bDrawFrame );
83
84     // Functions for managing screen and viewport bounds
85     BOOL    IsFullscreen()                  { return m_bIsFullscreen; }
86     RECT*   GetViewportRect()               { return &m_rcViewportRect; }
87     VOID    Move( INT x, INT y );
88
89     // Functions to support sprite-based rendering
90     HRESULT ChangeRenderTarget( LPDIRECTDRAWSURFACE4 pddsNewTarget );
91
92     // Creates the Framework
93     HRESULT Initialize( HWND hWnd, GUID* pDriverGUID, GUID* pDeviceGUID,
94                         DDSURFACEDESC2* pddsd, DWORD dwFlags );
95     HRESULT DestroyObjects();
96
97             CD3DFramework();
98            ~CD3DFramework();
99 };
100
101
102
103
104 //-----------------------------------------------------------------------------
105 // Flags used for the Initialize() method of a CD3DFramework object
106 //-----------------------------------------------------------------------------
107 #define D3DFW_FULLSCREEN    0x00000001 // Use fullscreen mode
108 #define D3DFW_BACKBUFFER    0x00000002 // Create and use a backbuffer
109 #define D3DFW_ZBUFFER       0x00000004 // Create and use a zbuffer
110 #define D3DFW_STENCILBUFFER 0x00000008 // Use a z-buffer w/stenciling
111 #define D3DFW_NO_FPUSETUP   0x00000010 // Don't use default DDSCL_FPUSETUP flag
112
113
114
115 //-----------------------------------------------------------------------------
116 // Errors that the Initialize() and ChangeDriver() calls may return
117 //-----------------------------------------------------------------------------
118 #define D3DFWERR_INITIALIZATIONFAILED 0x82000000
119 #define D3DFWERR_NODIRECTDRAW         0x82000001
120 #define D3DFWERR_COULDNTSETCOOPLEVEL  0x82000002
121 #define D3DFWERR_NODIRECT3D           0x82000003
122 #define D3DFWERR_NO3DDEVICE           0x82000004
123 #define D3DFWERR_NOZBUFFER            0x82000005
124 #define D3DFWERR_NOVIEWPORT           0x82000006
125 #define D3DFWERR_NOPRIMARY            0x82000007
126 #define D3DFWERR_NOCLIPPER            0x82000008
127 #define D3DFWERR_BADDISPLAYMODE       0x82000009
128 #define D3DFWERR_NOBACKBUFFER         0x8200000a
129 #define D3DFWERR_NONZEROREFCOUNT      0x8200000b
130 #define D3DFWERR_NORENDERTARGET       0x8200000c
131 #define D3DFWERR_INVALIDMODE          0x8200000d
132 #define D3DFWERR_NOTINITIALIZED       0x8200000e
133
134
135 #endif // D3DFRAME_H
136