ww3dformat.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/ww3dformat.h $*
  25. * *
  26. * Original Author:: Nathaniel Hoffman *
  27. * *
  28. * $Author:: Jani_p $*
  29. * *
  30. * $Modtime:: 8/20/01 9:41a $*
  31. * *
  32. * $Revision:: 9 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * Vector4_to_Color - converts a vector4 to the format in format *
  37. * Color_to_Vector4 - converts a color in the format described in format to a Vector4 *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #if defined(_MSC_VER)
  40. #pragma once
  41. #endif
  42. #ifndef WW3DFORMAT_H
  43. #define WW3DFORMAT_H
  44. class Vector4;
  45. class Targa;
  46. /*
  47. ** Enum for possible surface formats. This is a small subset of the D3DFORMAT
  48. ** enum which lists the formats supported by DX8; we will add new members to
  49. ** this list as needed (keeping it in the same order as D3DFORMAT).
  50. ** NOTE: Whenever this is changed, formconv.h/.cpp must be modified as well
  51. ** (that contains the code for converting between this and D3DFORMAT)..
  52. **
  53. ** The format names use the D3DFORMAT conventions:
  54. ** A = Alpha
  55. ** R = Red
  56. ** G = Green
  57. ** B = Blue
  58. ** X = Unused Bits
  59. ** P = Palette
  60. ** L = Luminance
  61. **
  62. ** Further, the order of the pieces are from MSB first; hence
  63. ** WW3D_FORMAT_A8L8 indicates that the high byte of this two byte
  64. ** format is alpha.
  65. */
  66. enum WW3DFormat {
  67. WW3D_FORMAT_UNKNOWN=0,
  68. WW3D_FORMAT_R8G8B8,
  69. WW3D_FORMAT_A8R8G8B8,
  70. WW3D_FORMAT_X8R8G8B8,
  71. WW3D_FORMAT_R5G6B5,
  72. WW3D_FORMAT_X1R5G5B5,
  73. WW3D_FORMAT_A1R5G5B5,
  74. WW3D_FORMAT_A4R4G4B4,
  75. WW3D_FORMAT_R3G3B2,
  76. WW3D_FORMAT_A8,
  77. WW3D_FORMAT_A8R3G3B2,
  78. WW3D_FORMAT_X4R4G4B4,
  79. WW3D_FORMAT_A8P8,
  80. WW3D_FORMAT_P8,
  81. WW3D_FORMAT_L8,
  82. WW3D_FORMAT_A8L8,
  83. WW3D_FORMAT_A4L4,
  84. WW3D_FORMAT_U8V8, // Bumpmap
  85. WW3D_FORMAT_L6V5U5, // Bumpmap
  86. WW3D_FORMAT_X8L8V8U8, // Bumpmap
  87. WW3D_FORMAT_DXT1,
  88. WW3D_FORMAT_DXT2,
  89. WW3D_FORMAT_DXT3,
  90. WW3D_FORMAT_DXT4,
  91. WW3D_FORMAT_DXT5,
  92. WW3D_FORMAT_COUNT // Used only to determine number of surface formats
  93. };
  94. // Utility function - not much used otherwise it would use an array.
  95. // NOTE: when adding values to WW3DFormat add here also (if they have alpha).
  96. inline bool Has_Alpha(WW3DFormat format) {
  97. switch (format) {
  98. case WW3D_FORMAT_A8R8G8B8:
  99. case WW3D_FORMAT_A1R5G5B5:
  100. case WW3D_FORMAT_A4R4G4B4:
  101. case WW3D_FORMAT_A8:
  102. case WW3D_FORMAT_A8R3G3B2:
  103. case WW3D_FORMAT_A8P8:
  104. case WW3D_FORMAT_A8L8:
  105. case WW3D_FORMAT_A4L4:
  106. case WW3D_FORMAT_DXT2:
  107. case WW3D_FORMAT_DXT3:
  108. case WW3D_FORMAT_DXT4:
  109. case WW3D_FORMAT_DXT5:
  110. return true;
  111. break;
  112. default:
  113. return false;
  114. break;
  115. };
  116. }
  117. inline int Alpha_Bits(WW3DFormat format) {
  118. switch (format) {
  119. case WW3D_FORMAT_A8R8G8B8:
  120. case WW3D_FORMAT_A8:
  121. case WW3D_FORMAT_A8R3G3B2:
  122. case WW3D_FORMAT_A8P8:
  123. case WW3D_FORMAT_A8L8:
  124. return 8;
  125. break;
  126. case WW3D_FORMAT_A4R4G4B4:
  127. case WW3D_FORMAT_A4L4:
  128. case WW3D_FORMAT_DXT3:
  129. case WW3D_FORMAT_DXT4:
  130. case WW3D_FORMAT_DXT5:
  131. return 4;
  132. break;
  133. case WW3D_FORMAT_A1R5G5B5:
  134. case WW3D_FORMAT_DXT2:
  135. return 1;
  136. break;
  137. default:
  138. return 0;
  139. break;
  140. };
  141. }
  142. // Color convertion routines
  143. // The color will be returned as an unsigned int always
  144. // any unused bits will be garbage
  145. void Vector4_to_Color(unsigned int *outc,const Vector4 &inc,const WW3DFormat format);
  146. // If the format does not support alpha
  147. // the alpha will be garbage
  148. void Color_to_Vector4(Vector4* outc,const unsigned int inc,const WW3DFormat format);
  149. // Define matching WW3D format based from Targa header.
  150. //
  151. // dest_format - WW3DFormat that can be used as a destination (D3D surface) on current hardware
  152. // src_format - WW3DFormat that represents the format the bitmap is stored in the targa file.
  153. // src_bpp - bytes per pixel in the source surface
  154. // targa - reference to the targa object...
  155. void Get_WW3D_Format(WW3DFormat& dest_format,WW3DFormat& src_format,unsigned& src_bpp,const Targa& targa);
  156. // Get valid texture format (on current hardware) that is closest to the given format (for instance, 32 bit ARGB8888 would
  157. // return 16 bit ARGB4444 if the device doesn't support 32 bit textures).
  158. // Pass false to the second parameter if you don't wish to consider compressed textures on hardware that supports them.
  159. // The parameter has no effect on hardware that doesn't support compression.
  160. WW3DFormat Get_Valid_Texture_Format(WW3DFormat format,bool is_compression_allowed);
  161. unsigned Get_Bytes_Per_Pixel(WW3DFormat format);
  162. #endif