Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
5.4 KiB

  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. // Copyright (c) 1997-1999 Microsoft Corporation. All rights reserved
  20. //-----------------------------------------------------------------------------
  21. #ifndef D3DFRAME_H
  22. #define D3DFRAME_H
  23. #include <ddraw.h>
  24. #include <d3d.h>
  25. //-----------------------------------------------------------------------------
  26. // Name: CD3DFramework7
  27. // Desc: The Direct3D sample framework class for DX7. Maintains the D3D
  28. // surfaces and device used for 3D rendering.
  29. //-----------------------------------------------------------------------------
  30. class CD3DFramework7
  31. {
  32. // Internal variables for the framework class
  33. HWND m_hWnd; // The window object
  34. BOOL m_bIsFullscreen; // Fullscreen vs. windowed
  35. BOOL m_bIsStereo; // Stereo view mode
  36. DWORD m_dwRenderWidth; // Dimensions of the render target
  37. DWORD m_dwRenderHeight;
  38. RECT m_rcScreenRect; // Screen rect for window
  39. LPDIRECTDRAW7 m_pDD; // The DirectDraw object
  40. LPDIRECT3D7 m_pD3D; // The Direct3D object
  41. LPDIRECT3DDEVICE7 m_pd3dDevice; // The D3D device
  42. LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer; // The primary surface
  43. LPDIRECTDRAWSURFACE7 m_pddsBackBuffer; // The backbuffer surface
  44. LPDIRECTDRAWSURFACE7 m_pddsBackBufferLeft; // For stereo modes
  45. LPDIRECTDRAWSURFACE7 m_pddsZBuffer; // The zbuffer surface
  46. DWORD m_dwDeviceMemType;
  47. // Internal functions for the framework class
  48. HRESULT CreateZBuffer(GUID*);
  49. HRESULT CreateFullscreenBuffers(DDSURFACEDESC2*);
  50. HRESULT CreateWindowedBuffers();
  51. HRESULT CreateDirectDraw(GUID*, DWORD);
  52. HRESULT CreateDirect3D(GUID*);
  53. HRESULT CreateEnvironment(GUID*, GUID*, DDSURFACEDESC2*, DWORD);
  54. public:
  55. // Access functions for DirectX objects
  56. LPDIRECTDRAW7 GetDirectDraw() { return m_pDD; }
  57. LPDIRECT3D7 GetDirect3D() { return m_pD3D; }
  58. LPDIRECT3DDEVICE7 GetD3DDevice() { return m_pd3dDevice; }
  59. LPDIRECTDRAWSURFACE7 GetFrontBuffer() { return m_pddsFrontBuffer; }
  60. LPDIRECTDRAWSURFACE7 GetBackBuffer() { return m_pddsBackBuffer; }
  61. LPDIRECTDRAWSURFACE7 GetRenderSurface() { return m_pddsBackBuffer; }
  62. LPDIRECTDRAWSURFACE7 GetRenderSurfaceLeft() { return m_pddsBackBufferLeft; }
  63. // Functions to aid rendering
  64. HRESULT RestoreSurfaces();
  65. HRESULT ShowFrame();
  66. HRESULT FlipToGDISurface(BOOL bDrawFrame = FALSE);
  67. // Functions for managing screen and viewport bounds
  68. BOOL IsFullscreen() { return m_bIsFullscreen; }
  69. BOOL IsStereo() { return m_bIsStereo; }
  70. VOID Move(INT x, INT y);
  71. // Creates the Framework
  72. HRESULT Initialize(HWND hWnd, GUID* pDriverGUID, GUID* pDeviceGUID,
  73. DDSURFACEDESC2* pddsd, DWORD dwFlags);
  74. HRESULT DestroyObjects();
  75. CD3DFramework7();
  76. ~CD3DFramework7();
  77. };
  78. //-----------------------------------------------------------------------------
  79. // Flags used for the Initialize() method of a CD3DFramework object
  80. //-----------------------------------------------------------------------------
  81. #define D3DFW_FULLSCREEN 0x00000001 // Use fullscreen mode
  82. #define D3DFW_STEREO 0x00000002 // Use stereo-scopic viewing
  83. #define D3DFW_ZBUFFER 0x00000004 // Create and use a zbuffer
  84. #define D3DFW_NO_FPUSETUP 0x00000008 // Don't use default DDSCL_FPUSETUP flag
  85. //-----------------------------------------------------------------------------
  86. // Errors that the Initialize() and ChangeDriver() calls may return
  87. //-----------------------------------------------------------------------------
  88. #define D3DFWERR_INITIALIZATIONFAILED 0x82000000
  89. #define D3DFWERR_NODIRECTDRAW 0x82000001
  90. #define D3DFWERR_COULDNTSETCOOPLEVEL 0x82000002
  91. #define D3DFWERR_NODIRECT3D 0x82000003
  92. #define D3DFWERR_NO3DDEVICE 0x82000004
  93. #define D3DFWERR_NOZBUFFER 0x82000005
  94. #define D3DFWERR_INVALIDZBUFFERDEPTH 0x82000006
  95. #define D3DFWERR_NOVIEWPORT 0x82000007
  96. #define D3DFWERR_NOPRIMARY 0x82000008
  97. #define D3DFWERR_NOCLIPPER 0x82000009
  98. #define D3DFWERR_BADDISPLAYMODE 0x8200000a
  99. #define D3DFWERR_NOBACKBUFFER 0x8200000b
  100. #define D3DFWERR_NONZEROREFCOUNT 0x8200000c
  101. #define D3DFWERR_NORENDERTARGET 0x8200000d
  102. #define D3DFWERR_INVALIDMODE 0x8200000e
  103. #define D3DFWERR_NOTINITIALIZED 0x8200000f
  104. #endif // D3DFRAME_H