ww3dformat.h 6.8 KB

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