d3ddevice.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include "pch.h"
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // D3DDevice
  5. //
  6. //////////////////////////////////////////////////////////////////////////////
  7. class D3DDeviceImpl : public D3DDevice {
  8. private:
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // Members
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. TRef<DDDevice> m_pdddevice;
  15. TRef<IDirect3DDeviceX> m_pd3dd;
  16. TRef<PixelFormat> m_ppfPrefered;
  17. TRef<PixelFormat> m_ppfTexture;
  18. bool m_bHardwareAccelerated;
  19. //////////////////////////////////////////////////////////////////////////////
  20. //
  21. // Texture Pixel Format Enumeration
  22. //
  23. //////////////////////////////////////////////////////////////////////////////
  24. static HRESULT WINAPI StaticEnumTextures(LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext)
  25. {
  26. D3DDeviceImpl* pthis = (D3DDeviceImpl*)lpContext;
  27. return pthis->EnumTextures(*(DDPixelFormat*)lpDDPixFmt);
  28. }
  29. HRESULT EnumTextures(const DDPixelFormat& ddpf)
  30. {
  31. TRef<PixelFormat> ppf = m_pdddevice->GetEngine()->GetPixelFormat(ddpf);
  32. if (
  33. ppf->ValidGDIFormat()
  34. && ppf->PixelBits() >= 16
  35. ) {
  36. if (
  37. (m_ppfTexture == NULL)
  38. || (ppf == m_ppfPrefered)
  39. || (ddpf.dwRGBBitCount < m_ppfTexture->PixelBits())
  40. ) {
  41. m_ppfTexture = ppf;
  42. }
  43. }
  44. return DDENUMRET_OK;
  45. }
  46. public:
  47. //////////////////////////////////////////////////////////////////////////////
  48. //
  49. // Constructor
  50. //
  51. //////////////////////////////////////////////////////////////////////////////
  52. D3DDeviceImpl(
  53. DDDevice* pdddevice,
  54. IDirect3DDeviceX* pd3dd,
  55. bool bHardwareAccelerated,
  56. PixelFormat* ppf
  57. ) :
  58. m_pdddevice(pdddevice),
  59. m_pd3dd(pd3dd),
  60. m_bHardwareAccelerated(bHardwareAccelerated),
  61. m_ppfPrefered(ppf)
  62. {
  63. //
  64. // Find a 16 bit Texture Format
  65. //
  66. m_pd3dd->EnumTextureFormats(StaticEnumTextures, (void*)this);
  67. }
  68. bool IsValid()
  69. {
  70. return m_ppfTexture != NULL;
  71. }
  72. //////////////////////////////////////////////////////////////////////////////
  73. //
  74. // Destructor
  75. //
  76. //////////////////////////////////////////////////////////////////////////////
  77. ~D3DDeviceImpl()
  78. {
  79. m_pdddevice->RemoveD3DDevice(this);
  80. }
  81. //////////////////////////////////////////////////////////////////////////////
  82. //
  83. // Termination
  84. //
  85. //////////////////////////////////////////////////////////////////////////////
  86. void Terminate()
  87. {
  88. m_pd3dd = NULL;
  89. }
  90. //////////////////////////////////////////////////////////////////////////////
  91. //
  92. // D3DDevice Methods
  93. //
  94. //////////////////////////////////////////////////////////////////////////////
  95. bool IsHardwareAccelerated()
  96. {
  97. return m_bHardwareAccelerated;
  98. }
  99. PixelFormat* GetTextureFormat()
  100. {
  101. return m_ppfTexture;
  102. }
  103. IDirect3DDeviceX* GetD3DDeviceX()
  104. {
  105. return m_pd3dd;
  106. }
  107. WinPoint GetMinTextureSize()
  108. {
  109. return WinPoint(1, 1);
  110. //return WinPoint(m_pd3ddd->dwMinTextureWidth, m_pd3ddd->dwMinTextureHeight);
  111. }
  112. WinPoint GetMaxTextureSize()
  113. {
  114. // : the 3DFX card doesn't report max texture size correctly
  115. // so return 256 x 256
  116. return WinPoint(256, 256);
  117. //return WinPoint(m_pd3ddd->dwMaxTextureWidth, m_pd3ddd->dwMaxTextureHeight);
  118. }
  119. };
  120. //////////////////////////////////////////////////////////////////////////////
  121. //
  122. // Constructor
  123. //
  124. //////////////////////////////////////////////////////////////////////////////
  125. TRef<D3DDevice> CreateD3DDevice(
  126. DDDevice* pdddevice,
  127. IDirect3DDeviceX* pd3dd,
  128. bool bHardwareAccelerated,
  129. PixelFormat* ppfPrefered
  130. ) {
  131. TRef<D3DDevice> pd3ddevice =
  132. new D3DDeviceImpl(
  133. pdddevice,
  134. pd3dd,
  135. bHardwareAccelerated,
  136. ppfPrefered
  137. );
  138. if (pd3ddevice->IsValid()) {
  139. return pd3ddevice;
  140. } else {
  141. return NULL;
  142. }
  143. }