formconv.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. ** Command & Conquer Renegade(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:: Jani_p $*
  29. * *
  30. * $Modtime:: 7/16/01 1:33p $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "formconv.h"
  38. D3DFORMAT WW3DFormatToD3DFormatConversionArray[WW3D_FORMAT_COUNT] = {
  39. D3DFMT_UNKNOWN,
  40. D3DFMT_R8G8B8,
  41. D3DFMT_A8R8G8B8,
  42. D3DFMT_X8R8G8B8,
  43. D3DFMT_R5G6B5,
  44. D3DFMT_X1R5G5B5,
  45. D3DFMT_A1R5G5B5,
  46. D3DFMT_A4R4G4B4,
  47. D3DFMT_R3G3B2,
  48. D3DFMT_A8,
  49. D3DFMT_A8R3G3B2,
  50. D3DFMT_X4R4G4B4,
  51. D3DFMT_A8P8,
  52. D3DFMT_P8,
  53. D3DFMT_L8,
  54. D3DFMT_A8L8,
  55. D3DFMT_A4L4,
  56. D3DFMT_V8U8, // Bumpmap
  57. D3DFMT_L6V5U5, // Bumpmap
  58. D3DFMT_X8L8V8U8, // Bumpmap
  59. D3DFMT_DXT1,
  60. D3DFMT_DXT2,
  61. D3DFMT_DXT3,
  62. D3DFMT_DXT4,
  63. D3DFMT_DXT5
  64. };
  65. /*
  66. #define HIGHEST_SUPPORTED_D3DFORMAT D3DFMT_X8L8V8U8 //A4L4
  67. WW3DFormat D3DFormatToWW3DFormatConversionArray[HIGHEST_SUPPORTED_D3DFORMAT + 1] = {
  68. WW3D_FORMAT_UNKNOWN, // 0
  69. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  70. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  71. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  72. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  73. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  74. WW3D_FORMAT_R8G8B8, // 20
  75. WW3D_FORMAT_A8R8G8B8,
  76. WW3D_FORMAT_X8R8G8B8,
  77. WW3D_FORMAT_R5G6B5,
  78. WW3D_FORMAT_X1R5G5B5,
  79. WW3D_FORMAT_A1R5G5B5,
  80. WW3D_FORMAT_A4R4G4B4,
  81. WW3D_FORMAT_R3G3B2,
  82. WW3D_FORMAT_A8,
  83. WW3D_FORMAT_A8R3G3B2,
  84. WW3D_FORMAT_X4R4G4B4, // 30
  85. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  86. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  87. WW3D_FORMAT_UNKNOWN,
  88. WW3D_FORMAT_A8P8, // 40
  89. WW3D_FORMAT_P8,
  90. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  91. WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
  92. WW3D_FORMAT_L8, // 50
  93. WW3D_FORMAT_A8L8,
  94. WW3D_FORMAT_A4L4
  95. };
  96. */
  97. #define HIGHEST_SUPPORTED_D3DFORMAT D3DFMT_X8L8V8U8
  98. WW3DFormat D3DFormatToWW3DFormatConversionArray[HIGHEST_SUPPORTED_D3DFORMAT + 1];
  99. D3DFORMAT WW3DFormat_To_D3DFormat(WW3DFormat ww3d_format) {
  100. if (ww3d_format >= WW3D_FORMAT_COUNT) {
  101. return D3DFMT_UNKNOWN;
  102. } else {
  103. return WW3DFormatToD3DFormatConversionArray[(unsigned int)ww3d_format];
  104. }
  105. }
  106. WW3DFormat D3DFormat_To_WW3DFormat(D3DFORMAT d3d_format)
  107. {
  108. switch (d3d_format) {
  109. // The DXT-codes are created with FOURCC macro and thus can't be placed in the conversion table
  110. case D3DFMT_DXT1: return WW3D_FORMAT_DXT1;
  111. case D3DFMT_DXT2: return WW3D_FORMAT_DXT2;
  112. case D3DFMT_DXT3: return WW3D_FORMAT_DXT3;
  113. case D3DFMT_DXT4: return WW3D_FORMAT_DXT4;
  114. case D3DFMT_DXT5: return WW3D_FORMAT_DXT5;
  115. default:
  116. if (d3d_format > HIGHEST_SUPPORTED_D3DFORMAT) {
  117. return WW3D_FORMAT_UNKNOWN;
  118. } else {
  119. return D3DFormatToWW3DFormatConversionArray[(unsigned int)d3d_format];
  120. }
  121. break;
  122. }
  123. }
  124. void Init_D3D_To_WW3_Conversion()
  125. {
  126. for (int i=0;i<HIGHEST_SUPPORTED_D3DFORMAT;++i) {
  127. D3DFormatToWW3DFormatConversionArray[i]=WW3D_FORMAT_UNKNOWN;
  128. }
  129. D3DFormatToWW3DFormatConversionArray[D3DFMT_R8G8B8]=WW3D_FORMAT_R8G8B8;
  130. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8R8G8B8]=WW3D_FORMAT_A8R8G8B8;
  131. D3DFormatToWW3DFormatConversionArray[D3DFMT_X8R8G8B8]=WW3D_FORMAT_X8R8G8B8;
  132. D3DFormatToWW3DFormatConversionArray[D3DFMT_R5G6B5]=WW3D_FORMAT_R5G6B5;
  133. D3DFormatToWW3DFormatConversionArray[D3DFMT_X1R5G5B5]=WW3D_FORMAT_X1R5G5B5;
  134. D3DFormatToWW3DFormatConversionArray[D3DFMT_A1R5G5B5]=WW3D_FORMAT_A1R5G5B5;
  135. D3DFormatToWW3DFormatConversionArray[D3DFMT_A4R4G4B4]=WW3D_FORMAT_A4R4G4B4;
  136. D3DFormatToWW3DFormatConversionArray[D3DFMT_R3G3B2]=WW3D_FORMAT_R3G3B2;
  137. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8]=WW3D_FORMAT_A8;
  138. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8R3G3B2]=WW3D_FORMAT_A8R3G3B2;
  139. D3DFormatToWW3DFormatConversionArray[D3DFMT_X4R4G4B4]=WW3D_FORMAT_X4R4G4B4;
  140. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8P8]=WW3D_FORMAT_A8P8;
  141. D3DFormatToWW3DFormatConversionArray[D3DFMT_P8]=WW3D_FORMAT_P8;
  142. D3DFormatToWW3DFormatConversionArray[D3DFMT_L8]=WW3D_FORMAT_L8;
  143. D3DFormatToWW3DFormatConversionArray[D3DFMT_A8L8]=WW3D_FORMAT_A8L8;
  144. D3DFormatToWW3DFormatConversionArray[D3DFMT_A4L4]=WW3D_FORMAT_A4L4;
  145. D3DFormatToWW3DFormatConversionArray[D3DFMT_V8U8]=WW3D_FORMAT_U8V8; // Bumpmap
  146. D3DFormatToWW3DFormatConversionArray[D3DFMT_L6V5U5]=WW3D_FORMAT_L6V5U5; // Bumpmap
  147. D3DFormatToWW3DFormatConversionArray[D3DFMT_X8L8V8U8]=WW3D_FORMAT_X8L8V8U8; // Bumpmap
  148. };