dx8caps.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : dx8 caps *
  23. * *
  24. * $Archive:: /VSS_Sync/ww3d2/dx8caps.cpp $*
  25. * *
  26. * Original Author:: Hector Yee *
  27. * *
  28. * $Author:: Vss_sync $*
  29. * *
  30. * $Modtime:: 8/29/01 8:16p $*
  31. * *
  32. * $Revision:: 11 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "always.h"
  38. #include "dx8caps.h"
  39. #include "dx8wrapper.h"
  40. #include "formconv.h"
  41. D3DCAPS8 DX8Caps::hwVPCaps;
  42. D3DCAPS8 DX8Caps::swVPCaps;
  43. bool DX8Caps::UseTnL;
  44. bool DX8Caps::SupportDOT3;
  45. bool DX8Caps::SupportDXTC;
  46. bool DX8Caps::supportGamma;
  47. bool DX8Caps::SupportNPatches;
  48. bool DX8Caps::SupportBumpEnvmap;
  49. bool DX8Caps::SupportBumpEnvmapLuminance;
  50. bool DX8Caps::SupportTextureFormat[WW3D_FORMAT_COUNT];
  51. int DX8Caps::VertexShaderVersion;
  52. int DX8Caps::PixelShaderVersion;
  53. int DX8Caps::MaxSimultaneousTextures;
  54. enum {
  55. VENDOR_ID_NVIDIA=0x10de,
  56. VENROD_ID_ATI=0x1002
  57. };
  58. // ----------------------------------------------------------------------------
  59. //
  60. // Init the caps structure
  61. //
  62. // ----------------------------------------------------------------------------
  63. void DX8Caps::Init_Caps(IDirect3DDevice8* D3DDevice)
  64. {
  65. D3DDevice->SetRenderState(D3DRS_SOFTWAREVERTEXPROCESSING,TRUE);
  66. DX8CALL(GetDeviceCaps(&swVPCaps));
  67. if ((swVPCaps.DevCaps&D3DDEVCAPS_HWTRANSFORMANDLIGHT)==D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
  68. UseTnL=true;
  69. D3DDevice->SetRenderState(D3DRS_SOFTWAREVERTEXPROCESSING,FALSE);
  70. DX8CALL(GetDeviceCaps(&hwVPCaps));
  71. } else {
  72. UseTnL=false;
  73. }
  74. }
  75. // ----------------------------------------------------------------------------
  76. //
  77. // Compute the caps bits
  78. //
  79. // ----------------------------------------------------------------------------
  80. void DX8Caps::Compute_Caps(D3DFORMAT display_format, D3DFORMAT depth_stencil_format, IDirect3DDevice8* D3DDevice)
  81. {
  82. const D3DADAPTER_IDENTIFIER8& adapter_id=DX8Wrapper::Get_Current_Adapter_Identifier();
  83. Init_Caps(D3DDevice);
  84. const D3DCAPS8& caps=Get_Default_Caps();
  85. if ((caps.DevCaps&D3DDEVCAPS_NPATCHES)==D3DDEVCAPS_NPATCHES) {
  86. SupportNPatches=true;
  87. } else {
  88. SupportNPatches=false;
  89. }
  90. if ((caps.TextureOpCaps&D3DTEXOPCAPS_DOTPRODUCT3)==D3DTEXOPCAPS_DOTPRODUCT3) {
  91. SupportDOT3=true;
  92. } else {
  93. SupportDOT3=false;
  94. }
  95. supportGamma=((swVPCaps.Caps2&D3DCAPS2_FULLSCREENGAMMA)==D3DCAPS2_FULLSCREENGAMMA);
  96. Check_Texture_Format_Support(display_format,caps);
  97. Check_Texture_Compression_Support(caps);
  98. Check_Bumpmap_Support(caps);
  99. Check_Shader_Support(caps);
  100. Check_Maximum_Texture_Support(caps);
  101. Vendor_Specific_Hacks(adapter_id);
  102. }
  103. // ----------------------------------------------------------------------------
  104. //
  105. // Check bump map texture support
  106. //
  107. // ----------------------------------------------------------------------------
  108. void DX8Caps::Check_Bumpmap_Support(const D3DCAPS8& caps)
  109. {
  110. SupportBumpEnvmap=!!(caps.TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAP);
  111. SupportBumpEnvmapLuminance=!!(caps.TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAPLUMINANCE);
  112. }
  113. // ----------------------------------------------------------------------------
  114. //
  115. // Check compressed texture support
  116. //
  117. // ----------------------------------------------------------------------------
  118. void DX8Caps::Check_Texture_Compression_Support(const D3DCAPS8& caps)
  119. {
  120. SupportDXTC=SupportTextureFormat[WW3D_FORMAT_DXT1]|
  121. SupportTextureFormat[WW3D_FORMAT_DXT2]|
  122. SupportTextureFormat[WW3D_FORMAT_DXT3]|
  123. SupportTextureFormat[WW3D_FORMAT_DXT4]|
  124. SupportTextureFormat[WW3D_FORMAT_DXT5];
  125. }
  126. void DX8Caps::Check_Texture_Format_Support(D3DFORMAT display_format,const D3DCAPS8& caps)
  127. {
  128. for (unsigned i=0;i<WW3D_FORMAT_COUNT;++i) {
  129. if (i==WW3D_FORMAT_UNKNOWN) {
  130. SupportTextureFormat[i]=false;
  131. }
  132. else {
  133. SupportTextureFormat[i]=SUCCEEDED(
  134. DX8Wrapper::_Get_D3D8()->CheckDeviceFormat(
  135. caps.AdapterOrdinal,
  136. caps.DeviceType,
  137. display_format,
  138. 0,
  139. D3DRTYPE_TEXTURE,
  140. WW3DFormat_To_D3DFormat((WW3DFormat)i)));
  141. }
  142. }
  143. }
  144. void DX8Caps::Check_Maximum_Texture_Support(const D3DCAPS8& caps)
  145. {
  146. MaxSimultaneousTextures=caps.MaxSimultaneousTextures;
  147. }
  148. void DX8Caps::Check_Shader_Support(const D3DCAPS8& caps)
  149. {
  150. VertexShaderVersion=caps.VertexShaderVersion;
  151. PixelShaderVersion=caps.PixelShaderVersion;
  152. }
  153. // ----------------------------------------------------------------------------
  154. //
  155. // Implement some vendor-specific hacks to fix certain driver bugs that can't be
  156. // avoided otherwise.
  157. //
  158. // ----------------------------------------------------------------------------
  159. void DX8Caps::Vendor_Specific_Hacks(const D3DADAPTER_IDENTIFIER8& adapter_id)
  160. {
  161. if (adapter_id.VendorId==VENDOR_ID_NVIDIA) {
  162. SupportNPatches = false; // Driver incorrectly report N-Patch support
  163. SupportTextureFormat[WW3D_FORMAT_DXT1] = false; // DXT1 is broken on NVidia hardware
  164. SupportDXTC=
  165. SupportTextureFormat[WW3D_FORMAT_DXT1]|
  166. SupportTextureFormat[WW3D_FORMAT_DXT2]|
  167. SupportTextureFormat[WW3D_FORMAT_DXT3]|
  168. SupportTextureFormat[WW3D_FORMAT_DXT4]|
  169. SupportTextureFormat[WW3D_FORMAT_DXT5];
  170. }
  171. // SupportDXTC=false;
  172. }