formconv.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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 : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/formconv.cpp $*
  25. * *
  26. * Original Author:: Nathaniel Hoffman *
  27. * *
  28. * Author : Kenny Mitchell *
  29. * *
  30. * $Modtime:: 06/27/02 1:27p $*
  31. * *
  32. * $Revision:: 3 $*
  33. * *
  34. * 06/27/02 KM Z Format support *
  35. *---------------------------------------------------------------------------------------------*
  36. * Functions: *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #include "formconv.h"
  39. D3DFORMAT WW3DFormatToD3DFormatConversionArray[WW3D_FORMAT_COUNT] = {
  40. D3DFMT_UNKNOWN,
  41. D3DFMT_R8G8B8,
  42. D3DFMT_A8R8G8B8,
  43. D3DFMT_X8R8G8B8,
  44. D3DFMT_R5G6B5,
  45. D3DFMT_X1R5G5B5,
  46. D3DFMT_A1R5G5B5,
  47. D3DFMT_A4R4G4B4,
  48. D3DFMT_R3G3B2,
  49. D3DFMT_A8,
  50. D3DFMT_A8R3G3B2,
  51. D3DFMT_X4R4G4B4,
  52. D3DFMT_A8P8,
  53. D3DFMT_P8,
  54. D3DFMT_L8,
  55. D3DFMT_A8L8,
  56. D3DFMT_A4L4,
  57. D3DFMT_V8U8, // Bumpmap
  58. D3DFMT_L6V5U5, // Bumpmap
  59. D3DFMT_X8L8V8U8, // Bumpmap
  60. D3DFMT_DXT1,
  61. D3DFMT_DXT2,
  62. D3DFMT_DXT3,
  63. D3DFMT_DXT4,
  64. D3DFMT_DXT5
  65. };
  66. // adding depth stencil format conversion
  67. D3DFORMAT WW3DZFormatToD3DFormatConversionArray[WW3D_ZFORMAT_COUNT] =
  68. {
  69. #ifndef _XBOX
  70. D3DFMT_UNKNOWN,
  71. D3DFMT_D16_LOCKABLE, // 16-bit z-buffer bit depth. This is an application-lockable surface format.
  72. D3DFMT_D32, // 32-bit z-buffer bit depth.
  73. D3DFMT_D15S1, // 16-bit z-buffer bit depth where 15 bits are reserved for the depth channel and 1 bit is reserved for the stencil channel.
  74. D3DFMT_D24S8, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel.
  75. D3DFMT_D16, // 16-bit z-buffer bit depth.
  76. D3DFMT_D24X8, // 32-bit z-buffer bit depth using 24 bits for the depth channel.
  77. D3DFMT_D24X4S4, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel.
  78. #else
  79. D3DFMT_UNKNOWN,
  80. D3DFMT_D16_LOCKABLE, // 16-bit z-buffer bit depth. This is an application-lockable surface format.
  81. D3DFMT_D32, // 32-bit z-buffer bit depth.
  82. D3DFMT_D15S1, // 16-bit z-buffer bit depth where 15 bits are reserved for the depth channel and 1 bit is reserved for the stencil channel.
  83. D3DFMT_D24S8, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel.
  84. D3DFMT_D16, // 16-bit z-buffer bit depth.
  85. D3DFMT_D24X8, // 32-bit z-buffer bit depth using 24 bits for the depth channel.
  86. D3DFMT_D24X4S4, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel.
  87. D3DFMT_LIN_D24S8,
  88. D3DFMT_LIN_F24S8,
  89. D3DFMT_LIN_D16,
  90. D3DFMT_LIN_F16
  91. #endif
  92. };
  93. /*
  94. #define HIGHEST_SUPPORTED_D3DFORMAT D3DFMT_X8L8V8U8 //A4L4
  95. WW3DFormat D3DFormatToWW3DFormatConversionArray[HIGHEST_SUPPORTED_D3DFORMAT + 1] = {
  96. WW3D_FORMAT_UNKNOWN, // 0
  97. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  98. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  99. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  100. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  101. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  102. WW3D_FORMAT_R8G8B8, // 20
  103. WW3D_FORMAT_A8R8G8B8,
  104. WW3D_FORMAT_X8R8G8B8,
  105. WW3D_FORMAT_R5G6B5,
  106. WW3D_FORMAT_X1R5G5B5,
  107. WW3D_FORMAT_A1R5G5B5,
  108. WW3D_FORMAT_A4R4G4B4,
  109. WW3D_FORMAT_R3G3B2,
  110. WW3D_FORMAT_A8,
  111. WW3D_FORMAT_A8R3G3B2,
  112. WW3D_FORMAT_X4R4G4B4, // 30
  113. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  114. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  115. WW3D_FORMAT_UNKNOWN,
  116. WW3D_FORMAT_A8P8, // 40
  117. WW3D_FORMAT_P8,
  118. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  119. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  120. WW3D_FORMAT_L8, // 50
  121. WW3D_FORMAT_A8L8,
  122. WW3D_FORMAT_A4L4
  123. };
  124. */
  125. #ifndef _XBOX
  126. #define HIGHEST_SUPPORTED_D3DFORMAT D3DFMT_X8L8V8U8
  127. #define HIGHEST_SUPPORTED_D3DZFORMAT D3DFMT_D24X4S4
  128. #else
  129. #define HIGHEST_SUPPORTED_D3DFORMAT D3DFMT_LIN_R8G8B8A8
  130. #define HIGHEST_SUPPORTED_D3DZFORMAT D3DFMT_LIN_F16
  131. #endif
  132. WW3DFormat D3DFormatToWW3DFormatConversionArray[HIGHEST_SUPPORTED_D3DFORMAT + 1];
  133. WW3DZFormat D3DFormatToWW3DZFormatConversionArray[HIGHEST_SUPPORTED_D3DZFORMAT + 1];
  134. D3DFORMAT WW3DFormat_To_D3DFormat(WW3DFormat ww3d_format) {
  135. if (ww3d_format >= WW3D_FORMAT_COUNT) {
  136. return D3DFMT_UNKNOWN;
  137. } else {
  138. return WW3DFormatToD3DFormatConversionArray[(unsigned int)ww3d_format];
  139. }
  140. }
  141. WW3DFormat D3DFormat_To_WW3DFormat(D3DFORMAT d3d_format)
  142. {
  143. switch (d3d_format) {
  144. // The DXT-codes are created with FOURCC macro and thus can't be placed in the conversion table
  145. case D3DFMT_DXT1: return WW3D_FORMAT_DXT1;
  146. case D3DFMT_DXT2: return WW3D_FORMAT_DXT2;
  147. case D3DFMT_DXT3: return WW3D_FORMAT_DXT3;
  148. case D3DFMT_DXT4: return WW3D_FORMAT_DXT4;
  149. case D3DFMT_DXT5: return WW3D_FORMAT_DXT5;
  150. default:
  151. if (d3d_format > HIGHEST_SUPPORTED_D3DFORMAT) {
  152. return WW3D_FORMAT_UNKNOWN;
  153. } else {
  154. return D3DFormatToWW3DFormatConversionArray[(unsigned int)d3d_format];
  155. }
  156. break;
  157. }
  158. }
  159. //**********************************************************************************************
  160. //! Depth Stencil W3D to D3D format conversion
  161. /*! KJM
  162. */
  163. D3DFORMAT WW3DZFormat_To_D3DFormat(WW3DZFormat ww3d_zformat)
  164. {
  165. if (ww3d_zformat >= WW3D_ZFORMAT_COUNT)
  166. {
  167. return D3DFMT_UNKNOWN;
  168. }
  169. else
  170. {
  171. return WW3DZFormatToD3DFormatConversionArray[(unsigned int)ww3d_zformat];
  172. }
  173. }
  174. //**********************************************************************************************
  175. //! D3D to Depth Stencil W3D format conversion
  176. /*! KJM
  177. */
  178. WW3DZFormat D3DFormat_To_WW3DZFormat(D3DFORMAT d3d_format)
  179. {
  180. if (d3d_format>HIGHEST_SUPPORTED_D3DZFORMAT)
  181. {
  182. return WW3D_ZFORMAT_UNKNOWN;
  183. }
  184. else
  185. {
  186. return D3DFormatToWW3DZFormatConversionArray[(unsigned int)d3d_format];
  187. }
  188. }
  189. //**********************************************************************************************
  190. //! Init format conversion tables
  191. /*!
  192. * 06/27/02 KM Z Format support *
  193. */
  194. void Init_D3D_To_WW3_Conversion()
  195. {
  196. for (int i=0;i<HIGHEST_SUPPORTED_D3DFORMAT;++i) {
  197. D3DFormatToWW3DFormatConversionArray[i]=WW3D_FORMAT_UNKNOWN;
  198. }
  199. D3DFormatToWW3DFormatConversionArray[D3DFMT_R8G8B8]=WW3D_FORMAT_R8G8B8;
  200. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8R8G8B8]=WW3D_FORMAT_A8R8G8B8;
  201. D3DFormatToWW3DFormatConversionArray[D3DFMT_X8R8G8B8]=WW3D_FORMAT_X8R8G8B8;
  202. D3DFormatToWW3DFormatConversionArray[D3DFMT_R5G6B5]=WW3D_FORMAT_R5G6B5;
  203. D3DFormatToWW3DFormatConversionArray[D3DFMT_X1R5G5B5]=WW3D_FORMAT_X1R5G5B5;
  204. D3DFormatToWW3DFormatConversionArray[D3DFMT_A1R5G5B5]=WW3D_FORMAT_A1R5G5B5;
  205. D3DFormatToWW3DFormatConversionArray[D3DFMT_A4R4G4B4]=WW3D_FORMAT_A4R4G4B4;
  206. D3DFormatToWW3DFormatConversionArray[D3DFMT_R3G3B2]=WW3D_FORMAT_R3G3B2;
  207. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8]=WW3D_FORMAT_A8;
  208. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8R3G3B2]=WW3D_FORMAT_A8R3G3B2;
  209. D3DFormatToWW3DFormatConversionArray[D3DFMT_X4R4G4B4]=WW3D_FORMAT_X4R4G4B4;
  210. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8P8]=WW3D_FORMAT_A8P8;
  211. D3DFormatToWW3DFormatConversionArray[D3DFMT_P8]=WW3D_FORMAT_P8;
  212. D3DFormatToWW3DFormatConversionArray[D3DFMT_L8]=WW3D_FORMAT_L8;
  213. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8L8]=WW3D_FORMAT_A8L8;
  214. D3DFormatToWW3DFormatConversionArray[D3DFMT_A4L4]=WW3D_FORMAT_A4L4;
  215. D3DFormatToWW3DFormatConversionArray[D3DFMT_V8U8]=WW3D_FORMAT_U8V8; // Bumpmap
  216. D3DFormatToWW3DFormatConversionArray[D3DFMT_L6V5U5]=WW3D_FORMAT_L6V5U5; // Bumpmap
  217. D3DFormatToWW3DFormatConversionArray[D3DFMT_X8L8V8U8]=WW3D_FORMAT_X8L8V8U8; // Bumpmap
  218. // init depth stencil conversion
  219. for (i=0; i<HIGHEST_SUPPORTED_D3DZFORMAT; i++)
  220. {
  221. D3DFormatToWW3DZFormatConversionArray[i]=WW3D_ZFORMAT_UNKNOWN;
  222. }
  223. D3DFormatToWW3DZFormatConversionArray[D3DFMT_D16_LOCKABLE]=WW3D_ZFORMAT_D16_LOCKABLE;
  224. D3DFormatToWW3DZFormatConversionArray[D3DFMT_D32]=WW3D_ZFORMAT_D32;
  225. D3DFormatToWW3DZFormatConversionArray[D3DFMT_D15S1]=WW3D_ZFORMAT_D15S1;
  226. D3DFormatToWW3DZFormatConversionArray[D3DFMT_D24S8]=WW3D_ZFORMAT_D24S8;
  227. D3DFormatToWW3DZFormatConversionArray[D3DFMT_D16]=WW3D_ZFORMAT_D16;
  228. D3DFormatToWW3DZFormatConversionArray[D3DFMT_D24X8]=WW3D_ZFORMAT_D24X8;
  229. D3DFormatToWW3DZFormatConversionArray[D3DFMT_D24X4S4]=WW3D_ZFORMAT_D24X4S4;
  230. #ifdef _XBOX
  231. D3DFormatToWW3DZFormatConversionArray[D3DFMT_LIN_D24S8]=WW3D_ZFORMAT_LIN_D24S8;
  232. D3DFormatToWW3DZFormatConversionArray[D3DFMT_LIN_F24S8]=WW3D_ZFORMAT_LIN_F24S8;
  233. D3DFormatToWW3DZFormatConversionArray[D3DFMT_LIN_D16]=WW3D_ZFORMAT_LIN_D16;
  234. D3DFormatToWW3DZFormatConversionArray[D3DFMT_LIN_F16]=WW3D_ZFORMAT_LIN_F16;
  235. #endif
  236. };